Skip to content

cargo test --test <testname> builds binaries #7958

@alkim0

Description

@alkim0

Problem
The documentation for cargo seems to suggest that if I run: cargo test --test apple, then,
this should run test apple without compiling any of the binaries. However, this doesn't seem to be the case.

Steps

  1. Build a new rust project using: cargo new banana.
  2. Create a simple lib.rs file in src/. My contents were:
pub struct A {}
  1. Create a binary directory bin/ in src/ then add a file run.rs; my contents were:
use banana::A;
fn main() {
    let a = A {};
    println!("Hi");
}
  1. Create a tests directory tests/ at the project root. Add a simple test file sample.rs with contents:
use banana::A;
#[test]
fn sample() {
    let a = A {};
    println!("Hi");
}
  1. Run cargo test --test sample
  2. bin/run.rs is compiled. We can tell since we can warnings about unused variables from it.

Notes

Output of cargo version:

cargo 1.43.0-nightly (e57bd0299 2020-02-21)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-cargo-targetsArea: selection and definition of targets (lib, bins, examples, tests, benches)A-documenting-cargo-itselfArea: Cargo's documentationC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions