Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Migrate some json tests to snapbox #14293

Merged
merged 10 commits into from
Jul 24, 2024
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ sha1 = "0.10.6"
sha2 = "0.10.8"
shell-escape = "0.1.5"
supports-hyperlinks = "3.0.0"
snapbox = { version = "0.6.9", features = ["diff", "dir", "term-svg", "regex", "json"] }
snapbox = { version = "0.6.14", features = ["diff", "dir", "term-svg", "regex", "json"] }
tar = { version = "0.4.40", default-features = false }
tempfile = "3.10.1"
thiserror = "1.0.59"
Expand Down
4 changes: 3 additions & 1 deletion crates/cargo-test-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,9 @@ impl Execs {
/// - The order of arrays is ignored.
/// - Strings support patterns described in [`compare`].
/// - Use `"{...}"` to match any object.
#[deprecated(note = "replaced with `Execs::with_stdout_data(expected.json_lines())`")]
#[deprecated(
note = "replaced with `Execs::with_stdout_data(expected.is_json().against_jsonlines())`"
)]
pub fn with_json(&mut self, expected: &str) -> &mut Self {
self.expect_json = Some(expected.to_string());
self
Expand Down
6 changes: 3 additions & 3 deletions tests/testsuite/alt_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ fn alt_reg_metadata() {
"workspace_root": "[ROOT]/foo"
}
"#]]
.json(),
.is_json(),
)
.run();

Expand Down Expand Up @@ -1353,7 +1353,7 @@ fn alt_reg_metadata() {
"workspace_root": "[ROOT]/foo"
}
"#]]
.json(),
.is_json(),
)
.run();
}
Expand Down Expand Up @@ -1615,7 +1615,7 @@ fn unknown_registry() {
"workspace_root": "[ROOT]/foo"
}
"#]]
.json(),
.is_json(),
)
.run();
}
Expand Down
40 changes: 28 additions & 12 deletions tests/testsuite/bad_manifest_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,14 @@ fn verify_project_dir_containing_cargo_toml() {
.with_status(1)
.with_stdout_data(
str![[r#"
{"invalid":"the manifest-path must be a path to a Cargo.toml file"}

[
{
"invalid": "the manifest-path must be a path to a Cargo.toml file"
}
]
"#]]
.json_lines(),
.is_json()
.against_jsonlines(),
)
.run();
}
Expand All @@ -351,10 +355,14 @@ fn verify_project_dir_plus_file() {
.with_status(1)
.with_stdout_data(
str![[r#"
{"invalid":"the manifest-path must be a path to a Cargo.toml file"}

[
{
"invalid": "the manifest-path must be a path to a Cargo.toml file"
}
]
"#]]
.json_lines(),
.is_json()
.against_jsonlines(),
)
.run();
}
Expand All @@ -371,10 +379,14 @@ fn verify_project_dir_plus_path() {
.with_status(1)
.with_stdout_data(
str![[r#"
{"invalid":"the manifest-path must be a path to a Cargo.toml file"}

[
{
"invalid": "the manifest-path must be a path to a Cargo.toml file"
}
]
"#]]
.json_lines(),
.is_json()
.against_jsonlines(),
)
.run();
}
Expand All @@ -387,10 +399,14 @@ fn verify_project_dir_to_nonexistent_cargo_toml() {
.with_status(1)
.with_stdout_data(
str![[r#"
{"invalid":"manifest path `foo/bar/baz/Cargo.toml` does not exist"}

[
{
"invalid": "manifest path `foo/bar/baz/Cargo.toml` does not exist"
}
]
"#]]
.json_lines(),
.is_json()
.against_jsonlines(),
)
.run();
}
36 changes: 32 additions & 4 deletions tests/testsuite/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2112,11 +2112,39 @@ fn json_artifact_includes_executable_for_benchmark() {
p.cargo("bench --no-run --message-format=json")
.with_stdout_data(
str![[r#"
{"executable":"[ROOT]/foo/target/release/deps/benchmark-[HASH][EXE]","features":[],"filenames":"{...}","fresh":false,"manifest_path":"[ROOT]/foo/Cargo.toml","package_id":"path+[ROOTURL]/foo#0.0.1","profile":"{...}","reason":"compiler-artifact","target":{"crate_types":["bin"],"doc":false,"doctest":false,"edition":"2015","kind":["bench"],"name":"benchmark","src_path":"[ROOT]/foo/benches/benchmark.rs","test":false}}
{"reason":"build-finished","success":true}

[
{
"executable": "[..]",
"features": [],
"filenames": "{...}",
"fresh": false,
"manifest_path": "[ROOT]/foo/Cargo.toml",
"package_id": "path+[ROOTURL]/foo#0.0.1",
"profile": "{...}",
"reason": "compiler-artifact",
"target": {
"crate_types": [
"bin"
],
"doc": false,
"doctest": false,
"edition": "2015",
"kind": [
"bench"
],
"name": "benchmark",
"src_path": "[ROOT]/foo/benches/benchmark.rs",
"test": false
}
},
{
"reason": "build-finished",
"success": true
}
]
"#]]
.json_lines(),
.is_json()
.against_jsonlines(),
)
.run();
}
Expand Down
28 changes: 23 additions & 5 deletions tests/testsuite/binary_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,28 @@ fn check_msg_format_json() {
// Run cargo build.
p.cargo("build --message-format=json")
.masquerade_as_nightly_cargo(&["different-binary-name"])
.with_stdout_data(str![[r#"
{"executable":"[ROOT]/foo/target/debug/007bar[EXE]","features":[],"filenames":"{...}","fresh":false,"manifest_path":"[ROOT]/foo/Cargo.toml","package_id":"path+[ROOTURL]/foo#0.0.1","profile":"{...}","reason":"compiler-artifact","target":"{...}"}
{"reason":"build-finished","success":true}

"#]].json_lines())
.with_stdout_data(
str![[r#"
[
{
"executable": "[ROOT]/foo/target/debug/007bar[EXE]",
"features": [],
"filenames": "{...}",
"fresh": false,
"manifest_path": "[ROOT]/foo/Cargo.toml",
"package_id": "path+[ROOTURL]/foo#0.0.1",
"profile": "{...}",
"reason": "compiler-artifact",
"target": "{...}"
},
{
"reason": "build-finished",
"success": true
}
]
"#]]
.is_json()
.against_jsonlines(),
)
.run();
}
6 changes: 3 additions & 3 deletions tests/testsuite/build_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn cargo_build_plan_simple() {
]
}
"#]]
.json(),
.is_json(),
)
.run();
assert!(!p.bin("foo").is_file());
Expand Down Expand Up @@ -126,7 +126,7 @@ fn cargo_build_plan_single_dep() {
]
}
"#]]
.json(),
.is_json(),
)
.run();
}
Expand Down Expand Up @@ -213,7 +213,7 @@ fn cargo_build_plan_build_script() {
]
}
"#]]
.json(),
.is_json(),
)
.run();
}
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/cargo_config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ fn get_json() {
}

"#
.json(),
.is_json(),
)
.with_stderr_data(str![[r#"
[NOTE] The following environment variables may affect the loaded values.
Expand Down Expand Up @@ -270,7 +270,7 @@ CARGO_HOME=[ROOT]/home/.cargo
}

"#
.json(),
.is_json(),
)
.with_stderr_data(str![[r#"
[NOTE] The following environment variables may affect the loaded values.
Expand Down
Loading