Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various nonsense error messages with assert_eq on windows #1532

Open
tbeckley opened this issue Sep 17, 2024 · 2 comments
Open

Various nonsense error messages with assert_eq on windows #1532

tbeckley opened this issue Sep 17, 2024 · 2 comments
Labels
A-unwind Area: Unwinding

Comments

@tbeckley
Copy link

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 test profile [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_test

Caused 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)
Finished test profile [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 == right failed: not equal
left: 4
right: 5
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

failures:
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)
@bjorn3
Copy link
Member

bjorn3 commented Sep 17, 2024

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.

@bjorn3 bjorn3 added the A-unwind Area: Unwinding label Sep 17, 2024
@tbeckley
Copy link
Author

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-unwind Area: Unwinding
Projects
None yet
Development

No branches or pull requests

2 participants