Skip to content

Commit aea5ca3

Browse files
committed
Remove the double-backslash escape for matching.
Using `with_json` is safer since it knows what JSON escaping is.
1 parent b73e3d4 commit aea5ca3

File tree

4 files changed

+13
-29
lines changed

4 files changed

+13
-29
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ fn normalize_expected(expected: &str, cwd: Option<&Path>) -> String {
5858
/// Normalizes text for both actual and expected strings.
5959
fn normalize_common(text: &str, cwd: Option<&Path>) -> String {
6060
// Let's not deal with / vs \ (windows...)
61-
// First replace backslash-escaped backslashes with forward slashes
62-
// which can occur in, for example, JSON output
63-
let text = text.replace("\\\\", "/").replace('\\', "/");
61+
let text = text.replace('\\', "/");
6462

6563
// Weirdness for paths on Windows extends beyond `/` vs `\` apparently.
6664
// Namely paths like `c:\` and `C:\` are equivalent and that can cause

tests/testsuite/cargo_command.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ fn cargo_subcommand_args() {
313313
r#"
314314
fn main() {
315315
let args: Vec<_> = ::std::env::args().collect();
316-
println!("{:?}", args);
316+
println!("{}", args.join(" "));
317317
}
318318
"#,
319319
)
@@ -329,9 +329,7 @@ fn cargo_subcommand_args() {
329329

330330
cargo_process("foo bar -v --help")
331331
.env("PATH", &path)
332-
.with_stdout(
333-
r#"["[CWD]/cargo-foo/target/debug/cargo-foo[EXE]", "foo", "bar", "-v", "--help"]"#,
334-
)
332+
.with_stdout("[CWD]/cargo-foo/target/debug/cargo-foo[EXE] foo bar -v --help")
335333
.run();
336334
}
337335

tests/testsuite/locate_project.rs

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,22 @@ use cargo_test_support::project;
55
#[cargo_test]
66
fn simple() {
77
let p = project().build();
8-
let root_manifest_path = p.root().join("Cargo.toml");
98

109
p.cargo("locate-project")
11-
.with_stdout(format!(
12-
r#"{{"root":"{}"}}"#,
13-
root_manifest_path.to_str().unwrap()
14-
))
10+
.with_json(r#"{"root": "[ROOT]/foo/Cargo.toml"}"#)
1511
.run();
1612
}
1713

1814
#[cargo_test]
1915
fn message_format() {
2016
let p = project().build();
21-
let root_manifest_path = p.root().join("Cargo.toml");
22-
let root_str = root_manifest_path.to_str().unwrap();
2317

2418
p.cargo("locate-project --message-format plain")
25-
.with_stdout(root_str)
19+
.with_stdout("[ROOT]/foo/Cargo.toml")
2620
.run();
2721

2822
p.cargo("locate-project --message-format json")
29-
.with_stdout(format!(r#"{{"root":"{}"}}"#, root_str))
23+
.with_json(r#"{"root": "[ROOT]/foo/Cargo.toml"}"#)
3024
.run();
3125

3226
p.cargo("locate-project --message-format cryptic")
@@ -61,28 +55,22 @@ fn workspace() {
6155
.file("inner/src/lib.rs", "")
6256
.build();
6357

64-
let outer_manifest = format!(
65-
r#"{{"root":"{}"}}"#,
66-
p.root().join("Cargo.toml").to_str().unwrap(),
67-
);
68-
let inner_manifest = format!(
69-
r#"{{"root":"{}"}}"#,
70-
p.root().join("inner").join("Cargo.toml").to_str().unwrap(),
71-
);
58+
let outer_manifest = r#"{"root": "[ROOT]/foo/Cargo.toml"}"#;
59+
let inner_manifest = r#"{"root": "[ROOT]/foo/inner/Cargo.toml"}"#;
7260

73-
p.cargo("locate-project").with_stdout(&outer_manifest).run();
61+
p.cargo("locate-project").with_json(outer_manifest).run();
7462

7563
p.cargo("locate-project")
7664
.cwd("inner")
77-
.with_stdout(&inner_manifest)
65+
.with_json(inner_manifest)
7866
.run();
7967

8068
p.cargo("locate-project --workspace")
81-
.with_stdout(&outer_manifest)
69+
.with_json(outer_manifest)
8270
.run();
8371

8472
p.cargo("locate-project --workspace")
8573
.cwd("inner")
86-
.with_stdout(&outer_manifest)
74+
.with_json(outer_manifest)
8775
.run();
8876
}

tests/testsuite/verify_project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@ fn cargo_verify_project_honours_unstable_features() {
6868

6969
p.cargo("verify-project")
7070
.with_status(1)
71-
.with_stdout(r#"{"invalid":"failed to parse manifest at `[CWD]/Cargo.toml`"}"#)
71+
.with_json(r#"{"invalid":"failed to parse manifest at `[CWD]/Cargo.toml`"}"#)
7272
.run();
7373
}

0 commit comments

Comments
 (0)