Skip to content

Commit

Permalink
Started with the test262 tester
Browse files Browse the repository at this point in the history
  • Loading branch information
Razican committed Jul 14, 2020
1 parent 0efe2a4 commit 9c93f15
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "test262"]
path = test262
url = https://github.com/tc39/test262.git
43 changes: 43 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ members = [
"boa",
"boa_cli",
"boa_wasm",
"tester",
]

# The release profile, used for `cargo build --release`.
Expand Down
1 change: 1 addition & 0 deletions test262
Submodule test262 added at d3c693
13 changes: 13 additions & 0 deletions tester/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "tester"
version = "0.1.0"
authors = ["Iban Eguia Moraza <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Boa = { path = "../boa" }
structopt = "0.3.15"
serde_yaml = "0.8.13"
bitflags = "1.2.1"
115 changes: 115 additions & 0 deletions tester/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
use std::{
fs, io,
path::{Path, PathBuf},
};
use structopt::StructOpt;

/// Boa test262 tester
#[derive(StructOpt, Debug)]
#[structopt(name = "Boa test262 tester")]
struct Cli {
// Whether to show verbose output.
#[structopt(short, long)]
verbose: bool,

/// Path to the Test262 suite.
#[structopt(short, long, parse(from_os_str), default_value = "./test262")]
suite: PathBuf,

// Run the tests only in parsing mode.
#[structopt(short = "p", long)]
only_parse: bool,
}

/// Program entry point.
fn main() {
let cli = Cli::from_args();

let (assert_js, sta_js) =
read_init(cli.suite.as_path()).expect("could not read initialization bindings");

let tests = test_suites(cli.suite.as_path()).expect("could not get the list of tests to run");
}

/// Reads the Test262 defined bindings.
fn read_init(suite: &Path) -> io::Result<(String, String)> {
let assert_js = fs::read_to_string(suite.join("harness/assert.js"))?;
let sta_js = fs::read_to_string(suite.join("harness/sta.js"))?;

Ok((assert_js, sta_js))
}

/// Represents a test suite.
#[derive(Debug, Clone)]
struct TestSuite {
suites: Box<[TestSuite]>,
cases: Box<[TestCase]>,
}

/// Represents a test case.
#[derive(Debug, Clone)]
struct TestCase {
name: Option<Box<str>>,
description: Box<str>,
template: Box<str>,
information: Option<Box<str>>,
expected_outcome: Outcome,
includes: Box<[Box<[str]>]>,
flags: TestCaseFlags,
locale: Box<[Locale]>,
content: Box<str>,
}

/// An outcome for a test.
#[derive(Debug, Default, Clone, Copy)]
enum Outcome {
Positive,
Negative { phase: Phase, error_type: Box<str> },
}

/// Phase for an error.
#[derive(Debug, Clone, Copy)]
enum Phase {
Parse,
Early,
Resolution,
Runtime,
}

/// Locale information structure.
#[derive(Debug, Clone)]
struct Locale {
locale: Box<[str]>,
}

/// Gets the list of tests to run.
fn test_suites(suite: &Path) -> io::Result<TestSuite> {
let path = suite.join("src");
read_suite(path.as_path());
}

/// Reads a test suite in the given path.
fn read_suite(path: &Path) -> io::Result<TestSuite> {
let mut suites = Vec::new();
let mut cases = Vec::new();
for entry in path.read_dir() {
let entry = entry?;
if entry.file_type()?.is_dir() {
suites.push(read_suite(entry.path().as_path())?);
} else {
cases.push(read_test_case(entry.path().as_path())?);
}
}

Ok(TestSuite {
suites: suites.to_boxed_slice(),
cases: cases.to_boxed_slice(),
})
}

/// Reads information about a given test case.
fn read_test_case(path: &Path) -> io::Result<TestCase> {
let name = path.file_stem();
let content = fs::read_to_string(path)?;
todo!()
}

0 comments on commit 9c93f15

Please sign in to comment.