-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
cargo test
builds binaries without panic
#5435
Comments
Yeah this is one of those things I'm not entirely sure about. On one hand this definitely seems like a bug and would possibly be good to fix. On the other hand though it's really subtle and unlikely to really bring up any otherwise existing bugs (and can also increase compile times as we have to compile the library twice). I think I'd be somewhat tempted to lean towards fixing this though if we can. It may be surprising to users using |
Fixes rust-lang#5435 Also re-enable tests now that rust-lang#5460 has landed.
Fixes rust-lang#5650. cc rust-lang#5435 As part of my recent work on profiles, I introduced some situations where a library can be compiled multiple times with different settings. Doctests were greedily grabbing all dependencies for a package, regardless of which target is was for. This can cause doctests to fail if it links multiple copies of the same library. One way to trigger this is `cargo test --release` if you have dependencies, a build script, and `panic="abort"`. There are other (more obscure) ways to trigger it with profile overrides.
Fix doctests linking too many libs. Fixes #5650. cc #5435 As part of my recent work on profiles, I introduced some situations where a library can be compiled multiple times with different settings. Doctests were greedily grabbing all dependencies for a package, regardless of which target is was for. This can cause doctests to fail if it links multiple copies of the same library. One way to trigger this is `cargo test --release` if you have dependencies, a build script, and `panic="abort"`. There are other (more obscure) ways to trigger it with profile overrides.
If you have
panic="abort"
set in thedev
profile and runcargo test
, the binaries (and examples) are built withoutpanic
set (assuming you have an integration test which triggers the inclusion of binaries). This doesn't seem correct to me.Repro:
Fixing this is not entirely simple. If you build the
lib.rs
dependency twice (once with panic, once without), thenrustdoc
(for doctests) will pick up both and fail to run. The code that collects the libraries to link (inCompilation.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:
Doctest
unit is always created. (This might be helpful for fixing other bugs, such ascargo test --doc
overriding all other command-line options.)run_doc_tests
, instead of iterating overCompilation.libraries
, grab the actual dependencies of theDoctest
unit.test
flag fromBuildConfig
.I also wanted to double-check. This would result in
lib.rs
being compiled three times withcargo test
when you havepanic
set (once with panic for bins, once without for tests, and once as a unit-test). Is that OK?The text was updated successfully, but these errors were encountered: