Skip to content

Commit 9a170d7

Browse files
committed
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
2 parents ff6df29 + be5a41d commit 9a170d7

File tree

4 files changed

+179
-152
lines changed

4 files changed

+179
-152
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ sha2 = "0.10.8"
9292
shell-escape = "0.1.5"
9393
similar = "2.6.0"
9494
supports-hyperlinks = "3.0.0"
95-
snapbox = { version = "0.6.16", features = ["diff", "dir", "term-svg", "regex", "json"] }
95+
snapbox = { version = "0.6.17", features = ["diff", "dir", "term-svg", "regex", "json"] }
9696
tar = { version = "0.4.41", default-features = false }
9797
tempfile = "3.10.1"
9898
thiserror = "1.0.63"

tests/testsuite/doc.rs

Lines changed: 100 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1879,24 +1879,25 @@ fn doc_message_format() {
18791879

18801880
p.cargo("doc --message-format=json")
18811881
.with_status(101)
1882-
.with_json_contains_unordered(
1883-
r#"
1884-
{
1885-
"message": {
1886-
"$message_type": "diagnostic",
1887-
"children": "{...}",
1888-
"code": "{...}",
1889-
"level": "error",
1890-
"message": "{...}",
1891-
"rendered": "{...}",
1892-
"spans": "{...}"
1893-
},
1894-
"package_id": "path+file:///[..]/foo#0.0.1",
1895-
"manifest_path": "[..]",
1896-
"reason": "compiler-message",
1897-
"target": "{...}"
1898-
}
1899-
"#,
1882+
.with_stdout_data(
1883+
str![[r##"
1884+
[
1885+
{
1886+
"manifest_path": "[ROOT]/foo/Cargo.toml",
1887+
"message": {
1888+
"$message_type": "diagnostic",
1889+
"level": "error",
1890+
"...": "{...}"
1891+
},
1892+
"package_id": "path+[ROOTURL]/foo#0.0.1",
1893+
"reason": "compiler-message",
1894+
"target": "{...}"
1895+
},
1896+
"{...}"
1897+
]
1898+
"##]]
1899+
.is_json()
1900+
.against_jsonlines(),
19001901
)
19011902
.run();
19021903
}
@@ -1911,76 +1912,95 @@ fn doc_json_artifacts() {
19111912
.build();
19121913

19131914
p.cargo("doc --message-format=json")
1914-
.with_json_contains_unordered(
1915-
r#"
1916-
{
1917-
"reason": "compiler-artifact",
1918-
"package_id": "path+file:///[..]/foo#0.0.1",
1915+
.with_stdout_data(
1916+
str![[r#"
1917+
[
1918+
{
1919+
"executable": null,
1920+
"features": [],
1921+
"filenames": [
1922+
"[ROOT]/foo/target/debug/deps/libfoo-[HASH].rmeta"
1923+
],
1924+
"fresh": false,
19191925
"manifest_path": "[ROOT]/foo/Cargo.toml",
1920-
"target":
1921-
{
1922-
"kind": ["lib"],
1923-
"crate_types": ["lib"],
1924-
"name": "foo",
1925-
"src_path": "[ROOT]/foo/src/lib.rs",
1926-
"edition": "2015",
1927-
"doc": true,
1928-
"doctest": true,
1929-
"test": true
1930-
},
1926+
"package_id": "path+[ROOTURL]/foo#0.0.1",
19311927
"profile": "{...}",
1932-
"features": [],
1933-
"filenames": ["[ROOT]/foo/target/debug/deps/libfoo-[..].rmeta"],
1934-
"executable": null,
1935-
"fresh": false
1936-
}
1937-
1938-
{
19391928
"reason": "compiler-artifact",
1940-
"package_id": "path+file:///[..]/foo#0.0.1",
1929+
"target": {
1930+
"crate_types": [
1931+
"lib"
1932+
],
1933+
"doc": true,
1934+
"doctest": true,
1935+
"edition": "2015",
1936+
"kind": [
1937+
"lib"
1938+
],
1939+
"name": "foo",
1940+
"src_path": "[ROOT]/foo/src/lib.rs",
1941+
"test": true
1942+
}
1943+
},
1944+
{
1945+
"executable": null,
1946+
"features": [],
1947+
"filenames": [
1948+
"[ROOT]/foo/target/doc/foo/index.html"
1949+
],
1950+
"fresh": false,
19411951
"manifest_path": "[ROOT]/foo/Cargo.toml",
1942-
"target":
1943-
{
1944-
"kind": ["lib"],
1945-
"crate_types": ["lib"],
1946-
"name": "foo",
1947-
"src_path": "[ROOT]/foo/src/lib.rs",
1948-
"edition": "2015",
1949-
"doc": true,
1950-
"doctest": true,
1951-
"test": true
1952-
},
1952+
"package_id": "path+[ROOTURL]/foo#0.0.1",
19531953
"profile": "{...}",
1954-
"features": [],
1955-
"filenames": ["[ROOT]/foo/target/doc/foo/index.html"],
1956-
"executable": null,
1957-
"fresh": false
1958-
}
1959-
1960-
{
19611954
"reason": "compiler-artifact",
1962-
"package_id": "path+file:///[..]/foo#0.0.1",
1955+
"target": {
1956+
"crate_types": [
1957+
"lib"
1958+
],
1959+
"doc": true,
1960+
"doctest": true,
1961+
"edition": "2015",
1962+
"kind": [
1963+
"lib"
1964+
],
1965+
"name": "foo",
1966+
"src_path": "[ROOT]/foo/src/lib.rs",
1967+
"test": true
1968+
}
1969+
},
1970+
{
1971+
"executable": null,
1972+
"features": [],
1973+
"filenames": [
1974+
"[ROOT]/foo/target/doc/somebin/index.html"
1975+
],
1976+
"fresh": false,
19631977
"manifest_path": "[ROOT]/foo/Cargo.toml",
1964-
"target":
1965-
{
1966-
"kind": ["bin"],
1967-
"crate_types": ["bin"],
1968-
"name": "somebin",
1969-
"src_path": "[ROOT]/foo/src/bin/somebin.rs",
1970-
"edition": "2015",
1971-
"doc": true,
1972-
"doctest": false,
1973-
"test": true
1974-
},
1978+
"package_id": "path+[ROOTURL]/foo#0.0.1",
19751979
"profile": "{...}",
1976-
"features": [],
1977-
"filenames": ["[ROOT]/foo/target/doc/somebin/index.html"],
1978-
"executable": null,
1979-
"fresh": false
1980-
}
1981-
1982-
{"reason":"build-finished","success":true}
1983-
"#,
1980+
"reason": "compiler-artifact",
1981+
"target": {
1982+
"crate_types": [
1983+
"bin"
1984+
],
1985+
"doc": true,
1986+
"doctest": false,
1987+
"edition": "2015",
1988+
"kind": [
1989+
"bin"
1990+
],
1991+
"name": "somebin",
1992+
"src_path": "[ROOT]/foo/src/bin/somebin.rs",
1993+
"test": true
1994+
}
1995+
},
1996+
{
1997+
"reason": "build-finished",
1998+
"success": true
1999+
}
2000+
]
2001+
"#]]
2002+
.is_json()
2003+
.against_jsonlines(),
19842004
)
19852005
.run();
19862006
}

tests/testsuite/metabuild.rs

Lines changed: 75 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -741,43 +741,48 @@ fn metabuild_json_artifact() {
741741
let p = basic_project();
742742
p.cargo("check --message-format=json")
743743
.masquerade_as_nightly_cargo(&["metabuild"])
744-
.with_json_contains_unordered(
745-
r#"
746-
{
747-
"executable": null,
748-
"features": [],
749-
"filenames": "{...}",
750-
"fresh": false,
751-
"package_id": "path+file:///[..]/foo#0.0.1",
752-
"manifest_path": "[..]",
753-
"profile": "{...}",
754-
"reason": "compiler-artifact",
755-
"target": {
756-
"crate_types": [
757-
"bin"
758-
],
759-
"doc": false,
760-
"doctest": false,
761-
"edition": "2018",
762-
"kind": [
763-
"custom-build"
764-
],
765-
"name": "metabuild-foo",
766-
"src_path": "[..]/foo/target/.metabuild/metabuild-foo-[..].rs",
767-
"test": false
768-
}
769-
}
770-
771-
{
772-
"cfgs": [],
773-
"env": [],
774-
"linked_libs": [],
775-
"linked_paths": [],
776-
"package_id": "path+file:///[..]/foo#0.0.1",
777-
"out_dir": "[..]",
778-
"reason": "build-script-executed"
779-
}
780-
"#,
744+
.with_stdout_data(
745+
str![[r#"
746+
[
747+
"{...}",
748+
{
749+
"executable": null,
750+
"features": [],
751+
"filenames": "{...}",
752+
"fresh": false,
753+
"manifest_path": "[ROOT]/foo/Cargo.toml",
754+
"package_id": "path+[ROOTURL]/foo#0.0.1",
755+
"profile": "{...}",
756+
"reason": "compiler-artifact",
757+
"target": {
758+
"crate_types": [
759+
"bin"
760+
],
761+
"doc": false,
762+
"doctest": false,
763+
"edition": "2018",
764+
"kind": [
765+
"custom-build"
766+
],
767+
"name": "metabuild-foo",
768+
"src_path": "[ROOT]/foo/target/.metabuild/metabuild-foo-[HASH].rs",
769+
"test": false
770+
}
771+
},
772+
{
773+
"cfgs": [],
774+
"env": [],
775+
"linked_libs": [],
776+
"linked_paths": [],
777+
"out_dir": "[ROOT]/foo/target/debug/build/foo-[HASH]/out",
778+
"package_id": "path+[ROOTURL]/foo#0.0.1",
779+
"reason": "build-script-executed"
780+
},
781+
"{...}"
782+
]
783+
"#]]
784+
.is_json()
785+
.against_jsonlines(),
781786
)
782787
.run();
783788
}
@@ -791,37 +796,39 @@ fn metabuild_failed_build_json() {
791796
p.cargo("check --message-format=json")
792797
.masquerade_as_nightly_cargo(&["metabuild"])
793798
.with_status(101)
794-
.with_json_contains_unordered(
795-
r#"
796-
{
797-
"message": {
798-
"$message_type": "diagnostic",
799-
"children": "{...}",
800-
"code": "{...}",
801-
"level": "error",
802-
"message": "cannot find function `metabuild`[..]",
803-
"rendered": "{...}",
804-
"spans": "{...}"
805-
},
806-
"package_id": "path+file:///[..]/foo#0.0.1",
807-
"manifest_path": "[..]",
808-
"reason": "compiler-message",
809-
"target": {
810-
"crate_types": [
811-
"bin"
812-
],
813-
"doc": false,
814-
"doctest": false,
815-
"edition": "2018",
816-
"kind": [
817-
"custom-build"
818-
],
819-
"name": "metabuild-foo",
820-
"src_path": null,
821-
"test": false
822-
}
823-
}
824-
"#,
799+
.with_stdout_data(
800+
str![[r#"
801+
[
802+
"{...}",
803+
{
804+
"manifest_path": "[ROOT]/foo/Cargo.toml",
805+
"message": {
806+
"level": "error",
807+
"message": "cannot find function `metabuild` in crate `mb`",
808+
"...": "{...}"
809+
},
810+
"package_id": "path+[ROOTURL]/foo#0.0.1",
811+
"reason": "compiler-message",
812+
"target": {
813+
"crate_types": [
814+
"bin"
815+
],
816+
"doc": false,
817+
"doctest": false,
818+
"edition": "2018",
819+
"kind": [
820+
"custom-build"
821+
],
822+
"name": "metabuild-foo",
823+
"src_path": null,
824+
"test": false
825+
}
826+
},
827+
"{...}"
828+
]
829+
"#]]
830+
.is_json()
831+
.against_jsonlines(),
825832
)
826833
.run();
827834
}

0 commit comments

Comments
 (0)