From 9e98055a9ebd654aa0166e8d402f1c0dab5fb4ba Mon Sep 17 00:00:00 2001 From: Jo <10510431+j178@users.noreply.github.com> Date: Wed, 9 Oct 2024 03:08:25 +0800 Subject: [PATCH] Add snapshot testing to contribution guide (#7882) ## Summary Add a `Snapshot testing` section to `CONTRIBUTING.md`. --------- Co-authored-by: Zanie Blue --- CONTRIBUTING.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 96285ed14..053f66dd6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -49,6 +49,30 @@ cargo run python install The storage directory can be configured with `UV_PYTHON_INSTALL_DIR`. +### Snapshot testing + +uv uses [insta](https://insta.rs/) for snapshot testing. It's recommended (but not necessary) to use +`cargo-insta` for a better snapshot review experience. See the +[installation guide](https://insta.rs/docs/cli/) for more information. + +In tests, you can use `uv_snapshot!` macro to simplify creating snapshots for uv commands. For +example: + +```rust +#[test] +fn test_add() { + let context = TestContext::new("3.12"); + uv_snapshot!(context.filters(), context.add().arg("requests"), @""); +} +``` + +To run and review a specific snapshot test: + +```shell +cargo test --package --test -- -- --exact +cargo insta review +``` + ### Local testing You can invoke your development version of uv with `cargo run -- `. For example: