From 9656b4e9f960e0fd47281944e1ddd54ae0abe967 Mon Sep 17 00:00:00 2001 From: sapphi-red <49056869+sapphi-red@users.noreply.github.com> Date: Sat, 28 Dec 2024 18:41:43 +0900 Subject: [PATCH 1/2] chore(tasks): print diff for minify idempotency assertion --- Cargo.lock | 19 ++++++++++++++++++- Cargo.toml | 1 + tasks/minsize/Cargo.toml | 2 ++ tasks/minsize/src/lib.rs | 23 ++++++++++++++++++++++- 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cab6130bbc748..9461a3e989753 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -174,6 +174,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a68f1f47cdf0ec8ee4b941b2eee2a80cb796db73118c0dd09ac63fbe405be22" dependencies = [ "memchr", + "regex-automata", "serde", ] @@ -1082,7 +1083,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] @@ -1787,6 +1788,7 @@ dependencies = [ name = "oxc_minsize" version = "0.0.0" dependencies = [ + "cow-utils", "flate2", "humansize", "oxc_allocator", @@ -1798,6 +1800,7 @@ dependencies = [ "oxc_tasks_common", "oxc_transformer", "rustc-hash", + "similar-asserts", ] [[package]] @@ -2749,6 +2752,20 @@ name = "similar" version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1de1d4f81173b03af4c0cbed3c898f6bff5b870e4a7f5d6f4057d62a7a4b686e" +dependencies = [ + "bstr", + "unicode-segmentation", +] + +[[package]] +name = "similar-asserts" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfe85670573cd6f0fa97940f26e7e6601213c3b0555246c24234131f88c5709e" +dependencies = [ + "console", + "similar", +] [[package]] name = "siphasher" diff --git a/Cargo.toml b/Cargo.toml index 1bd59663b3e21..4a6973a2955f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -174,6 +174,7 @@ num-traits = "0.2.19" petgraph = "0.6.5" phf = "0.11.2" pico-args = "0.5.0" +similar-asserts = "1.6.0" prettyplease = "0.2.25" project-root = "0.2.2" rayon = "1.10.0" diff --git a/tasks/minsize/Cargo.toml b/tasks/minsize/Cargo.toml index c842002da53fe..6adfccf6f6140 100644 --- a/tasks/minsize/Cargo.toml +++ b/tasks/minsize/Cargo.toml @@ -29,5 +29,7 @@ oxc_transformer = { workspace = true } flate2 = { workspace = true } oxc_tasks_common = { workspace = true } +cow-utils = { workspace = true } humansize = { workspace = true } +similar-asserts = { workspace = true } rustc-hash = { workspace = true } diff --git a/tasks/minsize/src/lib.rs b/tasks/minsize/src/lib.rs index 3c149505e568d..91eda08f1e8df 100644 --- a/tasks/minsize/src/lib.rs +++ b/tasks/minsize/src/lib.rs @@ -16,6 +16,7 @@ use oxc_span::SourceType; use oxc_tasks_common::{project_root, TestFile, TestFiles}; use oxc_transformer::{ReplaceGlobalDefines, ReplaceGlobalDefinesConfig}; use rustc_hash::FxHashMap; +use similar_asserts::assert_eq; // #[test] // #[cfg(any(coverage, coverage_nightly))] @@ -23,6 +24,21 @@ use rustc_hash::FxHashMap; // run().unwrap(); // } +macro_rules! assert_eq_minified_code { + ($left:expr, $right:expr, $($arg:tt)*) => { + if $left != $right { + let normalized_left = $crate::normalize_minified_code($left); + let normalized_right = $crate::normalize_minified_code($right); + assert_eq!(normalized_left, normalized_right, $($arg)*); + } + }; +} + +fn normalize_minified_code(code: &str) -> String { + use cow_utils::CowUtils; + code.cow_replace(";", ";\n").cow_replace(",", ",\n").into_owned() +} + /// # Panics /// # Errors pub fn run() -> Result<(), io::Error> { @@ -131,7 +147,12 @@ fn minify_twice(file: &TestFile) -> String { }; let source_text1 = minify(&file.source_text, source_type, options); let source_text2 = minify(&source_text1, source_type, options); - assert_eq!(source_text1, source_text2, "Minification failed for {}", &file.file_name); + assert_eq_minified_code!( + &source_text1, + &source_text2, + "Minification failed for {}", + &file.file_name + ); source_text2 } From f2e5a393a2a9d296ca3556e893f41c01a345008d Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Sat, 28 Dec 2024 09:48:12 +0000 Subject: [PATCH 2/2] [autofix.ci] apply automated fixes --- Cargo.toml | 2 +- tasks/minsize/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4a6973a2955f9..1eff0ff6634e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -174,7 +174,6 @@ num-traits = "0.2.19" petgraph = "0.6.5" phf = "0.11.2" pico-args = "0.5.0" -similar-asserts = "1.6.0" prettyplease = "0.2.25" project-root = "0.2.2" rayon = "1.10.0" @@ -190,6 +189,7 @@ serde-wasm-bindgen = "0.6.5" sha1 = "0.10.6" simdutf8 = { version = "0.1.5", features = ["aarch64_neon"] } similar = "2.6.0" +similar-asserts = "1.6.0" string_wizard = "0.0.25" tempfile = "3.14.0" tokio = "1.42.0" diff --git a/tasks/minsize/Cargo.toml b/tasks/minsize/Cargo.toml index 6adfccf6f6140..5a39fe439d403 100644 --- a/tasks/minsize/Cargo.toml +++ b/tasks/minsize/Cargo.toml @@ -31,5 +31,5 @@ oxc_tasks_common = { workspace = true } cow-utils = { workspace = true } humansize = { workspace = true } -similar-asserts = { workspace = true } rustc-hash = { workspace = true } +similar-asserts = { workspace = true }