Skip to content

Commit

Permalink
add stats
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Dec 18, 2024
1 parent 9853f35 commit b920eeb
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::feature::Feature;

#[derive(Default)]
pub struct Ctx {
diagnostics: Vec<OxcDiagnostic>,
pub(crate) diagnostics: Vec<OxcDiagnostic>,
}

impl Ctx {
Expand Down
7 changes: 6 additions & 1 deletion src/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct Scanner {

pub struct ScanReturn {
pub diagnostics: (PathBuf, Vec<Error>),
pub stats: Vec<usize>,
}

impl Scanner {
Expand All @@ -36,10 +37,13 @@ impl Scanner {

let semantic_ret = SemanticBuilder::new().build(&ret.program);
let mut ctx = Ctx::default();
let mut stats = vec![0; features.len()];

for node in semantic_ret.semantic.nodes() {
for feature in features {
for (i, feature) in features.iter().enumerate() {
let count = ctx.diagnostics.len();
feature.test(node, &mut ctx);
stats[i] = ctx.diagnostics.len() - count;
}
}

Expand All @@ -49,6 +53,7 @@ impl Scanner {
&self.source_text,
ctx.diagnostics(),
),
stats,
}
}
}
18 changes: 8 additions & 10 deletions tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,19 @@ fn test() {
let mut passed = true;
if !feature.spec().is_empty() {
let scanner = Scanner::new(path.clone(), feature.exec().to_string());
if let Some((_, d)) = scanner.scan(&[feature]) {
if d.is_empty() {
passed = false;
}
diagnostics.extend(d);
let d = scanner.scan(&[feature]).diagnostics.1;
if d.is_empty() {
passed = false;
}
diagnostics.extend(d);
}
for subtest in feature.subtests() {
let scanner = Scanner::new(path.clone(), subtest.exec.to_string());
if let Some((_, d)) = scanner.scan(&[feature]) {
if d.is_empty() {
passed = false;
}
diagnostics.extend(d);
let d = scanner.scan(&[feature]).diagnostics.1;
if d.is_empty() {
passed = false;
}
diagnostics.extend(d);
}
if !passed {
diagnostics.push(Error::msg(format!("Failed: {}", feature.name())));
Expand Down
24 changes: 24 additions & 0 deletions tests/snapshots/snapshot.snap
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ snapshot_kind: text
x Failed: Proxy internal calls, Array.prototype.includes
x Failed: strict fn w/ non-strict non-simple params is error
x Failed: arguments.caller removed
Expand Down Expand Up @@ -224,18 +227,33 @@ snapshot_kind: text
x Failed: Set methods
x Failed: Array methods
x Failed: Date methods
x Failed: Immutable globals
x Failed: Miscellaneous
x Failed: Number methods
x Failed: Object/array literal extensions
x Failed: Object static methods
x Failed: Strict mode
x Failed: String properties and methods
x Failed: Array is subclassable
Expand Down Expand Up @@ -284,6 +302,9 @@ snapshot_kind: text
x Failed: generators
x Failed: HTML-style comments
x Failed: let
Expand Down Expand Up @@ -434,6 +455,9 @@ snapshot_kind: text
x Failed: Class and Property Decorators
x Failed: Generator function.sent Meta Property
x Failed: Legacy RegExp features in JavaScript
Expand Down

0 comments on commit b920eeb

Please sign in to comment.