Disable caches in CLI tests (#1204)

Avoids creating extraneous directories while testing in your home
directory.

Closes #1197
This commit is contained in:
Alex Crichton
2020-03-02 11:43:47 -06:00
committed by GitHub
parent fe9debfed3
commit f7c2a58d23

View File

@@ -1,24 +1,23 @@
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use std::env;
use std::io::Write; use std::io::Write;
use std::path::Path; use std::path::Path;
use std::process::{Command, Stdio}; use std::process::Command;
use tempfile::NamedTempFile; use tempfile::NamedTempFile;
fn run_wasmtime(args: &[&str]) -> Result<()> { fn run_wasmtime(args: &[&str]) -> Result<String> {
let cargo = env::var("CARGO").unwrap_or("cargo".to_string()); let mut me = std::env::current_exe()?;
let pkg_dir = env!("CARGO_MANIFEST_DIR"); me.pop(); // chop off the file name
let success = Command::new(cargo) me.pop(); // chop off `deps`
.current_dir(pkg_dir) me.push("wasmtime");
.stdout(Stdio::null()) let output = Command::new(&me).args(args).output()?;
.args(&["run", "-q", "--"]) if !output.status.success() {
.args(args) bail!(
.status()? "Failed to execute wasmtime with: {:?}\n{}",
.success(); args,
if !success { String::from_utf8_lossy(&output.stderr)
bail!("Failed to execute wasmtime with: {:?}", args); );
} }
Ok(()) Ok(String::from_utf8(output.stdout).unwrap())
} }
fn build_wasm(wat_path: impl AsRef<Path>) -> Result<NamedTempFile> { fn build_wasm(wat_path: impl AsRef<Path>) -> Result<NamedTempFile> {
@@ -37,8 +36,10 @@ fn run_wasmtime_simple() -> Result<()> {
wasm.path().to_str().unwrap(), wasm.path().to_str().unwrap(),
"--invoke", "--invoke",
"simple", "simple",
"--disable-cache",
"4", "4",
]) ])?;
Ok(())
} }
// Wasmtime shakk when not enough arguments were provided. // 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<()> { fn run_wasmtime_simple_fail_no_args() -> Result<()> {
let wasm = build_wasm("tests/wasm/simple.wat")?; let wasm = build_wasm("tests/wasm/simple.wat")?;
assert!( 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" "shall fail"
); );
Ok(()) Ok(())
@@ -61,6 +69,8 @@ fn run_wasmtime_simple_wat() -> Result<()> {
wasm.path().to_str().unwrap(), wasm.path().to_str().unwrap(),
"--invoke", "--invoke",
"simple", "simple",
"--disable-cache",
"4", "4",
]) ])?;
Ok(())
} }