mirror of
https://github.com/swc-project/swc.git
synced 2025-01-03 02:54:43 +03:00
fix(es/trasnforms/testing): Improve test_fixture
(#2369)
swc_ecma_transforms_testing: - `test_fixture`: Don't print stderr to file. - Enable logging. - Add `test_fixture_allowing_error`.
This commit is contained in:
parent
4ff1b7568c
commit
7a19fc6e8c
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -2929,7 +2929,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "swc_ecma_transforms_testing"
|
||||
version = "0.36.0"
|
||||
version = "0.36.1"
|
||||
dependencies = [
|
||||
"ansi_term 0.12.1",
|
||||
"anyhow",
|
||||
|
@ -11,7 +11,7 @@ use swc_ecma_transforms_compat::{
|
||||
es3::property_literals,
|
||||
};
|
||||
use swc_ecma_transforms_module::common_js::common_js;
|
||||
use swc_ecma_transforms_testing::{parse_options, test, test_fixture, Tester};
|
||||
use swc_ecma_transforms_testing::{parse_options, test, test_fixture_allowing_error, Tester};
|
||||
|
||||
fn tr(t: &mut Tester, options: Options, top_level_mark: Mark) -> impl Fold {
|
||||
chain!(
|
||||
@ -1357,7 +1357,7 @@ fn fixture(input: PathBuf) {
|
||||
output = input.with_file_name("output.mjs");
|
||||
}
|
||||
|
||||
test_fixture(
|
||||
test_fixture_allowing_error(
|
||||
Syntax::Es(EsConfig {
|
||||
jsx: true,
|
||||
..Default::default()
|
||||
|
@ -1,12 +0,0 @@
|
||||
error: Expected ,, got :
|
||||
--> output.js:8:12
|
||||
|
|
||||
8 | foo-bar: true
|
||||
| ^
|
||||
|
||||
error: Expression expected
|
||||
--> output.js:8:8
|
||||
|
|
||||
8 | foo-bar: true
|
||||
| ^
|
||||
|
@ -1,12 +0,0 @@
|
||||
error: Expected ,, got :
|
||||
--> output.js:3:15
|
||||
|
|
||||
3 | data-value: "a value\n with\nnewlines\n and spaces",
|
||||
| ^
|
||||
|
||||
error: Expression expected
|
||||
--> output.js:3:9
|
||||
|
|
||||
3 | data-value: "a value\n with\nnewlines\n and spaces",
|
||||
| ^
|
||||
|
@ -1,12 +0,0 @@
|
||||
error: Expected ,, got :
|
||||
--> output.js:3:15
|
||||
|
|
||||
3 | data-value: "a value",
|
||||
| ^
|
||||
|
||||
error: Expression expected
|
||||
--> output.js:3:9
|
||||
|
|
||||
3 | data-value: "a value",
|
||||
| ^
|
||||
|
@ -6,7 +6,7 @@ edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecma_transforms_testing"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.36.0"
|
||||
version = "0.36.1"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
@ -610,6 +610,31 @@ pub fn test_fixture<P>(syntax: Syntax, tr: &dyn Fn(&mut Tester) -> P, input: &Pa
|
||||
where
|
||||
P: Fold,
|
||||
{
|
||||
test_fixture_inner(syntax, tr, input, output, false)
|
||||
}
|
||||
|
||||
pub fn test_fixture_allowing_error<P>(
|
||||
syntax: Syntax,
|
||||
tr: &dyn Fn(&mut Tester) -> P,
|
||||
input: &Path,
|
||||
output: &Path,
|
||||
) where
|
||||
P: Fold,
|
||||
{
|
||||
test_fixture_inner(syntax, tr, input, output, true)
|
||||
}
|
||||
|
||||
fn test_fixture_inner<P>(
|
||||
syntax: Syntax,
|
||||
tr: &dyn Fn(&mut Tester) -> P,
|
||||
input: &Path,
|
||||
output: &Path,
|
||||
allow_error: bool,
|
||||
) where
|
||||
P: Fold,
|
||||
{
|
||||
let _logger = testing::init();
|
||||
|
||||
let expected = read_to_string(output);
|
||||
let _is_really_expected = expected.is_ok();
|
||||
let expected = expected.unwrap_or_default();
|
||||
@ -675,9 +700,14 @@ where
|
||||
|
||||
let mut results = vec![];
|
||||
|
||||
if !stderr.is_empty() {
|
||||
results
|
||||
.push(NormalizedOutput::from(stderr).compare_to_file(output.with_extension("stderr")));
|
||||
if allow_error {
|
||||
NormalizedOutput::from(stderr)
|
||||
.compare_to_file(output.with_extension("stderr"))
|
||||
.unwrap();
|
||||
} else {
|
||||
if !stderr.is_empty() {
|
||||
panic!("stderr: {}", stderr);
|
||||
}
|
||||
}
|
||||
|
||||
match actual_src {
|
||||
|
Loading…
Reference in New Issue
Block a user