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 #14402

Merged
merged 3 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the snapbox patch now correctly handle unordered JSON lines, or this test doesn't need unordered assertion?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If by "now correctly" you mean "implicitly", then no, as that would not be correct. I am not seeing anything in this test case that needs .unordered() applied.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant to comment under doc_json_artifacts but that one doesn't seem to need unordered either.

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();
}