Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Added better error handling for the Boa tester #1984

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions boa_tester/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ hex = "0.4.3"
num-format = "0.4.0"
gc = { version = "0.4.1", features = ["derive"] }
rayon = "1.5.1"
anyhow = "1.0.56"
37 changes: 26 additions & 11 deletions boa_tester/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ use self::{
read::{read_harness, read_suite, read_test, MetaData, Negative, TestFlag},
results::{compare_results, write_json},
};
use anyhow::{bail, Context};
use bitflags::bitflags;
use colored::Colorize;
use fxhash::{FxHashMap, FxHashSet};
Expand Down Expand Up @@ -242,13 +243,21 @@ fn main() {
output,
disable_parallelism,
} => {
run_test_suite(
if let Err(e) = run_test_suite(
verbose,
!disable_parallelism,
test262_path.as_path(),
suite.as_path(),
output.as_deref(),
);
) {
eprintln!("Error: {e}");
let mut src = e.source();
while let Some(e) = src {
eprintln!(" caused by: {e}");
src = e.source();
}
std::process::exit(1);
}
}
Cli::Compare {
base,
Expand All @@ -265,25 +274,27 @@ fn run_test_suite(
test262_path: &Path,
suite: &Path,
output: Option<&Path>,
) {
) -> anyhow::Result<()> {
if let Some(path) = output {
if path.exists() {
if !path.is_dir() {
eprintln!("The output path must be a directory.");
std::process::exit(1);
bail!("the output path must be a directory.");
}
} else {
fs::create_dir_all(path).expect("could not create the output directory");
fs::create_dir_all(path).context("could not create the output directory")?;
}
}

if verbose != 0 {
println!("Loading the test suite...");
}
let harness = read_harness(test262_path).expect("could not read initialization bindings");
let harness = read_harness(test262_path).context("could not read harness")?;

if suite.to_string_lossy().ends_with(".js") {
let test = read_test(&test262_path.join(suite)).expect("could not get the test to run");
let test = read_test(&test262_path.join(suite)).with_context(|| {
let suite = suite.display();
format!("could not read the test {suite}")
})?;

if verbose != 0 {
println!("Test loaded, starting...");
Expand All @@ -292,8 +303,10 @@ fn run_test_suite(

println!();
} else {
let suite =
read_suite(&test262_path.join(suite)).expect("could not get the list of tests to run");
let suite = read_suite(&test262_path.join(suite)).with_context(|| {
let suite = suite.display();
format!("could not read the suite {suite}")
})?;

if verbose != 0 {
println!("Test suite loaded, starting tests...");
Expand All @@ -318,8 +331,10 @@ fn run_test_suite(
);

write_json(results, output, verbose)
.expect("could not write the results to the output JSON file");
.context("could not write the results to the output JSON file")?;
}

Ok(())
}

/// All the harness include files.
Expand Down
50 changes: 28 additions & 22 deletions boa_tester/src/read.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Module to read the list of test suites from disk.

use super::{Harness, Locale, Phase, Test, TestSuite, IGNORED};
use anyhow::Context;
use fxhash::FxHashMap;
use serde::Deserialize;
use std::{fs, io, path::Path, str::FromStr};
Expand Down Expand Up @@ -73,10 +74,12 @@ impl FromStr for TestFlag {
}

/// Reads the Test262 defined bindings.
pub(super) fn read_harness(test262_path: &Path) -> io::Result<Harness> {
pub(super) fn read_harness(test262_path: &Path) -> anyhow::Result<Harness> {
let mut includes = FxHashMap::default();

for entry in fs::read_dir(test262_path.join("harness"))? {
for entry in
fs::read_dir(test262_path.join("harness")).context("error reading the harness directory")?
{
let entry = entry?;
let file_name = entry.file_name();
let file_name = file_name.to_string_lossy();
Expand All @@ -85,15 +88,20 @@ pub(super) fn read_harness(test262_path: &Path) -> io::Result<Harness> {
continue;
}

let content = fs::read_to_string(entry.path())?;
let content = fs::read_to_string(entry.path())
.with_context(|| format!("error reading the harnes/{file_name}"))?;

includes.insert(
file_name.into_owned().into_boxed_str(),
content.into_boxed_str(),
);
}
let assert = fs::read_to_string(test262_path.join("harness/assert.js"))?.into_boxed_str();
let sta = fs::read_to_string(test262_path.join("harness/sta.js"))?.into_boxed_str();
let assert = fs::read_to_string(test262_path.join("harness/assert.js"))
.context("error reading harnes/assert.js")?
.into_boxed_str();
let sta = fs::read_to_string(test262_path.join("harness/sta.js"))
.context("error reading harnes/sta.js")?
.into_boxed_str();

Ok(Harness {
assert,
Expand All @@ -103,40 +111,38 @@ pub(super) fn read_harness(test262_path: &Path) -> io::Result<Harness> {
}

/// Reads a test suite in the given path.
pub(super) fn read_suite(path: &Path) -> io::Result<TestSuite> {
pub(super) fn read_suite(path: &Path) -> anyhow::Result<TestSuite> {
let name = path
.file_name()
.ok_or_else(|| {
io::Error::new(
io::ErrorKind::InvalidInput,
format!("test suite with no name found: {}", path.display()),
)
})?
.with_context(|| format!("test suite with no name found: {}", path.display()))?
.to_str()
.ok_or_else(|| {
io::Error::new(
io::ErrorKind::InvalidInput,
format!("non-UTF-8 suite name found: {}", path.display()),
)
})?;
.with_context(|| format!("non-UTF-8 suite name found: {}", path.display()))?;

let mut suites = Vec::new();
let mut tests = Vec::new();

// TODO: iterate in parallel
for entry in path.read_dir()? {
for entry in path.read_dir().context("retrieving entry")? {
let entry = entry?;

if entry.file_type()?.is_dir() {
suites.push(read_suite(entry.path().as_path())?);
if entry.file_type().context("retrieving file type")?.is_dir() {
suites.push(read_suite(entry.path().as_path()).with_context(|| {
let path = entry.path();
let suite = path.display();
format!("error reading sub-suite {suite}")
})?);
} else if entry.file_name().to_string_lossy().contains("_FIXTURE") {
continue;
} else if IGNORED.contains_file(&entry.file_name().to_string_lossy()) {
let mut test = Test::default();
test.set_name(entry.file_name().to_string_lossy());
tests.push(test);
} else {
tests.push(read_test(entry.path().as_path())?);
tests.push(read_test(entry.path().as_path()).with_context(|| {
let path = entry.path();
let suite = path.display();
format!("error reading test {suite}")
})?);
}
}

Expand Down