Skip to content

Commit eac2ab3

Browse files
committed
test262: Add an extremelly basic test262 runner
Many of the test262 test cases currently cause the interpreter to crash. First goal is to eliminate these crashes (or teach the test runner to tolerate them) so that this can actually be useful. At that point, the number of passing vs. failing test cases can start to be tracked and graphed, and then iteratively improved with Graph Driven Development (GDD).
1 parent 759d70b commit eac2ab3

File tree

5 files changed

+107
-0
lines changed

5 files changed

+107
-0
lines changed

.run/test262__run [release].run.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="test262::run [release]" type="CargoCommandRunConfiguration" factoryName="Cargo Command" folderName="test262">
3+
<option name="command" value="run --release --package jakescript-tests262" />
4+
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
5+
<option name="channel" value="DEFAULT" />
6+
<option name="requiredFeatures" value="true" />
7+
<option name="allFeatures" value="false" />
8+
<option name="emulateTerminal" value="false" />
9+
<option name="withSudo" value="false" />
10+
<option name="buildTarget" value="REMOTE" />
11+
<option name="backtrace" value="SHORT" />
12+
<envs />
13+
<option name="isRedirectInput" value="false" />
14+
<option name="redirectInputPath" value="" />
15+
<method v="2">
16+
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
17+
</method>
18+
</configuration>
19+
</component>

.run/test262__run.run.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="test262::run" type="CargoCommandRunConfiguration" factoryName="Cargo Command" folderName="test262">
3+
<option name="command" value="run --package jakescript-tests262" />
4+
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
5+
<option name="channel" value="DEFAULT" />
6+
<option name="requiredFeatures" value="true" />
7+
<option name="allFeatures" value="false" />
8+
<option name="emulateTerminal" value="false" />
9+
<option name="withSudo" value="false" />
10+
<option name="buildTarget" value="REMOTE" />
11+
<option name="backtrace" value="SHORT" />
12+
<envs />
13+
<option name="isRedirectInput" value="false" />
14+
<option name="redirectInputPath" value="" />
15+
<method v="2">
16+
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
17+
</method>
18+
</configuration>
19+
</component>

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
members = [
33
"jakescript",
44
"jakescript-cli",
5+
"jakescript-test262",
56
]
67

78
[profile.release]

jakescript-test262/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "jakescript-tests262"
3+
version = "0.1.0"
4+
authors = ["Jake Marsden <[email protected]>"]
5+
edition = "2021"
6+
publish = false
7+
8+
[dependencies]
9+
jakescript = { path = "../jakescript" }
10+
test262-harness = "0.1"

jakescript-test262/src/main.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//! It is expected that the _[test262](https://github.com/tc39/test262)_ repository is checked out
2+
//! next to this repository.
3+
4+
use jakescript::interpreter::{Eval, Interpreter, Vm};
5+
use jakescript::lexer::Lexer;
6+
use jakescript::parser::Parser;
7+
use jakescript::token::SourceLocation;
8+
use std::path::Path;
9+
use test262_harness::{Error, Harness, Test};
10+
11+
static TEST262_ROOT_DIR: &str = "../test262";
12+
static TEST262_TEST_DIR: &str = "../test262/test";
13+
14+
fn main() {
15+
let harness = Harness::new(TEST262_ROOT_DIR).expect("failed to initialize harness");
16+
for test in harness {
17+
match test {
18+
Ok(test) if is_test_we_care_about(&test.path) => {
19+
println!("running test from {:?}", test.path);
20+
exec_test(&test);
21+
}
22+
Err(Error::DescriptionInvalid(path)) if is_test_we_care_about(&path) => {
23+
eprintln!("description invalid: {}", path.display());
24+
}
25+
26+
Ok(..) | Err(Error::DescriptionInvalid(..)) => {}
27+
Err(err) => panic!("{}", err),
28+
};
29+
}
30+
}
31+
32+
fn is_test_we_care_about(path: impl AsRef<Path>) -> bool {
33+
path.as_ref().starts_with(TEST262_TEST_DIR)
34+
}
35+
36+
fn exec_test(test: &Test) {
37+
let lexer = Lexer::for_str(&test.source, SourceLocation::at_start_of(&test.path));
38+
let parser = Parser::for_lexer(lexer);
39+
40+
let script = match parser.execute() {
41+
Ok(script) => script,
42+
Err(err) => {
43+
eprintln!("FAIL (parse) {}: {}", test.path.display(), err);
44+
return;
45+
}
46+
};
47+
48+
let mut it = Interpreter::new(Vm::new().unwrap());
49+
match script.eval(&mut it) {
50+
Ok(_) => {}
51+
Err(err) => {
52+
eprintln!("FAIL (runtime) {}: {}", test.path.display(), err);
53+
return;
54+
}
55+
}
56+
57+
println!("PASS {}", test.path.display());
58+
}

0 commit comments

Comments
 (0)