Auto merge of #14402 - epage:snap, r=weihanglo

test: Migrate some json tests to snapbox

### What does this PR try to resolve?

This is part of #14039

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

### Additional information

This was unblocked because of assert-rs/snapbox#350
This commit is contained in:
bors 2024-08-15 18:46:48 +00:00
commit 9a170d718d
4 changed files with 182 additions and 155 deletions

6
Cargo.lock generated
View File

@ -2169,7 +2169,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"windows-targets 0.48.5", "windows-targets 0.52.6",
] ]
[[package]] [[package]]
@ -3216,9 +3216,9 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
[[package]] [[package]]
name = "snapbox" name = "snapbox"
version = "0.6.16" version = "0.6.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "027c936207f85d10d015e21faf5c676c7e08c453ed371adf55c0874c443ca77a" checksum = "840b73eb3148bc3cbc10ebe00ec9bc6d96033e658d022c4adcbf3f35596fd64a"
dependencies = [ dependencies = [
"anstream", "anstream",
"anstyle", "anstyle",

View File

@ -92,7 +92,7 @@ sha2 = "0.10.8"
shell-escape = "0.1.5" shell-escape = "0.1.5"
similar = "2.6.0" similar = "2.6.0"
supports-hyperlinks = "3.0.0" supports-hyperlinks = "3.0.0"
snapbox = { version = "0.6.16", features = ["diff", "dir", "term-svg", "regex", "json"] } snapbox = { version = "0.6.17", features = ["diff", "dir", "term-svg", "regex", "json"] }
tar = { version = "0.4.41", default-features = false } tar = { version = "0.4.41", default-features = false }
tempfile = "3.10.1" tempfile = "3.10.1"
thiserror = "1.0.63" thiserror = "1.0.63"

View File

@ -1879,24 +1879,25 @@ fn doc_message_format() {
p.cargo("doc --message-format=json") p.cargo("doc --message-format=json")
.with_status(101) .with_status(101)
.with_json_contains_unordered( .with_stdout_data(
r#" str![[r##"
{ [
"message": { {
"$message_type": "diagnostic", "manifest_path": "[ROOT]/foo/Cargo.toml",
"children": "{...}", "message": {
"code": "{...}", "$message_type": "diagnostic",
"level": "error", "level": "error",
"message": "{...}", "...": "{...}"
"rendered": "{...}", },
"spans": "{...}" "package_id": "path+[ROOTURL]/foo#0.0.1",
}, "reason": "compiler-message",
"package_id": "path+file:///[..]/foo#0.0.1", "target": "{...}"
"manifest_path": "[..]", },
"reason": "compiler-message", "{...}"
"target": "{...}" ]
} "##]]
"#, .is_json()
.against_jsonlines(),
) )
.run(); .run();
} }
@ -1911,76 +1912,95 @@ fn doc_json_artifacts() {
.build(); .build();
p.cargo("doc --message-format=json") p.cargo("doc --message-format=json")
.with_json_contains_unordered( .with_stdout_data(
r#" str![[r#"
{ [
"reason": "compiler-artifact", {
"package_id": "path+file:///[..]/foo#0.0.1",
"manifest_path": "[ROOT]/foo/Cargo.toml",
"target":
{
"kind": ["lib"],
"crate_types": ["lib"],
"name": "foo",
"src_path": "[ROOT]/foo/src/lib.rs",
"edition": "2015",
"doc": true,
"doctest": true,
"test": true
},
"profile": "{...}",
"features": [],
"filenames": ["[ROOT]/foo/target/debug/deps/libfoo-[..].rmeta"],
"executable": null, "executable": null,
"fresh": false
}
{
"reason": "compiler-artifact",
"package_id": "path+file:///[..]/foo#0.0.1",
"manifest_path": "[ROOT]/foo/Cargo.toml",
"target":
{
"kind": ["lib"],
"crate_types": ["lib"],
"name": "foo",
"src_path": "[ROOT]/foo/src/lib.rs",
"edition": "2015",
"doc": true,
"doctest": true,
"test": true
},
"profile": "{...}",
"features": [], "features": [],
"filenames": ["[ROOT]/foo/target/doc/foo/index.html"], "filenames": [
"executable": null, "[ROOT]/foo/target/debug/deps/libfoo-[HASH].rmeta"
"fresh": false ],
} "fresh": false,
{
"reason": "compiler-artifact",
"package_id": "path+file:///[..]/foo#0.0.1",
"manifest_path": "[ROOT]/foo/Cargo.toml", "manifest_path": "[ROOT]/foo/Cargo.toml",
"target": "package_id": "path+[ROOTURL]/foo#0.0.1",
{
"kind": ["bin"],
"crate_types": ["bin"],
"name": "somebin",
"src_path": "[ROOT]/foo/src/bin/somebin.rs",
"edition": "2015",
"doc": true,
"doctest": false,
"test": true
},
"profile": "{...}", "profile": "{...}",
"features": [], "reason": "compiler-artifact",
"filenames": ["[ROOT]/foo/target/doc/somebin/index.html"], "target": {
"crate_types": [
"lib"
],
"doc": true,
"doctest": true,
"edition": "2015",
"kind": [
"lib"
],
"name": "foo",
"src_path": "[ROOT]/foo/src/lib.rs",
"test": true
}
},
{
"executable": null, "executable": null,
"fresh": false "features": [],
} "filenames": [
"[ROOT]/foo/target/doc/foo/index.html"
{"reason":"build-finished","success":true} ],
"#, "fresh": false,
"manifest_path": "[ROOT]/foo/Cargo.toml",
"package_id": "path+[ROOTURL]/foo#0.0.1",
"profile": "{...}",
"reason": "compiler-artifact",
"target": {
"crate_types": [
"lib"
],
"doc": true,
"doctest": true,
"edition": "2015",
"kind": [
"lib"
],
"name": "foo",
"src_path": "[ROOT]/foo/src/lib.rs",
"test": true
}
},
{
"executable": null,
"features": [],
"filenames": [
"[ROOT]/foo/target/doc/somebin/index.html"
],
"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": true,
"doctest": false,
"edition": "2015",
"kind": [
"bin"
],
"name": "somebin",
"src_path": "[ROOT]/foo/src/bin/somebin.rs",
"test": true
}
},
{
"reason": "build-finished",
"success": true
}
]
"#]]
.is_json()
.against_jsonlines(),
) )
.run(); .run();
} }

View File

@ -741,43 +741,48 @@ fn metabuild_json_artifact() {
let p = basic_project(); let p = basic_project();
p.cargo("check --message-format=json") p.cargo("check --message-format=json")
.masquerade_as_nightly_cargo(&["metabuild"]) .masquerade_as_nightly_cargo(&["metabuild"])
.with_json_contains_unordered( .with_stdout_data(
r#" str![[r#"
{ [
"executable": null, "{...}",
"features": [], {
"filenames": "{...}", "executable": null,
"fresh": false, "features": [],
"package_id": "path+file:///[..]/foo#0.0.1", "filenames": "{...}",
"manifest_path": "[..]", "fresh": false,
"profile": "{...}", "manifest_path": "[ROOT]/foo/Cargo.toml",
"reason": "compiler-artifact", "package_id": "path+[ROOTURL]/foo#0.0.1",
"target": { "profile": "{...}",
"crate_types": [ "reason": "compiler-artifact",
"bin" "target": {
], "crate_types": [
"doc": false, "bin"
"doctest": false, ],
"edition": "2018", "doc": false,
"kind": [ "doctest": false,
"custom-build" "edition": "2018",
], "kind": [
"name": "metabuild-foo", "custom-build"
"src_path": "[..]/foo/target/.metabuild/metabuild-foo-[..].rs", ],
"test": false "name": "metabuild-foo",
} "src_path": "[ROOT]/foo/target/.metabuild/metabuild-foo-[HASH].rs",
} "test": false
}
{ },
"cfgs": [], {
"env": [], "cfgs": [],
"linked_libs": [], "env": [],
"linked_paths": [], "linked_libs": [],
"package_id": "path+file:///[..]/foo#0.0.1", "linked_paths": [],
"out_dir": "[..]", "out_dir": "[ROOT]/foo/target/debug/build/foo-[HASH]/out",
"reason": "build-script-executed" "package_id": "path+[ROOTURL]/foo#0.0.1",
} "reason": "build-script-executed"
"#, },
"{...}"
]
"#]]
.is_json()
.against_jsonlines(),
) )
.run(); .run();
} }
@ -791,37 +796,39 @@ fn metabuild_failed_build_json() {
p.cargo("check --message-format=json") p.cargo("check --message-format=json")
.masquerade_as_nightly_cargo(&["metabuild"]) .masquerade_as_nightly_cargo(&["metabuild"])
.with_status(101) .with_status(101)
.with_json_contains_unordered( .with_stdout_data(
r#" str![[r#"
{ [
"message": { "{...}",
"$message_type": "diagnostic", {
"children": "{...}", "manifest_path": "[ROOT]/foo/Cargo.toml",
"code": "{...}", "message": {
"level": "error", "level": "error",
"message": "cannot find function `metabuild`[..]", "message": "cannot find function `metabuild` in crate `mb`",
"rendered": "{...}", "...": "{...}"
"spans": "{...}" },
}, "package_id": "path+[ROOTURL]/foo#0.0.1",
"package_id": "path+file:///[..]/foo#0.0.1", "reason": "compiler-message",
"manifest_path": "[..]", "target": {
"reason": "compiler-message", "crate_types": [
"target": { "bin"
"crate_types": [ ],
"bin" "doc": false,
], "doctest": false,
"doc": false, "edition": "2018",
"doctest": false, "kind": [
"edition": "2018", "custom-build"
"kind": [ ],
"custom-build" "name": "metabuild-foo",
], "src_path": null,
"name": "metabuild-foo", "test": false
"src_path": null, }
"test": false },
} "{...}"
} ]
"#, "#]]
.is_json()
.against_jsonlines(),
) )
.run(); .run();
} }