From f4937a9b5840f29c4c660926e7951320cc957f9b Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 14 Aug 2024 16:16:06 -0500 Subject: [PATCH 1/3] chore: Update snapbox --- Cargo.lock | 6 +++--- Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a5b3703ba09..0bfa5561d38 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2169,7 +2169,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] @@ -3216,9 +3216,9 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "snapbox" -version = "0.6.16" +version = "0.6.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "027c936207f85d10d015e21faf5c676c7e08c453ed371adf55c0874c443ca77a" +checksum = "840b73eb3148bc3cbc10ebe00ec9bc6d96033e658d022c4adcbf3f35596fd64a" dependencies = [ "anstream", "anstyle", diff --git a/Cargo.toml b/Cargo.toml index 9dc40f90a8e..66203734344 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" From a58b2318d3e29b1d45571467759d2345626beb97 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 14 Aug 2024 16:03:02 -0500 Subject: [PATCH 2/3] test: migrate metabuild json to snapbox --- tests/testsuite/metabuild.rs | 143 ++++++++++++++++++----------------- 1 file changed, 75 insertions(+), 68 deletions(-) diff --git a/tests/testsuite/metabuild.rs b/tests/testsuite/metabuild.rs index 9efda97b5a1..91dad96afe0 100644 --- a/tests/testsuite/metabuild.rs +++ b/tests/testsuite/metabuild.rs @@ -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(); } @@ -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(); } From be5a41dd34a2fd874420987c54861a7c80b2cf83 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 14 Aug 2024 16:08:35 -0500 Subject: [PATCH 3/3] test: migrate doc json to snapbox --- tests/testsuite/doc.rs | 180 +++++++++++++++++++++++------------------ 1 file changed, 100 insertions(+), 80 deletions(-) diff --git a/tests/testsuite/doc.rs b/tests/testsuite/doc.rs index 713c841c5ad..2a358f2916f 100644 --- a/tests/testsuite/doc.rs +++ b/tests/testsuite/doc.rs @@ -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(); } @@ -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(); }