2
votes

I want to run tests with release optimisations using 1 test thread.

I can do these individually:

cargo test -- --test-threads=1
cargo test --release

How would I put these together?

1

1 Answers

2
votes

You can use both in a single command like this:

cargo test --release -- --test-threads=1

How Cargo interprets these arguments ?

According to test subcommand's synopsis in reference :

cargo test [OPTIONS] [TESTNAME] [-- TEST-OPTIONS]

Cargo interprets input as :

  • Arguments before separator (--) will be used as an option for test subcommand. In your case cargo test accepts profile parameter as an option since it builds the project. Available options can be found under this title, or by running cargo test --help.

  • Arguments after the separator will be passed to the test binaries. In Rust project, Cargo uses rustc's libtest to run unit tests. In your case --test-threads=1 will be an argument for libtest.

This interpretation might not be valid for other subcommands, it is best to check other cargo commands from here. Checking synopsis section will give you a huge hint about capabilities of cargo's subcommands.


See also:

  • Since arguments after the dash will be sent to the rustc's libtest you can see available options for testing by: cargo test -- --help.
  • Profile options can be found under this title