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 5edd27b
Show file tree
Hide file tree
Showing 5 changed files with 58 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
19 changes: 19 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use std::{
fs,
path::{Path, PathBuf},
sync::mpsc,
};

use oxc::{diagnostics::DiagnosticService, span::VALID_EXTENSIONS};
Expand Down Expand Up @@ -36,6 +37,8 @@ fn main() {
};

let mut diagnostic_service = DiagnosticService::default();
let paths_len = paths.len();
let (tx_stats, rx_stats) = mpsc::channel::<Vec<usize>>();

rayon::spawn({
let tx_error = diagnostic_service.sender().clone();
Expand All @@ -44,11 +47,27 @@ fn main() {
let source_text = fs::read_to_string(path).unwrap();
let scanner = Scanner::new(path.to_path_buf(), source_text);
let ret = scanner.scan(FEATURES);
tx_stats.send(ret.stats).unwrap();
tx_error.send(Some(ret.diagnostics)).unwrap();
});
tx_error.send(None).unwrap();
}
});

diagnostic_service.run();

let mut all_stats = vec![0; FEATURES.len()];
for _ in 0..paths_len {
let stats = rx_stats.recv().unwrap();
for (j, count) in stats.iter().enumerate() {
all_stats[j] += count;
}
}

for (i, feature) in FEATURES.iter().enumerate() {
let stats = all_stats[i];
if stats > 0 {
println!("{}: {}", feature.name(), stats);
}
}
}
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 5edd27b

Please sign in to comment.