]> git.proxmox.com Git - cargo.git/commitdiff
Only normalize paths on windows.
authorEric Huss <eric@huss.org>
Wed, 16 Jun 2021 17:28:43 +0000 (10:28 -0700)
committerEric Huss <eric@huss.org>
Wed, 16 Jun 2021 17:35:26 +0000 (10:35 -0700)
I don't trust that all these transformations won't have unintended
consequences on other platforms. It is nice to verify there aren't any
backslash shenanigans on other platforms.

crates/cargo-test-support/src/compare.rs
tests/testsuite/bad_config.rs
tests/testsuite/cargo_config.rs

index 3032319c07b211f443b7bf7a5fe8eb07d14b1898..bd62e79b768c778725106bbf2aefb7f386c0e100 100644 (file)
@@ -44,19 +44,32 @@ fn normalize_actual(actual: &str, cwd: Option<&Path>) -> String {
     // It's easier to read tabs in outputs if they don't show up as literal
     // hidden characters
     let actual = actual.replace('\t', "<tab>");
-    // Let's not deal with \r\n vs \n on windows...
-    let actual = actual.replace('\r', "");
-    normalize_common(&actual, cwd)
+    if cfg!(windows) {
+        // Let's not deal with \r\n vs \n on windows...
+        let actual = actual.replace('\r', "");
+        normalize_windows(&actual, cwd)
+    } else {
+        actual
+    }
 }
 
 /// Normalizes the expected string so that it can be compared against the actual output.
 fn normalize_expected(expected: &str, cwd: Option<&Path>) -> String {
     let expected = substitute_macros(expected);
-    normalize_common(&expected, cwd)
+    if cfg!(windows) {
+        normalize_windows(&expected, cwd)
+    } else {
+        let expected = match cwd {
+            None => expected,
+            Some(cwd) => expected.replace("[CWD]", &cwd.display().to_string()),
+        };
+        let expected = expected.replace("[ROOT]", &paths::root().display().to_string());
+        expected
+    }
 }
 
-/// Normalizes text for both actual and expected strings.
-fn normalize_common(text: &str, cwd: Option<&Path>) -> String {
+/// Normalizes text for both actual and expected strings on Windows.
+fn normalize_windows(text: &str, cwd: Option<&Path>) -> String {
     // Let's not deal with / vs \ (windows...)
     let text = text.replace('\\', "/");
 
index a8aacc737c13252dc4d3e6deec05c651abeb1256..be242bff22b78211c2b0de32f0a63422e197dee5 100644 (file)
@@ -1391,16 +1391,16 @@ fn bad_target_cfg() {
         .with_stderr(
             "\
 [ERROR] error in [..]/foo/.cargo/config: \
-could not load config key `target.\"cfg(not(target_os = /\"none/\"))\".runner`
+could not load config key `target.\"cfg(not(target_os = \\\"none\\\"))\".runner`
 
 Caused by:
   error in [..]/foo/.cargo/config: \
-  could not load config key `target.\"cfg(not(target_os = /\"none/\"))\".runner`
+  could not load config key `target.\"cfg(not(target_os = \\\"none\\\"))\".runner`
 
 Caused by:
-  invalid configuration for key `target.\"cfg(not(target_os = /\"none/\"))\".runner`
+  invalid configuration for key `target.\"cfg(not(target_os = \\\"none\\\"))\".runner`
   expected a string or array of strings, but found a boolean for \
-  `target.\"cfg(not(target_os = /\"none/\"))\".runner` in [..]/foo/.cargo/config
+  `target.\"cfg(not(target_os = \\\"none\\\"))\".runner` in [..]/foo/.cargo/config
 ",
         )
         .run();
index e130080097da7d3c0112833f08a890337a48a76c..a11e9afc58fb89c4c904a341a5a3a3d721c17a65 100644 (file)
@@ -86,7 +86,7 @@ build.rustflags = [\"--flag-directory\", \"--flag-global\"]
 extra-table.somekey = \"somevalue\"
 profile.dev.opt-level = 3
 profile.dev.package.foo.opt-level = 1
-target.\"cfg(target_os = /\"linux/\")\".runner = \"runme\"
+target.\"cfg(target_os = \\\"linux\\\")\".runner = \"runme\"
 # The following environment variables may affect the loaded values.
 # CARGO_ALIAS_BAR=[..]cat dog[..]
 # CARGO_BUILD_JOBS=100
@@ -263,7 +263,7 @@ build.rustflags = [
 extra-table.somekey = \"somevalue\" # [ROOT]/home/.cargo/config.toml
 profile.dev.opt-level = 3 # [ROOT]/home/.cargo/config.toml
 profile.dev.package.foo.opt-level = 1 # [ROOT]/home/.cargo/config.toml
-target.\"cfg(target_os = /\"linux/\")\".runner = \"runme\" # [ROOT]/home/.cargo/config.toml
+target.\"cfg(target_os = \\\"linux\\\")\".runner = \"runme\" # [ROOT]/home/.cargo/config.toml
 # The following environment variables may affect the loaded values.
 # CARGO_HOME=[ROOT]/home/.cargo
 ",
@@ -359,7 +359,7 @@ build.rustflags = [\"--flag-global\"]
 extra-table.somekey = \"somevalue\"
 profile.dev.opt-level = 3
 profile.dev.package.foo.opt-level = 1
-target.\"cfg(target_os = /\"linux/\")\".runner = \"runme\"
+target.\"cfg(target_os = \\\"linux\\\")\".runner = \"runme\"
 
 ",
         )
@@ -513,7 +513,7 @@ build.rustflags = [\"--flag-global\"]
 extra-table.somekey = \"somevalue\"
 profile.dev.opt-level = 3
 profile.dev.package.foo.opt-level = 1
-target.\"cfg(target_os = /\"linux/\")\".runner = \"runme\"
+target.\"cfg(target_os = \\\"linux\\\")\".runner = \"runme\"
 
 ",
         )