All checks were successful
CI / Check / Test (push) Successful in 3m40s
Co-authored-by: Copilot <copilot@github.com>
118 lines
2.9 KiB
Rust
118 lines
2.9 KiB
Rust
mod common;
|
|
|
|
use assets::{Platform, config_path};
|
|
use common::{env_of, path};
|
|
|
|
#[test]
|
|
fn xdg_prefers_config_home() {
|
|
let env = env_of(&[("XDG_CONFIG_HOME", "/xdg"), ("HOME", "/home/user")]);
|
|
|
|
assert_eq!(
|
|
config_path(Platform::Xdg, env),
|
|
path("/xdg/dvd-thing/logo.png")
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn xdg_falls_back_to_home_dot_config() {
|
|
let env = env_of(&[("HOME", "/home/user")]);
|
|
|
|
assert_eq!(
|
|
config_path(Platform::Xdg, env),
|
|
path("/home/user/.config/dvd-thing/logo.png")
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn xdg_ignores_a_relative_config_home() {
|
|
let env = env_of(&[("XDG_CONFIG_HOME", "relative/dir"), ("HOME", "/home/user")]);
|
|
|
|
assert_eq!(
|
|
config_path(Platform::Xdg, env),
|
|
path("/home/user/.config/dvd-thing/logo.png")
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn macos_uses_application_support() {
|
|
let env = env_of(&[("HOME", "/Users/gabriel")]);
|
|
|
|
assert_eq!(
|
|
config_path(Platform::MacOs, env),
|
|
path("/Users/gabriel/Library/Application Support/dvd-thing/logo.png")
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn macos_still_honours_an_explicit_xdg_config_home() {
|
|
let env = env_of(&[("XDG_CONFIG_HOME", "/Users/gabriel/.config")]);
|
|
|
|
assert_eq!(
|
|
config_path(Platform::MacOs, env),
|
|
path("/Users/gabriel/.config/dvd-thing/logo.png")
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn windows_prefers_appdata() {
|
|
let env = env_of(&[
|
|
("APPDATA", r"C:\Users\gabriel\AppData\Roaming"),
|
|
("USERPROFILE", r"C:\Users\gabriel"),
|
|
]);
|
|
|
|
assert_eq!(
|
|
config_path(Platform::Windows, env),
|
|
path(r"C:\Users\gabriel\AppData\Roaming/dvd-thing/logo.png")
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn windows_falls_back_to_user_profile() {
|
|
let env = env_of(&[("USERPROFILE", r"C:\Users\gabriel")]);
|
|
|
|
assert_eq!(
|
|
config_path(Platform::Windows, env),
|
|
path(r"C:\Users\gabriel/AppData/Roaming/dvd-thing/logo.png")
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn windows_ignores_unix_variables() {
|
|
let env = env_of(&[("HOME", "/home/user"), ("XDG_CONFIG_HOME", "/xdg")]);
|
|
|
|
assert_eq!(config_path(Platform::Windows, env), None);
|
|
}
|
|
|
|
#[test]
|
|
fn an_empty_environment_yields_no_path() {
|
|
for platform in [Platform::Xdg, Platform::MacOs, Platform::Windows] {
|
|
assert_eq!(config_path(platform, env_of(&[])), None);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn an_empty_variable_counts_as_unset() {
|
|
let env = env_of(&[("XDG_CONFIG_HOME", ""), ("HOME", "/home/user")]);
|
|
|
|
assert_eq!(
|
|
config_path(Platform::Xdg, env),
|
|
path("/home/user/.config/dvd-thing/logo.png")
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn an_empty_home_does_not_produce_a_relative_path() {
|
|
assert_eq!(config_path(Platform::Xdg, env_of(&[("HOME", "")])), None);
|
|
assert_eq!(config_path(Platform::MacOs, env_of(&[("HOME", "")])), None);
|
|
}
|
|
|
|
#[test]
|
|
fn an_empty_appdata_falls_back_to_user_profile() {
|
|
let env = env_of(&[("APPDATA", ""), ("USERPROFILE", r"C:\Users\gabriel")]);
|
|
|
|
assert_eq!(
|
|
config_path(Platform::Windows, env),
|
|
path(r"C:\Users\gabriel/AppData/Roaming/dvd-thing/logo.png")
|
|
);
|
|
}
|