mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
feat(coverage): transformer idempotency test (#3691)
This commit is contained in:
parent
a56cb1b482
commit
750a534455
4 changed files with 61 additions and 72 deletions
|
|
@ -24,11 +24,11 @@ fn main() {
|
||||||
let ret = Parser::new(&allocator, &source_text, source_type).parse();
|
let ret = Parser::new(&allocator, &source_text, source_type).parse();
|
||||||
|
|
||||||
if !ret.errors.is_empty() {
|
if !ret.errors.is_empty() {
|
||||||
|
println!("Parser Errors:");
|
||||||
for error in ret.errors {
|
for error in ret.errors {
|
||||||
let error = error.with_source_code(source_text.clone());
|
let error = error.with_source_code(source_text.clone());
|
||||||
println!("{error:?}");
|
println!("{error:?}");
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("Original:\n");
|
println!("Original:\n");
|
||||||
|
|
@ -46,7 +46,7 @@ fn main() {
|
||||||
},
|
},
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
Transformer::new(
|
let _ = Transformer::new(
|
||||||
&allocator,
|
&allocator,
|
||||||
path,
|
path,
|
||||||
source_type,
|
source_type,
|
||||||
|
|
@ -54,8 +54,7 @@ fn main() {
|
||||||
ret.trivias.clone(),
|
ret.trivias.clone(),
|
||||||
transform_options,
|
transform_options,
|
||||||
)
|
)
|
||||||
.build(&mut program)
|
.build(&mut program);
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let printed = Codegen::<false>::new("", &source_text, ret.trivias, CodegenOptions::default())
|
let printed = Codegen::<false>::new("", &source_text, ret.trivias, CodegenOptions::default())
|
||||||
.build(&program)
|
.build(&program)
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ use crate::{
|
||||||
typescript::TypeScriptCase,
|
typescript::TypeScriptCase,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Runs the transformer and make sure it doesn't crash.
|
/// Idempotency test
|
||||||
fn get_result(
|
fn get_result(
|
||||||
source_text: &str,
|
source_text: &str,
|
||||||
source_type: SourceType,
|
source_type: SourceType,
|
||||||
|
|
@ -27,76 +27,51 @@ fn get_result(
|
||||||
let allocator = Allocator::default();
|
let allocator = Allocator::default();
|
||||||
let filename = source_path.file_name().unwrap().to_string_lossy();
|
let filename = source_path.file_name().unwrap().to_string_lossy();
|
||||||
let options = options.unwrap_or_else(get_default_transformer_options);
|
let options = options.unwrap_or_else(get_default_transformer_options);
|
||||||
let parse_result1 = Parser::new(&allocator, source_text, source_type).parse();
|
|
||||||
let mut program = parse_result1.program;
|
|
||||||
let transform_result1 = Transformer::new(
|
|
||||||
&allocator,
|
|
||||||
source_path,
|
|
||||||
source_type,
|
|
||||||
source_text,
|
|
||||||
parse_result1.trivias.clone(),
|
|
||||||
options.clone(),
|
|
||||||
)
|
|
||||||
.build(&mut program);
|
|
||||||
|
|
||||||
let ts_source_text1 = Codegen::<false>::new(
|
// First pass
|
||||||
&filename,
|
let transformed1 = {
|
||||||
source_text,
|
let mut ret1 = Parser::new(&allocator, source_text, source_type).parse();
|
||||||
parse_result1.trivias.clone(),
|
let _ = Transformer::new(
|
||||||
CodegenOptions::default(),
|
&allocator,
|
||||||
)
|
source_path,
|
||||||
.build(&program)
|
source_type,
|
||||||
.source_text;
|
source_text,
|
||||||
|
ret1.trivias.clone(),
|
||||||
|
options.clone(),
|
||||||
|
)
|
||||||
|
.build(&mut ret1.program);
|
||||||
|
Codegen::<false>::new(
|
||||||
|
&filename,
|
||||||
|
source_text,
|
||||||
|
ret1.trivias.clone(),
|
||||||
|
CodegenOptions::default(),
|
||||||
|
)
|
||||||
|
.build(&ret1.program)
|
||||||
|
.source_text
|
||||||
|
};
|
||||||
|
|
||||||
let source_text1 = Codegen::<false>::new(
|
// Second pass with only JavaScript parsing
|
||||||
&filename,
|
let transformed2 = {
|
||||||
source_text,
|
let source_type = SourceType::default().with_module(source_type.is_module());
|
||||||
parse_result1.trivias.clone(),
|
let mut ret2 = Parser::new(&allocator, &transformed1, source_type).parse();
|
||||||
CodegenOptions::default(),
|
let _ = Transformer::new(
|
||||||
)
|
&allocator,
|
||||||
.build(&program)
|
source_path,
|
||||||
.source_text;
|
source_type,
|
||||||
|
&transformed1,
|
||||||
|
ret2.trivias.clone(),
|
||||||
|
options,
|
||||||
|
)
|
||||||
|
.build(&mut ret2.program);
|
||||||
|
Codegen::<false>::new(&filename, source_text, ret2.trivias, CodegenOptions::default())
|
||||||
|
.build(&ret2.program)
|
||||||
|
.source_text
|
||||||
|
};
|
||||||
|
|
||||||
if transform_result1.is_ok() && ts_source_text1 != source_text1 {
|
if transformed1 == transformed2 {
|
||||||
return TestResult::Mismatch(ts_source_text1.clone(), source_text1.clone());
|
|
||||||
}
|
|
||||||
|
|
||||||
let parse_result2 = Parser::new(&allocator, &ts_source_text1, source_type).parse();
|
|
||||||
let mut program = parse_result2.program;
|
|
||||||
|
|
||||||
let transform_result2 = Transformer::new(
|
|
||||||
&allocator,
|
|
||||||
source_path,
|
|
||||||
source_type,
|
|
||||||
&source_text1,
|
|
||||||
parse_result2.trivias.clone(),
|
|
||||||
options,
|
|
||||||
)
|
|
||||||
.build(&mut program);
|
|
||||||
|
|
||||||
let source_text2 = Codegen::<false>::new(
|
|
||||||
&filename,
|
|
||||||
&source_text1,
|
|
||||||
parse_result2.trivias,
|
|
||||||
CodegenOptions::default(),
|
|
||||||
)
|
|
||||||
.build(&program)
|
|
||||||
.source_text;
|
|
||||||
|
|
||||||
if source_text1 == source_text2
|
|
||||||
|| transform_result1.is_err_and(|err| {
|
|
||||||
// If error messages are the same, we consider it as a pass.
|
|
||||||
transform_result2
|
|
||||||
.map_err(|err| err.iter().map(ToString::to_string).collect::<Vec<_>>().join("\n"))
|
|
||||||
.is_err_and(|err_message| {
|
|
||||||
err.iter().map(ToString::to_string).collect::<Vec<_>>().join("\n")
|
|
||||||
== err_message
|
|
||||||
})
|
|
||||||
})
|
|
||||||
{
|
|
||||||
TestResult::Passed
|
TestResult::Passed
|
||||||
} else {
|
} else {
|
||||||
TestResult::Mismatch(source_text1.clone(), source_text2)
|
TestResult::Mismatch(transformed1, transformed2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,4 +2,5 @@ commit: 12619ffe
|
||||||
|
|
||||||
transformer_babel Summary:
|
transformer_babel Summary:
|
||||||
AST Parsed : 2101/2101 (100.00%)
|
AST Parsed : 2101/2101 (100.00%)
|
||||||
Positive Passed: 2101/2101 (100.00%)
|
Positive Passed: 2100/2101 (99.95%)
|
||||||
|
Mismatch: "typescript/class/accessor/input.ts"
|
||||||
|
|
|
||||||
|
|
@ -2,5 +2,19 @@ commit: d8086f14
|
||||||
|
|
||||||
transformer_typescript Summary:
|
transformer_typescript Summary:
|
||||||
AST Parsed : 5283/5283 (100.00%)
|
AST Parsed : 5283/5283 (100.00%)
|
||||||
Positive Passed: 5282/5283 (99.98%)
|
Positive Passed: 5268/5283 (99.72%)
|
||||||
Mismatch: "compiler/elidedEmbeddedStatementsReplacedWithSemicolon.ts"
|
Mismatch: "compiler/elidedEmbeddedStatementsReplacedWithSemicolon.ts"
|
||||||
|
Mismatch: "compiler/esDecoratorsClassFieldsCrash.ts"
|
||||||
|
Mismatch: "compiler/useBeforeDeclaration_classDecorators.2.ts"
|
||||||
|
Mismatch: "conformance/classes/propertyMemberDeclarations/autoAccessor10.ts"
|
||||||
|
Mismatch: "conformance/classes/propertyMemberDeclarations/autoAccessor2.ts"
|
||||||
|
Mismatch: "conformance/classes/propertyMemberDeclarations/autoAccessor9.ts"
|
||||||
|
Mismatch: "conformance/classes/propertyMemberDeclarations/autoAccessorAllowedModifiers.ts"
|
||||||
|
Mismatch: "conformance/classes/propertyMemberDeclarations/staticAutoAccessors.ts"
|
||||||
|
Mismatch: "conformance/classes/propertyMemberDeclarations/staticAutoAccessorsWithDecorators.ts"
|
||||||
|
Mismatch: "conformance/decorators/legacyDecorators-contextualTypes.ts"
|
||||||
|
Mismatch: "conformance/esDecorators/classDeclaration/classThisReference/esDecorators-classDeclaration-classThisReference.ts"
|
||||||
|
Mismatch: "conformance/esDecorators/classDeclaration/fields/esDecorators-classDeclaration-fields-staticAccessor.ts"
|
||||||
|
Mismatch: "conformance/esDecorators/classDeclaration/fields/esDecorators-classDeclaration-fields-staticPrivateAccessor.ts"
|
||||||
|
Mismatch: "conformance/esDecorators/classExpression/esDecorators-classExpression-commentPreservation.ts"
|
||||||
|
Mismatch: "conformance/esDecorators/esDecorators-contextualTypes.ts"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue