From 94d64ff4ee912dfd8225182949e4b6ef4df1323e Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Wed, 18 Feb 2026 14:12:00 -0600 Subject: [PATCH] Use `TestContext::with_filter` in more places (#18091) --- crates/uv/tests/it/build.rs | 10 +++--- crates/uv/tests/it/cache.rs | 14 ++++----- crates/uv/tests/it/edit.rs | 32 +++++++++---------- crates/uv/tests/it/format.rs | 5 ++- crates/uv/tests/it/pip_compile.rs | 5 ++- crates/uv/tests/it/pip_install.rs | 44 ++++++++++++-------------- crates/uv/tests/it/python_install.rs | 26 ++++++++-------- crates/uv/tests/it/python_upgrade.rs | 5 ++- crates/uv/tests/it/run.rs | 22 ++++++------- crates/uv/tests/it/sync.rs | 20 ++++++------ crates/uv/tests/it/tool_install.rs | 23 +++++++------- crates/uv/tests/it/tool_run.rs | 46 ++++++++++++++-------------- crates/uv/tests/it/venv.rs | 5 ++- 13 files changed, 119 insertions(+), 138 deletions(-) diff --git a/crates/uv/tests/it/build.rs b/crates/uv/tests/it/build.rs index 0a80736ba..589efc55e 100644 --- a/crates/uv/tests/it/build.rs +++ b/crates/uv/tests/it/build.rs @@ -1757,10 +1757,9 @@ fn build_list_files_errors() -> Result<()> { let built_by_uv = current_dir()?.join("../../test/packages/built-by-uv"); - let mut filters = context.filters(); + let context = context.with_filter(("--link-mode ", "")); // In CI, we run with link mode settings. - filters.push(("--link-mode ", "")); - uv_snapshot!(filters, context.build() + uv_snapshot!(context.filters(), context.build() .arg(&built_by_uv) .arg("--out-dir") .arg(context.temp_dir.join("output1")) @@ -1780,10 +1779,9 @@ fn build_list_files_errors() -> Result<()> { // Not a uv build backend package, we can't list it. let anyio_local = current_dir()?.join("../../test/packages/anyio_local"); - let mut filters = context.filters(); // Windows normalization - filters.push(("/crates/uv/../../", "/")); - uv_snapshot!(filters, context.build() + let context = context.with_filter(("/crates/uv/../../", "/")); + uv_snapshot!(context.filters(), context.build() .arg(&anyio_local) .arg("--out-dir") .arg(context.temp_dir.join("output2")) diff --git a/crates/uv/tests/it/cache.rs b/crates/uv/tests/it/cache.rs index 23f06494a..2d748ef4a 100644 --- a/crates/uv/tests/it/cache.rs +++ b/crates/uv/tests/it/cache.rs @@ -37,13 +37,13 @@ fn cache_init_failure() -> Result<()> { // Point the cache to a subdirectory within the read-only parent let cache_dir = cache_parent.child("cache"); - let mut filters = context.filters(); // Filter both the relative path (in the first line) and absolute path (in the cause) - filters.push((r"cache_parent/cache", "[CACHE_DIR]")); - filters.push(( - r"failed to create directory `.*`", - "failed to create directory `[CACHE_DIR]`", - )); + let context = context + .with_filter((r"cache_parent/cache", "[CACHE_DIR]")) + .with_filter(( + r"failed to create directory `.*`", + "failed to create directory `[CACHE_DIR]`", + )); // Build the sync command manually to use our custom cache directory. // We can't use context.sync() because it adds --cache-dir with the default cache. @@ -56,7 +56,7 @@ fn cache_init_failure() -> Result<()> { context.add_shared_env(&mut command, false); // Running a command should fail with a chained error about cache initialization - uv_snapshot!(&filters, command, @" + uv_snapshot!(context.filters(), command, @" success: false exit_code: 2 ----- stdout ----- diff --git a/crates/uv/tests/it/edit.rs b/crates/uv/tests/it/edit.rs index d5527ce5f..bfd714d13 100644 --- a/crates/uv/tests/it/edit.rs +++ b/crates/uv/tests/it/edit.rs @@ -408,8 +408,7 @@ fn add_git_private_source() -> Result<()> { fn add_git_private_raw() -> Result<()> { let context = uv_test::test_context!("3.12"); let token = decode_token(READ_ONLY_GITHUB_TOKEN); - let mut filters = context.filters(); - filters.push((&token, "***")); + let context = context.with_filter((&token, "***")); let pyproject_toml = context.temp_dir.child("pyproject.toml"); pyproject_toml.write_str(indoc! {r#" @@ -420,7 +419,7 @@ fn add_git_private_raw() -> Result<()> { dependencies = [] "#})?; - uv_snapshot!(filters, context.add().arg(format!("uv-private-pypackage @ git+https://{token}@github.com/astral-test/uv-private-pypackage")).arg("--raw-sources"), @" + uv_snapshot!(context.filters(), context.add().arg(format!("uv-private-pypackage @ git+https://{token}@github.com/astral-test/uv-private-pypackage")).arg("--raw-sources"), @" success: true exit_code: 0 ----- stdout ----- @@ -435,7 +434,7 @@ fn add_git_private_raw() -> Result<()> { let pyproject_toml = context.read("pyproject.toml"); insta::with_settings!({ - filters => filters.clone() + filters => context.filters() }, { assert_snapshot!( pyproject_toml, @r#" @@ -453,7 +452,7 @@ fn add_git_private_raw() -> Result<()> { let lock = context.read("uv.lock"); insta::with_settings!({ - filters => filters.clone(), + filters => context.filters(), }, { assert_snapshot!( lock, @r#" @@ -484,7 +483,7 @@ fn add_git_private_raw() -> Result<()> { }); // Install from the lockfile. - uv_snapshot!(filters, context.sync().arg("--frozen"), @" + uv_snapshot!(context.filters(), context.sync().arg("--frozen"), @" success: true exit_code: 0 ----- stdout ----- @@ -787,14 +786,14 @@ fn add_git_lfs() -> Result<()> { // calls to `git` and `git_metadata` functions which don't have guaranteed execution order. // In addition, we can get different error codes depending on where the failure occurs, // although we know the error code cannot be 0. - let mut filters = context.filters(); - filters.push((r"exit_code: -?[1-9]\d*", "exit_code: [ERROR_CODE]")); - filters.push(( - "(?s)(----- stderr -----).*?The source distribution `[^`]+` is missing Git LFS artifacts.*", - "$1\n[PREFIX]The source distribution `[DISTRIBUTION]` is missing Git LFS artifacts", - )); + let context = context + .with_filter((r"exit_code: -?[1-9]\d*", "exit_code: [ERROR_CODE]")) + .with_filter(( + "(?s)(----- stderr -----).*?The source distribution `[^`]+` is missing Git LFS artifacts.*", + "$1\n[PREFIX]The source distribution `[DISTRIBUTION]` is missing Git LFS artifacts", + )); - uv_snapshot!(filters, context.add() + uv_snapshot!(context.filters(), context.add() .env(EnvVars::UV_INTERNAL__TEST_LFS_DISABLED, "1") .arg("git+https://github.com/astral-sh/test-lfs-repo") .arg("--rev").arg("0fe88f7c2e2883521bf065c108d9ee8eb115674b") @@ -11122,8 +11121,7 @@ async fn add_index_empty_directory() -> Result<()> { #[test] fn add_index_with_ambiguous_relative_path() -> Result<()> { let context = uv_test::test_context!("3.12"); - let mut filters = context.filters(); - filters.push((r"\./|\.\\\\", r"[PREFIX]")); + let context = context.with_filter((r"\./|\.\\", r"[PREFIX]")); let pyproject_toml = context.temp_dir.child("pyproject.toml"); pyproject_toml.write_str(indoc! {r#" @@ -11135,7 +11133,7 @@ fn add_index_with_ambiguous_relative_path() -> Result<()> { "#})?; #[cfg(unix)] - uv_snapshot!(filters, context.add().arg("iniconfig").arg("--index").arg("test-index"), @" + uv_snapshot!(context.filters(), context.add().arg("iniconfig").arg("--index").arg("test-index"), @" success: false exit_code: 2 ----- stdout ----- @@ -11146,7 +11144,7 @@ fn add_index_with_ambiguous_relative_path() -> Result<()> { "); #[cfg(windows)] - uv_snapshot!(filters, context.add().arg("iniconfig").arg("--index").arg("test-index"), @r" + uv_snapshot!(context.filters(), context.add().arg("iniconfig").arg("--index").arg("test-index"), @r" success: false exit_code: 2 ----- stdout ----- diff --git a/crates/uv/tests/it/format.rs b/crates/uv/tests/it/format.rs index d72e5d049..61d931c0e 100644 --- a/crates/uv/tests/it/format.rs +++ b/crates/uv/tests/it/format.rs @@ -609,12 +609,11 @@ fn format_no_matching_version() -> Result<()> { "})?; // Run format with impossible version constraints - should fail - let mut filters = context.filters(); - filters.push(( + let context = context.with_filter(( r"\b[a-z0-9_]+-(?:apple|pc|unknown)-[a-z0-9_]+(?:-[a-z0-9_]+)?\b", "[PLATFORM]", )); - uv_snapshot!(filters, context.format().arg("--version").arg(">=999.0.0"), @" + uv_snapshot!(context.filters(), context.format().arg("--version").arg(">=999.0.0"), @" success: false exit_code: 2 ----- stdout ----- diff --git a/crates/uv/tests/it/pip_compile.rs b/crates/uv/tests/it/pip_compile.rs index 211652986..92373fc05 100644 --- a/crates/uv/tests/it/pip_compile.rs +++ b/crates/uv/tests/it/pip_compile.rs @@ -13234,8 +13234,7 @@ fn git_source_refs() -> Result<()> { fn git_source_missing_tag() -> Result<()> { let context = uv_test::test_context!("3.12"); - let mut filters = context.filters(); - filters.push(("`.*/git fetch (.*)`", "`git fetch $1`")); + let context = context.with_filter(("`.*/git fetch (.*)`", "`git fetch $1`")); let pyproject_toml = context.temp_dir.child("pyproject.toml"); pyproject_toml.write_str(indoc! {r#" @@ -13250,7 +13249,7 @@ fn git_source_missing_tag() -> Result<()> { uv-public-pypackage = { git = "https://github.com/astral-test/uv-public-pypackage", tag = "missing" } "#})?; - uv_snapshot!(filters, context.pip_compile() + uv_snapshot!(context.filters(), context.pip_compile() .arg("pyproject.toml"), @" success: false exit_code: 1 diff --git a/crates/uv/tests/it/pip_install.rs b/crates/uv/tests/it/pip_install.rs index c30e42572..3d29517ca 100644 --- a/crates/uv/tests/it/pip_install.rs +++ b/crates/uv/tests/it/pip_install.rs @@ -215,13 +215,12 @@ fn invalid_pyproject_toml_option_unknown_field() -> Result<()> { build-backend = "setuptools.build_meta" "#})?; - let mut filters = context.filters(); - filters.push(( + let context = context.with_filter(( "expected one of `required-version`, `native-tls`, .*", "expected one of `required-version`, `native-tls`, [...]", )); - uv_snapshot!(filters, context.pip_install() + uv_snapshot!(context.filters(), context.pip_install() .arg("-r") .arg("pyproject.toml"), @r#" success: true @@ -2205,14 +2204,12 @@ fn update_ref_git_public_https() { #[test] #[cfg(feature = "test-git")] fn install_git_public_https_missing_branch_or_tag() { - let context = uv_test::test_context!(DEFAULT_PYTHON_VERSION); - - let mut filters = context.filters(); // Windows does not style the command the same as Unix, so we must omit it from the snapshot - filters.push(("`.*/git(.exe)? fetch .*`", "`git fetch [...]`")); - filters.push(("exit status", "exit code")); + let context = uv_test::test_context!(DEFAULT_PYTHON_VERSION) + .with_filter(("`.*/git(.exe)? fetch .*`", "`git fetch [...]`")) + .with_filter(("exit status", "exit code")); - uv_snapshot!(filters, context.pip_install() + uv_snapshot!(context.filters(), context.pip_install() // 2.0.0 does not exist .arg("uv-public-pypackage @ git+https://github.com/astral-test/uv-public-pypackage@2.0.0"), @" success: false @@ -2293,20 +2290,17 @@ async fn install_git_public_rate_limited_by_github_rest_api_429_response() { #[test] #[cfg(feature = "test-git")] fn install_git_public_https_missing_commit() { - let context = uv_test::test_context!(DEFAULT_PYTHON_VERSION); - - let mut filters = context.filters(); // Windows does not style the command the same as Unix, so we must omit it from the snapshot - filters.push(("`.*/git(.exe)? rev-parse .*`", "`git rev-parse [...]`")); - filters.push(("exit status", "exit code")); + let context = uv_test::test_context!(DEFAULT_PYTHON_VERSION) + .with_filter(("`.*/git(.exe)? rev-parse .*`", "`git rev-parse [...]`")) + .with_filter(("exit status", "exit code")) + // There are flakes on Windows where this irrelevant error is appended + .with_filter(( + "fatal: unable to write response end packet: Broken pipe\n", + "", + )); - // There are flakes on Windows where this irrelevant error is appended - filters.push(( - "fatal: unable to write response end packet: Broken pipe\n", - "", - )); - - uv_snapshot!(filters, context.pip_install() + uv_snapshot!(context.filters(), context.pip_install() // 2.0.0 does not exist .arg("uv-public-pypackage @ git+https://github.com/astral-test/uv-public-pypackage@79a935a7a1a0ad6d0bdf72dce0e16cb0a24a1b3b") , @" @@ -2536,16 +2530,16 @@ fn install_git_private_https_pat_not_authorized() { // A revoked token let token = "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"; - let mut filters = context.filters(); // TODO(john): We need this filter because we are displaying the token when // an underlying process error message is being displayed. We should actually // mask it. - filters.push((token, "***")); - filters.push(("`.*/git fetch (.*)`", "`git fetch $1`")); + let context = context + .with_filter((token, "***")) + .with_filter(("`.*/git fetch (.*)`", "`git fetch $1`")); // We provide a username otherwise (since the token is invalid), the git cli will prompt for a password // and hang the test - uv_snapshot!(filters, context.pip_install() + uv_snapshot!(context.filters(), context.pip_install() .arg(format!("uv-private-pypackage @ git+https://git:{token}@github.com/astral-test/uv-private-pypackage")) , @" success: false diff --git a/crates/uv/tests/it/python_install.rs b/crates/uv/tests/it/python_install.rs index 275befb98..b710fa551 100644 --- a/crates/uv/tests/it/python_install.rs +++ b/crates/uv/tests/it/python_install.rs @@ -2622,12 +2622,11 @@ fn python_install_cached() { "); // 3.12 isn't cached, so it can't be installed - let mut filters = context.filters(); - filters.push(( + let context = context.with_filter(( "cpython-3.12.*.tar.gz", "cpython-3.12.[PATCH]-[DATE]-[PLATFORM].tar.gz", )); - uv_snapshot!(filters, context + uv_snapshot!(context.filters(), context .python_install() .arg("3.12") .arg("--offline") @@ -2733,13 +2732,13 @@ fn python_install_no_cache() { "); // 3.12 isn't cached, so it can't be installed - let mut filters = context.filters(); - filters.push(( - "cpython-3.12.*.tar.gz", - "cpython-3.12.[PATCH]-[DATE]-[PLATFORM].tar.gz", - )); - filters.push((r"releases/download/\d{8}/", "releases/download/[DATE]/")); - uv_snapshot!(filters, context + let context = context + .with_filter(( + "cpython-3.12.*.tar.gz", + "cpython-3.12.[PATCH]-[DATE]-[PLATFORM].tar.gz", + )) + .with_filter((r"releases/download/\d{8}/", "releases/download/[DATE]/")); + uv_snapshot!(context.filters(), context .python_install() .arg("3.12") .arg("--offline"), @" @@ -3497,11 +3496,10 @@ fn uninstall_last_patch() { " ); - let mut filters = context.filters(); - filters.push(("python3", "python")); + let context = context.with_filter(("python3", "python")); #[cfg(unix)] - uv_snapshot!(filters, context.run().arg("python").arg("--version"), @" + uv_snapshot!(context.filters(), context.run().arg("python").arg("--version"), @" success: false exit_code: 2 ----- stdout ----- @@ -3515,7 +3513,7 @@ fn uninstall_last_patch() { ); #[cfg(windows)] - uv_snapshot!(filters, context.run().arg("python").arg("--version"), @r" + uv_snapshot!(context.filters(), context.run().arg("python").arg("--version"), @r" success: false exit_code: 2 ----- stdout ----- diff --git a/crates/uv/tests/it/python_upgrade.rs b/crates/uv/tests/it/python_upgrade.rs index 2b505fca8..ea2df761f 100644 --- a/crates/uv/tests/it/python_upgrade.rs +++ b/crates/uv/tests/it/python_upgrade.rs @@ -122,11 +122,10 @@ fn python_upgrade_without_version() { + cpython-3.13.1-[PLATFORM] (python3.13) "); - let mut filters = context.filters().clone(); - filters.push((r"3.13.\d+", "3.13.[X]")); + let context = context.with_filter((r"3.13.\d+", "3.13.[X]")); // Upgrade one patch version - uv_snapshot!(filters, context.python_upgrade().arg("3.13"), @" + uv_snapshot!(context.filters(), context.python_upgrade().arg("3.13"), @" success: true exit_code: 0 ----- stdout ----- diff --git a/crates/uv/tests/it/run.rs b/crates/uv/tests/it/run.rs index 8922bb71e..2dc8d532f 100644 --- a/crates/uv/tests/it/run.rs +++ b/crates/uv/tests/it/run.rs @@ -143,9 +143,9 @@ fn run_with_python_version() -> Result<()> { fn run_args() -> Result<()> { let context = uv_test::test_context!("3.12"); - let mut filters = context.filters(); - filters.push((r"Usage: (uv|\.exe) run \[OPTIONS\] (?s).*", "[UV RUN HELP]")); - filters.push((r"usage: .*(\n|.*)*", "usage: [PYTHON HELP]")); + let context = context + .with_filter((r"Usage: uv(\.exe)? run \[OPTIONS\] (?s).*", "[UV RUN HELP]")) + .with_filter((r"usage: .*(\n|.*)*", "usage: [PYTHON HELP]")); let pyproject_toml = context.temp_dir.child("pyproject.toml"); pyproject_toml.write_str(indoc! { r#" @@ -162,7 +162,7 @@ fn run_args() -> Result<()> { })?; // We treat arguments before the command as uv arguments - uv_snapshot!(filters, context.run().arg("--help").arg("python"), @" + uv_snapshot!(context.filters(), context.run().arg("--help").arg("python"), @" success: true exit_code: 0 ----- stdout ----- @@ -172,7 +172,7 @@ fn run_args() -> Result<()> { "); // We don't treat arguments after the command as uv arguments - uv_snapshot!(filters, context.run().arg("python").arg("--help"), @" + uv_snapshot!(context.filters(), context.run().arg("python").arg("--help"), @" success: true exit_code: 0 ----- stdout ----- @@ -180,7 +180,7 @@ fn run_args() -> Result<()> { "); // Can use `--` to separate uv arguments from the command arguments. - uv_snapshot!(filters, context.run().arg("--").arg("python").arg("--version"), @" + uv_snapshot!(context.filters(), context.run().arg("--").arg("python").arg("--version"), @" success: true exit_code: 0 ----- stdout ----- @@ -4452,12 +4452,11 @@ fn run_gui_script_explicit_stdin_unix() -> Result<()> { #[test] fn run_remote_pep723_script() { let context = uv_test::test_context!("3.12").with_filtered_python_names(); - let mut filters = context.filters(); - filters.push(( + let context = context.with_filter(( r"(?m)^Downloaded remote script to:.*\.py$", "Downloaded remote script to: [TEMP_PATH].py", )); - uv_snapshot!(filters, context.run().arg("https://raw.githubusercontent.com/astral-sh/uv/df45b9ac2584824309ff29a6a09421055ad730f6/scripts/uv-run-remote-script-test.py").arg(EnvVars::CI), @" + uv_snapshot!(context.filters(), context.run().arg("https://raw.githubusercontent.com/astral-sh/uv/df45b9ac2584824309ff29a6a09421055ad730f6/scripts/uv-run-remote-script-test.py").arg(EnvVars::CI), @" success: true exit_code: 0 ----- stdout ----- @@ -4735,13 +4734,12 @@ fn run_with_not_existing_env_file() -> Result<()> { " })?; - let mut filters = context.filters(); - filters.push(( + let context = context.with_filter(( r"(?m)^error: Failed to read environment file `.env.development`: .*$", "error: Failed to read environment file `.env.development`: [ERR]", )); - uv_snapshot!(filters, context.run().arg("--env-file").arg(".env.development").arg("test.py"), @" + uv_snapshot!(context.filters(), context.run().arg("--env-file").arg(".env.development").arg("test.py"), @" success: false exit_code: 2 ----- stdout ----- diff --git a/crates/uv/tests/it/sync.rs b/crates/uv/tests/it/sync.rs index f60f7f7b4..9039c2ff4 100644 --- a/crates/uv/tests/it/sync.rs +++ b/crates/uv/tests/it/sync.rs @@ -12616,17 +12616,17 @@ fn sync_required_environment_hint() -> Result<()> { Resolved 2 packages in [TIME] "); - let mut filters = context.filters(); - filters.push(( - r"You're on [^ ]+ \(`.*`\)", - "You're on [PLATFORM] (`[TAG]`)", - )); - filters.push(( - r"sys_platform == '[^']+' and platform_machine == '[^']+'", - "sys_platform == '[PLATFORM]' and platform_machine == '[MACHINE]'", - )); + let context = context + .with_filter(( + r"You're on [^ ]+ \(`.*`\)", + "You're on [PLATFORM] (`[TAG]`)", + )) + .with_filter(( + r"sys_platform == '[^']+' and platform_machine == '[^']+'", + "sys_platform == '[PLATFORM]' and platform_machine == '[MACHINE]'", + )); - uv_snapshot!(filters, context.sync().env_remove(EnvVars::UV_EXCLUDE_NEWER), @r#" + uv_snapshot!(context.filters(), context.sync().env_remove(EnvVars::UV_EXCLUDE_NEWER), @r#" success: false exit_code: 2 ----- stdout ----- diff --git a/crates/uv/tests/it/tool_install.rs b/crates/uv/tests/it/tool_install.rs index c08be55e4..9a13c1697 100644 --- a/crates/uv/tests/it/tool_install.rs +++ b/crates/uv/tests/it/tool_install.rs @@ -568,10 +568,9 @@ fn tool_install_suggest_other_packages_with_executable() { .with_filtered_exe_suffix(); let tool_dir = context.temp_dir.child("tools"); let bin_dir = context.temp_dir.child("bin"); - let mut filters = context.filters(); - filters.push(("\\+ uvloop(.+)\n ", "")); + let context = context.with_filter(("\\+ uvloop(.+)\n ", "")); - uv_snapshot!(filters, context.tool_install() + uv_snapshot!(context.filters(), context.tool_install() .arg("fastapi==0.111.0") .env(EnvVars::UV_TOOL_DIR, tool_dir.as_os_str()) .env(EnvVars::XDG_BIN_HOME, bin_dir.as_os_str()), @" @@ -2150,14 +2149,14 @@ fn tool_install_git_lfs() { // calls to `git` and `git_metadata` functions which don't have guaranteed execution order. // In addition, we can get different error codes depending on where the failure occurs, // although we know the error code cannot be 0. - let mut filters = context.filters(); - filters.push((r"exit_code: -?[1-9]\d*", "exit_code: [ERROR_CODE]")); - filters.push(( - "(?s)(----- stderr -----).*?The source distribution `[^`]+` is missing Git LFS artifacts.*", - "$1\n[PREFIX]The source distribution `[DISTRIBUTION]` is missing Git LFS artifacts", - )); + let context = context + .with_filter((r"exit_code: -?[1-9]\d*", "exit_code: [ERROR_CODE]")) + .with_filter(( + "(?s)(----- stderr -----).*?The source distribution `[^`]+` is missing Git LFS artifacts.*", + "$1\n[PREFIX]The source distribution `[DISTRIBUTION]` is missing Git LFS artifacts", + )); - uv_snapshot!(filters, context.tool_install() + uv_snapshot!(context.filters(), context.tool_install() .arg("--reinstall") .arg("--lfs") .arg("test-lfs-repo @ git+https://github.com/astral-sh/test-lfs-repo@54e5eebd3c6851b1353fc7b1e5b4eca11e27581c") @@ -2196,7 +2195,7 @@ fn tool_install_git_lfs() { #[cfg(not(windows))] uv_snapshot!(context.filters(), Command::new("test-lfs-repo-assets").env(EnvVars::PATH, bin_dir.as_os_str()), @r#" success: false - exit_code: 1 + exit_code: [ERROR_CODE] ----- stdout ----- ----- stderr ----- @@ -2215,7 +2214,7 @@ fn tool_install_git_lfs() { #[cfg(windows)] uv_snapshot!(context.filters(), Command::new("test-lfs-repo-assets").env(EnvVars::PATH, bin_dir.as_os_str()), @r#" success: false - exit_code: 1 + exit_code: [ERROR_CODE] ----- stdout ----- ----- stderr ----- diff --git a/crates/uv/tests/it/tool_run.rs b/crates/uv/tests/it/tool_run.rs index db604e212..bd5bb0cef 100644 --- a/crates/uv/tests/it/tool_run.rs +++ b/crates/uv/tests/it/tool_run.rs @@ -9,17 +9,17 @@ use uv_test::{uv_snapshot, venv_bin_path}; #[test] fn tool_run_args() { let context = uv_test::test_context!("3.12").with_filtered_counts(); - let mut filters = context.filters(); - filters.push(( - r"Usage: uv tool run \[OPTIONS\] (?s).*", - "[UV TOOL RUN HELP]", - )); - filters.push((r"usage: pytest \[options\] (?s).*", "[PYTEST HELP]")); + let context = context + .with_filter(( + r"Usage: uv(\.exe)? tool run \[OPTIONS\] (?s).*", + "[UV TOOL RUN HELP]", + )) + .with_filter((r"usage: pytest \[options\] (?s).*", "[PYTEST HELP]")); let tool_dir = context.temp_dir.child("tools"); let bin_dir = context.temp_dir.child("bin"); // We treat arguments before the command as uv tool run arguments - uv_snapshot!(filters, context.tool_run() + uv_snapshot!(context.filters(), context.tool_run() .arg("--help") .arg("pytest") .env(EnvVars::UV_TOOL_DIR, tool_dir.as_os_str()) @@ -33,7 +33,7 @@ fn tool_run_args() { "); // We don't treat arguments after the command as uv tool run arguments - uv_snapshot!(filters, context.tool_run() + uv_snapshot!(context.filters(), context.tool_run() .arg("pytest") .arg("--help") .env(EnvVars::UV_TOOL_DIR, tool_dir.as_os_str()) @@ -45,7 +45,7 @@ fn tool_run_args() { "); // Can use `--` to separate uv arguments from the command arguments. - uv_snapshot!(filters, context.tool_run() + uv_snapshot!(context.filters(), context.tool_run() .arg("--") .arg("pytest") .arg("--version") @@ -309,12 +309,12 @@ fn tool_run_warn_executable_not_in_from() { let tool_dir = context.temp_dir.child("tools"); let bin_dir = context.temp_dir.child("bin"); - let mut filters = context.filters(); - filters.push(("\\+ uvloop(.+)\n ", "")); - // Strip off the `fastapi` command output. - filters.push(("(?s)fastapi` instead.*", "fastapi` instead.")); + let context = context + .with_filter(("\\+ uvloop(.+)\n ", "")) + // Strip off the `fastapi` command output. + .with_filter(("(?s)fastapi` instead.*", "fastapi` instead.")); - uv_snapshot!(filters, context.tool_run() + uv_snapshot!(context.filters(), context.tool_run() .arg("--from") .arg("fastapi") .arg("fastapi") @@ -1113,14 +1113,14 @@ fn tool_run_git_lfs() { // calls to `git` and `git_metadata` functions which don't have guaranteed execution order. // In addition, we can get different error codes depending on where the failure occurs, // although we know the error code cannot be 0. - let mut filters = context.filters(); - filters.push((r"exit_code: -?[1-9]\d*", "exit_code: [ERROR_CODE]")); - filters.push(( - "(?s)(----- stderr -----).*?The source distribution `[^`]+` is missing Git LFS artifacts.*", - "$1\n[PREFIX]The source distribution `[DISTRIBUTION]` is missing Git LFS artifacts", - )); + let context = context + .with_filter((r"exit_code: -?[1-9]\d*", "exit_code: [ERROR_CODE]")) + .with_filter(( + "(?s)(----- stderr -----).*?The source distribution `[^`]+` is missing Git LFS artifacts.*", + "$1\n[PREFIX]The source distribution `[DISTRIBUTION]` is missing Git LFS artifacts", + )); - uv_snapshot!(filters, context.tool_run() + uv_snapshot!(context.filters(), context.tool_run() .arg("--lfs") .arg("test-lfs-repo @ git+https://github.com/astral-sh/test-lfs-repo@54e5eebd3c6851b1353fc7b1e5b4eca11e27581c") .env(EnvVars::UV_INTERNAL__TEST_LFS_DISABLED, "1") @@ -1143,7 +1143,7 @@ fn tool_run_git_lfs() { .env(EnvVars::UV_TOOL_DIR, tool_dir.as_os_str()) .env(EnvVars::XDG_BIN_HOME, bin_dir.as_os_str()), @r#" success: false - exit_code: 1 + exit_code: [ERROR_CODE] ----- stdout ----- ----- stderr ----- @@ -1171,7 +1171,7 @@ fn tool_run_git_lfs() { .env(EnvVars::UV_TOOL_DIR, tool_dir.as_os_str()) .env(EnvVars::XDG_BIN_HOME, bin_dir.as_os_str()), @r#" success: false - exit_code: 1 + exit_code: [ERROR_CODE] ----- stdout ----- ----- stderr ----- diff --git a/crates/uv/tests/it/venv.rs b/crates/uv/tests/it/venv.rs index 89e93a402..279afe931 100644 --- a/crates/uv/tests/it/venv.rs +++ b/crates/uv/tests/it/venv.rs @@ -1416,14 +1416,13 @@ fn path_with_trailing_space_gives_proper_error() { // Set a custom cache directory with a trailing space let path_with_trailing_slash = format!("{} ", context.cache_dir.path().display()); - let mut filters = context.filters(); // Windows translates error messages, for example i get: // ": Das System kann den angegebenen Pfad nicht finden. (os error 3)" - filters.push(( + let context = context.with_filter(( r"CACHEDIR.TAG`: .* \(os error 3\)", "CACHEDIR.TAG`: The system cannot find the path specified. (os error 3)", )); - uv_snapshot!(filters, std::process::Command::new(uv_test::get_bin!()) + uv_snapshot!(context.filters(), std::process::Command::new(uv_test::get_bin!()) .arg("venv") .env(EnvVars::UV_CACHE_DIR, path_with_trailing_slash), @r###" success: false