Skip to content

Commit b68e588

Browse files
committed
Fixed conformance reporting
1 parent fee4048 commit b68e588

File tree

3 files changed

+114
-150
lines changed

3 files changed

+114
-150
lines changed

boa_tester/src/exec/mod.rs

Lines changed: 41 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use boa_engine::{
1919
};
2020
use colored::Colorize;
2121
use rayon::prelude::*;
22-
use rustc_hash::FxHashSet;
22+
use rustc_hash::FxHashMap;
2323
use std::{cell::RefCell, eprintln, rc::Rc};
2424

2525
impl TestSuite {
@@ -31,12 +31,12 @@ impl TestSuite {
3131
parallel: bool,
3232
max_edition: SpecEdition,
3333
optimizer_options: OptimizerOptions,
34-
) -> SuiteResult {
34+
) -> (Box<str>, SuiteResult) {
3535
if verbose != 0 {
3636
println!("Suite {}:", self.path.display());
3737
}
3838

39-
let suites: Vec<_> = if parallel {
39+
let suites: FxHashMap<_, _> = if parallel {
4040
self.suites
4141
.par_iter()
4242
.map(|suite| suite.run(harness, verbose, parallel, max_edition, optimizer_options))
@@ -48,25 +48,20 @@ impl TestSuite {
4848
.collect()
4949
};
5050

51-
let tests: Vec<_> = if parallel {
51+
let tests: FxHashMap<_, _> = if parallel {
5252
self.tests
5353
.par_iter()
5454
.filter(|test| test.edition <= max_edition)
55-
.flat_map(|test| test.run(harness, verbose, optimizer_options))
55+
.map(|test| test.run(harness, verbose, optimizer_options))
5656
.collect()
5757
} else {
5858
self.tests
5959
.iter()
6060
.filter(|test| test.edition <= max_edition)
61-
.flat_map(|test| test.run(harness, verbose, optimizer_options))
61+
.map(|test| test.run(harness, verbose, optimizer_options))
6262
.collect()
6363
};
6464

65-
let mut features = FxHashSet::default();
66-
for test_iter in &*self.tests {
67-
features.extend(test_iter.features.iter().map(ToString::to_string));
68-
}
69-
7065
if verbose != 0 {
7166
println!();
7267
}
@@ -75,27 +70,29 @@ impl TestSuite {
7570
let mut versioned_stats = VersionedStats::default();
7671
let mut es_next = Statistics::default();
7772

78-
for test in &tests {
79-
match test.result {
80-
TestOutcomeResult::Passed => {
73+
for test in tests.values() {
74+
match (test.strict, test.no_strict) {
75+
(Some(TestOutcomeResult::Passed), None | Some(TestOutcomeResult::Passed))
76+
| (None, Some(TestOutcomeResult::Passed)) => {
8177
versioned_stats.apply(test.edition, |stats| {
8278
stats.passed += 1;
8379
});
8480
es_next.passed += 1;
8581
}
86-
TestOutcomeResult::Ignored => {
82+
(Some(TestOutcomeResult::Ignored), _) | (_, Some(TestOutcomeResult::Ignored)) => {
8783
versioned_stats.apply(test.edition, |stats| {
8884
stats.ignored += 1;
8985
});
9086
es_next.ignored += 1;
9187
}
92-
TestOutcomeResult::Panic => {
88+
(Some(TestOutcomeResult::Panic), _) | (_, Some(TestOutcomeResult::Panic)) => {
9389
versioned_stats.apply(test.edition, |stats| {
9490
stats.panic += 1;
9591
});
9692
es_next.panic += 1;
9793
}
98-
TestOutcomeResult::Failed => {}
94+
(Some(TestOutcomeResult::Failed), _) | (_, Some(TestOutcomeResult::Failed)) => {}
95+
(None, None) => unreachable!("test should have at least one result"),
9996
}
10097
versioned_stats.apply(test.edition, |stats| {
10198
stats.total += 1;
@@ -104,10 +101,9 @@ impl TestSuite {
104101
}
105102

106103
// Count total tests
107-
for suite in &suites {
104+
for suite in suites.values() {
108105
versioned_stats += suite.versioned_stats;
109106
es_next += suite.stats;
110-
features.extend(suite.features.iter().cloned());
111107
}
112108

113109
if verbose != 0 {
@@ -128,39 +124,47 @@ impl TestSuite {
128124
(es_next.passed as f64 / es_next.total as f64) * 100.0
129125
);
130126
}
131-
SuiteResult {
132-
name: self.name.clone(),
133-
stats: es_next,
134-
versioned_stats,
135-
suites,
136-
tests,
137-
features,
138-
}
127+
(
128+
self.name.clone(),
129+
SuiteResult {
130+
stats: es_next,
131+
versioned_stats,
132+
suites,
133+
tests,
134+
},
135+
)
139136
}
140137
}
141138

142139
impl Test {
143140
/// Runs the test.
141+
///
142+
/// Returns the test name and the result of the test.
144143
pub(crate) fn run(
145144
&self,
146145
harness: &Harness,
147146
verbose: u8,
148147
optimizer_options: OptimizerOptions,
149-
) -> Vec<TestResult> {
150-
let mut results = Vec::new();
148+
) -> (Box<str>, TestResult) {
149+
let mut result = TestResult {
150+
edition: self.edition,
151+
strict: None,
152+
no_strict: None,
153+
};
154+
151155
if self.flags.contains(TestFlags::MODULE) {
152-
results.push(self.run_once(harness, false, verbose, optimizer_options));
156+
result.no_strict = Some(self.run_once(harness, false, verbose, optimizer_options));
153157
} else {
154158
if self.flags.contains(TestFlags::STRICT) && !self.flags.contains(TestFlags::RAW) {
155-
results.push(self.run_once(harness, true, verbose, optimizer_options));
159+
result.strict = Some(self.run_once(harness, true, verbose, optimizer_options));
156160
}
157161

158162
if self.flags.contains(TestFlags::NO_STRICT) || self.flags.contains(TestFlags::RAW) {
159-
results.push(self.run_once(harness, false, verbose, optimizer_options));
163+
result.no_strict = Some(self.run_once(harness, false, verbose, optimizer_options));
160164
}
161165
}
162166

163-
results
167+
(self.name.clone(), result)
164168
}
165169

166170
/// Runs the test once, in strict or non-strict mode
@@ -170,7 +174,7 @@ impl Test {
170174
strict: bool,
171175
verbose: u8,
172176
optimizer_options: OptimizerOptions,
173-
) -> TestResult {
177+
) -> TestOutcomeResult {
174178
let Ok(source) = Source::from_filepath(&self.path) else {
175179
if verbose > 1 {
176180
println!(
@@ -182,13 +186,7 @@ impl Test {
182186
} else {
183187
print!("{}", "F".red());
184188
}
185-
return TestResult {
186-
name: self.name.clone(),
187-
edition: self.edition,
188-
strict,
189-
result: TestOutcomeResult::Failed,
190-
result_text: Box::from("Could not read test file."),
191-
};
189+
return TestOutcomeResult::Failed;
192190
};
193191
if self.ignored {
194192
if verbose > 1 {
@@ -201,13 +199,7 @@ impl Test {
201199
} else {
202200
print!("{}", "-".yellow());
203201
}
204-
return TestResult {
205-
name: self.name.clone(),
206-
edition: self.edition,
207-
strict,
208-
result: TestOutcomeResult::Ignored,
209-
result_text: Box::default(),
210-
};
202+
return TestOutcomeResult::Ignored;
211203
}
212204
if verbose > 1 {
213205
println!(
@@ -512,13 +504,7 @@ impl Test {
512504
println!();
513505
}
514506

515-
TestResult {
516-
name: self.name.clone(),
517-
edition: self.edition,
518-
strict,
519-
result,
520-
result_text: result_text.into_boxed_str(),
521-
}
507+
result
522508
}
523509

524510
/// Sets the environment up to run the test.

boa_tester/src/main.rs

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ fn run_test_suite(
485485
if verbose != 0 {
486486
println!("Test suite loaded, starting tests...");
487487
}
488-
let results = suite.run(&harness, verbose, parallel, edition, optimizer_options);
488+
let (_name, results) = suite.run(&harness, verbose, parallel, edition, optimizer_options);
489489

490490
if versioned {
491491
let mut table = comfy_table::Table::new();
@@ -617,15 +617,25 @@ impl AddAssign for Statistics {
617617
/// Represents tests statistics separated by ECMAScript edition
618618
#[derive(Default, Debug, Copy, Clone, Serialize)]
619619
struct VersionedStats {
620+
#[serde(rename = "5")]
620621
es5: Statistics,
622+
#[serde(rename = "6")]
621623
es6: Statistics,
624+
#[serde(rename = "7")]
622625
es7: Statistics,
626+
#[serde(rename = "8")]
623627
es8: Statistics,
628+
#[serde(rename = "9")]
624629
es9: Statistics,
630+
#[serde(rename = "10")]
625631
es10: Statistics,
632+
#[serde(rename = "11")]
626633
es11: Statistics,
634+
#[serde(rename = "12")]
627635
es12: Statistics,
636+
#[serde(rename = "13")]
628637
es13: Statistics,
638+
#[serde(rename = "14")]
629639
es14: Statistics,
630640
}
631641

@@ -636,16 +646,26 @@ impl<'de> Deserialize<'de> for VersionedStats {
636646
{
637647
#[derive(Deserialize)]
638648
struct Inner {
649+
#[serde(rename = "5")]
639650
es5: Statistics,
651+
#[serde(rename = "6")]
640652
es6: Statistics,
653+
#[serde(rename = "7")]
641654
es7: Statistics,
655+
#[serde(rename = "8")]
642656
es8: Statistics,
657+
#[serde(rename = "9")]
643658
es9: Statistics,
659+
#[serde(rename = "10")]
644660
es10: Statistics,
661+
#[serde(rename = "11")]
645662
es11: Statistics,
663+
#[serde(rename = "12")]
646664
es12: Statistics,
665+
#[serde(rename = "13")]
647666
es13: Statistics,
648667
#[serde(default)]
668+
#[serde(rename = "14")]
649669
es14: Option<Statistics>,
650670
}
651671

@@ -767,37 +787,28 @@ impl AddAssign for VersionedStats {
767787
/// Outcome of a test suite.
768788
#[derive(Debug, Clone, Serialize, Deserialize)]
769789
struct SuiteResult {
770-
#[serde(rename = "n")]
771-
name: Box<str>,
772790
#[serde(rename = "a")]
773791
stats: Statistics,
774792
#[serde(rename = "av", default)]
775793
versioned_stats: VersionedStats,
776-
#[serde(skip_serializing_if = "Vec::is_empty", default)]
794+
#[serde(skip_serializing_if = "FxHashMap::is_empty", default)]
777795
#[serde(rename = "s")]
778-
suites: Vec<SuiteResult>,
779-
#[serde(skip_serializing_if = "Vec::is_empty", default)]
796+
suites: FxHashMap<Box<str>, SuiteResult>,
797+
#[serde(skip_serializing_if = "FxHashMap::is_empty", default)]
780798
#[serde(rename = "t")]
781-
tests: Vec<TestResult>,
782-
#[serde(skip_serializing_if = "FxHashSet::is_empty", default)]
783-
#[serde(rename = "f")]
784-
features: FxHashSet<String>,
799+
tests: FxHashMap<Box<str>, TestResult>,
785800
}
786801

787-
/// Outcome of a test.
802+
/// Result of a test, including the outcome for strict and non-strict mode.
788803
#[derive(Debug, Clone, Serialize, Deserialize)]
789804
#[allow(dead_code)]
790805
struct TestResult {
791-
#[serde(rename = "n")]
792-
name: Box<str>,
793806
#[serde(rename = "v", default)]
794807
edition: SpecEdition,
795808
#[serde(rename = "s", default)]
796-
strict: bool,
797-
#[serde(skip)]
798-
result_text: Box<str>,
799-
#[serde(rename = "r")]
800-
result: TestOutcomeResult,
809+
strict: Option<TestOutcomeResult>,
810+
#[serde(rename = "r", default)]
811+
no_strict: Option<TestOutcomeResult>,
801812
}
802813

803814
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]

0 commit comments

Comments
 (0)