mirror of
https://github.com/swc-project/swc.git
synced 2024-10-04 20:28:43 +03:00
test(es/minifier): Enable size tests created from creduce
(#6646)
This commit is contained in:
parent
b569cee03b
commit
7f3e6983e5
@ -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,
|
||||
};
|
||||
@ -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>
|
||||
@ -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")]
|
||||
@ -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> {
|
||||
@ -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,
|
||||
|
@ -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();
|
||||
@ -431,7 +431,7 @@ fn projects_bench(input: PathBuf) {
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
/// Tests ported from terser.
|
||||
@ -1712,7 +1712,8 @@ fn full(input: PathBuf) {
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
unignore_fixture(&input);
|
||||
}
|
||||
|
||||
struct DropParens;
|
||||
|
@ -0,0 +1 @@
|
||||
[]({c(){a({c:()=>b})}});
|
@ -0,0 +1 @@
|
||||
[](function(){});
|
@ -0,0 +1 @@
|
||||
[](function(){a={b:{c:{"":{d:"Az̧ Z̧a‘āyin"}}}}});
|
@ -0,0 +1 @@
|
||||
[](function(){a});
|
@ -0,0 +1 @@
|
||||
[]({d(){b(b)}});
|
@ -0,0 +1 @@
|
||||
[]({a(){b({c:{c:d?{c:{e:". We’re working to bring this to a frameworks soon."}}:0}})}});
|
@ -0,0 +1 @@
|
||||
[](function(){var n=function(){n[b]}});
|
@ -0,0 +1 @@
|
||||
c(function(){b});
|
@ -0,0 +1 @@
|
||||
[](function(){});
|
@ -0,0 +1 @@
|
||||
[](function(){var n=function(){0(function(){return n})}});
|
@ -0,0 +1 @@
|
||||
[](function(){var n=function(){b(function(){b(n)})}});
|
@ -0,0 +1 @@
|
||||
({function:()=>({})})();
|
@ -0,0 +1 @@
|
||||
[](function(){var n=function(){n.b}});
|
@ -0,0 +1 @@
|
||||
[](function(){var a=b;d.e(a);var r=b;d.e(r);var v=e(v)});
|
@ -0,0 +1 @@
|
||||
[](function(){});
|
@ -0,0 +1 @@
|
||||
[](function(){});
|
@ -0,0 +1 @@
|
||||
[]({d(){if(a)try{for(c;;);}catch{}}});
|
@ -0,0 +1 @@
|
||||
[](function(){});
|
@ -0,0 +1 @@
|
||||
[](function(){});
|
@ -0,0 +1 @@
|
||||
[](function(){a(function(){})});
|
@ -0,0 +1 @@
|
||||
[]({function(){a(function(){b(function(){for(var f;;)if(void 0==d)for(var f=e;;f);})})}});
|
@ -0,0 +1 @@
|
||||
self=self||[].push[{8:function(){0()}}];
|
@ -0,0 +1 @@
|
||||
[](function(){var n;n=function(){b(n)}});
|
@ -0,0 +1 @@
|
||||
a=b?function(){}:function(){};
|
@ -0,0 +1 @@
|
||||
0(function(){});
|
@ -0,0 +1 @@
|
||||
[](function(){var n=function(){b(n)}});
|
@ -0,0 +1 @@
|
||||
self=self||[].push[{4:function(){0()},80288:0}];
|
@ -0,0 +1 @@
|
||||
[]({c(){a=({}).b}});
|
@ -0,0 +1 @@
|
||||
[]({b(){a;"use strict"}});
|
@ -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,
|
||||
@ -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");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user