#[cfg(target_os = "macos")]
mod macos;
#[cfg(all(target_family = "unix", not(target_os = "macos")))]
mod unix;
#[cfg(target_os = "windows")]
mod windows;
pub(crate) mod xdg;
use std::{env, path::PathBuf};
#[cfg(target_os = "macos")]
use macos as os;
#[cfg(all(target_family = "unix", not(target_os = "macos")))]
use unix as os;
#[cfg(target_os = "windows")]
use windows as os;
pub fn bin_home() -> Option<PathBuf> {
os::bin_home()
}
pub fn cache_home() -> Option<PathBuf> {
os::cache_home()
}
pub fn config_home() -> Option<PathBuf> {
os::config_home()
}
pub fn config_local() -> Option<PathBuf> {
os::config_local()
}
pub fn data_home() -> Option<PathBuf> {
os::data_home()
}
pub fn data_local() -> Option<PathBuf> {
os::data_local()
}
pub fn desktop() -> Option<PathBuf> {
os::desktop()
}
pub fn documents() -> Option<PathBuf> {
os::documents()
}
pub fn downloads() -> Option<PathBuf> {
os::downloads()
}
pub fn fonts() -> Option<PathBuf> {
os::fonts()
}
pub fn home() -> Option<PathBuf> {
env::home_dir()
}
pub fn music() -> Option<PathBuf> {
os::music()
}
pub fn pictures() -> Option<PathBuf> {
os::pictures()
}
pub fn preferences() -> Option<PathBuf> {
os::preferences()
}
pub fn publicshare() -> Option<PathBuf> {
os::publicshare()
}
pub fn runtime() -> Option<PathBuf> {
os::runtime()
}
pub fn state_home() -> Option<PathBuf> {
os::state_home()
}
pub fn templates() -> Option<PathBuf> {
os::templates()
}
pub fn videos() -> Option<PathBuf> {
os::videos()
}
pub fn xdg_bin_home_or(default: impl Into<PathBuf>) -> PathBuf {
xdg::resolve_path(xdg::BIN_HOME).unwrap_or_else(|| default.into())
}
pub fn xdg_cache_home_or(default: impl Into<PathBuf>) -> PathBuf {
xdg::resolve_path(xdg::CACHE_HOME).unwrap_or_else(|| default.into())
}
pub fn xdg_config_home_or(default: impl Into<PathBuf>) -> PathBuf {
xdg::resolve_path(xdg::CONFIG_HOME).unwrap_or_else(|| default.into())
}
pub fn xdg_data_home_or(default: impl Into<PathBuf>) -> PathBuf {
xdg::resolve_path(xdg::DATA_HOME).unwrap_or_else(|| default.into())
}
pub fn xdg_desktop_dir_or(default: impl Into<PathBuf>) -> PathBuf {
xdg::resolve_path(xdg::DESKTOP_DIR).unwrap_or_else(|| default.into())
}
pub fn xdg_documents_dir_or(default: impl Into<PathBuf>) -> PathBuf {
xdg::resolve_path(xdg::DOCUMENTS_DIR).unwrap_or_else(|| default.into())
}
pub fn xdg_download_dir_or(default: impl Into<PathBuf>) -> PathBuf {
xdg::resolve_path(xdg::DOWNLOAD_DIR).unwrap_or_else(|| default.into())
}
pub fn xdg_music_dir_or(default: impl Into<PathBuf>) -> PathBuf {
xdg::resolve_path(xdg::MUSIC_DIR).unwrap_or_else(|| default.into())
}
pub fn xdg_pictures_dir_or(default: impl Into<PathBuf>) -> PathBuf {
xdg::resolve_path(xdg::PICTURES_DIR).unwrap_or_else(|| default.into())
}
pub fn xdg_publicshare_dir_or(default: impl Into<PathBuf>) -> PathBuf {
xdg::resolve_path(xdg::PUBLICSHARE_DIR).unwrap_or_else(|| default.into())
}
pub fn xdg_runtime_dir_or(default: impl Into<PathBuf>) -> PathBuf {
xdg::resolve_path(xdg::RUNTIME_DIR).unwrap_or_else(|| default.into())
}
pub fn xdg_state_home_or(default: impl Into<PathBuf>) -> PathBuf {
xdg::resolve_path(xdg::STATE_HOME).unwrap_or_else(|| default.into())
}
pub fn xdg_templates_dir_or(default: impl Into<PathBuf>) -> PathBuf {
xdg::resolve_path(xdg::TEMPLATES_DIR).unwrap_or_else(|| default.into())
}
pub fn xdg_videos_dir_or(default: impl Into<PathBuf>) -> PathBuf {
xdg::resolve_path(xdg::VIDEOS_DIR).unwrap_or_else(|| default.into())
}
#[cfg(test)]
mod tests {
use super::*;
mod bin_home {
use temp_env::{with_var, with_var_unset};
use super::*;
#[test]
fn respects_xdg_bin_home() {
let test_path = if cfg!(windows) { "C:\\test\\bin" } else { "/test/bin" };
with_var("XDG_BIN_HOME", Some(test_path), || {
let result = bin_home();
assert_eq!(result, Some(PathBuf::from(test_path)));
});
}
#[test]
fn ignores_relative_xdg_bin_home() {
with_var("XDG_BIN_HOME", Some("relative/bin"), || {
let result = bin_home();
if let Some(path) = result {
assert!(path.is_absolute());
}
});
}
#[test]
fn uses_platform_default_when_xdg_unset() {
with_var_unset("XDG_BIN_HOME", || {
let result = bin_home();
if let Some(bin_path) = result {
assert!(bin_path.is_absolute());
#[cfg(any(target_os = "linux", target_os = "macos"))]
assert!(bin_path.to_string_lossy().ends_with(".local/bin"));
#[cfg(target_os = "windows")]
assert!(bin_path.to_string_lossy().contains("Programs"));
}
});
}
}
mod cache_home {
use temp_env::{with_var, with_var_unset};
use super::*;
#[test]
fn respects_xdg_cache_home() {
let test_path = if cfg!(windows) {
"C:\\test\\cache"
} else {
"/test/cache"
};
with_var("XDG_CACHE_HOME", Some(test_path), || {
let result = cache_home();
assert_eq!(result, Some(PathBuf::from(test_path)));
});
}
#[test]
fn ignores_relative_xdg_cache_home() {
with_var("XDG_CACHE_HOME", Some("relative/cache"), || {
let result = cache_home();
if let Some(path) = result {
assert!(path.is_absolute());
}
});
}
#[test]
fn uses_platform_default_when_xdg_unset() {
with_var_unset("XDG_CACHE_HOME", || {
let result = cache_home();
if let Some(cache_path) = result {
assert!(cache_path.is_absolute());
#[cfg(target_os = "linux")]
assert!(cache_path.to_string_lossy().ends_with(".cache"));
#[cfg(target_os = "macos")]
assert!(cache_path.to_string_lossy().contains("Library/Caches"));
#[cfg(target_os = "windows")]
{
if let Ok(localappdata) = env::var("LOCALAPPDATA") {
assert_eq!(cache_path, PathBuf::from(localappdata));
}
}
}
});
}
}
mod config_home {
use temp_env::{with_var, with_var_unset};
use super::*;
#[test]
fn respects_xdg_config_home() {
let test_path = if cfg!(windows) {
"C:\\test\\config"
} else {
"/test/config"
};
with_var("XDG_CONFIG_HOME", Some(test_path), || {
let result = config_home();
assert_eq!(result, Some(PathBuf::from(test_path)));
});
}
#[test]
fn ignores_relative_xdg_config_home() {
with_var("XDG_CONFIG_HOME", Some("relative/config"), || {
let result = config_home();
if let Some(path) = result {
assert!(path.is_absolute());
}
});
}
#[test]
fn uses_platform_default_when_xdg_unset() {
with_var_unset("XDG_CONFIG_HOME", || {
let result = config_home();
if let Some(config_path) = result {
assert!(config_path.is_absolute());
#[cfg(target_os = "linux")]
assert!(config_path.to_string_lossy().ends_with(".config"));
#[cfg(target_os = "macos")]
assert!(config_path.to_string_lossy().contains("Library/Application Support"));
#[cfg(target_os = "windows")]
{
if let Ok(appdata) = env::var("APPDATA") {
assert_eq!(config_path, PathBuf::from(appdata));
}
}
}
});
}
}
mod config_local {
use super::*;
#[test]
fn uses_localappdata_on_windows() {
let result = config_local();
if let Some(config_local_path) = result {
assert!(config_local_path.is_absolute());
#[cfg(target_os = "windows")]
{
if let Ok(localappdata) = env::var("LOCALAPPDATA") {
assert_eq!(config_local_path, PathBuf::from(localappdata));
}
}
#[cfg(not(target_os = "windows"))]
{
assert_eq!(Some(config_local_path), config_home());
}
}
}
#[test]
fn matches_config_home_on_non_windows() {
#[cfg(not(target_os = "windows"))]
{
let config_local = config_local();
let config_home = config_home();
assert_eq!(config_local, config_home);
}
}
}
mod data_home {
use temp_env::{with_var, with_var_unset};
use super::*;
#[test]
fn respects_xdg_data_home() {
let test_path = if cfg!(windows) { "C:\\test\\data" } else { "/test/data" };
with_var("XDG_DATA_HOME", Some(test_path), || {
let result = data_home();
assert_eq!(result, Some(PathBuf::from(test_path)));
});
}
#[test]
fn ignores_relative_xdg_data_home() {
with_var("XDG_DATA_HOME", Some("relative/data"), || {
let result = data_home();
if let Some(path) = result {
assert!(path.is_absolute());
}
});
}
#[test]
fn uses_platform_default_when_xdg_unset() {
with_var_unset("XDG_DATA_HOME", || {
let result = data_home();
if let Some(data_path) = result {
assert!(data_path.is_absolute());
#[cfg(target_os = "linux")]
assert!(data_path.to_string_lossy().ends_with(".local/share"));
#[cfg(target_os = "macos")]
assert!(data_path.to_string_lossy().contains("Library/Application Support"));
#[cfg(target_os = "windows")]
{
if let Ok(appdata) = env::var("APPDATA") {
assert_eq!(data_path, PathBuf::from(appdata));
}
}
}
});
}
}
mod data_local {
use super::*;
#[test]
fn uses_localappdata_on_windows() {
let result = data_local();
if let Some(data_local_path) = result {
assert!(data_local_path.is_absolute());
#[cfg(target_os = "windows")]
{
if let Ok(localappdata) = env::var("LOCALAPPDATA") {
assert_eq!(data_local_path, PathBuf::from(localappdata));
}
}
#[cfg(not(target_os = "windows"))]
{
assert_eq!(Some(data_local_path), data_home());
}
}
}
#[test]
fn matches_data_home_on_non_windows() {
#[cfg(not(target_os = "windows"))]
{
let data_local = data_local();
let data_home = data_home();
assert_eq!(data_local, data_home);
}
}
}
mod desktop {
use temp_env::{with_var, with_var_unset};
use super::*;
#[test]
fn respects_xdg_desktop_dir() {
let test_path = if cfg!(windows) {
"C:\\test\\desktop"
} else {
"/test/desktop"
};
with_var("XDG_DESKTOP_DIR", Some(test_path), || {
let result = desktop();
assert_eq!(result, Some(PathBuf::from(test_path)));
});
}
#[test]
fn ignores_relative_xdg_desktop_dir() {
with_var("XDG_DESKTOP_DIR", Some("relative/desktop"), || {
let result = desktop();
if let Some(path) = result {
assert!(path.is_absolute());
}
});
}
#[test]
fn uses_platform_default_when_xdg_unset() {
with_var_unset("XDG_DESKTOP_DIR", || {
let result = desktop();
if let Some(desktop_path) = result {
assert!(desktop_path.is_absolute());
assert!(desktop_path.to_string_lossy().ends_with("Desktop"));
}
});
}
}
mod documents {
use temp_env::{with_var, with_var_unset};
use super::*;
#[test]
fn respects_xdg_documents_dir() {
let test_path = if cfg!(windows) {
"C:\\test\\documents"
} else {
"/test/documents"
};
with_var("XDG_DOCUMENTS_DIR", Some(test_path), || {
let result = documents();
assert_eq!(result, Some(PathBuf::from(test_path)));
});
}
#[test]
fn ignores_relative_xdg_documents_dir() {
with_var("XDG_DOCUMENTS_DIR", Some("relative/documents"), || {
let result = documents();
if let Some(path) = result {
assert!(path.is_absolute());
}
});
}
#[test]
fn uses_platform_default_when_xdg_unset() {
with_var_unset("XDG_DOCUMENTS_DIR", || {
let result = documents();
if let Some(documents_path) = result {
assert!(documents_path.is_absolute());
assert!(documents_path.to_string_lossy().ends_with("Documents"));
}
});
}
}
mod downloads {
use temp_env::{with_var, with_var_unset};
use super::*;
#[test]
fn respects_xdg_download_dir() {
let test_path = if cfg!(windows) {
"C:\\test\\downloads"
} else {
"/test/downloads"
};
with_var("XDG_DOWNLOAD_DIR", Some(test_path), || {
let result = downloads();
assert_eq!(result, Some(PathBuf::from(test_path)));
});
}
#[test]
fn ignores_relative_xdg_download_dir() {
with_var("XDG_DOWNLOAD_DIR", Some("relative/downloads"), || {
let result = downloads();
if let Some(path) = result {
assert!(path.is_absolute());
}
});
}
#[test]
fn uses_platform_default_when_xdg_unset() {
with_var_unset("XDG_DOWNLOAD_DIR", || {
let result = downloads();
if let Some(downloads_path) = result {
assert!(downloads_path.is_absolute());
assert!(downloads_path.to_string_lossy().ends_with("Downloads"));
}
});
}
}
mod fonts {
use super::*;
#[test]
fn returns_platform_specific_path() {
let result = fonts();
#[cfg(target_os = "linux")]
if let Some(fonts_path) = result {
assert!(fonts_path.is_absolute());
assert!(fonts_path.to_string_lossy().ends_with(".local/share/fonts"));
}
#[cfg(target_os = "macos")]
if let Some(fonts_path) = result {
assert!(fonts_path.is_absolute());
assert!(fonts_path.to_string_lossy().ends_with("Library/Fonts"));
}
#[cfg(target_os = "windows")]
assert_eq!(result, None);
}
#[test]
fn returns_none_on_windows() {
#[cfg(target_os = "windows")]
{
let result = fonts();
assert_eq!(result, None);
}
}
#[test]
fn returns_some_on_unix() {
#[cfg(any(target_os = "linux", target_os = "macos"))]
{
let result = fonts();
assert!(result.is_some());
if let Some(path) = result {
assert!(path.is_absolute());
}
}
}
}
mod home {
use super::*;
#[test]
fn returns_absolute_path_when_available() {
let result = home();
if let Some(home_path) = result {
assert!(home_path.is_absolute());
}
}
#[test]
fn delegates_to_std_env_home_dir() {
let std_result = std::env::home_dir();
let our_result = home();
assert_eq!(std_result, our_result);
}
}
mod music {
use temp_env::{with_var, with_var_unset};
use super::*;
#[test]
fn respects_xdg_music_dir() {
let test_path = if cfg!(windows) {
"C:\\test\\music"
} else {
"/test/music"
};
with_var("XDG_MUSIC_DIR", Some(test_path), || {
let result = music();
assert_eq!(result, Some(PathBuf::from(test_path)));
});
}
#[test]
fn ignores_relative_xdg_music_dir() {
with_var("XDG_MUSIC_DIR", Some("relative/music"), || {
let result = music();
if let Some(path) = result {
assert!(path.is_absolute());
}
});
}
#[test]
fn uses_platform_default_when_xdg_unset() {
with_var_unset("XDG_MUSIC_DIR", || {
let result = music();
if let Some(music_path) = result {
assert!(music_path.is_absolute());
assert!(music_path.to_string_lossy().ends_with("Music"));
}
});
}
}
mod pictures {
use temp_env::{with_var, with_var_unset};
use super::*;
#[test]
fn respects_xdg_pictures_dir() {
let test_path = if cfg!(windows) {
"C:\\test\\pictures"
} else {
"/test/pictures"
};
with_var("XDG_PICTURES_DIR", Some(test_path), || {
let result = pictures();
assert_eq!(result, Some(PathBuf::from(test_path)));
});
}
#[test]
fn ignores_relative_xdg_pictures_dir() {
with_var("XDG_PICTURES_DIR", Some("relative/pictures"), || {
let result = pictures();
if let Some(path) = result {
assert!(path.is_absolute());
}
});
}
#[test]
fn uses_platform_default_when_xdg_unset() {
with_var_unset("XDG_PICTURES_DIR", || {
let result = pictures();
if let Some(pictures_path) = result {
assert!(pictures_path.is_absolute());
assert!(pictures_path.to_string_lossy().ends_with("Pictures"));
}
});
}
}
mod preferences {
use super::*;
#[test]
fn returns_platform_specific_path() {
let result = preferences();
if let Some(preferences_path) = result {
assert!(preferences_path.is_absolute());
#[cfg(target_os = "macos")]
assert!(preferences_path.to_string_lossy().ends_with("Library/Preferences"));
#[cfg(not(target_os = "macos"))]
assert_eq!(Some(preferences_path), config_home());
}
}
#[test]
fn matches_config_home_on_non_macos() {
#[cfg(not(target_os = "macos"))]
{
let preferences = preferences();
let config_home = config_home();
assert_eq!(preferences, config_home);
}
}
#[test]
fn uses_library_preferences_on_macos() {
#[cfg(target_os = "macos")]
{
let result = preferences();
if let Some(path) = result {
assert!(path.to_string_lossy().ends_with("Library/Preferences"));
}
}
}
}
mod publicshare {
use temp_env::{with_var, with_var_unset};
use super::*;
#[test]
fn respects_xdg_publicshare_dir() {
let test_path = if cfg!(windows) {
"C:\\test\\public"
} else {
"/test/public"
};
with_var("XDG_PUBLICSHARE_DIR", Some(test_path), || {
let result = publicshare();
assert_eq!(result, Some(PathBuf::from(test_path)));
});
}
#[test]
fn ignores_relative_xdg_publicshare_dir() {
with_var("XDG_PUBLICSHARE_DIR", Some("relative/public"), || {
let result = publicshare();
if let Some(path) = result {
assert!(path.is_absolute());
}
});
}
#[test]
fn uses_platform_default_when_xdg_unset() {
with_var_unset("XDG_PUBLICSHARE_DIR", || {
let result = publicshare();
if let Some(public_path) = result {
assert!(public_path.is_absolute());
#[cfg(target_os = "windows")]
assert_eq!(public_path, PathBuf::from("C:\\Users\\Public"));
#[cfg(any(target_os = "linux", target_os = "macos"))]
assert!(public_path.to_string_lossy().ends_with("Public"));
}
});
}
#[test]
fn uses_system_public_on_windows() {
#[cfg(target_os = "windows")]
{
with_var_unset("XDG_PUBLICSHARE_DIR", || {
let result = publicshare();
assert_eq!(result, Some(PathBuf::from("C:\\Users\\Public")));
});
}
}
}
mod runtime {
use temp_env::{with_var, with_var_unset};
use super::*;
#[test]
fn respects_xdg_runtime_dir() {
let test_path = if cfg!(windows) {
"C:\\test\\runtime"
} else {
"/test/runtime"
};
with_var("XDG_RUNTIME_DIR", Some(test_path), || {
let result = runtime();
assert_eq!(result, Some(PathBuf::from(test_path)));
});
}
#[test]
fn ignores_relative_xdg_runtime_dir() {
with_var("XDG_RUNTIME_DIR", Some("relative/runtime"), || {
let result = runtime();
if let Some(path) = result {
assert!(path.is_absolute());
}
});
}
#[test]
fn uses_platform_default_when_xdg_unset() {
with_var_unset("XDG_RUNTIME_DIR", || {
let result = runtime();
if let Some(runtime_path) = result {
assert!(runtime_path.is_absolute());
#[cfg(any(target_os = "linux", target_os = "macos"))]
{
let path_str = runtime_path.to_string_lossy();
assert!(path_str.contains("tmp") || path_str.starts_with("/var/folders"));
}
#[cfg(target_os = "windows")]
{
if let Ok(temp) = env::var("TEMP") {
assert_eq!(runtime_path, PathBuf::from(temp));
}
}
}
});
}
#[test]
fn falls_back_to_tmp_on_unix() {
#[cfg(any(target_os = "linux", target_os = "macos"))]
{
with_var_unset("XDG_RUNTIME_DIR", || {
with_var_unset("TMPDIR", || {
let result = runtime();
assert_eq!(result, Some(PathBuf::from("/tmp")));
});
});
}
}
}
mod state_home {
use temp_env::{with_var, with_var_unset};
use super::*;
#[test]
fn respects_xdg_state_home() {
let test_path = if cfg!(windows) {
"C:\\test\\state"
} else {
"/test/state"
};
with_var("XDG_STATE_HOME", Some(test_path), || {
let result = state_home();
assert_eq!(result, Some(PathBuf::from(test_path)));
});
}
#[test]
fn ignores_relative_xdg_state_home() {
with_var("XDG_STATE_HOME", Some("relative/state"), || {
let result = state_home();
if let Some(path) = result {
assert!(path.is_absolute());
}
});
}
#[test]
fn uses_platform_default_when_xdg_unset() {
with_var_unset("XDG_STATE_HOME", || {
let result = state_home();
if let Some(state_path) = result {
assert!(state_path.is_absolute());
#[cfg(target_os = "linux")]
assert!(state_path.to_string_lossy().ends_with(".local/state"));
#[cfg(target_os = "macos")]
assert!(state_path.to_string_lossy().contains("Library/Application Support"));
#[cfg(target_os = "windows")]
{
if let Ok(localappdata) = env::var("LOCALAPPDATA") {
assert_eq!(state_path, PathBuf::from(localappdata));
}
}
}
});
}
}
mod templates {
use temp_env::{with_var, with_var_unset};
use super::*;
#[test]
fn respects_xdg_templates_dir() {
let test_path = if cfg!(windows) {
"C:\\test\\templates"
} else {
"/test/templates"
};
with_var("XDG_TEMPLATES_DIR", Some(test_path), || {
let result = templates();
assert_eq!(result, Some(PathBuf::from(test_path)));
});
}
#[test]
fn ignores_relative_xdg_templates_dir() {
with_var("XDG_TEMPLATES_DIR", Some("relative/templates"), || {
let result = templates();
if let Some(path) = result {
assert!(path.is_absolute());
}
});
}
#[test]
fn uses_platform_default_when_xdg_unset() {
with_var_unset("XDG_TEMPLATES_DIR", || {
let result = templates();
if let Some(templates_path) = result {
assert!(templates_path.is_absolute());
assert!(templates_path.to_string_lossy().ends_with("Templates"));
}
});
}
}
mod videos {
use temp_env::{with_var, with_var_unset};
use super::*;
#[test]
fn respects_xdg_videos_dir() {
let test_path = if cfg!(windows) {
"C:\\test\\videos"
} else {
"/test/videos"
};
with_var("XDG_VIDEOS_DIR", Some(test_path), || {
let result = videos();
assert_eq!(result, Some(PathBuf::from(test_path)));
});
}
#[test]
fn ignores_relative_xdg_videos_dir() {
with_var("XDG_VIDEOS_DIR", Some("relative/videos"), || {
let result = videos();
if let Some(path) = result {
assert!(path.is_absolute());
}
});
}
#[test]
fn uses_platform_default_when_xdg_unset() {
with_var_unset("XDG_VIDEOS_DIR", || {
let result = videos();
if let Some(videos_path) = result {
assert!(videos_path.is_absolute());
#[cfg(target_os = "linux")]
assert!(videos_path.to_string_lossy().ends_with("Videos"));
#[cfg(target_os = "macos")]
assert!(videos_path.to_string_lossy().ends_with("Movies"));
#[cfg(target_os = "windows")]
assert!(videos_path.to_string_lossy().ends_with("Videos"));
}
});
}
}
macro_rules! xdg_or_tests {
($mod_name:ident, $fn_name:ident, $xdg_var:expr) => {
mod $mod_name {
use temp_env::{with_var, with_var_unset};
use super::*;
#[test]
fn returns_xdg_value_when_set() {
let test_path = if cfg!(windows) {
"C:\\test\\xdg_or"
} else {
"/test/xdg_or"
};
with_var($xdg_var, Some(test_path), || {
let result = $fn_name(PathBuf::from("/fallback"));
assert_eq!(result, PathBuf::from(test_path));
});
}
#[test]
fn returns_default_when_xdg_unset() {
let fallback = if cfg!(windows) {
"C:\\fallback"
} else {
"/fallback"
};
with_var_unset($xdg_var, || {
let result = $fn_name(fallback);
assert_eq!(result, PathBuf::from(fallback));
});
}
#[test]
fn returns_default_when_xdg_relative() {
let fallback = if cfg!(windows) {
"C:\\fallback"
} else {
"/fallback"
};
with_var($xdg_var, Some("relative/path"), || {
let result = $fn_name(fallback);
assert_eq!(result, PathBuf::from(fallback));
});
}
}
};
}
xdg_or_tests!(xdg_bin_home_or, xdg_bin_home_or, "XDG_BIN_HOME");
xdg_or_tests!(xdg_cache_home_or, xdg_cache_home_or, "XDG_CACHE_HOME");
xdg_or_tests!(xdg_config_home_or, xdg_config_home_or, "XDG_CONFIG_HOME");
xdg_or_tests!(xdg_data_home_or, xdg_data_home_or, "XDG_DATA_HOME");
xdg_or_tests!(xdg_desktop_dir_or, xdg_desktop_dir_or, "XDG_DESKTOP_DIR");
xdg_or_tests!(xdg_documents_dir_or, xdg_documents_dir_or, "XDG_DOCUMENTS_DIR");
xdg_or_tests!(xdg_download_dir_or, xdg_download_dir_or, "XDG_DOWNLOAD_DIR");
xdg_or_tests!(xdg_music_dir_or, xdg_music_dir_or, "XDG_MUSIC_DIR");
xdg_or_tests!(xdg_pictures_dir_or, xdg_pictures_dir_or, "XDG_PICTURES_DIR");
xdg_or_tests!(xdg_publicshare_dir_or, xdg_publicshare_dir_or, "XDG_PUBLICSHARE_DIR");
xdg_or_tests!(xdg_runtime_dir_or, xdg_runtime_dir_or, "XDG_RUNTIME_DIR");
xdg_or_tests!(xdg_state_home_or, xdg_state_home_or, "XDG_STATE_HOME");
xdg_or_tests!(xdg_templates_dir_or, xdg_templates_dir_or, "XDG_TEMPLATES_DIR");
xdg_or_tests!(xdg_videos_dir_or, xdg_videos_dir_or, "XDG_VIDEOS_DIR");
}