From f7c2a58d236bf23819139930bf1e469a47e08140 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 2 Mar 2020 11:43:47 -0600 Subject: [PATCH] Disable caches in CLI tests (#1204) Avoids creating extraneous directories while testing in your home directory. Closes #1197 --- tests/cli_tests.rs | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/tests/cli_tests.rs b/tests/cli_tests.rs index f2b194a647..3387158d56 100644 --- a/tests/cli_tests.rs +++ b/tests/cli_tests.rs @@ -1,24 +1,23 @@ use anyhow::{bail, Result}; -use std::env; use std::io::Write; use std::path::Path; -use std::process::{Command, Stdio}; +use std::process::Command; use tempfile::NamedTempFile; -fn run_wasmtime(args: &[&str]) -> Result<()> { - let cargo = env::var("CARGO").unwrap_or("cargo".to_string()); - let pkg_dir = env!("CARGO_MANIFEST_DIR"); - let success = Command::new(cargo) - .current_dir(pkg_dir) - .stdout(Stdio::null()) - .args(&["run", "-q", "--"]) - .args(args) - .status()? - .success(); - if !success { - bail!("Failed to execute wasmtime with: {:?}", args); +fn run_wasmtime(args: &[&str]) -> Result { + let mut me = std::env::current_exe()?; + me.pop(); // chop off the file name + me.pop(); // chop off `deps` + me.push("wasmtime"); + let output = Command::new(&me).args(args).output()?; + if !output.status.success() { + bail!( + "Failed to execute wasmtime with: {:?}\n{}", + args, + String::from_utf8_lossy(&output.stderr) + ); } - Ok(()) + Ok(String::from_utf8(output.stdout).unwrap()) } fn build_wasm(wat_path: impl AsRef) -> Result { @@ -37,8 +36,10 @@ fn run_wasmtime_simple() -> Result<()> { wasm.path().to_str().unwrap(), "--invoke", "simple", + "--disable-cache", "4", - ]) + ])?; + Ok(()) } // Wasmtime shakk when not enough arguments were provided. @@ -46,7 +47,14 @@ fn run_wasmtime_simple() -> Result<()> { fn run_wasmtime_simple_fail_no_args() -> Result<()> { let wasm = build_wasm("tests/wasm/simple.wat")?; assert!( - run_wasmtime(&["run", wasm.path().to_str().unwrap(), "--invoke", "simple"]).is_err(), + run_wasmtime(&[ + "run", + wasm.path().to_str().unwrap(), + "--disable-cache", + "--invoke", + "simple", + ]) + .is_err(), "shall fail" ); Ok(()) @@ -61,6 +69,8 @@ fn run_wasmtime_simple_wat() -> Result<()> { wasm.path().to_str().unwrap(), "--invoke", "simple", + "--disable-cache", "4", - ]) + ])?; + Ok(()) }