Skip to content

Commit

Permalink
normalization test
Browse files Browse the repository at this point in the history
  • Loading branch information
Th0mz committed Jun 6, 2024
1 parent 9669c1e commit 693c541
Show file tree
Hide file tree
Showing 148 changed files with 11,967 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/ast/normalize.ml
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,12 @@ and normalize_statement (context : context) (stmt : ('M, 'T) Ast'.Statement.t) :
let fnlzr_stmts = Option.map (ns << block_to_statement) finalizer in

(* process catch clause *)
let handler_stmts, handler' = map_default normalize_catch ([], None) handler in
let handler' = map_default normalize_catch (None) handler in

(* build try statement*)
let try_stmt = Statement.Try.build (loc_f loc) block_stmts handler' fnlzr_stmts in

handler_stmts @ [try_stmt]
[try_stmt]

(* --------- W I T H --------- *)
| loc, Ast'.Statement.With {_object; body; _} ->
Expand Down Expand Up @@ -864,14 +864,14 @@ and normalize_case (loc, {Ast'.Statement.Switch.Case.test; consequent; _}) : m S
let case = Statement.Switch.Case.build (loc_f loc) test_expr cnsq_stmts in
(case, test_stmts)

and normalize_catch (loc, { Ast'.Statement.Try.CatchClause.param; body; _}) : norm_stmt_t * m Statement.Try.Catch.t option =
and normalize_catch (loc, { Ast'.Statement.Try.CatchClause.param; body; _}) : m Statement.Try.Catch.t option =
let is_id, id = map_default is_identifier (false, None) param in
let param' = if is_id then id else failwith "param is not an identifier" in
let body_stmts = normalize_statement empty_context (block_to_statement body) in

let catch = Statement.Try.Catch.build (loc_f loc) param' body_stmts in
(body_stmts, Some catch)
Some catch

and normalize_array_elem (array : m Identifier.t) (index : int) (element : ('M, 'T) Ast'.Expression.Array.element) : norm_stmt_t =

match element with
Expand Down
11,833 changes: 11,833 additions & 0 deletions results.txt

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
128 changes: 128 additions & 0 deletions test/normalization/test262.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import argparse
from pathlib import Path
import subprocess

test_root = None
USE_STRICT = "use strict;\n"
TO_PROCESS = ["tests/language/expressions/", "tests/language/statements/"]
TIME_OUT = 10

# colors
RED = "\033[91m"
GREEN = "\033[92m"
YELLOW = "\033[93m"
RESET = "\033[0m"

# info
TOUT = "tout"
PASS = "pass"
FAIL = "fail"

# analysis information
total = 0
norm_error = 0
smnt_error = 0
timeout = 0
ok = 0

def simplify_path (path):
return path.relative_to(test_root/"tests/language")

def test_output (negative, path, color, normalization, semantics):
print(f"{color}{negative}{simplify_path(path)}\t norm [{normalization}]\tsemantics [{semantics}]{RESET}")


def normalize(path):
try:
# run normalization
result = subprocess.run(["ast_gen", path], capture_output=True, text=True, check=True, timeout=TIME_OUT)
norm_program = result.stdout

return PASS, norm_program
except subprocess.CalledProcessError:
info = FAIL
except subprocess.TimeoutExpired:
info = TOUT

return info, None


def test(program):
try:
result = subprocess.run(["node", "-e", program], capture_output=True, text=True, check=True, timeout=TIME_OUT)
if result.stderr:
print(result.stderr)

return PASS, ""
except subprocess.CalledProcessError as e:
info = FAIL
error = e.stderr + "\n"
except subprocess.TimeoutExpired:
info = TOUT
error = ""

return info, error

def main():
global test_root
global total, norm_error, smnt_error, ok, timeout

# setup command line interface
parser = argparse.ArgumentParser(description="test normalization against test262 test suite")
parser.add_argument("test_root", type=str, help="path to the test262 test suite root")
args = parser.parse_args()

test_root = Path(args.test_root)
# get harness
with open(f"{test_root}/environment/harness.js") as file:
harness = file.read()

# run all tests
for test_dir in TO_PROCESS:
for path in (test_root/test_dir).rglob("*"):
if path.is_file():
total += 1

# preprocess file
with open(path) as file:
content = file.read()
is_negative = content.find("negative:") != -1
negative = "NEGATIVE - " if is_negative else ""
is_strict = content.find("onlyStrict") != -1

# normalize + test program
test_info, test_error = "", ""
norm_info, norm_prog = normalize(path)
if norm_prog:
test_prog = (USE_STRICT if is_strict else "") + harness + "\n" + norm_prog
test_info, test_error = test(test_prog)

# output report
failed = (norm_info == FAIL or test_info == FAIL)
timed_out = (norm_info == TOUT or test_info == TOUT)
color = YELLOW
if failed == is_negative:
color = GREEN
ok += 1
else:
color = RED
norm_error += norm_info == FAIL
smnt_error += test_info == FAIL

timeout += timed_out
test_output(negative, path, color, norm_info, test_info)
print(test_error, end="")

# report
print("==============================")
print(f"total : {total}")
print(f"ok : {ok}")
print(f"error : {norm_error}/{smnt_error} (normalization/semantics)")
print(f"timeout : {timeout}")
print("=============================")


#run_node_script(f"{test262_root}/tests/language/expressions/array/11.1.4-0.js" )

if __name__ == "__main__":
main()
File renamed without changes.
File renamed without changes.

0 comments on commit 693c541

Please sign in to comment.