mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
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.
This commit is contained in:
parent
aea5ca3ca0
commit
205148e645
@ -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>");
|
||||
if cfg!(windows) {
|
||||
// Let's not deal with \r\n vs \n on windows...
|
||||
let actual = actual.replace('\r', "");
|
||||
normalize_common(&actual, cwd)
|
||||
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('\\', "/");
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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\"
|
||||
|
||||
",
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user