-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Support death tests in libtest #32512
Comments
In #43788 I had two possible solutions to the panic=abort problem, although only the former solves the "death test" problem
|
I think we definitively should address the "death test" problem – there are a lot of situations where programs call About the performance: wouldn't it be possible to limit the re-execution to "death tests" or |
It's pretty easy to write your own |
I'm working on a change to libtest that will implement the first of @alexcrichton's solutions above, specifically to support panic=abort. It should be pretty easy to extend to allow proper death tests, though. So far I have a working prototype that's around 150 lines of implementation code. My intention is to make it "opt-in," so you have to either compile with a special flag or supply an argument on the command line. (Not sure how I'm going to go about this yet. Ideally for me, we can supply an option while building libtest to enable this for all tests, because we want panic=abort in our whole build.) cc @rust-lang/libs, WDYT? Would this be a welcome addition to libtest? |
I would personally at least welcome a change to libtest to support |
I agree that this would be ideal. Any suggestions on how to do it? The best way I can think of off the top of my head is choosing a mode at the time of building libtest. I'm not sure how to detect that a specific binary is linked as panic=abort. |
Choosing when libtest is built is possible but probably not gonna work out well because we ship a prebuilt libtest which is always compiled as panic=unwind. I think though that |
The Currently, the compiler selects libtest's |
I think for |
I would like to be able to mark a test as a death test of some kind, like, running this code should trigger an
abort
(instead of just an unwind), anexit
with a particular exit code, or anassert
(in caseassert
doesn't unwind if, e.g.panic=abort
).This requires two fundamental ingredients, libtests needs to support:
A way to mark a test as a death test is important, since in the case in which
panic != abort
one still wants all the non death tests to happen within the same process for speed, but libtest stills need to spawn different processes for the death tests only (so it needs a way to tell these apart).For crates in which
panic == abort
, it would be nice if one could turn all tests into death tests at the crate level.This issue is tangentially related to: rust-lang/rfcs#1513
Google Test is probably the most famous unit-testing framework that supports these although in C++ other frameworks do as well. It usually takes 3k LOC C++ code to implement a "portable" process spawning/set up/tear down mechanism for spawning death tests, so it is quite a bit of machinery that might better belong outside of rustc.
The text was updated successfully, but these errors were encountered: