runtime_environment/
lib.rs

1use std::env;
2
3pub fn is_mac_os() -> bool {
4    env::consts::OS == "macos"
5}
6
7pub fn is_windows() -> bool {
8    env::consts::OS == "windows"
9}
10
11pub fn is_linux() -> bool {
12    env::consts::OS == "linux"
13}
14
15#[cfg(test)]
16mod tests {
17    use super::*;
18
19    #[test]
20    fn test_is_mac_os() {
21        if cfg!(target_os = "macos") {
22            assert!(is_mac_os());
23        } else {
24            assert!(!is_mac_os());
25        }
26    }
27
28    #[test]
29    fn test_is_windows() {
30        if cfg!(target_os = "windows") {
31            assert!(is_windows());
32        } else {
33            assert!(!is_windows());
34        }
35    }
36
37    #[test]
38    fn test_is_linux() {
39        if cfg!(target_os = "linux") {
40            assert!(is_linux());
41        } else {
42            assert!(!is_linux());
43        }
44    }
45}