-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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 doesn't run doctest for staticlib #2442
Comments
See: rust-lang/cargo#2442 Seems that cargo requires `crate-type = ["lib"]` to run tests.
Ah yeah this is probably just something that needs to be filtered when we run doctests, I think we already handle other pieces specially? |
I think the current behavior is the correct behavior, this is filtered here: cargo/src/cargo/core/manifest.rs Line 312 in 8b0c007
and reasoned here cargo/src/cargo/ops/cargo_test.rs Line 147 in 8b0c007
If cargo run doctests will fail in any test that needs to be linked to the module. |
Hm weird, so shouldn't we already handle this in that case? |
We can add a warning when you run tests and doctested function return false. |
In theory given that logic we shouldn't even attempt to test staticlibs b/c only rlibs are tested. We may just be forgetting a conditional somewhere to check that method return value. |
Not really, the only problem with staticlibs is on "doctests" not on code tests. The problem is related with linking, then, to run doctests with staticlibs you have to compile it in another linkable format (lib or rlib). An approach (a bit weird in my opinion) when you dont have lib or rlib in your crate-type, compile it anyway and run doctests using it. I think the solution is to warn the user that doctests aren't run when you don't have one of the doctesteable crate types. |
From the user point of view, I advocate producing a warning. That's enough to resolve the issue as nobody will be surprised by the behavior. I don't like silently producing lib or rlib as I found that may change compilation result. (My library once failed to build as rlib due to linkage error to |
Wait whoa, I'm sorry! I misread this bug and thought it was saying that we were trying to run doctests but they were failing (legitimately). This is intentional behavior in that case because as pointed out by @jespino it's fundamentally not possible to run documentation tests for staticlibs (like executables). We tend to not print warnings that aren't really actionable (there's no great way to solve this), so this is currently intended, so closing. |
Steps to reproduce:
cargo new mylib
src/lib.rs
and add:Cargo.toml
:cargo test
Build passes. Doctests aren't run.
The text was updated successfully, but these errors were encountered: