File: regress.awk

package info (click to toggle)
gnugo 3.6-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 17,384 kB
  • ctags: 4,137
  • sloc: ansic: 55,120; perl: 3,742; lisp: 1,753; python: 742; sh: 731; makefile: 696; awk: 113; sed: 26
file content (137 lines) | stat: -rw-r--r-- 2,876 bytes parent folder | download | duplicates (9)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#invoke with gnugo --mode gtp < reading.tst | awk -f regress.awk tst=reading.tst

# store results of gnugo in array gtpout

# store test numbers in array test to be able
# to retrieve test results in same order as in gtp file

BEGIN {
  ntest = 0;
  nexpect = 0;
  passes = 0;
  unexpected_pass = 0;
  unexpected_fail = 0;
  failures = 0;
}

/^[=?][0-9]+ /{
  sub(/\r/, "");
  sub(/^[=?]/, "");
  num = $1;
  sub(/^[0-9]+ */, "");
  gtpout[num] = $0;
  test[ntest] = num;
  ntest++;
}

/^;/{
  print
}

END {

# store test results in tst file in array expect

  while (getline < tst) {
    if (match ($0, /^#\?/)) {
      sub(/^#\? */, "");
      expect[num] = $0;
      nexpect++;
    } else {
      num = $1;
    }
  }

  if (nexpect != ntest) {
    if (ntest > 0) {
      print "Possible crash!: expected " nexpect " results, got " ntest ". Last successful test was " test[ntest-1] ".";
    } else {
      print "Possible crash!: expected " nexpect " results, got " ntest ". Crash in first test.";
    }
  }

# check results of gnugo --mode gtp

  for (i=0; i<ntest; i++) {

    num = test[i];
    correct_prn = expect[num];
    sub(/^\[/, "", correct_prn);
    sub(/\][&*]*$/, "", correct_prn);

    ignore = 0;
    fail = 0;
    negate = 0;
    if (match(expect[num], /&$/)) {
      ignore = 1;
    }
    if (match(expect[num], /\*$/)) {
      fail = 1;
    }
    correct_re = correct_prn;
    if (match(correct_re, /^!/)) {
      negate = 1;
      sub(/^!/, "", correct_re);
    }
    sub(/^/, "^", correct_re);
    sub(/$/, "$", correct_re);

    result = gtpout[num];
    if (!ignore) {
      match_result = match(result, correct_re);
      if (negate)
	match_result = !match_result;
      if (match_result) {
	passes++;
	if (fail) {
	  unexpected_pass++;
	  if (verbose)
	    print num " PASSED";
	  else
	    print num " unexpected PASS!";
         if (url)
           print "   "url""tst":"num;

	} else {
	  if (verbose) {
	    print num " passed";
	  }
	}
      } else {
	failures++;
	if (!fail) {
	  unexpected_fail++;
	  if (verbose)
	    print num " FAILED: Correct '" correct_prn "', got '" result "'";
	  else  
	    print num " unexpected FAIL: Correct '" correct_prn "', got '" result "'";
          if (url)
            print "   "url""tst":"num;
	} else {
	  if (verbose) {
	    print num " failed: Correct '" correct_prn "', got '" result "'";
	  }
	}
      }
    } else {
      if (verbose) {
        print num " " result;
      }
    }
  }
  if (verbose) {
    total = passes + failures;
    
    if (unexpected_pass == 1)
      pass_string = "pass";
    else
      pass_string = "passes";
    
    if (unexpected_fail == 1)
      fail_string = "failure";
    else
      fail_string = "failures";
    
    print "Summary: " passes "/" total " passes. " unexpected_pass " unexpected " pass_string ", " unexpected_fail " unexpected " fail_string;
  }
}