Skip to content

Commit 0ba1929

Browse files
committed
Fixing the result generation & comparison (still not building)
1 parent b68e588 commit 0ba1929

File tree

2 files changed

+50
-42
lines changed

2 files changed

+50
-42
lines changed

boa_tester/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ impl AddAssign for VersionedStats {
789789
struct SuiteResult {
790790
#[serde(rename = "a")]
791791
stats: Statistics,
792-
#[serde(rename = "av", default)]
792+
#[serde(rename = "v", default)]
793793
versioned_stats: VersionedStats,
794794
#[serde(skip_serializing_if = "FxHashMap::is_empty", default)]
795795
#[serde(rename = "s")]

boa_tester/src/results.rs

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::{Statistics, TestOutcomeResult, VersionedStats};
22

33
use super::SuiteResult;
44
use color_eyre::{eyre::WrapErr, Result};
5+
use rustc_hash::FxHashMap;
56
use serde::{Deserialize, Serialize};
67
use std::{
78
env, fs,
@@ -16,8 +17,12 @@ struct ResultInfo {
1617
commit: Box<str>,
1718
#[serde(rename = "u")]
1819
test262_commit: Box<str>,
20+
#[serde(rename = "a")]
21+
stats: Statistics,
22+
#[serde(rename = "v")]
23+
versioned_results: VersionedStats,
1924
#[serde(rename = "r")]
20-
results: SuiteResult,
25+
results: FxHashMap<Box<str>, SuiteResult>,
2126
}
2227

2328
/// Structure to store full result information.
@@ -29,8 +34,6 @@ struct ReducedResultInfo {
2934
test262_commit: Box<str>,
3035
#[serde(rename = "a")]
3136
stats: Statistics,
32-
#[serde(rename = "av", default)]
33-
versioned_stats: VersionedStats,
3437
}
3538

3639
impl From<ResultInfo> for ReducedResultInfo {
@@ -39,8 +42,7 @@ impl From<ResultInfo> for ReducedResultInfo {
3942
Self {
4043
commit: info.commit,
4144
test262_commit: info.test262_commit,
42-
stats: info.results.stats,
43-
versioned_stats: info.results.versioned_stats,
45+
stats: info.stats,
4446
}
4547
}
4648
}
@@ -68,13 +70,13 @@ pub(crate) fn write_json(
6870
let output_dir = if branch.is_empty() {
6971
output_dir.to_path_buf()
7072
} else {
71-
let folder = output_dir.join(branch);
73+
let folder = output_dir.join(&branch);
7274
fs::create_dir_all(&folder)?;
7375
folder
7476
};
7577

7678
// We make sure we are using the latest commit information in GitHub pages:
77-
update_gh_pages_repo(output_dir.as_path(), verbose);
79+
update_gh_pages_repo(output_dir.as_path(), &branch, verbose);
7880

7981
if verbose != 0 {
8082
println!("Writing the results to {}...", output_dir.display());
@@ -86,27 +88,32 @@ pub(crate) fn write_json(
8688

8789
let new_results = ResultInfo {
8890
commit: env::var("GITHUB_SHA").unwrap_or_default().into_boxed_str(),
89-
test262_commit: get_test262_commit(test262_path)?,
90-
results,
91+
test262_commit: get_test262_commit(test262_path)
92+
.context("could not get the test262 commit")?,
93+
stats: results.stats,
94+
versioned_results: results.versioned_stats,
95+
results: results.suites,
9196
};
9297

9398
let latest = BufWriter::new(fs::File::create(latest)?);
9499
serde_json::to_writer(latest, &new_results)?;
95100

96-
// Write the full list of results, retrieving the existing ones first.
101+
// Write the full result history for "main"
102+
if branch == "main" {
103+
let all_path = output_dir.join(RESULTS_FILE_NAME);
97104

98-
let all_path = output_dir.join(RESULTS_FILE_NAME);
99-
100-
let mut all_results: Vec<ReducedResultInfo> = if all_path.exists() {
101-
serde_json::from_reader(BufReader::new(fs::File::open(&all_path)?))?
102-
} else {
103-
Vec::new()
104-
};
105+
// We only keep history for the main branch
106+
let mut all_results: Vec<ReducedResultInfo> = if all_path.is_file() {
107+
serde_json::from_reader(BufReader::new(fs::File::open(&all_path)?))?
108+
} else {
109+
Vec::new()
110+
};
105111

106-
all_results.push(new_results.into());
112+
all_results.push(new_results.into());
107113

108-
let output = BufWriter::new(fs::File::create(&all_path)?);
109-
serde_json::to_writer(output, &all_results)?;
114+
let output = BufWriter::new(fs::File::create(&all_path)?);
115+
serde_json::to_writer(output, &all_results)?;
116+
}
110117

111118
if verbose != 0 {
112119
println!("Results written correctly");
@@ -125,17 +132,20 @@ fn get_test262_commit(test262_path: &Path) -> Result<Box<str>> {
125132
}
126133

127134
/// Updates the GitHub pages repository by pulling latest changes before writing the new things.
128-
fn update_gh_pages_repo(path: &Path, verbose: u8) {
129-
if env::var("GITHUB_REF").is_ok() {
130-
use std::process::Command;
135+
fn update_gh_pages_repo(path: &Path, branch: &str, verbose: u8) {
136+
use std::process::Command;
131137

132-
// We run the command to pull the gh-pages branch: git -C ../gh-pages/ pull origin
133-
Command::new("git")
134-
.args(["-C", "../gh-pages", "pull", "--ff-only"])
135-
.output()
136-
.expect("could not update GitHub Pages");
138+
// We run the command to pull the gh-pages branch: git -C ../gh-pages/ pull --ff-only
139+
if verbose != 0 {
140+
println!("Cloning the Github Pages branch in ../gh-pages/...");
141+
}
142+
Command::new("git")
143+
.args(["-C", "../gh-pages", "pull", "--ff-only"])
144+
.output()
145+
.expect("could not update GitHub Pages");
137146

138-
// Copy the full results file
147+
if branch == "main" {
148+
// Copy the full results file if in the main branch
139149
let from = Path::new("../gh-pages/test262/refs/heads/main/").join(RESULTS_FILE_NAME);
140150
let to = path.join(RESULTS_FILE_NAME);
141151

@@ -147,8 +157,6 @@ fn update_gh_pages_repo(path: &Path, verbose: u8) {
147157
);
148158
}
149159

150-
// TO-DO: only copy the last result, not the whole file.
151-
152160
fs::copy(from, to).expect("could not copy the main results file");
153161
}
154162
}
@@ -166,24 +174,24 @@ pub(crate) fn compare_results(base: &Path, new: &Path, markdown: bool) -> Result
166174
))
167175
.wrap_err("could not read the new results")?;
168176

169-
let base_total = base_results.results.stats.total as isize;
170-
let new_total = new_results.results.stats.total as isize;
177+
let base_total = base_results.stats.total as isize;
178+
let new_total = new_results.stats.total as isize;
171179
let total_diff = new_total - base_total;
172180

173-
let base_passed = base_results.results.stats.passed as isize;
174-
let new_passed = new_results.results.stats.passed as isize;
181+
let base_passed = base_results.stats.passed as isize;
182+
let new_passed = new_results.stats.passed as isize;
175183
let passed_diff = new_passed - base_passed;
176184

177-
let base_ignored = base_results.results.stats.ignored as isize;
178-
let new_ignored = new_results.results.stats.ignored as isize;
185+
let base_ignored = base_results.stats.ignored as isize;
186+
let new_ignored = new_results.stats.ignored as isize;
179187
let ignored_diff = new_ignored - base_ignored;
180188

181189
let base_failed = base_total - base_passed - base_ignored;
182190
let new_failed = new_total - new_passed - new_ignored;
183191
let failed_diff = new_failed - base_failed;
184192

185-
let base_panics = base_results.results.stats.panic as isize;
186-
let new_panics = new_results.results.stats.panic as isize;
193+
let base_panics = base_results.stats.panic as isize;
194+
let new_panics = new_results.stats.panic as isize;
187195
let panic_diff = new_panics - base_panics;
188196

189197
let base_conformance = (base_passed as f64 / base_total as f64) * 100_f64;
@@ -406,8 +414,8 @@ impl ResultDiff {
406414
/// Compares a base and a new result and returns the list of differences.
407415
fn compute_result_diff(
408416
base: &Path,
409-
base_result: &SuiteResult,
410-
new_result: &SuiteResult,
417+
base_result: &FxHashMap<Box<str>, SuiteResult>,
418+
new_result: &FxHashMap<Box<str>, SuiteResult>,
411419
) -> ResultDiff {
412420
let mut final_diff = ResultDiff::default();
413421

0 commit comments

Comments
 (0)