Skip to content

Commit

Permalink
chore(tasks): print diff for minify idempotency assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Dec 28, 2024
1 parent 37c9959 commit 9656b4e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
19 changes: 18 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions tasks/minsize/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
23 changes: 22 additions & 1 deletion tasks/minsize/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,29 @@ 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))]
// fn test() {
// 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> {
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 9656b4e

Please sign in to comment.