Skip to content

Commit

Permalink
A confirming test (should revert after test passed)
Browse files Browse the repository at this point in the history
  • Loading branch information
j178 committed Oct 9, 2024
1 parent 319b3b4 commit df5066d
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 2 deletions.
42 changes: 41 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/uv-cache/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::ffi::c_float;
use std::io;
use std::path::{Path, PathBuf};

Expand Down
4 changes: 4 additions & 0 deletions crates/uv-tool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ thiserror = { workspace = true }
toml = { workspace = true }
toml_edit = { workspace = true }
tracing = { workspace = true }

[dev-dependencies]
directories = "5.0.1"
dirs-sys = "0.4.1"
82 changes: 82 additions & 0 deletions crates/uv-tool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,3 +458,85 @@ pub fn entrypoint_paths(

Ok(entrypoints)
}

#[cfg(test)]
mod tests {
use etcetera::BaseStrategy;
use std::path::PathBuf;

fn dirs_before() -> (PathBuf, PathBuf, PathBuf, PathBuf) {
let data_dir = directories::ProjectDirs::from("", "", "uv")
.unwrap()
.data_dir()
.to_path_buf();

let cache_dir = directories::ProjectDirs::from("", "", "uv")
.unwrap()
.cache_dir()
.to_path_buf();

let config_dir = {
// On Windows, use, e.g., C:\Users\Alice\AppData\Roaming
#[cfg(windows)]
{
dirs_sys::known_folder_roaming_app_data()
}
// On Linux and macOS, use, e.g., /home/alice/.config.
#[cfg(not(windows))]
{
std::env::var_os("XDG_CONFIG_HOME")
.and_then(dirs_sys::is_absolute_path)
.or_else(|| dirs_sys::home_dir().map(|path| path.join(".config")))
}
};

let home_dir = {
#[cfg(windows)]
{
dirs_sys::known_folder_profile()
}
#[cfg(not(windows))]
{
dirs_sys::home_dir()
}
};

(data_dir, cache_dir, config_dir.unwrap(), home_dir.unwrap())
}

fn dirs_after() -> (PathBuf, PathBuf, PathBuf, PathBuf) {
let data_dir = etcetera::base_strategy::choose_native_strategy()
.unwrap()
.data_dir()
.join("uv");
let data_dir = if cfg!(windows) {
data_dir.join("data")
} else {
data_dir
};

let cache_dir = etcetera::base_strategy::choose_native_strategy()
.unwrap()
.cache_dir()
.join("uv");
let cache_dir = if cfg!(windows) {
cache_dir.join("cache")
} else {
cache_dir
};

let config_dir = etcetera::base_strategy::choose_base_strategy()
.unwrap()
.config_dir();
let home_dir = etcetera::home_dir().unwrap();

(data_dir, cache_dir, config_dir, home_dir)
}

#[test]
fn ensure_directory_not_changed() {
let before = dirs_before();
let after = dirs_after();
assert_eq!(before, after);
}
}

0 comments on commit df5066d

Please sign in to comment.