An example of using cargo workspace
and snapshot testing to create a REPL-like experience.
cargo install cargo-insta
- Develop in "library" crates in the workspaces, keep their dependency lean.
- Make an "application" crate that depends on all the crates you developed in 1. Heavy dependencies (such as tokio) should only exist in this crate.
- Explore your code in the
scratchpad
crate. Use insta for inline snapshot to evaluate and print results directly in the code. - If there's anything worth keeping, make it a test in library crates.
Typically, you want to do inline snapshot test for the scratchpad
crate with the command cargo insta test -p scratchpad --accept
.
You can invoke the command by:
- in vim:
:!make
- in clion: setup a custom cargo run configuration for the command
- via
cargo-watch
:cargo watch -x 'insta test -p scratchpad --accept'