Skip to content

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

@davidhewitt

Description

@davidhewitt
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

Activity

added
A-libtestArea: `#[test]` / the `test` library
requires-nightlyThis issue requires a nightly compiler in some way.
on Jul 13, 2020
davidhewitt

davidhewitt commented on Jul 13, 2020

@davidhewitt
ContributorAuthor

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

tmandry commented on Jul 14, 2020

@tmandry
Member

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

davidhewitt commented on Jul 14, 2020

@davidhewitt
ContributorAuthor

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

tmandry commented on Jul 15, 2020

@tmandry
Member

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.

added a commit that references this issue on Nov 9, 2020
46bce9f
Enselic

Enselic commented on Dec 12, 2023

@Enselic
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-libtestArea: `#[test]` / the `test` libraryC-bugCategory: This is a bug.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Enselic@jonas-schievink@davidhewitt@tmandry

        Issue actions

          Tests using resume_unwind fail with -Cpanic=abort and -Zpanic_abort_tests · Issue #74301 · rust-lang/rust