Skip to content

Commit 9bda502

Browse files
committed
Auto merge of #14293 - epage:jsonlines, r=weihanglo
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
2 parents ca330a2 + 3085b54 commit 9bda502

23 files changed

+425
-332
lines changed

Cargo.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ sha1 = "0.10.6"
9191
sha2 = "0.10.8"
9292
shell-escape = "0.1.5"
9393
supports-hyperlinks = "3.0.0"
94-
snapbox = { version = "0.6.9", features = ["diff", "dir", "term-svg", "regex", "json"] }
94+
snapbox = { version = "0.6.14", features = ["diff", "dir", "term-svg", "regex", "json"] }
9595
tar = { version = "0.4.40", default-features = false }
9696
tempfile = "3.10.1"
9797
thiserror = "1.0.59"

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,9 @@ impl Execs {
876876
/// - The order of arrays is ignored.
877877
/// - Strings support patterns described in [`compare`].
878878
/// - Use `"{...}"` to match any object.
879-
#[deprecated(note = "replaced with `Execs::with_stdout_data(expected.json_lines())`")]
879+
#[deprecated(
880+
note = "replaced with `Execs::with_stdout_data(expected.is_json().against_jsonlines())`"
881+
)]
880882
pub fn with_json(&mut self, expected: &str) -> &mut Self {
881883
self.expect_json = Some(expected.to_string());
882884
self

tests/testsuite/alt_registry.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ fn alt_reg_metadata() {
989989
"workspace_root": "[ROOT]/foo"
990990
}
991991
"#]]
992-
.json(),
992+
.is_json(),
993993
)
994994
.run();
995995

@@ -1353,7 +1353,7 @@ fn alt_reg_metadata() {
13531353
"workspace_root": "[ROOT]/foo"
13541354
}
13551355
"#]]
1356-
.json(),
1356+
.is_json(),
13571357
)
13581358
.run();
13591359
}
@@ -1615,7 +1615,7 @@ fn unknown_registry() {
16151615
"workspace_root": "[ROOT]/foo"
16161616
}
16171617
"#]]
1618-
.json(),
1618+
.is_json(),
16191619
)
16201620
.run();
16211621
}

tests/testsuite/bad_manifest_path.rs

+28-12
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,14 @@ fn verify_project_dir_containing_cargo_toml() {
331331
.with_status(1)
332332
.with_stdout_data(
333333
str![[r#"
334-
{"invalid":"the manifest-path must be a path to a Cargo.toml file"}
335-
334+
[
335+
{
336+
"invalid": "the manifest-path must be a path to a Cargo.toml file"
337+
}
338+
]
336339
"#]]
337-
.json_lines(),
340+
.is_json()
341+
.against_jsonlines(),
338342
)
339343
.run();
340344
}
@@ -351,10 +355,14 @@ fn verify_project_dir_plus_file() {
351355
.with_status(1)
352356
.with_stdout_data(
353357
str![[r#"
354-
{"invalid":"the manifest-path must be a path to a Cargo.toml file"}
355-
358+
[
359+
{
360+
"invalid": "the manifest-path must be a path to a Cargo.toml file"
361+
}
362+
]
356363
"#]]
357-
.json_lines(),
364+
.is_json()
365+
.against_jsonlines(),
358366
)
359367
.run();
360368
}
@@ -371,10 +379,14 @@ fn verify_project_dir_plus_path() {
371379
.with_status(1)
372380
.with_stdout_data(
373381
str![[r#"
374-
{"invalid":"the manifest-path must be a path to a Cargo.toml file"}
375-
382+
[
383+
{
384+
"invalid": "the manifest-path must be a path to a Cargo.toml file"
385+
}
386+
]
376387
"#]]
377-
.json_lines(),
388+
.is_json()
389+
.against_jsonlines(),
378390
)
379391
.run();
380392
}
@@ -387,10 +399,14 @@ fn verify_project_dir_to_nonexistent_cargo_toml() {
387399
.with_status(1)
388400
.with_stdout_data(
389401
str![[r#"
390-
{"invalid":"manifest path `foo/bar/baz/Cargo.toml` does not exist"}
391-
402+
[
403+
{
404+
"invalid": "manifest path `foo/bar/baz/Cargo.toml` does not exist"
405+
}
406+
]
392407
"#]]
393-
.json_lines(),
408+
.is_json()
409+
.against_jsonlines(),
394410
)
395411
.run();
396412
}

tests/testsuite/bench.rs

+32-4
Original file line numberDiff line numberDiff line change
@@ -2112,11 +2112,39 @@ fn json_artifact_includes_executable_for_benchmark() {
21122112
p.cargo("bench --no-run --message-format=json")
21132113
.with_stdout_data(
21142114
str![[r#"
2115-
{"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}}
2116-
{"reason":"build-finished","success":true}
2117-
2115+
[
2116+
{
2117+
"executable": "[..]",
2118+
"features": [],
2119+
"filenames": "{...}",
2120+
"fresh": false,
2121+
"manifest_path": "[ROOT]/foo/Cargo.toml",
2122+
"package_id": "path+[ROOTURL]/foo#0.0.1",
2123+
"profile": "{...}",
2124+
"reason": "compiler-artifact",
2125+
"target": {
2126+
"crate_types": [
2127+
"bin"
2128+
],
2129+
"doc": false,
2130+
"doctest": false,
2131+
"edition": "2015",
2132+
"kind": [
2133+
"bench"
2134+
],
2135+
"name": "benchmark",
2136+
"src_path": "[ROOT]/foo/benches/benchmark.rs",
2137+
"test": false
2138+
}
2139+
},
2140+
{
2141+
"reason": "build-finished",
2142+
"success": true
2143+
}
2144+
]
21182145
"#]]
2119-
.json_lines(),
2146+
.is_json()
2147+
.against_jsonlines(),
21202148
)
21212149
.run();
21222150
}

tests/testsuite/binary_name.rs

+23-5
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,28 @@ fn check_msg_format_json() {
315315
// Run cargo build.
316316
p.cargo("build --message-format=json")
317317
.masquerade_as_nightly_cargo(&["different-binary-name"])
318-
.with_stdout_data(str![[r#"
319-
{"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":"{...}"}
320-
{"reason":"build-finished","success":true}
321-
322-
"#]].json_lines())
318+
.with_stdout_data(
319+
str![[r#"
320+
[
321+
{
322+
"executable": "[ROOT]/foo/target/debug/007bar[EXE]",
323+
"features": [],
324+
"filenames": "{...}",
325+
"fresh": false,
326+
"manifest_path": "[ROOT]/foo/Cargo.toml",
327+
"package_id": "path+[ROOTURL]/foo#0.0.1",
328+
"profile": "{...}",
329+
"reason": "compiler-artifact",
330+
"target": "{...}"
331+
},
332+
{
333+
"reason": "build-finished",
334+
"success": true
335+
}
336+
]
337+
"#]]
338+
.is_json()
339+
.against_jsonlines(),
340+
)
323341
.run();
324342
}

tests/testsuite/build_plan.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn cargo_build_plan_simple() {
3939
]
4040
}
4141
"#]]
42-
.json(),
42+
.is_json(),
4343
)
4444
.run();
4545
assert!(!p.bin("foo").is_file());
@@ -126,7 +126,7 @@ fn cargo_build_plan_single_dep() {
126126
]
127127
}
128128
"#]]
129-
.json(),
129+
.is_json(),
130130
)
131131
.run();
132132
}
@@ -213,7 +213,7 @@ fn cargo_build_plan_build_script() {
213213
]
214214
}
215215
"#]]
216-
.json(),
216+
.is_json(),
217217
)
218218
.run();
219219
}

tests/testsuite/cargo_config/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ fn get_json() {
217217
}
218218
219219
"#
220-
.json(),
220+
.is_json(),
221221
)
222222
.with_stderr_data(str![[r#"
223223
[NOTE] The following environment variables may affect the loaded values.
@@ -270,7 +270,7 @@ CARGO_HOME=[ROOT]/home/.cargo
270270
}
271271
272272
"#
273-
.json(),
273+
.is_json(),
274274
)
275275
.with_stderr_data(str![[r#"
276276
[NOTE] The following environment variables may affect the loaded values.

0 commit comments

Comments
 (0)