-
Notifications
You must be signed in to change notification settings - Fork 1
/
UnitTestStep.ml
77 lines (69 loc) · 2.12 KB
/
UnitTestStep.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
(* UnitTestStep.ml *)
(*open Sexplib.Std*)
(*open Common*)
(*open Pattern*)
open ReadPattern
open CorePattern
(*open Simulate*)
open SimStep
open Buffer
open Core.Result
TYPE_CONV_PATH "UnitTestStep"
let manifest="test-manifest.txt"
let format_match (g,_) =
let b = Buffer.create 12 in
let add_match (l,r) =
begin
add_char b '(';
(match l with
(-1) -> add_char b '?'
| x -> add_string b (string_of_int x));
add_char b ',';
(match r with
(-1) -> add_char b '?'
| x -> add_string b (string_of_int x));
add_char b ')';
end
in
Array.iter add_match g;
contents b
let runTestFile name =
let storeSAME = ref "" in
let runTest n sREIn sTextIn sOut =
let sN = string_of_int n in
let sRE = if sREIn = "SAME" then !storeSAME
else (storeSAME := sREIn ; sREIn)
in
match (parseRegex sRE) with
Error err -> Printf.printf "Failed to parse: %s %s\nError message: %s\n" sN sRE err
| Ok p ->
(* let s = Sexplib.Sexp.to_string_hum (sexp_of_pattern p) in Printf.printf "Pattern %s\n" s;*)
let cr = toCorePattern p in
let sText = if sTextIn="NULL" then "" else sTextIn in
let found = match uWrap cr sText with
[] -> "NOMATCH"
| (h::_) -> format_match h
in
if (found=sOut)
then
if (0<=n)
then Printf.printf "expected pass %s\n %s %s %s\n" sN sRE sText sOut
else Printf.printf "UNEXPECTED PASS %s\n %s %s %s\n" sN sRE sText sOut
else
if (n<0)
then Printf.printf "expected failed %s\n %s %s %s : %s\n" sN sRE sText sOut found
else Printf.printf "UNEXPECTED FAILED %s\n %s %s %s : %s\n" sN sRE sText sOut found
in
let readTest (lineIn : string) = Scanf.sscanf lineIn " %d %s %s %s" runTest
in
let g = open_in name
in
Printf.printf "\nLoading Tests from: %s\n" name;
Core.In_channel.iter_lines g ~f:readTest;
close_in g
let runAllTestFiles () =
let chan = open_in manifest in
Core.In_channel.iter_lines ~fix_win_eol:true chan ~f:runTestFile;
();;
Printf.printf "unitTestStep\n";;
runAllTestFiles ();;