Why you can't pass arguments such as -- --some_arg to cargo test?

when I try to do this I get:
Unrecognized option: 'x'

but in usage section of the cargo test is reported:
Usage: cargo.exe test [OPTIONS] [TESTNAME] [-- [args]...]

That separates arguments to cargo test and arguments to libtest, the default Rust test harness.

Here are some usage examples:

https://doc.rust-lang.org/book/ch11-02-running-tests.html

1 Like

Thank you, as I understood, it's not possible to pass arguments to my test files?

Not in the default test harness, but you have several options:

  • include_str! and include_bin! to include test data files
  • Building a path from std::env::current_exe
  • Using #[ignored] tests and std::process::env to obtain your inputs
  • Writing additional binaries and using them as manually run tests

Please keep your default cargo test clean with no additional inputs required so that your project is included in ecosystem-wide regression testing! :slight_smile:

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.