mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +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();
|
||||
|
||||
if !ret.errors.is_empty() {
|
||||
println!("Parser Errors:");
|
||||
for error in ret.errors {
|
||||
let error = error.with_source_code(source_text.clone());
|
||||
println!("{error:?}");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
println!("Original:\n");
|
||||
|
|
@ -46,7 +46,7 @@ fn main() {
|
|||
},
|
||||
..Default::default()
|
||||
};
|
||||
Transformer::new(
|
||||
let _ = Transformer::new(
|
||||
&allocator,
|
||||
path,
|
||||
source_type,
|
||||
|
|
@ -54,8 +54,7 @@ fn main() {
|
|||
ret.trivias.clone(),
|
||||
transform_options,
|
||||
)
|
||||
.build(&mut program)
|
||||
.unwrap();
|
||||
.build(&mut program);
|
||||
|
||||
let printed = Codegen::<false>::new("", &source_text, ret.trivias, CodegenOptions::default())
|
||||
.build(&program)
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ use crate::{
|
|||
typescript::TypeScriptCase,
|
||||
};
|
||||
|
||||
/// Runs the transformer and make sure it doesn't crash.
|
||||
/// Idempotency test
|
||||
fn get_result(
|
||||
source_text: &str,
|
||||
source_type: SourceType,
|
||||
|
|
@ -27,76 +27,51 @@ fn get_result(
|
|||
let allocator = Allocator::default();
|
||||
let filename = source_path.file_name().unwrap().to_string_lossy();
|
||||
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(
|
||||
&filename,
|
||||
source_text,
|
||||
parse_result1.trivias.clone(),
|
||||
CodegenOptions::default(),
|
||||
)
|
||||
.build(&program)
|
||||
.source_text;
|
||||
// First pass
|
||||
let transformed1 = {
|
||||
let mut ret1 = Parser::new(&allocator, source_text, source_type).parse();
|
||||
let _ = Transformer::new(
|
||||
&allocator,
|
||||
source_path,
|
||||
source_type,
|
||||
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(
|
||||
&filename,
|
||||
source_text,
|
||||
parse_result1.trivias.clone(),
|
||||
CodegenOptions::default(),
|
||||
)
|
||||
.build(&program)
|
||||
.source_text;
|
||||
// Second pass with only JavaScript parsing
|
||||
let transformed2 = {
|
||||
let source_type = SourceType::default().with_module(source_type.is_module());
|
||||
let mut ret2 = Parser::new(&allocator, &transformed1, source_type).parse();
|
||||
let _ = Transformer::new(
|
||||
&allocator,
|
||||
source_path,
|
||||
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 {
|
||||
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
|
||||
})
|
||||
})
|
||||
{
|
||||
if transformed1 == transformed2 {
|
||||
TestResult::Passed
|
||||
} else {
|
||||
TestResult::Mismatch(source_text1.clone(), source_text2)
|
||||
TestResult::Mismatch(transformed1, transformed2)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,4 +2,5 @@ commit: 12619ffe
|
|||
|
||||
transformer_babel Summary:
|
||||
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:
|
||||
AST Parsed : 5283/5283 (100.00%)
|
||||
Positive Passed: 5282/5283 (99.98%)
|
||||
Positive Passed: 5268/5283 (99.72%)
|
||||
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