-
Notifications
You must be signed in to change notification settings - Fork 13k
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 incorrectly warns for dead code #46379
Comments
This is not actually a bug, as far as I know!
Cargo is also attempting to compile this file as its own test. See the explanation here: https://doc.rust-lang.org/book/second-edition/ch11-03-test-organization.html#submodules-in-integration-tests I believe if you move this file to |
Yes, when replacing But, the warning is still raised at the first execution of Here the details of what I do after changing
For exactly the same code, |
I believe cargo compiles each "integration test" (i.e. file in ( I've worked around this by using |
So we're running into the same issue and I think the workaround |
This is either a bug or a design flaw. In TypeScript, an exported item (even if it is never used) is never considered dead code. I don't why it is in Rust. |
@KSXGitHub well, if you export the items from the crate with What @svenstaro is asking for would require considering all targets/configurations before determining if an item is dead code instead of letting the rust compiler report them when compiling an individual crate... |
I am noticing this issue, when will the PR above be released in rust ? ^ |
We are encountering the same issue. I am not sure I am comfortable with no dead code warnings. Perhaps an alternative approach to organizing code people would suggest if there is no re-design any time soon? |
If the module is implemented in
So, it looks to me that exported stuff is also not considered a dead code in rust, but it needs to be declared/imported with |
We are still encountering this issue with the last version of Rust (1.45.0 nightly) |
Previously `cargo test` would wrongly complain about dead code in `tests/common.rs`. This patch adds a workaround from rust-lang/rust#46379.
Allowing dead code warnings, and running "cargo test", seems to show truly dead code warnings. |
Not ideal but this will still catch tests not marked with using a test utility that we won't be told about it by Ferris, sadly See: rust-lang/rust#46379
* Extract new_page test utility to utils module * Derive the temp dirs names from test name automatically * Allow dead_code inside of utils to avoid unactionable warnings Not ideal but this will still catch tests not marked with using a test utility that we won't be told about it by Ferris, sadly See: rust-lang/rust#46379
Future commits will remove the hacky integration test setup. There are still some annoying warnings present for ununsed functions when they are really used. rust-lang/rust#46379
Future commits will remove the hacky integration test setup. There are still some annoying warnings present for ununsed functions when they are really used. rust-lang/rust#46379 Disambiguiate rand feature with dev dependancy https://users.rust-lang.org/t/features-and-dependencies-cannot-have-the-same-name/47746
* Initial integration tests * hackety hack * Cleanup, fix dead code warnings See rust-lang/rust#46379. * tests: more integration tests
139324a Remove integration test code (sanket1729) 90b5f10 Remove warnings (sanket1729) 967b95e Add support for running integration tests via cargo test (sanket1729) Pull request description: There are still some annoying warnings present for unused functions when they are used. rust-lang/rust#46379 Later commits will remove the hacky integration test setup. Running `cargo test` now should also run integration tests Our testing infrastructure now takes a long time to build because we have more than 100 dependencies (transitive). But all of these are dev dependencies, so our library isn't getting bloated. Fixes #361 ACKs for top commit: apoelstra: ACK 139324a Tree-SHA512: debf68fd0ac98cffa9c8c89964d6d1c45ee542fe17eb2fdab6295357efc06eb43a0412e6ed5d0fd7264a987989984eebb0c5b3bbf7169ecb780d31dce887cb0b
Future commits will remove the hacky integration test setup. There are still some annoying warnings present for ununsed functions when they are really used. rust-lang/rust#46379 Disambiguiate rand feature with dev dependancy https://users.rust-lang.org/t/features-and-dependencies-cannot-have-the-same-name/47746
This is still a problem, with any test not using all helpers cargo reports the helpers as dead code. |
In #33 we saw weirdness adding code to `tests/common/mod.rs` creating dead code warnings. This is because of Cargo's slightly funky rules for compiling integration test modules (rust-lang/rust#46379). We can fix it by claiming the module is public.
In #33 we saw weirdness adding code to `tests/common/mod.rs` creating dead code warnings. This is because of Cargo's slightly funky rules for compiling integration test modules (rust-lang/rust#46379). We can fix it by claiming the module is public.
We're running afoul of rust-lang/rust#46379, where each test is compiled independently, so any test that doesn't use every helper method triggers a dead code warning.
We're running afoul of rust-lang/rust#46379, where each test is compiled independently, so any test that doesn't use every helper method triggers a dead code warning.
Print "ok" and exit cleanly, rather than run off the end of a bunch of nops or nil bytes. DOSBox still cannot run some text executables for other reasons, such as (I suspect) large stack pointers or e_minalloc values. I had to do `pub` on the imports of the common module in tests, to avoid dead_code lints. rust-lang/rust#46379
Avoid the dead code false alarm + avoid it show up in tests. The solution is not super ideal but apparently there isn't anything better: rust-lang/rust#46379
The rust book's 11.3. Test Organization encourages to create However, this results to false positive in some cases such as |
A workaround for this issue is to use the |
+1 to following the |
The issue with dead code compiler warnings in tests is desribed here: rust-lang/rust#46379.
Because of issue rust-lang/rust#46379
Because of issue rust-lang/rust#46379
Hi!
I got unexpected dead code warnings when executing
cargo test
with multiple test files. I use a very simple example below that reproduces the issue.I have two files that contains tests,
tests/test_one.rs
andtests/test_two.rs
. Both contains exactly the same content (except for the unique test function name they contain):And another file called
tests/routines.rs
that simply contains:When I execute
cargo test
, the two tests are executed successfully and there is no raised warning. But if I remove themy_routine()
call from one of the two tests,cargo test
stills end up successfully but raises a warning onpub fn routine()
sayingfunction is never used
. However, one test still calls the function, so there is no dead code as stated.I got the same issue with both rust stable (1.22.1) and rust nightly (1.24.0).
Thanks.
The text was updated successfully, but these errors were encountered: