I used to be able to run specific, named tests from the command-line interface like this: cargo test <test_name>. But now this gives me the error
running 1 test
error: Found argument '<test_name>' which wasn't expected, or isn't valid in this context
Other arguments to cargo test also don't work.
The line that causes the error is this line in the test setup:
let cli_default_args = Arc::new(cli_args::Args::from_args());
Where the cli_args::Args struct is a struct that holds the value of the command line arguments and the from_args function comes from the StructOpt package derivation. cli_args::Args is decorated with #[derive(StructOpt)].
The problem was that arguments intended for
cargo testwere interpreted as arguments for the application.Replacing the problematic line in the test setup
with
fixes the problem. The above code means that your test setup runs as if the program didn't get any CLI arguments, everything is running with its default values.