Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/crates/bevy_platform/tests/preferences_dir.rs
30635 views
1
//! Tests for [`bevy_platform::dirs::preferences_dir`] with platform-specific behavior.
2
3
#![allow(unsafe_code, reason = "Tests manipulate environment variables.")]
4
5
#[cfg(target_os = "linux")]
6
#[test]
7
fn preferences_dir_follows_xdg() {
8
use bevy_platform::dirs::preferences_dir;
9
use std::env;
10
11
// a default path should be returned when XDG_CONFIG_HOME is not set
12
// SAFETY: no multi-threaded access to the environment
13
// 1. integration tests are a standalone process
14
// 2. we have a single #[test], so no parallel execution
15
unsafe { env::remove_var("XDG_CONFIG_HOME") }
16
let default = preferences_dir().unwrap();
17
18
// the default path should also be returned when XDG_CONFIG_HOME is set but empty
19
// SAFETY: no multi-threaded access to the environment
20
unsafe { env::set_var("XDG_CONFIG_HOME", "") }
21
assert_eq!(preferences_dir(), Some(default.clone()));
22
23
// when set, the path should be returned if it's absolute
24
// SAFETY: no multi-threaded access to the environment
25
unsafe { env::set_var("XDG_CONFIG_HOME", "/tmp") }
26
assert_eq!(preferences_dir(), Some("/tmp".into()));
27
28
// when set to a relative path, it should be ignored and the default path should be returned
29
// SAFETY: no multi-threaded access to the environment
30
unsafe { env::set_var("XDG_CONFIG_HOME", "relative/path") }
31
assert_eq!(preferences_dir(), Some(default));
32
}
33
34