home ~ socials ~ other projects

Cargo start-watch Script with Tests and Clippy for Rust Projects

This is the script I use when I'm working on rust projects:

cargo watch -c -x 'test solo -- --nocapture && cargo test -- --nocapture && cargo clippy && cargo run'

It does the following:

  • Watches for file changes and runs the various sub-processes when one occurs
  • clears the screen
  • Runs all tests with "solo" in the name
  • If all "solo" tests run, the full test suite is run
  • If all tests pass cargo clippy is run to look for possible improvements to the code
  • Finally, the project is run

Adding that to a script file called start-watcher is the first thing I do in every project. In terms of code to quality of life improvement it's way up there on the ratio.

-a

-- end of line --

Endnotes

The solo approach is one of my favorites. It's the reverse of adding ignore to a test to take it out of the mix. Prepending tests with solo- runs them in the first batch. Makes it easier to see the results of one test instead of them being mushed in with all the others.