diff --git a/crates/cargo-test-support/src/compare.rs b/crates/cargo-test-support/src/compare.rs index 3032319c0..bd62e79b7 100644 --- a/crates/cargo-test-support/src/compare.rs +++ b/crates/cargo-test-support/src/compare.rs @@ -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', ""); - // 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('\\', "/"); diff --git a/tests/testsuite/bad_config.rs b/tests/testsuite/bad_config.rs index a8aacc737..be242bff2 100644 --- a/tests/testsuite/bad_config.rs +++ b/tests/testsuite/bad_config.rs @@ -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(); diff --git a/tests/testsuite/cargo_config.rs b/tests/testsuite/cargo_config.rs index e13008009..a11e9afc5 100644 --- a/tests/testsuite/cargo_config.rs +++ b/tests/testsuite/cargo_config.rs @@ -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\" ", )