From fe3e11b2fbe0381c09348396a67f2dc2b4672f8a Mon Sep 17 00:00:00 2001 From: Rain Date: Sat, 4 Jan 2025 11:35:20 +0000 Subject: [PATCH] [target-spec-miette] switch fixtures to snapbox I like `cargo insta`, but snapbox's SVGs are awesome and worth recommending. --- Cargo.lock | 88 ++++++++++++++----- Cargo.toml | 1 + target-spec-miette/Cargo.toml | 2 +- .../tests/datatest-snapshot/custom.rs | 17 ++-- .../tests/datatest-snapshot/expr.rs | 15 +--- .../tests/datatest-snapshot/helpers.rs | 40 ++++++--- ...ch.json-display.snap => invalid-arch.ansi} | 6 +- .../snapshots/custom-invalid/invalid-arch.svg | 45 ++++++++++ ....json-display.snap => invalid-endian.ansi} | 6 +- .../custom-invalid/invalid-endian.svg | 45 ++++++++++ ....json-display.snap => invalid-family.ansi} | 6 +- .../custom-invalid/invalid-family.svg | 45 ++++++++++ ...snap => invalid-target-pointer-width.ansi} | 6 +- .../invalid-target-pointer-width.svg | 45 ++++++++++ ...ch.json-display.snap => missing-arch.ansi} | 6 +- .../snapshots/custom-invalid/missing-arch.svg | 43 +++++++++ ...or.json-display.snap => syntax-error.ansi} | 6 +- .../snapshots/custom-invalid/syntax-error.svg | 43 +++++++++ ...put-display.snap => multiline-output.ansi} | 6 +- .../expr-invalid/multiline-output.svg | 41 +++++++++ ...r-display.snap => unclosed-delimiter.ansi} | 6 +- .../expr-invalid/unclosed-delimiter.svg | 41 +++++++++ ...value-display.snap => unquoted-value.ansi} | 6 +- .../snapshots/expr-invalid/unquoted-value.svg | 41 +++++++++ target-spec-miette/tests/integration/main.rs | 20 ++++- .../integration__unavailable_snapshot.snap | 7 -- .../integration/snapshots/unavailable.ansi | 3 + .../integration/snapshots/unavailable.svg | 30 +++++++ workspace-hack/Cargo.toml | 1 - 29 files changed, 555 insertions(+), 112 deletions(-) rename target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/{invalid-arch.json-display.snap => invalid-arch.ansi} (66%) create mode 100644 target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-arch.svg rename target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/{invalid-endian.json-display.snap => invalid-endian.ansi} (71%) create mode 100644 target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-endian.svg rename target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/{invalid-family.json-display.snap => invalid-family.ansi} (71%) create mode 100644 target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-family.svg rename target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/{invalid-target-pointer-width.json-display.snap => invalid-target-pointer-width.ansi} (71%) create mode 100644 target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-target-pointer-width.svg rename target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/{missing-arch.json-display.snap => missing-arch.ansi} (61%) create mode 100644 target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/missing-arch.svg rename target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/{syntax-error.json-display.snap => syntax-error.ansi} (63%) create mode 100644 target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/syntax-error.svg rename target-spec-miette/tests/datatest-snapshot/snapshots/expr-invalid/{multiline-output-display.snap => multiline-output.ansi} (73%) create mode 100644 target-spec-miette/tests/datatest-snapshot/snapshots/expr-invalid/multiline-output.svg rename target-spec-miette/tests/datatest-snapshot/snapshots/expr-invalid/{unclosed-delimiter-display.snap => unclosed-delimiter.ansi} (56%) create mode 100644 target-spec-miette/tests/datatest-snapshot/snapshots/expr-invalid/unclosed-delimiter.svg rename target-spec-miette/tests/datatest-snapshot/snapshots/expr-invalid/{unquoted-value-display.snap => unquoted-value.ansi} (60%) create mode 100644 target-spec-miette/tests/datatest-snapshot/snapshots/expr-invalid/unquoted-value.svg delete mode 100644 target-spec-miette/tests/integration/snapshots/integration__unavailable_snapshot.snap create mode 100644 target-spec-miette/tests/integration/snapshots/unavailable.ansi create mode 100644 target-spec-miette/tests/integration/snapshots/unavailable.svg diff --git a/Cargo.lock b/Cargo.lock index 7ab1c6af16b..84b75f653ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -91,6 +91,15 @@ version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" +[[package]] +name = "anstyle-lossy" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "934ff8719effd2023a48cf63e69536c1c3ced9d3895068f6f5cc9a4ff845e59b" +dependencies = [ + "anstyle", +] + [[package]] name = "anstyle-parse" version = "0.2.3" @@ -109,6 +118,19 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "anstyle-svg" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3607949e9f6de49ea4bafe12f5e4fd73613ebf24795e48587302a8cc0e4bb35" +dependencies = [ + "anstream", + "anstyle", + "anstyle-lossy", + "html-escape", + "unicode-width 0.2.0", +] + [[package]] name = "anstyle-wincon" version = "3.0.2" @@ -2337,7 +2359,6 @@ dependencies = [ "camino", "clap 4.5.22", "clap_builder", - "console", "getrandom", "include_dir", "indexmap 1.9.3", @@ -2503,6 +2524,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "html-escape" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d1ad449764d627e22bfd7cd5e8868264fc9236e07c752972b4080cd351cb476" +dependencies = [ + "utf8-width", +] + [[package]] name = "http-auth" version = "0.1.9" @@ -2610,18 +2640,6 @@ version = "2.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5" -[[package]] -name = "insta" -version = "1.41.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e9ffc4d4892617c50a928c52b2961cb5174b6fc6ebf252b2fac9d21955c48b8" -dependencies = [ - "console", - "lazy_static", - "linked-hash-map", - "similar", -] - [[package]] name = "is-terminal" version = "0.4.10" @@ -2822,12 +2840,6 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "linked-hash-map" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" - [[package]] name = "linux-raw-sys" version = "0.4.13" @@ -2965,6 +2977,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "normalize-line-endings" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" + [[package]] name = "normpath" version = "1.1.1" @@ -3836,6 +3854,30 @@ version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +[[package]] +name = "snapbox" +version = "0.6.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96dcfc4581e3355d70ac2ee14cfdf81dce3d85c85f1ed9e2c1d3013f53b3436b" +dependencies = [ + "anstream", + "anstyle", + "anstyle-svg", + "normalize-line-endings", + "serde_json", + "similar", + "snapbox-macros", +] + +[[package]] +name = "snapbox-macros" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16569f53ca23a41bb6f62e0a5084aa1661f4814a67fa33696a79073e03a664af" +dependencies = [ + "anstream", +] + [[package]] name = "socket2" version = "0.5.7" @@ -4020,8 +4062,8 @@ dependencies = [ "datatest-stable", "guppy-workspace-hack", "include_dir", - "insta", "miette", + "snapbox", "target-spec", ] @@ -4455,6 +4497,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utf8-width" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86bd8d4e895da8537e5315b8254664e6b769c4ff3db18321b297a1e7004392e3" + [[package]] name = "utf8parse" version = "0.2.1" diff --git a/Cargo.toml b/Cargo.toml index 07bcc3c8e34..ec9f3c32bf5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ guppy-workspace-hack = "0.1.0" include_dir = "0.7.4" insta = "1.41.1" miette = "7.4.0" +snapbox = { version = "0.6.21", features = ["term-svg"] } [workspace.package] # Note: we commit to supporting the last 6 months of Rust releases. This diff --git a/target-spec-miette/Cargo.toml b/target-spec-miette/Cargo.toml index 685527d9823..3a193c0b473 100644 --- a/target-spec-miette/Cargo.toml +++ b/target-spec-miette/Cargo.toml @@ -23,8 +23,8 @@ target-spec = { version = "3.3.1", path = "../target-spec" } [dev-dependencies] datatest-stable.workspace = true -insta.workspace = true miette = { workspace = true, features = ["fancy"] } +snapbox.workspace = true target-spec = { version = "3.3.1", path = "../target-spec", features = [ "custom", ] } diff --git a/target-spec-miette/tests/datatest-snapshot/custom.rs b/target-spec-miette/tests/datatest-snapshot/custom.rs index 81f2d854e61..491f7483edc 100644 --- a/target-spec-miette/tests/datatest-snapshot/custom.rs +++ b/target-spec-miette/tests/datatest-snapshot/custom.rs @@ -6,7 +6,7 @@ //! These tests live here because they depend on target-spec with the custom //! feature enabled, as well as target-spec-miette. -use crate::helpers::bind_insta_settings; +use crate::helpers::snapbox_assert_ansi; use datatest_stable::Utf8Path; use target_spec::TargetFeatures; use target_spec_miette::IntoMietteDiagnostic; @@ -14,20 +14,13 @@ use target_spec_miette::IntoMietteDiagnostic; pub(crate) fn custom_invalid(path: &Utf8Path, contents: String) -> datatest_stable::Result<()> { std::env::set_var("CLICOLOR_FORCE", "1"); - let (_guard, insta_prefix) = - bind_insta_settings(path, "../datatest-snapshot/snapshots/custom-invalid"); - let error = target_spec::Platform::new_custom("my-target", &contents, TargetFeatures::none()) .expect_err("expected input to fail"); - let diagnostic = error.into_diagnostic(); - insta::assert_snapshot!( - format!("{insta_prefix}-display"), - // This displays fancy output. Note the use of assert_snapshot, not - // assert_debug_snapshot, since the latter uses the pretty-printed Debug - // (which doesn't do what you would expect with miette/anyhow etc). - format!("{:?}", miette::Report::new_boxed(diagnostic)), - ); + // Use Debug output on the report to get the nicely formatted output. + let output = format!("{:?}", miette::Report::new_boxed(diagnostic)); + + snapbox_assert_ansi("custom-invalid", path, output); Ok(()) } diff --git a/target-spec-miette/tests/datatest-snapshot/expr.rs b/target-spec-miette/tests/datatest-snapshot/expr.rs index 3860df194a9..f08f838697a 100644 --- a/target-spec-miette/tests/datatest-snapshot/expr.rs +++ b/target-spec-miette/tests/datatest-snapshot/expr.rs @@ -1,27 +1,20 @@ // Copyright (c) The cargo-guppy Contributors // SPDX-License-Identifier: MIT OR Apache-2.0 -use crate::helpers::bind_insta_settings; +use crate::helpers::snapbox_assert_ansi; use datatest_stable::Utf8Path; use target_spec_miette::IntoMietteDiagnostic; pub(crate) fn expr_invalid(path: &Utf8Path, contents: String) -> datatest_stable::Result<()> { std::env::set_var("CLICOLOR_FORCE", "1"); - let (_guard, insta_prefix) = - bind_insta_settings(path, "../datatest-snapshot/snapshots/expr-invalid"); - let error = target_spec::TargetSpec::new(contents.trim_end().to_owned()) .expect_err("expected input to fail"); let diagnostic = error.into_diagnostic(); - insta::assert_snapshot!( - format!("{insta_prefix}-display"), - // This displays fancy output. Note the use of assert_snapshot, not - // assert_debug_snapshot, since the latter uses the pretty-printed Debug - // (which doesn't do what you would expect with miette/anyhow etc). - format!("{:?}", miette::Report::new_boxed(diagnostic)), - ); + // Use Debug output on the report to get the nicely formatted output. + let output = format!("{:?}", miette::Report::new_boxed(diagnostic)); + snapbox_assert_ansi("expr-invalid", path, output); Ok(()) } diff --git a/target-spec-miette/tests/datatest-snapshot/helpers.rs b/target-spec-miette/tests/datatest-snapshot/helpers.rs index 3e3aca98ff0..c4ecbea9bf6 100644 --- a/target-spec-miette/tests/datatest-snapshot/helpers.rs +++ b/target-spec-miette/tests/datatest-snapshot/helpers.rs @@ -2,21 +2,33 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 use datatest_stable::Utf8Path; -use insta::internals::SettingsBindDropGuard; +use snapbox::{data::DataFormat, Data}; +use std::path::PathBuf; -/// Binds insta settings for a test, and returns the prefix to use for snapshots. -pub(crate) fn bind_insta_settings<'a>( - path: &'a Utf8Path, - snapshot_path: &str, -) -> (SettingsBindDropGuard, &'a str) { - let mut settings = insta::Settings::clone_current(); - // Make insta suitable for datatest-stable use. - settings.set_input_file(path); - settings.set_snapshot_path(snapshot_path); - settings.set_prepend_module_to_snapshot(false); +pub(crate) fn snapbox_assert_ansi(test_name: &str, path: &Utf8Path, actual_ansi: String) { + // Currently assuming all files are in a single directory. + let b = snapbox::Assert::new().action_env("SNAPSHOTS"); + let file_name = path.file_name().unwrap(); - let guard = settings.bind_to_scope(); - let insta_prefix = path.file_name().unwrap(); + // Store SVG and ANSI snapshots. Use the binary representation to ensure + // that no post-processing of text happens. + b.eq( + Data::binary(actual_ansi.clone()).coerce_to(DataFormat::TermSvg), + Data::read_from( + &snapshot_path(test_name, file_name, "svg"), + Some(DataFormat::TermSvg), + ), + ); + b.eq( + Data::binary(actual_ansi), + Data::read_from(&snapshot_path(test_name, file_name, "ansi"), None), + ); +} - (guard, insta_prefix) +fn snapshot_path(test_name: &str, file_name: &str, ext: &str) -> PathBuf { + snapbox::utils::current_dir!() + .join("snapshots") + .join(test_name) + .join(file_name) + .with_extension(ext) } diff --git a/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-arch.json-display.snap b/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-arch.ansi similarity index 66% rename from target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-arch.json-display.snap rename to target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-arch.ansi index 0143868125d..0342dea90ee 100644 --- a/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-arch.json-display.snap +++ b/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-arch.ansi @@ -1,8 +1,4 @@ ---- -source: target-spec-miette/tests/datatest-snapshot/custom.rs -expression: "format!(\"{:?}\", miette::Report::new_boxed(diagnostic))" -snapshot_kind: text ---- + ร— error deserializing custom target JSON for `my-target` โ•ญโ”€[2:13] 1 โ”‚ { diff --git a/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-arch.svg b/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-arch.svg new file mode 100644 index 00000000000..d29596e59f9 --- /dev/null +++ b/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-arch.svg @@ -0,0 +1,45 @@ + + + + + + + + + ร— error deserializing custom target JSON for `my-target` + + โ•ญโ”€[2:13] + + 1 โ”‚ { + + 2 โ”‚ "arch": 123, + + ยท โ–ฒ + + ยท โ•ฐโ”€โ”€ invalid type: integer `123`, expected a string + + 3 โ”‚ "cpu": "x86-64", + + โ•ฐโ”€โ”€โ”€โ”€ + + + + + + diff --git a/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-endian.json-display.snap b/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-endian.ansi similarity index 71% rename from target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-endian.json-display.snap rename to target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-endian.ansi index 10b7979b405..e4e2c8385a1 100644 --- a/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-endian.json-display.snap +++ b/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-endian.ansi @@ -1,8 +1,4 @@ ---- -source: target-spec-miette/tests/datatest-snapshot/custom.rs -expression: "format!(\"{:?}\", miette::Report::new_boxed(diagnostic))" -snapshot_kind: text ---- + ร— error deserializing custom target JSON for `my-target` โ•ญโ”€[32:29] 31 โ”‚ }, diff --git a/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-endian.svg b/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-endian.svg new file mode 100644 index 00000000000..dd9038e554b --- /dev/null +++ b/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-endian.svg @@ -0,0 +1,45 @@ + + + + + + + + + ร— error deserializing custom target JSON for `my-target` + + โ•ญโ”€[32:29] + + 31 โ”‚ }, + + 32 โ”‚ "target-endian": "middle", + + ยท โ–ฒ + + ยท โ•ฐโ”€โ”€ unknown variant `middle`, expected `little` or `big` + + 33 โ”‚ "target-family": ["unix"], + + โ•ฐโ”€โ”€โ”€โ”€ + + + + + + diff --git a/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-family.json-display.snap b/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-family.ansi similarity index 71% rename from target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-family.json-display.snap rename to target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-family.ansi index 806da960d71..c80e48dc32f 100644 --- a/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-family.json-display.snap +++ b/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-family.ansi @@ -1,8 +1,4 @@ ---- -source: target-spec-miette/tests/datatest-snapshot/custom.rs -expression: "format!(\"{:?}\", miette::Report::new_boxed(diagnostic))" -snapshot_kind: text ---- + ร— error deserializing custom target JSON for `my-target` โ•ญโ”€[33:27] 32 โ”‚ "target-endian": "big", diff --git a/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-family.svg b/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-family.svg new file mode 100644 index 00000000000..68b864f6c0e --- /dev/null +++ b/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-family.svg @@ -0,0 +1,45 @@ + + + + + + + + + ร— error deserializing custom target JSON for `my-target` + + โ•ญโ”€[33:27] + + 32 โ”‚ "target-endian": "big", + + 33 โ”‚ "target-family": "none", + + ยท โ–ฒ + + ยท โ•ฐโ”€โ”€ invalid type: string "none", expected a sequence + + 34 โ”‚ "target-mcount": "_mcount", + + โ•ฐโ”€โ”€โ”€โ”€ + + + + + + diff --git a/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-target-pointer-width.json-display.snap b/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-target-pointer-width.ansi similarity index 71% rename from target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-target-pointer-width.json-display.snap rename to target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-target-pointer-width.ansi index 4ea91b22b4c..60a21fc99d7 100644 --- a/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-target-pointer-width.json-display.snap +++ b/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-target-pointer-width.ansi @@ -1,8 +1,4 @@ ---- -source: target-spec-miette/tests/datatest-snapshot/custom.rs -expression: "format!(\"{:?}\", miette::Report::new_boxed(diagnostic))" -snapshot_kind: text ---- + ร— error deserializing custom target JSON for `my-target` โ•ญโ”€[52:30] 51 โ”‚ ], diff --git a/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-target-pointer-width.svg b/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-target-pointer-width.svg new file mode 100644 index 00000000000..8db4a824316 --- /dev/null +++ b/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/invalid-target-pointer-width.svg @@ -0,0 +1,45 @@ + + + + + + + + + ร— error deserializing custom target JSON for `my-target` + + โ•ญโ”€[52:30] + + 51 โ”‚ ], + + 52 โ”‚ "target-pointer-width": "xx", + + ยท โ–ฒ + + ยท โ•ฐโ”€โ”€ error parsing as integer: invalid digit found in string + + 53 โ”‚ "supports-xray": true, + + โ•ฐโ”€โ”€โ”€โ”€ + + + + + + diff --git a/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/missing-arch.json-display.snap b/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/missing-arch.ansi similarity index 61% rename from target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/missing-arch.json-display.snap rename to target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/missing-arch.ansi index 7633fc83c1f..afb1abea4d4 100644 --- a/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/missing-arch.json-display.snap +++ b/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/missing-arch.ansi @@ -1,8 +1,4 @@ ---- -source: target-spec-miette/tests/datatest-snapshot/custom.rs -expression: "format!(\"{:?}\", miette::Report::new_boxed(diagnostic))" -snapshot_kind: text ---- + ร— error deserializing custom target JSON for `my-target` โ•ญโ”€[35:1] 34 โ”‚ "target-pointer-width": "64" diff --git a/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/missing-arch.svg b/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/missing-arch.svg new file mode 100644 index 00000000000..9a6ca0ff96a --- /dev/null +++ b/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/missing-arch.svg @@ -0,0 +1,43 @@ + + + + + + + + + ร— error deserializing custom target JSON for `my-target` + + โ•ญโ”€[35:1] + + 34 โ”‚ "target-pointer-width": "64" + + 35 โ”‚ } + + ยท โ–ฒ + + ยท โ•ฐโ”€โ”€ missing field `arch` + + โ•ฐโ”€โ”€โ”€โ”€ + + + + + + diff --git a/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/syntax-error.json-display.snap b/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/syntax-error.ansi similarity index 63% rename from target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/syntax-error.json-display.snap rename to target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/syntax-error.ansi index 7f369ef23d7..bdaf084156b 100644 --- a/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/syntax-error.json-display.snap +++ b/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/syntax-error.ansi @@ -1,8 +1,4 @@ ---- -source: target-spec-miette/tests/datatest-snapshot/custom.rs -expression: "format!(\"{:?}\", miette::Report::new_boxed(diagnostic))" -snapshot_kind: text ---- + ร— error deserializing custom target JSON for `my-target` โ•ญโ”€[40:13] 39 โ”‚ "leak", diff --git a/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/syntax-error.svg b/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/syntax-error.svg new file mode 100644 index 00000000000..d9490498bf5 --- /dev/null +++ b/target-spec-miette/tests/datatest-snapshot/snapshots/custom-invalid/syntax-error.svg @@ -0,0 +1,43 @@ + + + + + + + + + ร— error deserializing custom target JSON for `my-target` + + โ•ญโ”€[40:13] + + 39 โ”‚ "leak", + + 40 โ”‚ "memory", + + ยท โ–ฒ + + ยท โ•ฐโ”€โ”€ EOF while parsing a value + + โ•ฐโ”€โ”€โ”€โ”€ + + + + + + diff --git a/target-spec-miette/tests/datatest-snapshot/snapshots/expr-invalid/multiline-output-display.snap b/target-spec-miette/tests/datatest-snapshot/snapshots/expr-invalid/multiline-output.ansi similarity index 73% rename from target-spec-miette/tests/datatest-snapshot/snapshots/expr-invalid/multiline-output-display.snap rename to target-spec-miette/tests/datatest-snapshot/snapshots/expr-invalid/multiline-output.ansi index 549e59cfd80..904e376c016 100644 --- a/target-spec-miette/tests/datatest-snapshot/snapshots/expr-invalid/multiline-output-display.snap +++ b/target-spec-miette/tests/datatest-snapshot/snapshots/expr-invalid/multiline-output.ansi @@ -1,8 +1,4 @@ ---- -source: target-spec-miette/tests/datatest-snapshot/expr.rs -expression: "format!(\"{:?}\", miette::Report::new_boxed(diagnostic))" -snapshot_kind: text ---- + ร— error parsing cfg() expression โ•ญโ”€โ”€โ”€โ”€ 1 โ”‚ cfg(target_does_not_exist = "unix") diff --git a/target-spec-miette/tests/datatest-snapshot/snapshots/expr-invalid/multiline-output.svg b/target-spec-miette/tests/datatest-snapshot/snapshots/expr-invalid/multiline-output.svg new file mode 100644 index 00000000000..c1ce86464a0 --- /dev/null +++ b/target-spec-miette/tests/datatest-snapshot/snapshots/expr-invalid/multiline-output.svg @@ -0,0 +1,41 @@ + + + + + + + + + ร— error parsing cfg() expression + + โ•ญโ”€โ”€โ”€โ”€ + + 1 โ”‚ cfg(target_does_not_exist = "unix") + + ยท โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + + ยท โ•ฐโ”€โ”€ expected one of `target_arch`, `target_feature`, `target_os`, `target_family`, `target_env`, `target_endian`, `target_has_atomic`, `target_pointer_width`, `target_vendor` here + + โ•ฐโ”€โ”€โ”€โ”€ + + + + + + diff --git a/target-spec-miette/tests/datatest-snapshot/snapshots/expr-invalid/unclosed-delimiter-display.snap b/target-spec-miette/tests/datatest-snapshot/snapshots/expr-invalid/unclosed-delimiter.ansi similarity index 56% rename from target-spec-miette/tests/datatest-snapshot/snapshots/expr-invalid/unclosed-delimiter-display.snap rename to target-spec-miette/tests/datatest-snapshot/snapshots/expr-invalid/unclosed-delimiter.ansi index 00fcc412510..528708b7510 100644 --- a/target-spec-miette/tests/datatest-snapshot/snapshots/expr-invalid/unclosed-delimiter-display.snap +++ b/target-spec-miette/tests/datatest-snapshot/snapshots/expr-invalid/unclosed-delimiter.ansi @@ -1,8 +1,4 @@ ---- -source: target-spec-miette/tests/datatest-snapshot/expr.rs -expression: "format!(\"{:?}\", miette::Report::new_boxed(diagnostic))" -snapshot_kind: text ---- + ร— error parsing cfg() expression โ•ญโ”€โ”€โ”€โ”€ 1 โ”‚ cfg(unix diff --git a/target-spec-miette/tests/datatest-snapshot/snapshots/expr-invalid/unclosed-delimiter.svg b/target-spec-miette/tests/datatest-snapshot/snapshots/expr-invalid/unclosed-delimiter.svg new file mode 100644 index 00000000000..4a345bb31a2 --- /dev/null +++ b/target-spec-miette/tests/datatest-snapshot/snapshots/expr-invalid/unclosed-delimiter.svg @@ -0,0 +1,41 @@ + + + + + + + + + ร— error parsing cfg() expression + + โ•ญโ”€โ”€โ”€โ”€ + + 1 โ”‚ cfg(unix + + ยท โ”ฌ + + ยท โ•ฐโ”€โ”€ expected one of `=`, `,`, `)` here + + โ•ฐโ”€โ”€โ”€โ”€ + + + + + + diff --git a/target-spec-miette/tests/datatest-snapshot/snapshots/expr-invalid/unquoted-value-display.snap b/target-spec-miette/tests/datatest-snapshot/snapshots/expr-invalid/unquoted-value.ansi similarity index 60% rename from target-spec-miette/tests/datatest-snapshot/snapshots/expr-invalid/unquoted-value-display.snap rename to target-spec-miette/tests/datatest-snapshot/snapshots/expr-invalid/unquoted-value.ansi index 1a874392834..f6f8e9727ac 100644 --- a/target-spec-miette/tests/datatest-snapshot/snapshots/expr-invalid/unquoted-value-display.snap +++ b/target-spec-miette/tests/datatest-snapshot/snapshots/expr-invalid/unquoted-value.ansi @@ -1,8 +1,4 @@ ---- -source: target-spec-miette/tests/datatest-snapshot/expr.rs -expression: "format!(\"{:?}\", miette::Report::new_boxed(diagnostic))" -snapshot_kind: text ---- + ร— error parsing cfg() expression โ•ญโ”€โ”€โ”€โ”€ 1 โ”‚ cfg(target_os = none) diff --git a/target-spec-miette/tests/datatest-snapshot/snapshots/expr-invalid/unquoted-value.svg b/target-spec-miette/tests/datatest-snapshot/snapshots/expr-invalid/unquoted-value.svg new file mode 100644 index 00000000000..cbfd1d6fb56 --- /dev/null +++ b/target-spec-miette/tests/datatest-snapshot/snapshots/expr-invalid/unquoted-value.svg @@ -0,0 +1,41 @@ + + + + + + + + + ร— error parsing cfg() expression + + โ•ญโ”€โ”€โ”€โ”€ + + 1 โ”‚ cfg(target_os = none) + + ยท โ”€โ”€โ”ฌโ”€ + + ยท โ•ฐโ”€โ”€ expected a `"` here + + โ•ฐโ”€โ”€โ”€โ”€ + + + + + + diff --git a/target-spec-miette/tests/integration/main.rs b/target-spec-miette/tests/integration/main.rs index 3026e4dbee6..1946234be28 100644 --- a/target-spec-miette/tests/integration/main.rs +++ b/target-spec-miette/tests/integration/main.rs @@ -1,12 +1,30 @@ // Copyright (c) The cargo-guppy Contributors // SPDX-License-Identifier: MIT OR Apache-2.0 +use snapbox::{data::DataFormat, Data}; use target_spec::errors::CustomTripleCreateError; use target_spec_miette::IntoMietteDiagnostic; #[test] fn unavailable_snapshot() { + std::env::set_var("CLICOLOR_FORCE", "1"); + // Test that the unavailable diagnostic shows properly as a report. let report = miette::Report::new(CustomTripleCreateError::Unavailable.into_diagnostic()); - insta::assert_snapshot!(format!("{report:?}")); + // Use the Debug format to get the report ace the fancy displayer would show + // it. + let actual = format!("{:?}", report); + + let b = snapbox::Assert::new().action_env("SNAPSHOTS"); + + // Store SVG and ANSI snapshots. Use the binary representation to ensure + // that no post-processing of text happens. + b.eq( + Data::binary(actual.clone()).coerce_to(DataFormat::TermSvg), + snapbox::file!["snapshots/unavailable.svg"], + ); + b.eq( + Data::binary(actual), + snapbox::file!["snapshots/unavailable.ansi"], + ); } diff --git a/target-spec-miette/tests/integration/snapshots/integration__unavailable_snapshot.snap b/target-spec-miette/tests/integration/snapshots/integration__unavailable_snapshot.snap deleted file mode 100644 index 0113a90eab2..00000000000 --- a/target-spec-miette/tests/integration/snapshots/integration__unavailable_snapshot.snap +++ /dev/null @@ -1,7 +0,0 @@ ---- -source: target-spec-miette/tests/integration/main.rs -expression: "format!(\"{report:?}\")" -snapshot_kind: text ---- - ร— custom platforms are currently unavailable: to enable them, add the - โ”‚ `custom` feature to target-spec diff --git a/target-spec-miette/tests/integration/snapshots/unavailable.ansi b/target-spec-miette/tests/integration/snapshots/unavailable.ansi new file mode 100644 index 00000000000..af17424f7fc --- /dev/null +++ b/target-spec-miette/tests/integration/snapshots/unavailable.ansi @@ -0,0 +1,3 @@ + + ร— custom platforms are currently unavailable: to enable them, add the + โ”‚ `custom` feature to target-spec diff --git a/target-spec-miette/tests/integration/snapshots/unavailable.svg b/target-spec-miette/tests/integration/snapshots/unavailable.svg new file mode 100644 index 00000000000..2d1ac1e7995 --- /dev/null +++ b/target-spec-miette/tests/integration/snapshots/unavailable.svg @@ -0,0 +1,30 @@ + + + + + + + + + ร— custom platforms are currently unavailable: to enable them, add the + + โ”‚ `custom` feature to target-spec + + + + + + diff --git a/workspace-hack/Cargo.toml b/workspace-hack/Cargo.toml index b5cf3008a45..892ed8f1e31 100644 --- a/workspace-hack/Cargo.toml +++ b/workspace-hack/Cargo.toml @@ -22,7 +22,6 @@ backtrace = { version = "0.3.69", features = ["gimli-symbolize"] } camino = { version = "1.1.9", default-features = false, features = ["serde1"] } clap = { version = "4.5.22", features = ["derive"] } clap_builder = { version = "4.5.22", default-features = false, features = ["color", "help", "std", "suggestions", "usage"] } -console = { version = "0.15.8" } getrandom = { version = "0.2.12", default-features = false, features = ["std"] } include_dir = { version = "0.7.4", features = ["glob"] } indexmap = { version = "1.9.3", default-features = false, features = ["std"] }