-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
If you have panic="abort" set in the dev profile and run cargo test, the binaries (and examples) are built without panic set (assuming you have an integration test which triggers the inclusion of binaries). This doesn't seem correct to me.
Repro:
cargo new --lib foo
cd foo
cat > src/main.rs <<EOL
extern crate foo;
fn main() { foo::f(); }
EOL
echo "pub fn f() { panic!(\"xxx\"); }" >> src/lib.rs
mkdir tests
touch tests/t1.rs
cat >> Cargo.toml <<EOL
[profile.dev]
panic = "abort"
EOL
cargo test -v
target/debug/foo # <- NOTE this does not abort!
Fixing this is not entirely simple. If you build the lib.rs dependency twice (once with panic, once without), then rustdoc (for doctests) will pick up both and fail to run. The code that collects the libraries to link (in Compilation.libraries) would probably need to be adjusted to collect only the libs that are needed for doctests.
I can tackle this if you'd like. One idea I had to approach this would be:
- Fix doctests to not be over-eager in what it links with:
- Ensure a
Doctestunit is always created. (This might be helpful for fixing other bugs, such ascargo test --docoverriding all other command-line options.) - In
run_doc_tests, instead of iterating overCompilation.libraries, grab the actual dependencies of theDoctestunit.
- Ensure a
- Remove the global
testflag fromBuildConfig.
I also wanted to double-check. This would result in lib.rs being compiled three times with cargo test when you have panic set (once with panic for bins, once without for tests, and once as a unit-test). Is that OK?