about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-12-26 10:52:56 +0000
committerbors <bors@rust-lang.org>2016-12-26 10:52:56 +0000
commit8493dbed6c29b30844830d6e50a33493c6ea70af (patch)
tree34379f5a01301433027a70ed831e167000e59a36 /src/libstd
parent5752eae5f5ce3517d36f6668619dd2c70e6d2d88 (diff)
parent23cfcddd775e5e4b3888033b65d90a0f6c4c3506 (diff)
downloadrust-8493dbed6c29b30844830d6e50a33493c6ea70af.tar.gz
rust-8493dbed6c29b30844830d6e50a33493c6ea70af.zip
Auto merge of #38536 - retep998:flauschige-kaninchen, r=petrochenkov
Fix fs tests on Windows systems with non-english locales.

Fixes https://github.com/rust-lang/rust/issues/34628

r? @alexcrichton
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/fs.rs45
1 files changed, 25 insertions, 20 deletions
diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs
index 6d4d02caa0b..41934dc057e 100644
--- a/src/libstd/fs.rs
+++ b/src/libstd/fs.rs
@@ -1799,6 +1799,16 @@ mod tests {
         }
     ) }
 
+    #[cfg(windows)]
+    macro_rules! error { ($e:expr, $s:expr) => (
+        match $e {
+            Ok(_) => panic!("Unexpected success. Should've been: {:?}", $s),
+            Err(ref err) => assert!(err.raw_os_error() == Some($s),
+                                    format!("`{}` did not have a code of `{}`", err, $s))
+        }
+    ) }
+
+    #[cfg(unix)]
     macro_rules! error { ($e:expr, $s:expr) => (
         match $e {
             Ok(_) => panic!("Unexpected success. Should've been: {:?}", $s),
@@ -1819,12 +1829,9 @@ mod tests {
 
         match symlink_file(r"nonexisting_target", link) {
             Ok(_) => true,
-            Err(ref err) =>
-                if err.to_string().contains("A required privilege is not held by the client.") {
-                    false
-                } else {
-                    true
-                }
+            // ERROR_PRIVILEGE_NOT_HELD = 1314
+            Err(ref err) if err.raw_os_error() == Some(1314) => false,
+            Err(_) => true,
         }
     }
 
@@ -1855,12 +1862,10 @@ mod tests {
         let filename = &tmpdir.join("file_that_does_not_exist.txt");
         let result = File::open(filename);
 
-        if cfg!(unix) {
-            error!(result, "No such file or directory");
-        }
-        if cfg!(windows) {
-            error!(result, "The system cannot find the file specified");
-        }
+        #[cfg(unix)]
+        error!(result, "No such file or directory");
+        #[cfg(windows)]
+        error!(result, 2); // ERROR_FILE_NOT_FOUND
     }
 
     #[test]
@@ -1870,12 +1875,10 @@ mod tests {
 
         let result = fs::remove_file(filename);
 
-        if cfg!(unix) {
-            error!(result, "No such file or directory");
-        }
-        if cfg!(windows) {
-            error!(result, "The system cannot find the file specified");
-        }
+        #[cfg(unix)]
+        error!(result, "No such file or directory");
+        #[cfg(windows)]
+        error!(result, 2); // ERROR_FILE_NOT_FOUND
     }
 
     #[test]
@@ -2630,8 +2633,10 @@ mod tests {
         let mut a = OO::new(); a.append(true);
         let mut ra = OO::new(); ra.read(true).append(true);
 
-        let invalid_options = if cfg!(windows) { "The parameter is incorrect" }
-                              else { "Invalid argument" };
+        #[cfg(windows)]
+        let invalid_options = 87; // ERROR_INVALID_PARAMETER
+        #[cfg(unix)]
+        let invalid_options = "Invalid argument";
 
         // Test various combinations of creation modes and access modes.
         //