Skip to content

Commit 8493dbe

Browse files
committed
Auto merge of #38536 - retep998:flauschige-kaninchen, r=petrochenkov
Fix fs tests on Windows systems with non-english locales. Fixes #34628 r? @alexcrichton
2 parents 5752eae + 23cfcdd commit 8493dbe

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

src/libstd/fs.rs

+25-20
Original file line numberDiff line numberDiff line change
@@ -1799,6 +1799,16 @@ mod tests {
17991799
}
18001800
) }
18011801

1802+
#[cfg(windows)]
1803+
macro_rules! error { ($e:expr, $s:expr) => (
1804+
match $e {
1805+
Ok(_) => panic!("Unexpected success. Should've been: {:?}", $s),
1806+
Err(ref err) => assert!(err.raw_os_error() == Some($s),
1807+
format!("`{}` did not have a code of `{}`", err, $s))
1808+
}
1809+
) }
1810+
1811+
#[cfg(unix)]
18021812
macro_rules! error { ($e:expr, $s:expr) => (
18031813
match $e {
18041814
Ok(_) => panic!("Unexpected success. Should've been: {:?}", $s),
@@ -1819,12 +1829,9 @@ mod tests {
18191829

18201830
match symlink_file(r"nonexisting_target", link) {
18211831
Ok(_) => true,
1822-
Err(ref err) =>
1823-
if err.to_string().contains("A required privilege is not held by the client.") {
1824-
false
1825-
} else {
1826-
true
1827-
}
1832+
// ERROR_PRIVILEGE_NOT_HELD = 1314
1833+
Err(ref err) if err.raw_os_error() == Some(1314) => false,
1834+
Err(_) => true,
18281835
}
18291836
}
18301837

@@ -1855,12 +1862,10 @@ mod tests {
18551862
let filename = &tmpdir.join("file_that_does_not_exist.txt");
18561863
let result = File::open(filename);
18571864

1858-
if cfg!(unix) {
1859-
error!(result, "No such file or directory");
1860-
}
1861-
if cfg!(windows) {
1862-
error!(result, "The system cannot find the file specified");
1863-
}
1865+
#[cfg(unix)]
1866+
error!(result, "No such file or directory");
1867+
#[cfg(windows)]
1868+
error!(result, 2); // ERROR_FILE_NOT_FOUND
18641869
}
18651870

18661871
#[test]
@@ -1870,12 +1875,10 @@ mod tests {
18701875

18711876
let result = fs::remove_file(filename);
18721877

1873-
if cfg!(unix) {
1874-
error!(result, "No such file or directory");
1875-
}
1876-
if cfg!(windows) {
1877-
error!(result, "The system cannot find the file specified");
1878-
}
1878+
#[cfg(unix)]
1879+
error!(result, "No such file or directory");
1880+
#[cfg(windows)]
1881+
error!(result, 2); // ERROR_FILE_NOT_FOUND
18791882
}
18801883

18811884
#[test]
@@ -2630,8 +2633,10 @@ mod tests {
26302633
let mut a = OO::new(); a.append(true);
26312634
let mut ra = OO::new(); ra.read(true).append(true);
26322635

2633-
let invalid_options = if cfg!(windows) { "The parameter is incorrect" }
2634-
else { "Invalid argument" };
2636+
#[cfg(windows)]
2637+
let invalid_options = 87; // ERROR_INVALID_PARAMETER
2638+
#[cfg(unix)]
2639+
let invalid_options = "Invalid argument";
26352640

26362641
// Test various combinations of creation modes and access modes.
26372642
//

0 commit comments

Comments
 (0)