blob: cce3a8d450f735c03843d05ac634b5ebd0f2f7d6 [file] [log] [blame]
Neels Hofmeyr3cf797d2018-04-05 16:56:38 +02001#!/usr/bin/env bash
2expected_file="$1"
3results_file="$2"
4
5usage() {
6 echo "
7Usage:
8
9 $(basename "$0") expected_results.junit-log current_results.junit-log [--allow-* [...]]
10
11Return 0 if the expected results match the current results exactly.
12
13 --allow-skip Allow runnning less tests than are listed in the expected file.
14 Default is to return failure on any skipped tests.
15 --allow-new Allow more test results than found in the expected file.
16 Default is to return failure on any unknown tests.
17 --allow-xpass If a test was expected to fail but passed, return success.
18 Default is to return failure on any mismatch.
19"
20}
21
22if [ ! -f "$expected_file" ]; then
23 usage
24 echo "Expected file not found: '$expected_file'"
25 exit 1
26fi
27
28if [ ! -f "$results_file" ]; then
29 usage
30 echo "Current results file not found: '$results_file'"
31 exit 1
32fi
33
34shift
35shift
36
37allow_xpass=0
38allow_skip=0
39allow_new=0
40
41while test -n "$1"; do
42 arg="$1"
43 if [ "x$arg" = "x--allow-xpass" ]; then
44 allow_xpass=1
45 elif [ "x$arg" = "x--allow-skip" ]; then
46 allow_skip=1
47 elif [ "x$arg" = "x--allow-new" ]; then
48 allow_new=1
49 else
50 usage
51 echo "Unknown argument: '$arg'"
52 exit 1
53 fi
54 shift
55done
56
57echo "Comparing expected results $expected_file against results in $results_file
58--------------------"
59
60parse_testcase() {
61 line="$1"
62 suite_name="$(echo "$line" | sed 's,.*classname='"'"'\([^'"'"']*\)'"'"'.*,\1,')"
63 test_name="$(echo "$line" | sed 's,.*\<name='"'"'\([^'"'"']*\)'"'"'.*,\1,')"
64 if [ -n "$(echo "$line" | grep '/>$')" ]; then
65 test_result="pass"
66 else
67 test_result="FAIL"
68 fi
69}
70
71pass=0
72xfail=0
73more_failures=0
74more_successes=0
75skipped=0
76new=0
77
78while read line; do
79 parse_testcase "$line"
80 exp_suite_name="$suite_name"
81 exp_test_name="$test_name"
82 exp_test_result="$test_result"
83 matched="0"
84
85 while read line; do
86 parse_testcase "$line"
87 if [ "x$exp_suite_name" != "x$suite_name" ]; then
88 continue
89 fi
90 if [ "x$exp_test_name" != "x$test_name" ]; then
91 continue
92 fi
93
94 if [ "x$exp_test_result" = "x$test_result" ]; then
95 if [ "x$exp_test_result" = "xFAIL" ]; then
96 exp_test_result="xfail"
97 (( xfail += 1 ))
98 else
99 (( pass += 1 ))
100 fi
101 echo "$exp_test_result $suite_name.$test_name"
102 else
103 if [ "x$exp_test_result" = "xFAIL" ]; then
104 exp_test_result="xfail"
105 fi
106 echo "$exp_test_result->$test_result $suite_name.$test_name"
107 if [ "x$test_result" = "xFAIL" ]; then
108 (( more_failures += 1 ))
109 else
110 (( more_successes += 1 ))
111 fi
112 fi
113 matched="1"
114 break
Neels Hofmeyra9acec42018-09-06 14:33:37 +0200115 done <<< "$(grep "<testcase.*$exp_test_name" "$results_file")"
Neels Hofmeyr3cf797d2018-04-05 16:56:38 +0200116
117 if [ "x$matched" = "x0" ]; then
118 echo "skipped $exp_suite_name.$exp_test_name"
119 (( skipped += 1 ))
120 fi
121
122done <<< "$(grep "<testcase" "$expected_file")"
123
124# Also catch all new tests that aren't covered in the expected results
125while read line; do
126 parse_testcase "$line"
127 got_suite_name="$suite_name"
128 got_test_name="$test_name"
129 got_test_result="$test_result"
130 matched="0"
131
132 while read line; do
133 parse_testcase "$line"
134 if [ "x$got_suite_name" != "x$suite_name" ]; then
135 continue
136 fi
137 if [ "x$got_test_name" != "x$test_name" ]; then
138 continue
139 fi
140
141 matched="1"
142 break
Neels Hofmeyra9acec42018-09-06 14:33:37 +0200143 done <<< "$(grep "<testcase.*$test_name" "$expected_file")"
Neels Hofmeyr3cf797d2018-04-05 16:56:38 +0200144
145 if [ "x$matched" = "x0" ]; then
146 echo "NEW-$got_test_result $got_suite_name.$got_test_name"
147 (( new += 1 ))
148 fi
149
150done <<< "$(grep "<testcase" "$results_file")"
151
152echo "--------------------"
153overall_verdict=0
154
Neels Hofmeyr2068f432018-09-06 14:30:03 +0200155ask_update=""
156
Neels Hofmeyr3cf797d2018-04-05 16:56:38 +0200157if [ "x$pass" != x0 ]; then
158 echo "$pass pass"
159fi
160
161if [ "x$xfail" != x0 ]; then
162 echo "$xfail xfail"
163fi
164
165if [ "x$skipped" != x0 ]; then
166 echo "$skipped skipped"
Neels Hofmeyr2068f432018-09-06 14:30:03 +0200167 ask_update="$ask_update removed=$skipped"
Neels Hofmeyr3cf797d2018-04-05 16:56:38 +0200168 if [ "x$allow_skip" = x0 ]; then
169 overall_verdict=4
Neels Hofmeyr3cf797d2018-04-05 16:56:38 +0200170 fi
171fi
172
173if [ "x$new" != x0 ]; then
174 echo "$new new"
Neels Hofmeyr2068f432018-09-06 14:30:03 +0200175 ask_update="$ask_update new=$new"
Neels Hofmeyr3cf797d2018-04-05 16:56:38 +0200176 if [ "x$allow_new" = x0 ]; then
177 overall_verdict=3
Neels Hofmeyr3cf797d2018-04-05 16:56:38 +0200178 fi
179fi
180
181if [ "x$more_successes" != x0 ]; then
182 echo "$more_successes pass unexpectedly"
Neels Hofmeyr2068f432018-09-06 14:30:03 +0200183 ask_update="$ask_update xpass=$more_successes"
Neels Hofmeyr3cf797d2018-04-05 16:56:38 +0200184 if [ "x$allow_xpass" = x0 ]; then
185 overall_verdict=2
Neels Hofmeyr3cf797d2018-04-05 16:56:38 +0200186 fi
187fi
188
189if [ "x$more_failures" != x0 ]; then
190 echo "$more_failures FAIL"
191 overall_verdict=1
192fi
193
Neels Hofmeyr2068f432018-09-06 14:30:03 +0200194if [ -n "$ask_update" ]; then
195 echo
196 echo "(Please update the expected results:$ask_update)"
Neels Hofmeyr3cf797d2018-04-05 16:56:38 +0200197fi
Neels Hofmeyr2068f432018-09-06 14:30:03 +0200198
Neels Hofmeyr3cf797d2018-04-05 16:56:38 +0200199exit $overall_verdict