Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(es/minifier): Enable size tests created from creduce #6646

Merged
merged 7 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 5 additions & 33 deletions crates/swc/tests/exec.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{
env,
fs::{self, create_dir_all, rename},
path::{Component, Path, PathBuf},
env, fs,
path::{Path, PathBuf},
process::Command,
sync::Arc,
};
Expand All @@ -16,7 +15,7 @@ use swc_common::{errors::ColorConfig, SourceMap, GLOBALS};
use swc_ecma_ast::EsVersion;
use swc_ecma_parser::{EsConfig, Syntax, TsConfig};
use swc_ecma_testing::{exec_node_js, JsExecOptions};
use testing::{assert_eq, find_executable};
use testing::{assert_eq, find_executable, unignore_fixture};
use tracing::{span, Level};

trait IterExt<T>: Sized + IntoIterator<Item = T>
Expand Down Expand Up @@ -220,7 +219,7 @@ fn run_fixture_test(entry: PathBuf) {

// Test was successful.

unignore(&entry);
unignore_fixture(&entry);
}

#[testing::fixture("tests/babel-exec/**/exec.js")]
Expand Down Expand Up @@ -249,7 +248,7 @@ fn run_babel_fixture_exec_test(entry: PathBuf) {

// Test was successful.

unignore(&entry);
unignore_fixture(&entry);
}

fn get_expected_stdout(input: &Path) -> Result<String, Error> {
Expand Down Expand Up @@ -315,33 +314,6 @@ fn get_expected_stdout(input: &Path) -> Result<String, Error> {
})
}

/// Rename `foo/.bar/exec.js` => `foo/bar/exec.js`
fn unignore(path: &Path) {
if path.components().all(|c| {
!matches!(c, Component::Normal(..)) || !c.as_os_str().to_string_lossy().starts_with('.')
}) {
return;
}
//

let mut new_path = PathBuf::new();

for c in path.components() {
if let Component::Normal(s) = c {
if let Some(s) = s.to_string_lossy().strip_prefix('.') {
new_path.push(s);

continue;
}
}
new_path.push(c);
}

create_dir_all(new_path.parent().unwrap()).expect("failed to create parent dir");

rename(path, &new_path).expect("failed to rename");
}

fn test_file_with_opts(
entry: &Path,
opts: &Options,
Expand Down
7 changes: 4 additions & 3 deletions crates/swc_ecma_minifier/tests/compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use swc_ecma_testing::{exec_node_js, JsExecOptions};
use swc_ecma_transforms_base::{fixer::fixer, hygiene::hygiene, resolver};
use swc_ecma_utils::drop_span;
use swc_ecma_visit::{FoldWith, Visit, VisitMut, VisitMutWith, VisitWith};
use testing::{assert_eq, DebugUsingDisplay, NormalizedOutput};
use testing::{assert_eq, unignore_fixture, DebugUsingDisplay, NormalizedOutput};

fn load_txt(filename: &str) -> Vec<String> {
let lines = read_to_string(filename).unwrap();
Expand Down Expand Up @@ -431,7 +431,7 @@ fn projects_bench(input: PathBuf) {

Ok(())
})
.unwrap()
.unwrap();
}

/// Tests ported from terser.
Expand Down Expand Up @@ -1712,7 +1712,8 @@ fn full(input: PathBuf) {

Ok(())
})
.unwrap()
.unwrap();
unignore_fixture(&input);
}

struct DropParens;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]({c(){a({c:()=>b})}});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[](function(){});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[](function(){a={b:{c:{"":{d:"Az̧ Z̧a‘āyin"}}}}});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[](function(){a});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]({d(){b(b)}});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]({a(){b({c:{c:d?{c:{e:". We’re working to bring this to a frameworks soon."}}:0}})}});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[](function(){var n=function(){n[b]}});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c(function(){b});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[](function(){});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[](function(){var n=function(){0(function(){return n})}});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[](function(){var n=function(){b(function(){b(n)})}});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
({function:()=>({})})();
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[](function(){var n=function(){n.b}});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[](function(){var a=b;d.e(a);var r=b;d.e(r);var v=e(v)});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[](function(){});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[](function(){});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]({d(){if(a)try{for(c;;);}catch{}}});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[](function(){});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[](function(){});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[](function(){a(function(){})});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]({function(){a(function(){b(function(){for(var f;;)if(void 0==d)for(var f=e;;f);})})}});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
self=self||[].push[{8:function(){0()}}];
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[](function(){var n;n=function(){b(n)}});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a=b?function(){}:function(){};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0(function(){});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[](function(){var n=function(){b(n)}});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
self=self||[].push[{4:function(){0()},80288:0}];
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]({c(){a=({}).b}});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]({b(){a;"use strict"}});
31 changes: 29 additions & 2 deletions crates/testing/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::{
env, fmt,
fmt::{Debug, Display, Formatter},
fs::{create_dir_all, File},
fs::{create_dir_all, rename, File},
io::Write,
path::{Path, PathBuf},
path::{Component, Path, PathBuf},
str::FromStr,
sync::RwLock,
thread,
Expand Down Expand Up @@ -282,3 +282,30 @@ impl<'a> Debug for DebugUsingDisplay<'a> {
Display::fmt(self.0, f)
}
}

/// Rename `foo/.bar/exec.js` => `foo/bar/exec.js`
pub fn unignore_fixture(fixture_path: &Path) {
if fixture_path.components().all(|c| {
!matches!(c, Component::Normal(..)) || !c.as_os_str().to_string_lossy().starts_with('.')
}) {
return;
}
//

let mut new_path = PathBuf::new();

for c in fixture_path.components() {
if let Component::Normal(s) = c {
if let Some(s) = s.to_string_lossy().strip_prefix('.') {
new_path.push(s);

continue;
}
}
new_path.push(c);
}

create_dir_all(new_path.parent().unwrap()).expect("failed to create parent dir");

rename(fixture_path, &new_path).expect("failed to rename");
}