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

Tests using resume_unwind fail with -Cpanic=abort and -Zpanic_abort_tests #74301

Closed
davidhewitt opened this issue Jul 13, 2020 · 5 comments
Closed
Labels
A-libtest Area: #[test] related C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way.

Comments

@davidhewitt
Copy link
Contributor

I tried this test code with RUSTFLAGS="-Cpanic=abort -Zpanic_abort_tests":

    #[test]
    #[should_panic(expected = "new panic")]
    fn resume_unwind_panics() {
        std::panic::resume_unwind(Box::new("new panic"));
    }

I expected to see this happen: The test result should be "ok".

Instead, this happened: The test fails:

failures:

---- err::tests::resume_unwind_panics stdout ----
---- err::tests::resume_unwind_panics stderr ----
Unexpected error: child process exited with signal 6

Meta

rustc --version --verbose:

rustc 1.46.0-nightly (daecab3a7 2020-07-10)
binary: rustc
commit-hash: daecab3a784f28082df90cebb204998051f3557d
commit-date: 2020-07-10
host: x86_64-unknown-linux-gnu
release: 1.46.0-nightly
LLVM version: 10.0

@davidhewitt davidhewitt added the C-bug Category: This is a bug. label Jul 13, 2020
@jonas-schievink jonas-schievink added A-libtest Area: #[test] related requires-nightly This issue requires a nightly compiler in some way. labels Jul 13, 2020
@davidhewitt
Copy link
Contributor Author

I'd be happy to write a patch to resolve this, but I'd need some guidance first as to what a solution might entail. (cc @tmandry ?)

@tmandry
Copy link
Member

tmandry commented Jul 14, 2020

I don't think this is a bug, with the testing machinery at least. The same thing happens when this code is run outside a test in a binary with -Cpanic=abort: the process aborts (signal 6) with no information printed.

resume_unwind doesn't necessarily translate to panic when panic=abort, and there's no way to unwind. That said, a friendlier error message would be nice.

@davidhewitt
Copy link
Contributor Author

I don't think this is a bug, with the testing machinery at least.

That's a reasonable argument. That said, a test suite running with panic=abort can fail despite running fine with panic=unwind, so it would be desirable to have a way to resolve it.

Perhaps a #[cfg(not(panic="abort"))] attribute would be a reasonable way to just remove problematic tests like this?

@tmandry
Copy link
Member

tmandry commented Jul 15, 2020

panic=abort changes the semantics of your program, so that's expected in some cases.

I think that'd be reasonable, but as far as I know there isn't a conditional compilation flag for panic behavior (I believe there's an issue for this floating around somewhere). In Fuchsia we manually added a --cfg flag for it to our build. I'd support an effort to add a standard one.

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Nov 9, 2020
…orse

Add `#[cfg(panic = '...')]`

This PR adds conditional compilation according to the panic strategy.

I've come across a need for a flag like this a couple of times while writing tests: rust-lang#74301 , rust-lang#73670 (comment)

I'm not sure if I need to add a feature gate for this flag?
@Enselic
Copy link
Member

Enselic commented Dec 12, 2023

Triage: Looks like this was resolved with #74754? I'll go ahead and close. Please re-open if I am mistaken.

@Enselic Enselic closed this as completed Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-libtest Area: #[test] related C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way.
Projects
Development

No branches or pull requests

4 participants