Skip to content

Commit

Permalink
Auto merge of #14402 - epage:snap, 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 is part of #14039

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

### Additional information

This was unblocked because of assert-rs/snapbox#350
  • Loading branch information
bors committed Aug 15, 2024
2 parents ff6df29 + be5a41d commit 9a170d7
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 152 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 @@ -92,7 +92,7 @@ sha2 = "0.10.8"
shell-escape = "0.1.5"
similar = "2.6.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 }
tempfile = "3.10.1"
thiserror = "1.0.63"
Expand Down
180 changes: 100 additions & 80 deletions tests/testsuite/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1879,24 +1879,25 @@ fn doc_message_format() {

p.cargo("doc --message-format=json")
.with_status(101)
.with_json_contains_unordered(
r#"
{
"message": {
"$message_type": "diagnostic",
"children": "{...}",
"code": "{...}",
"level": "error",
"message": "{...}",
"rendered": "{...}",
"spans": "{...}"
},
"package_id": "path+file:///[..]/foo#0.0.1",
"manifest_path": "[..]",
"reason": "compiler-message",
"target": "{...}"
}
"#,
.with_stdout_data(
str![[r##"
[
{
"manifest_path": "[ROOT]/foo/Cargo.toml",
"message": {
"$message_type": "diagnostic",
"level": "error",
"...": "{...}"
},
"package_id": "path+[ROOTURL]/foo#0.0.1",
"reason": "compiler-message",
"target": "{...}"
},
"{...}"
]
"##]]
.is_json()
.against_jsonlines(),
)
.run();
}
Expand All @@ -1911,76 +1912,95 @@ fn doc_json_artifacts() {
.build();

p.cargo("doc --message-format=json")
.with_json_contains_unordered(
r#"
{
"reason": "compiler-artifact",
"package_id": "path+file:///[..]/foo#0.0.1",
.with_stdout_data(
str![[r#"
[
{
"executable": null,
"features": [],
"filenames": [
"[ROOT]/foo/target/debug/deps/libfoo-[HASH].rmeta"
],
"fresh": false,
"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
},
"package_id": "path+[ROOTURL]/foo#0.0.1",
"profile": "{...}",
"features": [],
"filenames": ["[ROOT]/foo/target/debug/deps/libfoo-[..].rmeta"],
"executable": null,
"fresh": false
}
{
"reason": "compiler-artifact",
"package_id": "path+file:///[..]/foo#0.0.1",
"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/foo/index.html"
],
"fresh": false,
"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
},
"package_id": "path+[ROOTURL]/foo#0.0.1",
"profile": "{...}",
"features": [],
"filenames": ["[ROOT]/foo/target/doc/foo/index.html"],
"executable": null,
"fresh": false
}
{
"reason": "compiler-artifact",
"package_id": "path+file:///[..]/foo#0.0.1",
"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",
"target":
{
"kind": ["bin"],
"crate_types": ["bin"],
"name": "somebin",
"src_path": "[ROOT]/foo/src/bin/somebin.rs",
"edition": "2015",
"doc": true,
"doctest": false,
"test": true
},
"package_id": "path+[ROOTURL]/foo#0.0.1",
"profile": "{...}",
"features": [],
"filenames": ["[ROOT]/foo/target/doc/somebin/index.html"],
"executable": null,
"fresh": false
}
{"reason":"build-finished","success":true}
"#,
"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();
}
Expand Down
143 changes: 75 additions & 68 deletions tests/testsuite/metabuild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,43 +741,48 @@ fn metabuild_json_artifact() {
let p = basic_project();
p.cargo("check --message-format=json")
.masquerade_as_nightly_cargo(&["metabuild"])
.with_json_contains_unordered(
r#"
{
"executable": null,
"features": [],
"filenames": "{...}",
"fresh": false,
"package_id": "path+file:///[..]/foo#0.0.1",
"manifest_path": "[..]",
"profile": "{...}",
"reason": "compiler-artifact",
"target": {
"crate_types": [
"bin"
],
"doc": false,
"doctest": false,
"edition": "2018",
"kind": [
"custom-build"
],
"name": "metabuild-foo",
"src_path": "[..]/foo/target/.metabuild/metabuild-foo-[..].rs",
"test": false
}
}
{
"cfgs": [],
"env": [],
"linked_libs": [],
"linked_paths": [],
"package_id": "path+file:///[..]/foo#0.0.1",
"out_dir": "[..]",
"reason": "build-script-executed"
}
"#,
.with_stdout_data(
str![[r#"
[
"{...}",
{
"executable": null,
"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": "2018",
"kind": [
"custom-build"
],
"name": "metabuild-foo",
"src_path": "[ROOT]/foo/target/.metabuild/metabuild-foo-[HASH].rs",
"test": false
}
},
{
"cfgs": [],
"env": [],
"linked_libs": [],
"linked_paths": [],
"out_dir": "[ROOT]/foo/target/debug/build/foo-[HASH]/out",
"package_id": "path+[ROOTURL]/foo#0.0.1",
"reason": "build-script-executed"
},
"{...}"
]
"#]]
.is_json()
.against_jsonlines(),
)
.run();
}
Expand All @@ -791,37 +796,39 @@ fn metabuild_failed_build_json() {
p.cargo("check --message-format=json")
.masquerade_as_nightly_cargo(&["metabuild"])
.with_status(101)
.with_json_contains_unordered(
r#"
{
"message": {
"$message_type": "diagnostic",
"children": "{...}",
"code": "{...}",
"level": "error",
"message": "cannot find function `metabuild`[..]",
"rendered": "{...}",
"spans": "{...}"
},
"package_id": "path+file:///[..]/foo#0.0.1",
"manifest_path": "[..]",
"reason": "compiler-message",
"target": {
"crate_types": [
"bin"
],
"doc": false,
"doctest": false,
"edition": "2018",
"kind": [
"custom-build"
],
"name": "metabuild-foo",
"src_path": null,
"test": false
}
}
"#,
.with_stdout_data(
str![[r#"
[
"{...}",
{
"manifest_path": "[ROOT]/foo/Cargo.toml",
"message": {
"level": "error",
"message": "cannot find function `metabuild` in crate `mb`",
"...": "{...}"
},
"package_id": "path+[ROOTURL]/foo#0.0.1",
"reason": "compiler-message",
"target": {
"crate_types": [
"bin"
],
"doc": false,
"doctest": false,
"edition": "2018",
"kind": [
"custom-build"
],
"name": "metabuild-foo",
"src_path": null,
"test": false
}
},
"{...}"
]
"#]]
.is_json()
.against_jsonlines(),
)
.run();
}

0 comments on commit 9a170d7

Please sign in to comment.