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

Flycheck does not include dev-dependencies when running tests #55

Closed
Dushistov opened this issue Apr 4, 2017 · 3 comments
Closed

Flycheck does not include dev-dependencies when running tests #55

Dushistov opened this issue Apr 4, 2017 · 3 comments

Comments

@Dushistov
Copy link

Steps to reproduce:

  1. cargo new --lib foo
  2. Add to Cargo.toml such lines:
[dev-dependencies]
lazy_static = "0.2.2"

  1. Add to lib.rs such lines:
#[cfg(test)]
#[macro_use]
extern crate lazy_static;
  1. Run cargo build

after that flycheck underline with red line: extern crate lazy_static; and show hint around this line:
can't find create for 'lazy_static',
but cargo test|build|check reports no errors.

@fmdkdd
Copy link
Member

fmdkdd commented Apr 5, 2017

I can reproduce.

So with this setup, we end up calling cargo rustc --lib -- --test. But the lazy_static crate is never included that way, because cargo doesn't know we want to build tests (we pass the flag directly to rustc).

Note that here, neither cargo build nor cargo check do compile the test code; only cargo test does. But not only cargo test compiles the test, it runs it as well. In Flycheck, we only want compilation errors, so at the very least we should add --no-run.

$ cargo test --no-run -v -v
   Compiling foo v0.1.0 (file:///tmp/foo)
   Compiling lazy_static v0.2.6
     Running `rustc --crate-name foo src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=3f482a6be9713984 -C extra-filename=-3f482a6be9713984 --out-dir /tmp/foo/target/debug/deps -L dependency=/tmp/foo/target/debug/deps`
     Running `rustc --crate-name lazy_static /home/fmdkdd/.cargo/registry/src/github.com-1ecc6299db9ec823/lazy_static-0.2.6/src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=3b17cb290f94de07 -C extra-filename=-3b17cb290f94de07 --out-dir /tmp/foo/target/debug/deps -L dependency=/tmp/foo/target/debug/deps`
     Running `rustc --crate-name foo src/lib.rs --emit=dep-info,link -C debuginfo=2 --test -C metadata=21239f184ac91d21 -C extra-filename=-21239f184ac91d21 --out-dir /tmp/foo/target/debug/deps -L dependency=/tmp/foo/target/debug/deps --extern lazy_static=/tmp/foo/target/debug/deps/liblazy_static-3b17cb290f94de07.rlib`
warning: unused `#[macro_use]` import, #[warn(unused_imports)] on by default
 --> src/lib.rs:2:1
  |
2 | #[macro_use]
  | ^^^^^^^^^^^^

    Finished dev [unoptimized + debuginfo] target(s) in 0.43 secs

So we may be able to fix it by running cargo test --no-run in a second pass instead of passing --test to cargo rustc. Or, we can wait for rust-lang/cargo/issues/3431.

I'll look into the first option tomorrow.

@fmdkdd fmdkdd changed the title dev dependicies == can't find crate Flycheck does not include dev-dependencies when running tests Apr 6, 2017
fmdkdd added a commit to flycheck/flycheck that referenced this issue Apr 6, 2017
In concert, they cover all of our cases, and support additional setups, like
using [dev-dependencies] in Cargo.toml.  (See flycheck/flycheck-rust/issues/55)

Unfortunately, unlike ~cargo rustc~, they emit warnings only on their first
invocation, so they are not quite usable for Flycheck yet.

As an aside, since we are not building anything, we can get rid of the ~notes~
case.
@fmdkdd
Copy link
Member

fmdkdd commented Apr 6, 2017

I've found a way to make it work without breaking other cases using a combination of cargo check and cargo test. You can try out the branch.

There is one downside though: unlike cargo rustc, cargo check and cargo test will emit warnings only the first time they are run. I enquire about this behavior on cargo itself.

Untill this is fixed, I think I'd rather not merge it as-is, since I've got some flickering. Sometimes after you've saved, warnings appear, sometimes not.

fmdkdd added a commit to flycheck/flycheck that referenced this issue Jul 21, 2017
In concert, they cover all of our cases, and support additional setups, like
using [dev-dependencies] in Cargo.toml.  (See flycheck/flycheck-rust/issues/55)

Unfortunately, unlike ~cargo rustc~, they emit warnings only on their first
invocation, so they are not quite usable for Flycheck yet.

As an aside, since we are not building anything, we can get rid of the ~notes~
case.
fmdkdd added a commit to flycheck/flycheck that referenced this issue Jul 21, 2017
In concert, they cover all of our cases, and support additional setups, like
using [dev-dependencies] in Cargo.toml.  (See flycheck/flycheck-rust/issues/55)

Unfortunately, unlike ~cargo rustc~, they emit warnings only on their first
invocation, so they are not quite usable for Flycheck yet.

As an aside, since we are not building anything, we can get rid of the ~notes~
case.
fmdkdd added a commit to flycheck/flycheck that referenced this issue Jul 21, 2017
In concert, they cover all of our cases, and support additional setups, like
using [dev-dependencies] in Cargo.toml.  (See flycheck/flycheck-rust/issues/55)

Unfortunately, unlike ~cargo rustc~, they emit warnings only on their first
invocation, so they are not quite usable for Flycheck yet.

As an aside, since we are not building anything, we can get rid of the ~notes~
case.
fmdkdd added a commit to flycheck/flycheck that referenced this issue Jan 15, 2018
In concert, they cover all of our cases, and support additional setups, like
using [dev-dependencies] in Cargo.toml.  (See flycheck/flycheck-rust/issues/55)

Unfortunately, unlike ~cargo rustc~, they emit warnings only on their first
invocation.  In practice, this means warnings may not appear if the same files
are visited multiple times with Flycheck, and no changes are mode to them.

As a bonus, since we are not building anything, we can get rid of the ~notes~
test case.
fmdkdd added a commit to flycheck/flycheck that referenced this issue Jan 16, 2018
In concert, they cover all of our cases, and support additional setups, like
using [dev-dependencies] in Cargo.toml.  (See flycheck/flycheck-rust/issues/55)

Unfortunately, unlike ~cargo rustc~, they emit warnings only on their first
invocation.  In practice, this means warnings may not appear if the same files
are visited multiple times with Flycheck, and no changes are mode to them.

As a bonus, since we are not building anything, we can get rid of the ~notes~
test case.
@fmdkdd
Copy link
Member

fmdkdd commented Mar 14, 2018

Fixed in flycheck/flycheck@b8084a2.

@fmdkdd fmdkdd closed this as completed Mar 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants