Skip to content

Commit

Permalink
Support running a specific test/suite in boa_tester (#886)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeroman authored Oct 18, 2020
1 parent 580c7f1 commit 09d1889
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 25 deletions.
54 changes: 38 additions & 16 deletions boa_tester/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ mod read;
mod results;

use self::{
read::{read_global_suite, read_harness, MetaData, Negative, TestFlag},
read::{read_harness, read_suite, read_test, MetaData, Negative, TestFlag},
results::write_json,
};
use bitflags::bitflags;
Expand Down Expand Up @@ -69,6 +69,10 @@ struct Cli {
#[structopt(long, parse(from_os_str), default_value = "./test262")]
test262_path: PathBuf,

/// Which specific test or test suite to run.
#[structopt(short, long, parse(from_os_str), default_value = "test")]
suite: PathBuf,

/// Optional output folder for the full results information.
#[structopt(short, long, parse(from_os_str))]
output: Option<PathBuf>,
Expand All @@ -85,6 +89,11 @@ impl Cli {
self.test262_path.as_path()
}

/// Which specific test or test suite to run.
fn suite(&self) -> &Path {
self.suite.as_path()
}

/// Optional output folder for the full results information.
fn output(&self) -> Option<&Path> {
self.output.as_deref()
Expand All @@ -109,23 +118,36 @@ fn main() {
}
let harness = read_harness().expect("could not read initialization bindings");

let global_suite = read_global_suite().expect("could not get the list of tests to run");
if CLI.suite().to_string_lossy().ends_with(".js") {
let test = read_test(&CLI.test262_path().join(CLI.suite()))
.expect("could not get the test to run");

if CLI.verbose() {
println!("Test suite loaded, starting tests...");
if CLI.verbose() {
println!("Test loaded, starting...");
}
test.run(&harness);

println!();
} else {
let suite = read_suite(&CLI.test262_path().join(CLI.suite()))
.expect("could not get the list of tests to run");

if CLI.verbose() {
println!("Test suite loaded, starting tests...");
}
let results = suite.run(&harness);

println!();
println!("Results:");
println!("Total tests: {}", results.total);
println!("Passed tests: {}", results.passed);
println!(
"Conformance: {:.2}%",
(results.passed as f64 / results.total as f64) * 100.0
);

write_json(results).expect("could not write the results to the output JSON file");
}
let results = global_suite.run(&harness);
println!();

println!("Results:");
println!("Total tests: {}", results.total);
println!("Passed tests: {}", results.passed);
println!(
"Conformance: {:.2}%",
(results.passed as f64 / results.total as f64) * 100.0
);

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

/// All the harness include files.
Expand Down
11 changes: 2 additions & 9 deletions boa_tester/src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,8 @@ pub(super) fn read_harness() -> io::Result<Harness> {
})
}

/// Reads the global suite from disk.
pub(super) fn read_global_suite() -> io::Result<TestSuite> {
let path = CLI.test262_path().join("test");

Ok(read_suite(path.as_path())?)
}

/// Reads a test suite in the given path.
fn read_suite(path: &Path) -> io::Result<TestSuite> {
pub(super) fn read_suite(path: &Path) -> io::Result<TestSuite> {
use std::ffi::OsStr;

let name = path
Expand Down Expand Up @@ -139,7 +132,7 @@ fn read_suite(path: &Path) -> io::Result<TestSuite> {
}

/// Reads information about a given test case.
fn read_test(path: &Path) -> io::Result<Test> {
pub(super) fn read_test(path: &Path) -> io::Result<Test> {
let name = path
.file_stem()
.ok_or_else(|| {
Expand Down

0 comments on commit 09d1889

Please sign in to comment.