Skip to content

Commit

Permalink
Auto merge of #14293 - epage:jsonlines, r=weihanglo
Browse files Browse the repository at this point in the history
test: Migrate some json tests to snapbox

### What does this PR try to resolve?

This builds on assert-rs/snapbox#348 and is part of #14039.

Note: this also updates existing `.is_jsonlines()` usage to `.is_json().against_jsonlines()`.

### How should we test and review this PR?

### Additional information
  • Loading branch information
bors committed Jul 24, 2024
2 parents ca330a2 + 3085b54 commit 9bda502
Show file tree
Hide file tree
Showing 23 changed files with 425 additions and 332 deletions.
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

0 comments on commit 9bda502

Please sign in to comment.