mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 21:35:00 +00:00
Ignore UV_CACHE_DIR
in help
tests (#7895)
This commit is contained in:
parent
ad638d7fa3
commit
ff1a896dd0
5 changed files with 41 additions and 25 deletions
|
@ -16,5 +16,8 @@ indent_size = 4
|
|||
[*.snap]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[crates/uv/tests/help.rs]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[*.md]
|
||||
max_line_length = 100
|
||||
|
|
18
.github/workflows/ci.yml
vendored
18
.github/workflows/ci.yml
vendored
|
@ -173,11 +173,12 @@ jobs:
|
|||
- name: "Install Rust toolchain"
|
||||
run: rustup show
|
||||
|
||||
- uses: astral-sh/setup-uv@v3
|
||||
with:
|
||||
version: "latest"
|
||||
enable-cache: true
|
||||
- name: "Install required Python versions"
|
||||
run: |
|
||||
# astral-sh/setup-uv sets `UV_CACHE_DIR` which disrupts the help message check
|
||||
curl -LsSf https://astral.sh/uv/install.sh | sh
|
||||
uv python install
|
||||
run: uv python install
|
||||
|
||||
- name: "Install cargo nextest"
|
||||
uses: taiki-e/install-action@v2
|
||||
|
@ -221,11 +222,12 @@ jobs:
|
|||
- name: "Install Rust toolchain"
|
||||
run: rustup show
|
||||
|
||||
- uses: astral-sh/setup-uv@v3
|
||||
with:
|
||||
version: "latest"
|
||||
enable-cache: true
|
||||
- name: "Install required Python versions"
|
||||
run: |
|
||||
# astral-sh/setup-uv sets `UV_CACHE_DIR` which disrupts the help message check
|
||||
curl -LsSf https://astral.sh/uv/install.sh | sh
|
||||
uv python install
|
||||
run: uv python install
|
||||
|
||||
- name: "Install cargo nextest"
|
||||
uses: taiki-e/install-action@v2
|
||||
|
|
|
@ -194,6 +194,20 @@ impl TestContext {
|
|||
self
|
||||
}
|
||||
|
||||
/// Ignore `UV_CACHE_DIR` env variable in tests.
|
||||
#[must_use]
|
||||
pub fn with_ignore_cache_dir(mut self) -> Self {
|
||||
self.filters.push((
|
||||
r"\[env:[\n\s]* UV_CACHE_DIR=.+\]".to_string(),
|
||||
"[env: UV_CACHE_DIR=]".to_string(),
|
||||
));
|
||||
// When `--cache-dir` is followed with other options,
|
||||
// remove it from the text. Since its presence is inconsistent.
|
||||
self.filters
|
||||
.push((r"--cache-dir <CACHE_DIR> <".to_string(), "<".to_string()));
|
||||
self
|
||||
}
|
||||
|
||||
/// Discover the path to the XDG state directory. We use this, rather than the OS-specific
|
||||
/// temporary directory, because on macOS (and Windows on GitHub Actions), they involve
|
||||
/// symlinks. (On macOS, the temporary directory is, like `/var/...`, which resolves to
|
||||
|
|
|
@ -4,7 +4,7 @@ mod common;
|
|||
|
||||
#[test]
|
||||
fn help() {
|
||||
let context = TestContext::new_with_versions(&[]);
|
||||
let context = TestContext::new_with_versions(&[]).with_ignore_cache_dir();
|
||||
|
||||
// The `uv help` command should show the long help message
|
||||
uv_snapshot!(context.filters(), context.help(), @r###"
|
||||
|
@ -74,7 +74,8 @@ fn help() {
|
|||
|
||||
#[test]
|
||||
fn help_flag() {
|
||||
let context = TestContext::new_with_versions(&[]);
|
||||
let context = TestContext::new_with_versions(&[]).with_ignore_cache_dir();
|
||||
|
||||
uv_snapshot!(context.filters(), context.command().arg("--help"), @r###"
|
||||
success: true
|
||||
exit_code: 0
|
||||
|
@ -140,7 +141,8 @@ fn help_flag() {
|
|||
|
||||
#[test]
|
||||
fn help_short_flag() {
|
||||
let context = TestContext::new_with_versions(&[]);
|
||||
let context = TestContext::new_with_versions(&[]).with_ignore_cache_dir();
|
||||
|
||||
uv_snapshot!(context.filters(), context.command().arg("-h"), @r###"
|
||||
success: true
|
||||
exit_code: 0
|
||||
|
@ -206,7 +208,7 @@ fn help_short_flag() {
|
|||
|
||||
#[test]
|
||||
fn help_subcommand() {
|
||||
let context = TestContext::new_with_versions(&[]);
|
||||
let context = TestContext::new_with_versions(&[]).with_ignore_cache_dir();
|
||||
|
||||
uv_snapshot!(context.filters(), context.help().arg("python"), @r###"
|
||||
success: true
|
||||
|
@ -394,7 +396,7 @@ fn help_subcommand() {
|
|||
|
||||
#[test]
|
||||
fn help_subsubcommand() {
|
||||
let context = TestContext::new_with_versions(&[]);
|
||||
let context = TestContext::new_with_versions(&[]).with_ignore_cache_dir();
|
||||
|
||||
uv_snapshot!(context.filters(), context.help().arg("python").arg("install"), @r###"
|
||||
success: true
|
||||
|
@ -562,7 +564,7 @@ fn help_subsubcommand() {
|
|||
|
||||
#[test]
|
||||
fn help_flag_subcommand() {
|
||||
let context = TestContext::new_with_versions(&[]);
|
||||
let context = TestContext::new_with_versions(&[]).with_ignore_cache_dir();
|
||||
|
||||
uv_snapshot!(context.filters(), context.command().arg("python").arg("--help"), @r###"
|
||||
success: true
|
||||
|
@ -618,7 +620,7 @@ fn help_flag_subcommand() {
|
|||
|
||||
#[test]
|
||||
fn help_flag_subsubcommand() {
|
||||
let context = TestContext::new_with_versions(&[]);
|
||||
let context = TestContext::new_with_versions(&[]).with_ignore_cache_dir();
|
||||
|
||||
uv_snapshot!(context.filters(), context.command().arg("python").arg("install").arg("--help"), @r###"
|
||||
success: true
|
||||
|
@ -747,7 +749,7 @@ fn help_unknown_subsubcommand() {
|
|||
|
||||
#[test]
|
||||
fn help_with_global_option() {
|
||||
let context = TestContext::new_with_versions(&[]);
|
||||
let context = TestContext::new_with_versions(&[]).with_ignore_cache_dir();
|
||||
|
||||
uv_snapshot!(context.filters(), context.help().arg("--no-cache"), @r###"
|
||||
success: true
|
||||
|
@ -849,7 +851,7 @@ fn help_with_version() {
|
|||
|
||||
#[test]
|
||||
fn help_with_no_pager() {
|
||||
let context = TestContext::new_with_versions(&[]);
|
||||
let context = TestContext::new_with_versions(&[]).with_ignore_cache_dir();
|
||||
|
||||
// We can't really test whether the --no-pager option works with a snapshot test.
|
||||
// It's still nice to have a test for the option to confirm the option exists.
|
||||
|
|
|
@ -12,13 +12,10 @@ use crate::common::{get_bin, venv_to_interpreter, TestContext};
|
|||
mod common;
|
||||
|
||||
#[test]
|
||||
fn no_arguments() -> Result<()> {
|
||||
let temp_dir = assert_fs::TempDir::new()?;
|
||||
fn no_arguments() {
|
||||
let context = TestContext::new_with_versions(&[]).with_ignore_cache_dir();
|
||||
|
||||
uv_snapshot!(Command::new(get_bin())
|
||||
.arg("pip")
|
||||
.arg("uninstall")
|
||||
.current_dir(&temp_dir), @r###"
|
||||
uv_snapshot!(context.filters(), context.pip_uninstall(), @r###"
|
||||
success: false
|
||||
exit_code: 2
|
||||
----- stdout -----
|
||||
|
@ -32,8 +29,6 @@ fn no_arguments() -> Result<()> {
|
|||
For more information, try '--help'.
|
||||
"###
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue