Remove the double-backslash escape for matching.

Using `with_json` is safer since it knows what JSON escaping is.
This commit is contained in:
Eric Huss 2021-06-16 09:41:38 -07:00
parent b73e3d4fa5
commit aea5ca3ca0
4 changed files with 13 additions and 29 deletions

View file

@ -58,9 +58,7 @@ fn normalize_expected(expected: &str, cwd: Option<&Path>) -> String {
/// Normalizes text for both actual and expected strings.
fn normalize_common(text: &str, cwd: Option<&Path>) -> String {
// Let's not deal with / vs \ (windows...)
// First replace backslash-escaped backslashes with forward slashes
// which can occur in, for example, JSON output
let text = text.replace("\\\\", "/").replace('\\', "/");
let text = text.replace('\\', "/");
// Weirdness for paths on Windows extends beyond `/` vs `\` apparently.
// Namely paths like `c:\` and `C:\` are equivalent and that can cause

View file

@ -313,7 +313,7 @@ fn cargo_subcommand_args() {
r#"
fn main() {
let args: Vec<_> = ::std::env::args().collect();
println!("{:?}", args);
println!("{}", args.join(" "));
}
"#,
)
@ -329,9 +329,7 @@ fn cargo_subcommand_args() {
cargo_process("foo bar -v --help")
.env("PATH", &path)
.with_stdout(
r#"["[CWD]/cargo-foo/target/debug/cargo-foo[EXE]", "foo", "bar", "-v", "--help"]"#,
)
.with_stdout("[CWD]/cargo-foo/target/debug/cargo-foo[EXE] foo bar -v --help")
.run();
}

View file

@ -5,28 +5,22 @@ use cargo_test_support::project;
#[cargo_test]
fn simple() {
let p = project().build();
let root_manifest_path = p.root().join("Cargo.toml");
p.cargo("locate-project")
.with_stdout(format!(
r#"{{"root":"{}"}}"#,
root_manifest_path.to_str().unwrap()
))
.with_json(r#"{"root": "[ROOT]/foo/Cargo.toml"}"#)
.run();
}
#[cargo_test]
fn message_format() {
let p = project().build();
let root_manifest_path = p.root().join("Cargo.toml");
let root_str = root_manifest_path.to_str().unwrap();
p.cargo("locate-project --message-format plain")
.with_stdout(root_str)
.with_stdout("[ROOT]/foo/Cargo.toml")
.run();
p.cargo("locate-project --message-format json")
.with_stdout(format!(r#"{{"root":"{}"}}"#, root_str))
.with_json(r#"{"root": "[ROOT]/foo/Cargo.toml"}"#)
.run();
p.cargo("locate-project --message-format cryptic")
@ -61,28 +55,22 @@ fn workspace() {
.file("inner/src/lib.rs", "")
.build();
let outer_manifest = format!(
r#"{{"root":"{}"}}"#,
p.root().join("Cargo.toml").to_str().unwrap(),
);
let inner_manifest = format!(
r#"{{"root":"{}"}}"#,
p.root().join("inner").join("Cargo.toml").to_str().unwrap(),
);
let outer_manifest = r#"{"root": "[ROOT]/foo/Cargo.toml"}"#;
let inner_manifest = r#"{"root": "[ROOT]/foo/inner/Cargo.toml"}"#;
p.cargo("locate-project").with_stdout(&outer_manifest).run();
p.cargo("locate-project").with_json(outer_manifest).run();
p.cargo("locate-project")
.cwd("inner")
.with_stdout(&inner_manifest)
.with_json(inner_manifest)
.run();
p.cargo("locate-project --workspace")
.with_stdout(&outer_manifest)
.with_json(outer_manifest)
.run();
p.cargo("locate-project --workspace")
.cwd("inner")
.with_stdout(&outer_manifest)
.with_json(outer_manifest)
.run();
}

View file

@ -68,6 +68,6 @@ fn cargo_verify_project_honours_unstable_features() {
p.cargo("verify-project")
.with_status(1)
.with_stdout(r#"{"invalid":"failed to parse manifest at `[CWD]/Cargo.toml`"}"#)
.with_json(r#"{"invalid":"failed to parse manifest at `[CWD]/Cargo.toml`"}"#)
.run();
}