Various nonsense error messages with assert_eq on windows
Hi guys,
Apologies if this is a dupe, I searched but couldn't find anything. Big GUI project here and have been playing around with using cranelift to improve compile times. When running my tests on windows, any failing assert_eq!() will trigger nonsensical error messages as opposed to the correct error message about a failing assertion. Minimal example:
fn main() {
println!("Hello, world!");
}
#[cfg(test)]
mod tests {
#[test]
fn test_panics() {
assert_eq!(4, 5, "not equal");
}
}
cargo.toml:
cargo-features = ["codegen-backend"]
[package]
name = "panic_test"
version = "0.1.0"
edition = "2021"
[profile.dev]
codegen-backend = "cranelift"
[dependencies]
Error message when using cranelift:
C:\Users\tbeckley...\Documents\code\panic_test>cargo test Finished
testprofile [unoptimized + debuginfo] target(s) in 0.05s Running unittests src/main.rs (target\debug\deps\panic_test-58a397beba7a73c1.exe)running 1 test error: test failed, to rerun pass
--bin panic_testCaused by: process didn't exit successfully:
C:\Users\tbeckley\...\Documents\code\panic_test\target\debug\deps\panic_test-58a397beba7a73c1.exe(exit code: 0xe06d7363)
note: test exited abnormally; to see the full output pass --nocapture to the harness.
And without cranelift:
C:\Users\tbeckley...\Documents\code\panic_test>cargo test
Compiling panic_test v0.1.0 (C:\Users\tbeckley...\Documents\code\panic_test) Finishedtestprofile [unoptimized + debuginfo] target(s) in 0.36s Running unittests src/main.rs (target\debug\deps\panic_test-36ac1adaeb9d3e34.exe)running 1 test test tests::test_panics ... FAILED
failures:
---- tests::test_panics stdout ---- thread 'tests::test_panics' panicked at src/main.rs:9:9: assertion
left == rightfailed: not equal left: 4 right: 5 note: run withRUST_BACKTRACE=1environment variable to display a backtracefailures: tests::test_panics
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
error: test failed, to rerun pass
--bin panic_test
I've also seen errors for memory access violation and stack overflows.
Result of rustup show:
Default host: x86_64-pc-windows-msvc
rustup home: C:\Users\tbeckley\.rustup
installed toolchains
--------------------
stable-x86_64-pc-windows-msvc (default)
nightly-x86_64-pc-windows-msvc
active toolchain
----------------
nightly-x86_64-pc-windows-msvc (overridden by 'C:\Users\tbeckley\...\Documents\code\panic_test\rust-toolchain.toml')
rustc 1.83.0-nightly (c52c23b6f 2024-09-16)
Unwinding on panics isn't supported yet. Because of this libtest is unable to catch the test failure and show the test result it saved. Instead the process is aborted. Try using RUSTFLAGS="-Cpanic=abort -Zpanic-abort-tests" which will make libtest handle panic=abort correctly by running each test in a new subprocess. Be aware however that spawning processes is relatively slow on Windows.
That works perfectly! Sorry for the dumb question and thank you for the quick response! I hadn't actually considered that the test fail causes a panic...