Skip to content

libtest Shouldn't Panic On Unexpected Command-line Arg #47241

Open
@bheisler

Description

Right now, if the user passes a command-line argument to a test or benchmark executable that isn't recognized, it will produce an error like the following:

thread 'main' panicked at '"Unrecognized option: \'example\'."', /checkout/src/libtest/lib.rs:278:26
note: Run with `RUST_BACKTRACE=1` for a backtrace.
error: bench failed

There are two problems with this. First, it would be nice to give a cleaner error message, since this is an expected case. Second and more importantly, the panic halts the cargo bench or cargo test run without running other executables.

I've attached an example project showing this. The fake benchmark harness in benches/example.rs checks for the argument --example. However, the libtest harness for the tests in the src directory is launched first and panics on seeing the same argument. This means that the naive cargo bench -- --example doesn't work as one would expect.

command-line-example.zip

This is a problem for me because it means I can't add command-line arguments to Criterion.rs benchmarks without an extra hassle for users unless libtest also accepts those same arguments.

Activity

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

Metadata

Assignees

No one assigned

    Labels

    A-libtestArea: `#[test]` / the `test` libraryC-bugCategory: This is a bug.T-dev-toolsRelevant to the dev-tools subteam, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    • Status

      No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions