Skip to content
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 check --tests not working #4330

Closed
davemilter opened this issue Jul 26, 2017 · 1 comment
Closed

cargo check --tests not working #4330

davemilter opened this issue Jul 26, 2017 · 1 comment

Comments

@davemilter
Copy link

cargo check --help tells

--tests Check all tests

I expect that at least it cheks syntax of tests.
I created simple project cargo new foo,
and edit src/lib.rs like this:

#[cfg(test)]
mod tests {
    #[test]
    fn it_works() {
        baguaga
    }
}

I run cargo check --tests (cargo 0.22.0-nightly (88aa6423a 2017-07-22)) and
it reports nothing:

$ cargo check --tests
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
$ cargo test
   Compiling foo v0.1.0 (file:///tmp/foo)
error[E0425]: cannot find value `baguaga` in this scope
 --> src/lib.rs:5:9
  |
5 |         baguaga
  |         ^^^^^^^ not found in this scope

error: aborting due to previous error

error: Could not compile `foo`.

To learn more, run the command again with --verbose.

I expected the same error report from cargo check --tests as from cargo test
foo directory in attachment.
foo.zip

ehuss added a commit to ehuss/cargo that referenced this issue Oct 15, 2017
- Add `--profile test` flag to `cargo check` that will enable checking of unit tests.
- `--tests` will implicitly enable checking of unit tests within the lib.
- Don't implicitly compile binaries when using just `--test` filters.
- Fix erroneously linking tests when run with `--test`.

Fixes rust-lang#3431, rust-lang#4003, rust-lang#4059, rust-lang#4330.
bors added a commit that referenced this issue Oct 30, 2017
Add unit test checking to `cargo check`

This is an extension of PR #4039, fixing #3431, #4003, #4059, #4330.  The fixes for #4059 can potentially be separated into a separate PR, though there may be some overlap.

The general gist of the changes:

- Add `--profile test` flag to `cargo check` that will enable checking of unit tests.
- `--tests` will implicitly enable checking of unit tests within the lib (checks the same targets as `cargo test`).  This affects the `check`, `test`, and `build` commands.
- `--benches` behaves similarly by using the same targets as `cargo bench`.
- Fix erroneously linking tests when run with `--test`.

There is one thing I did not do because I wanted more feedback on what others think the expected behavior should be.  What should the behavior of `--all-targets` be?  This patch does not (yet) make any changes to its behavior.  My initial thinking is that it should *add* a target of `--lib --bins --profile test`, but that essentially means the lib and bin targets will be checked twice (and thus any errors/warnings outside of `#[cfg(test)]` will appear twice, which may be confusing, and generally take twice as long to run).  I can add that, but I think it would require adding a new `All` variant to `CompileFilter` so that the code in `generate_targets` can detect this scenario.  I wanted feedback before making a more extensive change like that.  The downside of not adding it is that `--all-targets` will ignore unit tests (if you don't specify `--profile test`).

Summary of the profiles used with this patch:

Command                         | Lib               | Bin foo     | Test t1 | Example e1 | Bench b1 |
-------                         | ---               | -------     | ------- | ---------- | -------- |
`check`                         | check             | check       | -       | -          | -        |
`check --profile test`          | check_test†       | check_test† | -       | -          | -        |
`check --lib`                   | check             | -           | -       | -          | -        |
`check --lib --profile test`    | check_test†       | -           | -       | -          | -        |
`check --bin foo`               | check             | check       | -       | -          | -        |
`check -–bin foo –profile test` | check_test†       | check_test† | -       | -          | -        |
`check --bins`                  | check             | check       | -       | -          | -        |
`check --test t1`               | check             | check       | check_test   | -          | -        |
`check --tests`                 | check, check_test†  | check, check_test† | check_test | check†, check_test†  | -    |
`check --all-targets`           | check, check_test†  | check, check_test†  | check_test   | check, check_test† | check_test    |

† = different behavior from today
@ehuss
Copy link
Contributor

ehuss commented Oct 30, 2017

This is fixed by #4592. cargo check --tests now really does all tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants