From 75ed75e8ee8fa09420ee7b0234e7c94b8ba140ca Mon Sep 17 00:00:00 2001 From: j178 <10510431+j178@users.noreply.github.com> Date: Thu, 3 Oct 2024 11:11:00 +0800 Subject: [PATCH 1/4] Add snapshot testing to contribution guide --- CONTRIBUTING.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 96285ed144428..3a8b23fbdc94a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -49,6 +49,35 @@ 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: + +```shell +# Unix +curl -LsSf https://insta.rs/install.sh | sh + +# Windows +powershell -c "irm https://insta.rs/install.ps1 | iex" +``` + +In tests, you can use `uv_snapshot!` 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("pip"), @r""); +} +``` + +To run and review a specific snapshot test: + +```shell +cargo insta test --review --package --test -- -- --exact +``` + ### Local testing You can invoke your development version of uv with `cargo run -- `. For example: From 6ef499223a87ebb6e32cd867f386fc8153e49a13 Mon Sep 17 00:00:00 2001 From: j178 <10510431+j178@users.noreply.github.com> Date: Thu, 3 Oct 2024 21:32:15 +0800 Subject: [PATCH 2/4] Tweak --- CONTRIBUTING.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3a8b23fbdc94a..a0ab41eac285d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -62,19 +62,24 @@ curl -LsSf https://insta.rs/install.sh | sh powershell -c "irm https://insta.rs/install.ps1 | iex" ``` -In tests, you can use `uv_snapshot!` to simplify creating snapshots for uv commands. For example: +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("pip"), @r""); + 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 + +# or combined into one command: cargo insta test --review --package --test -- -- --exact ``` From 6f4098dc56313ff84b13a24057d102e8440ef3cb Mon Sep 17 00:00:00 2001 From: j178 <10510431+j178@users.noreply.github.com> Date: Thu, 3 Oct 2024 23:23:02 +0800 Subject: [PATCH 3/4] Refer to installation doc --- CONTRIBUTING.md | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a0ab41eac285d..60d8db5c44f3c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -52,15 +52,8 @@ 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: - -```shell -# Unix -curl -LsSf https://insta.rs/install.sh | sh - -# Windows -powershell -c "irm https://insta.rs/install.ps1 | iex" -``` +`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: From f7b38f44b9faaa9c39dbcd332250ef262ebcb272 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Tue, 8 Oct 2024 14:07:37 -0500 Subject: [PATCH 4/4] Drop `insta test` suggestion --- CONTRIBUTING.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 60d8db5c44f3c..053f66dd67953 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -71,9 +71,6 @@ To run and review a specific snapshot test: ```shell cargo test --package --test -- -- --exact cargo insta review - -# or combined into one command: -cargo insta test --review --package --test -- -- --exact ``` ### Local testing