libtest Shouldn't Panic On Unexpected Command-line Arg #47241
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.
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.
Metadata
Assignees
Labels
Type
Projects
Status
No status
Activity