Commit | Line | Data |
---|---|---|
7eeb782e AT |
1 | #invoke with gnugo --mode gtp < reading.tst | awk -f regress.awk tst=reading.tst |
2 | ||
3 | # store results of gnugo in array gtpout | |
4 | ||
5 | # store test numbers in array test to be able | |
6 | # to retrieve test results in same order as in gtp file | |
7 | ||
8 | BEGIN { | |
9 | ntest = 0; | |
10 | nexpect = 0; | |
11 | passes = 0; | |
12 | unexpected_pass = 0; | |
13 | unexpected_fail = 0; | |
14 | failures = 0; | |
15 | } | |
16 | ||
17 | /^[=?][0-9]+ /{ | |
18 | sub(/\r/, ""); | |
19 | sub(/^[=?]/, ""); | |
20 | num = $1; | |
21 | sub(/^[0-9]+ */, ""); | |
22 | gtpout[num] = $0; | |
23 | test[ntest] = num; | |
24 | ntest++; | |
25 | } | |
26 | ||
27 | /^;/{ | |
28 | ||
29 | } | |
30 | ||
31 | END { | |
32 | ||
33 | # store test results in tst file in array expect | |
34 | ||
35 | while (getline < tst) { | |
36 | if (match ($0, /^#\?/)) { | |
37 | sub(/^#\? */, ""); | |
38 | expect[num] = $0; | |
39 | nexpect++; | |
40 | } else { | |
41 | num = $1; | |
42 | } | |
43 | } | |
44 | ||
45 | if (nexpect != ntest) { | |
46 | if (ntest > 0) { | |
47 | print "Possible crash!: expected " nexpect " results, got " ntest ". Last successful test was " test[ntest-1] "."; | |
48 | } else { | |
49 | print "Possible crash!: expected " nexpect " results, got " ntest ". Crash in first test."; | |
50 | } | |
51 | } | |
52 | ||
53 | # check results of gnugo --mode gtp | |
54 | ||
55 | for (i=0; i<ntest; i++) { | |
56 | ||
57 | num = test[i]; | |
58 | correct_prn = expect[num]; | |
59 | sub(/^\[/, "", correct_prn); | |
60 | sub(/\][&*]*$/, "", correct_prn); | |
61 | ||
62 | ignore = 0; | |
63 | fail = 0; | |
64 | negate = 0; | |
65 | if (match(expect[num], /&$/)) { | |
66 | ignore = 1; | |
67 | } | |
68 | if (match(expect[num], /\*$/)) { | |
69 | fail = 1; | |
70 | } | |
71 | correct_re = correct_prn; | |
72 | if (match(correct_re, /^!/)) { | |
73 | negate = 1; | |
74 | sub(/^!/, "", correct_re); | |
75 | } | |
76 | sub(/^/, "^", correct_re); | |
77 | sub(/$/, "$", correct_re); | |
78 | ||
79 | result = gtpout[num]; | |
80 | if (!ignore) { | |
81 | match_result = match(result, correct_re); | |
82 | if (negate) | |
83 | match_result = !match_result; | |
84 | if (match_result) { | |
85 | passes++; | |
86 | if (fail) { | |
87 | unexpected_pass++; | |
88 | if (verbose) | |
89 | print num " PASSED"; | |
90 | else | |
91 | print num " unexpected PASS!"; | |
92 | if (url) | |
93 | print " "url""tst":"num; | |
94 | ||
95 | } else { | |
96 | if (verbose) { | |
97 | print num " passed"; | |
98 | } | |
99 | } | |
100 | } else { | |
101 | failures++; | |
102 | if (!fail) { | |
103 | unexpected_fail++; | |
104 | if (verbose) | |
105 | print num " FAILED: Correct '" correct_prn "', got '" result "'"; | |
106 | else | |
107 | print num " unexpected FAIL: Correct '" correct_prn "', got '" result "'"; | |
108 | if (url) | |
109 | print " "url""tst":"num; | |
110 | } else { | |
111 | if (verbose) { | |
112 | print num " failed: Correct '" correct_prn "', got '" result "'"; | |
113 | } | |
114 | } | |
115 | } | |
116 | } else { | |
117 | if (verbose) { | |
118 | print num " " result; | |
119 | } | |
120 | } | |
121 | } | |
122 | if (verbose) { | |
123 | total = passes + failures; | |
124 | ||
125 | if (unexpected_pass == 1) | |
126 | pass_string = "pass"; | |
127 | else | |
128 | pass_string = "passes"; | |
129 | ||
130 | if (unexpected_fail == 1) | |
131 | fail_string = "failure"; | |
132 | else | |
133 | fail_string = "failures"; | |
134 | ||
135 | print "Summary: " passes "/" total " passes. " unexpected_pass " unexpected " pass_string ", " unexpected_fail " unexpected " fail_string; | |
136 | } | |
137 | } |