From eb3837b47c01dd3aacbd8ad7237b6dd247772cdf Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 1 May 2020 16:49:45 -0700 Subject: [PATCH] Fix exit-status tests on Windows. --- src/commands/run.rs | 9 +++++---- tests/all/cli_tests.rs | 12 ++++++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/commands/run.rs b/src/commands/run.rs index 123669c6697d..1e94cc08a899 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -146,11 +146,12 @@ impl RunCommand { // a message and exit. if let Some(exit) = e.downcast_ref::() { eprintln!("Error: {}", exit); - if cfg!(unix) { - // On Unix, if it's a normal exit status, return it. - process::exit(exit.status().get()); + // On Windows, exit status 3 indicates an abort (see below), + // so just return 1 indicating a non-zero status. + if cfg!(windows) { + process::exit(1); } - process::exit(1); + process::exit(exit.status().get()); } // If the program exited because of a trap, return an error code diff --git a/tests/all/cli_tests.rs b/tests/all/cli_tests.rs index b56387f11e84..94e3597516df 100644 --- a/tests/all/cli_tests.rs +++ b/tests/all/cli_tests.rs @@ -189,7 +189,11 @@ fn timeout_in_invoke() -> Result<()> { fn exit125_wasi_snapshot0() -> Result<()> { let wasm = build_wasm("tests/wasm/exit125_wasi_snapshot0.wat")?; let output = run_wasmtime_for_output(&[wasm.path().to_str().unwrap(), "--disable-cache"])?; - assert_eq!(output.status.code().unwrap(), 125); + if cfg!(windows) { + assert_eq!(output.status.code().unwrap(), 1); + } else { + assert_eq!(output.status.code().unwrap(), 125); + } Ok(()) } @@ -198,7 +202,11 @@ fn exit125_wasi_snapshot0() -> Result<()> { fn exit125_wasi_snapshot1() -> Result<()> { let wasm = build_wasm("tests/wasm/exit125_wasi_snapshot1.wat")?; let output = run_wasmtime_for_output(&[wasm.path().to_str().unwrap(), "--disable-cache"])?; - assert_eq!(output.status.code().unwrap(), 125); + if cfg!(windows) { + assert_eq!(output.status.code().unwrap(), 1); + } else { + assert_eq!(output.status.code().unwrap(), 125); + } Ok(()) }