Path: blob/main/crates/bevy_platform/tests/preferences_dir.rs
30635 views
//! Tests for [`bevy_platform::dirs::preferences_dir`] with platform-specific behavior.12#![allow(unsafe_code, reason = "Tests manipulate environment variables.")]34#[cfg(target_os = "linux")]5#[test]6fn preferences_dir_follows_xdg() {7use bevy_platform::dirs::preferences_dir;8use std::env;910// a default path should be returned when XDG_CONFIG_HOME is not set11// SAFETY: no multi-threaded access to the environment12// 1. integration tests are a standalone process13// 2. we have a single #[test], so no parallel execution14unsafe { env::remove_var("XDG_CONFIG_HOME") }15let default = preferences_dir().unwrap();1617// the default path should also be returned when XDG_CONFIG_HOME is set but empty18// SAFETY: no multi-threaded access to the environment19unsafe { env::set_var("XDG_CONFIG_HOME", "") }20assert_eq!(preferences_dir(), Some(default.clone()));2122// when set, the path should be returned if it's absolute23// SAFETY: no multi-threaded access to the environment24unsafe { env::set_var("XDG_CONFIG_HOME", "/tmp") }25assert_eq!(preferences_dir(), Some("/tmp".into()));2627// when set to a relative path, it should be ignored and the default path should be returned28// SAFETY: no multi-threaded access to the environment29unsafe { env::set_var("XDG_CONFIG_HOME", "relative/path") }30assert_eq!(preferences_dir(), Some(default));31}323334