Skip to content

Commit 205148e

Browse files
committed
Only normalize paths on windows.
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.
1 parent aea5ca3 commit 205148e

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

crates/cargo-test-support/src/compare.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,32 @@ fn normalize_actual(actual: &str, cwd: Option<&Path>) -> String {
4444
// It's easier to read tabs in outputs if they don't show up as literal
4545
// hidden characters
4646
let actual = actual.replace('\t', "<tab>");
47-
// Let's not deal with \r\n vs \n on windows...
48-
let actual = actual.replace('\r', "");
49-
normalize_common(&actual, cwd)
47+
if cfg!(windows) {
48+
// Let's not deal with \r\n vs \n on windows...
49+
let actual = actual.replace('\r', "");
50+
normalize_windows(&actual, cwd)
51+
} else {
52+
actual
53+
}
5054
}
5155

5256
/// Normalizes the expected string so that it can be compared against the actual output.
5357
fn normalize_expected(expected: &str, cwd: Option<&Path>) -> String {
5458
let expected = substitute_macros(expected);
55-
normalize_common(&expected, cwd)
59+
if cfg!(windows) {
60+
normalize_windows(&expected, cwd)
61+
} else {
62+
let expected = match cwd {
63+
None => expected,
64+
Some(cwd) => expected.replace("[CWD]", &cwd.display().to_string()),
65+
};
66+
let expected = expected.replace("[ROOT]", &paths::root().display().to_string());
67+
expected
68+
}
5669
}
5770

58-
/// Normalizes text for both actual and expected strings.
59-
fn normalize_common(text: &str, cwd: Option<&Path>) -> String {
71+
/// Normalizes text for both actual and expected strings on Windows.
72+
fn normalize_windows(text: &str, cwd: Option<&Path>) -> String {
6073
// Let's not deal with / vs \ (windows...)
6174
let text = text.replace('\\', "/");
6275

tests/testsuite/bad_config.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,16 +1391,16 @@ fn bad_target_cfg() {
13911391
.with_stderr(
13921392
"\
13931393
[ERROR] error in [..]/foo/.cargo/config: \
1394-
could not load config key `target.\"cfg(not(target_os = /\"none/\"))\".runner`
1394+
could not load config key `target.\"cfg(not(target_os = \\\"none\\\"))\".runner`
13951395
13961396
Caused by:
13971397
error in [..]/foo/.cargo/config: \
1398-
could not load config key `target.\"cfg(not(target_os = /\"none/\"))\".runner`
1398+
could not load config key `target.\"cfg(not(target_os = \\\"none\\\"))\".runner`
13991399
14001400
Caused by:
1401-
invalid configuration for key `target.\"cfg(not(target_os = /\"none/\"))\".runner`
1401+
invalid configuration for key `target.\"cfg(not(target_os = \\\"none\\\"))\".runner`
14021402
expected a string or array of strings, but found a boolean for \
1403-
`target.\"cfg(not(target_os = /\"none/\"))\".runner` in [..]/foo/.cargo/config
1403+
`target.\"cfg(not(target_os = \\\"none\\\"))\".runner` in [..]/foo/.cargo/config
14041404
",
14051405
)
14061406
.run();

tests/testsuite/cargo_config.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ build.rustflags = [\"--flag-directory\", \"--flag-global\"]
8686
extra-table.somekey = \"somevalue\"
8787
profile.dev.opt-level = 3
8888
profile.dev.package.foo.opt-level = 1
89-
target.\"cfg(target_os = /\"linux/\")\".runner = \"runme\"
89+
target.\"cfg(target_os = \\\"linux\\\")\".runner = \"runme\"
9090
# The following environment variables may affect the loaded values.
9191
# CARGO_ALIAS_BAR=[..]cat dog[..]
9292
# CARGO_BUILD_JOBS=100
@@ -263,7 +263,7 @@ build.rustflags = [
263263
extra-table.somekey = \"somevalue\" # [ROOT]/home/.cargo/config.toml
264264
profile.dev.opt-level = 3 # [ROOT]/home/.cargo/config.toml
265265
profile.dev.package.foo.opt-level = 1 # [ROOT]/home/.cargo/config.toml
266-
target.\"cfg(target_os = /\"linux/\")\".runner = \"runme\" # [ROOT]/home/.cargo/config.toml
266+
target.\"cfg(target_os = \\\"linux\\\")\".runner = \"runme\" # [ROOT]/home/.cargo/config.toml
267267
# The following environment variables may affect the loaded values.
268268
# CARGO_HOME=[ROOT]/home/.cargo
269269
",
@@ -359,7 +359,7 @@ build.rustflags = [\"--flag-global\"]
359359
extra-table.somekey = \"somevalue\"
360360
profile.dev.opt-level = 3
361361
profile.dev.package.foo.opt-level = 1
362-
target.\"cfg(target_os = /\"linux/\")\".runner = \"runme\"
362+
target.\"cfg(target_os = \\\"linux\\\")\".runner = \"runme\"
363363
364364
",
365365
)
@@ -513,7 +513,7 @@ build.rustflags = [\"--flag-global\"]
513513
extra-table.somekey = \"somevalue\"
514514
profile.dev.opt-level = 3
515515
profile.dev.package.foo.opt-level = 1
516-
target.\"cfg(target_os = /\"linux/\")\".runner = \"runme\"
516+
target.\"cfg(target_os = \\\"linux\\\")\".runner = \"runme\"
517517
518518
",
519519
)

0 commit comments

Comments
 (0)