How to run single rust test?

On the new readme for ninja tools this are the test instructions:

Running tests/checks

To run all tests at once, from the top-level folder:

./ninja check

(tools\ninja check on Windows).

You can also run specific checks. For example, if you see during the checks
that check:svelte:editor is failing, you can use ./ninja check:svelte:editor

Looking at the code, I figured out the target for rust tests would be ninja check:rust_test, but after the first build, running it takes 60 seconds:

# ninja check:rust_test
    Finished dev [unoptimized + debuginfo] target(s) in 1.17s
[2/2; 1 active; 61.140s] check:rust_test

Build succeeded.

The output looks like it was built in 1 second and took 60 seconds running tests. How can I tell ninja only to run a single test file? For example, if I am creating a new test inside the file anki/rslib/src/card_rendering/parser.rs, how could I only run the tests for that file instead of all rust code tests?

Related questions:

  1. What's a good way to fake time to simulate reviews in tests?
  2. Test has different results when run singly vs run with all tests
  3. Can't run cargo test

Building the Rust tests will depend on the speed of your machine - I see about 8s here for a no-change build:

dae@dtop:code/desktop/anki% ./ninja check:rust_test
    Finished dev [unoptimized + debuginfo] target(s) in 0.10s
[2/2; 1 active; 8.080s] check:rust_test

You can save a bit of time by invoking cargo directly, which avoids rebuilding the Python library.

dae@dtop:code/desktop/anki% time cargo test -p anki > /dev/null
   Compiling anki v0.0.0 (/home/dae/Work/code/desktop/anki/rslib)
    Finished test [unoptimized + debuginfo] target(s) in 3.53s
     Running unittests src/lib.rs (/home/dae/Local/rust/debug/deps/anki-0afea6626d330407)
   Doc-tests anki
cargo test -p anki > /dev/null  8.14s user 13.04s system 405% cpu 5.222 total

You can also do that by running a unit test inside VS Code with the play button.

1 Like

Thanks. I will try that next time I need to run rust tests and report here if I find how to improve performance.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.