Skip to content

Make libtest flags more discoverable #12494

Closed
@jyn514

Description

@jyn514

Problem

The libtest unit test runner has a lot of flags. Cargo allows passing these through with cargo test --lib -- . This is not super easy to discover - cargo test --help does say "Run cargo test -- --help for test binary options" at the end, but if you don't know that libtest and cargo have different flags, the error messages aren't great:

; cargo +nightly test --ignored
error: unexpected argument '--ignored' found

  tip: a similar argument exists: '--ignore-rust-version'

Usage: cargo test --ignore-rust-version [TESTNAME] [-- [args]...]

For more information, try '--help'.

Proposed Solution

Ideally, cargo would know which flags libtest supports and suggest passing those through:

error: unexpected argument '--ignored' found

  tip: libtest supports the `--ignored` argument; try `cargo test -- --ignored`
  tip: a similar argument exists: '--ignore-rust-version'

Usage: cargo test --ignore-rust-version [TESTNAME] [-- [args]...]

Notes

Right now, it's kind of hard to parse the --help output of libtest programmatically, so cargo would either have to hack a parser together or hardcode the options, neither of which is particularly maintainable. Ideally --help --format json would output a structured list that cargo can easily parse (I can open an upstream issue in rust-lang/rust if you're interested in pursuing this) and then idk embed it at build time or something like that.

My motivation for opening this issue is that I want to suggest --ignored in libtest if 1 or more tests are ignored, but right now that will be kind of confusing for people using cargo because it's a libtest flag and not a cargo test flag.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-console-outputArea: Terminal output, colors, progress bar, etc.C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Command-testS-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions