Skip to content

Support discoverability of test targets accepted by cargo test --test #8717

Open
@rrnewton

Description

Problem

Context: I have many test targets and want to narrow down the scope of cargo test while in the development loop. Regular test filtering still spends a bunch of time running targets that say ok. 0 passed.

This interaction is frustrating:

$ cargo test --test foobar
error: no test target named `foobar`

Ok, great, but please tell me what the set of test targets is or how to find it. In this case, I want to run an integration test corresponding to a file tests/foobar.rs, but not how to express that in the right format for --test. Let's check the help:

$ cargo test --help
...
        --test <NAME>...                             Test only the specified test target

That doesn't shine any more light on it. What is the set from which NAME is drawn? What's the "type", if you will?

Next I looked for something like --list-targets but didn't find it.

Finally, I look through the output of cargo test, hoping that it essentially serves the function of listing test targets. But the printouts during a test run look like this:

     Running target/debug/deps/foobar-ed66a800a301dfb1

And that's clearly not the string I'm supposed to provide to --test!

Solution

Here are three possible solutions:

  1. Provide a cargo test --list and mention it from the cargo test --test error message.
  2. Print out the list of literal target strings as part of the cargo test --test error message. This can be truncated if it's excessively long.
  3. Print precise target strings in a clear way while running tests.

Related

It seems #8396 is the only other issue that mentions this error message.
There was also this very old #812 discussing the documentation for cargo test vs cargo test --test.

Metadata

Assignees

No one assigned

    Labels

    A-cargo-targetsArea: selection and definition of targets (lib, bins, examples, tests, benches)A-diagnosticsArea: Error and warning messages generated by Cargo itself.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`S-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions