home ~ projects ~ socials

Run cargo test And cargo run Together When Files Change With watchexec

watchexec -e rs "bash -c 'cargo test -- --nocapture && cargo run'"

You can also put it in a script like:

#!/bin/bash

watchexec -e rs "bash -c 'cargo test -- --nocapture && cargo run'"

Notes

  • There's probably a way to do that directly with cargo watch but I haven't figured that out yet
  • This also let you add other extensions to watch for (e.g. for template files). I wouldn't be surprised if cargo watch can do that too give its use of watchexec under the hood
-- end of line --