1 use super::*;
2 
3 use crate::path::Path;
4 
5 #[test]
6 #[cfg_attr(any(target_os = "emscripten", target_env = "sgx"), ignore)]
test_self_exe_path()7 fn test_self_exe_path() {
8     let path = current_exe();
9     assert!(path.is_ok());
10     let path = path.unwrap();
11 
12     // Hard to test this function
13     assert!(path.is_absolute());
14 }
15 
16 #[test]
test()17 fn test() {
18     assert!((!Path::new("test-path").is_absolute()));
19 
20     #[cfg(not(target_env = "sgx"))]
21     current_dir().unwrap();
22 }
23 
24 #[test]
25 #[cfg(windows)]
split_paths_windows()26 fn split_paths_windows() {
27     use crate::path::PathBuf;
28 
29     fn check_parse(unparsed: &str, parsed: &[&str]) -> bool {
30         split_paths(unparsed).collect::<Vec<_>>()
31             == parsed.iter().map(|s| PathBuf::from(*s)).collect::<Vec<_>>()
32     }
33 
34     assert!(check_parse("", &mut [""]));
35     assert!(check_parse(r#""""#, &mut [""]));
36     assert!(check_parse(";;", &mut ["", "", ""]));
37     assert!(check_parse(r"c:\", &mut [r"c:\"]));
38     assert!(check_parse(r"c:\;", &mut [r"c:\", ""]));
39     assert!(check_parse(r"c:\;c:\Program Files\", &mut [r"c:\", r"c:\Program Files\"]));
40     assert!(check_parse(r#"c:\;c:\"foo"\"#, &mut [r"c:\", r"c:\foo\"]));
41     assert!(check_parse(r#"c:\;c:\"foo;bar"\;c:\baz"#, &mut [r"c:\", r"c:\foo;bar\", r"c:\baz"]));
42 }
43 
44 #[test]
45 #[cfg(unix)]
split_paths_unix()46 fn split_paths_unix() {
47     use crate::path::PathBuf;
48 
49     fn check_parse(unparsed: &str, parsed: &[&str]) -> bool {
50         split_paths(unparsed).collect::<Vec<_>>()
51             == parsed.iter().map(|s| PathBuf::from(*s)).collect::<Vec<_>>()
52     }
53 
54     assert!(check_parse("", &mut [""]));
55     assert!(check_parse("::", &mut ["", "", ""]));
56     assert!(check_parse("/", &mut ["/"]));
57     assert!(check_parse("/:", &mut ["/", ""]));
58     assert!(check_parse("/:/usr/local", &mut ["/", "/usr/local"]));
59 }
60 
61 #[test]
62 #[cfg(unix)]
join_paths_unix()63 fn join_paths_unix() {
64     use crate::ffi::OsStr;
65 
66     fn test_eq(input: &[&str], output: &str) -> bool {
67         &*join_paths(input.iter().cloned()).unwrap() == OsStr::new(output)
68     }
69 
70     assert!(test_eq(&[], ""));
71     assert!(test_eq(&["/bin", "/usr/bin", "/usr/local/bin"], "/bin:/usr/bin:/usr/local/bin"));
72     assert!(test_eq(&["", "/bin", "", "", "/usr/bin", ""], ":/bin:::/usr/bin:"));
73     assert!(join_paths(["/te:st"].iter().cloned()).is_err());
74 }
75 
76 #[test]
77 #[cfg(windows)]
join_paths_windows()78 fn join_paths_windows() {
79     use crate::ffi::OsStr;
80 
81     fn test_eq(input: &[&str], output: &str) -> bool {
82         &*join_paths(input.iter().cloned()).unwrap() == OsStr::new(output)
83     }
84 
85     assert!(test_eq(&[], ""));
86     assert!(test_eq(&[r"c:\windows", r"c:\"], r"c:\windows;c:\"));
87     assert!(test_eq(&["", r"c:\windows", "", "", r"c:\", ""], r";c:\windows;;;c:\;"));
88     assert!(test_eq(&[r"c:\te;st", r"c:\"], r#""c:\te;st";c:\"#));
89     assert!(join_paths([r#"c:\te"st"#].iter().cloned()).is_err());
90 }
91 
92 #[test]
args_debug()93 fn args_debug() {
94     assert_eq!(
95         format!("Args {{ inner: {:?} }}", args().collect::<Vec<_>>()),
96         format!("{:?}", args())
97     );
98     assert_eq!(
99         format!("ArgsOs {{ inner: {:?} }}", args_os().collect::<Vec<_>>()),
100         format!("{:?}", args_os())
101     );
102 }
103