Neels Hofmeyr | 3cf797d | 2018-04-05 16:56:38 +0200 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | expected_file="$1" |
| 3 | results_file="$2" |
| 4 | |
| 5 | usage() { |
| 6 | echo " |
| 7 | Usage: |
| 8 | |
| 9 | $(basename "$0") expected_results.junit-log current_results.junit-log [--allow-* [...]] |
| 10 | |
| 11 | Return 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 | |
| 22 | if [ ! -f "$expected_file" ]; then |
| 23 | usage |
| 24 | echo "Expected file not found: '$expected_file'" |
| 25 | exit 1 |
| 26 | fi |
| 27 | |
| 28 | if [ ! -f "$results_file" ]; then |
| 29 | usage |
| 30 | echo "Current results file not found: '$results_file'" |
| 31 | exit 1 |
| 32 | fi |
| 33 | |
| 34 | shift |
| 35 | shift |
| 36 | |
| 37 | allow_xpass=0 |
| 38 | allow_skip=0 |
| 39 | allow_new=0 |
| 40 | |
| 41 | while 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 |
| 55 | done |
| 56 | |
| 57 | echo "Comparing expected results $expected_file against results in $results_file |
| 58 | --------------------" |
| 59 | |
| 60 | parse_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 | |
| 71 | pass=0 |
| 72 | xfail=0 |
| 73 | more_failures=0 |
| 74 | more_successes=0 |
| 75 | skipped=0 |
| 76 | new=0 |
| 77 | |
| 78 | while 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 Hofmeyr | a9acec4 | 2018-09-06 14:33:37 +0200 | [diff] [blame] | 115 | done <<< "$(grep "<testcase.*$exp_test_name" "$results_file")" |
Neels Hofmeyr | 3cf797d | 2018-04-05 16:56:38 +0200 | [diff] [blame] | 116 | |
| 117 | if [ "x$matched" = "x0" ]; then |
| 118 | echo "skipped $exp_suite_name.$exp_test_name" |
| 119 | (( skipped += 1 )) |
| 120 | fi |
| 121 | |
| 122 | done <<< "$(grep "<testcase" "$expected_file")" |
| 123 | |
| 124 | # Also catch all new tests that aren't covered in the expected results |
| 125 | while 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 Hofmeyr | a9acec4 | 2018-09-06 14:33:37 +0200 | [diff] [blame] | 143 | done <<< "$(grep "<testcase.*$test_name" "$expected_file")" |
Neels Hofmeyr | 3cf797d | 2018-04-05 16:56:38 +0200 | [diff] [blame] | 144 | |
| 145 | if [ "x$matched" = "x0" ]; then |
| 146 | echo "NEW-$got_test_result $got_suite_name.$got_test_name" |
| 147 | (( new += 1 )) |
| 148 | fi |
| 149 | |
| 150 | done <<< "$(grep "<testcase" "$results_file")" |
| 151 | |
| 152 | echo "--------------------" |
| 153 | overall_verdict=0 |
| 154 | |
Neels Hofmeyr | 2068f43 | 2018-09-06 14:30:03 +0200 | [diff] [blame] | 155 | ask_update="" |
| 156 | |
Neels Hofmeyr | 3cf797d | 2018-04-05 16:56:38 +0200 | [diff] [blame] | 157 | if [ "x$pass" != x0 ]; then |
| 158 | echo "$pass pass" |
| 159 | fi |
| 160 | |
| 161 | if [ "x$xfail" != x0 ]; then |
| 162 | echo "$xfail xfail" |
| 163 | fi |
| 164 | |
| 165 | if [ "x$skipped" != x0 ]; then |
| 166 | echo "$skipped skipped" |
Neels Hofmeyr | 2068f43 | 2018-09-06 14:30:03 +0200 | [diff] [blame] | 167 | ask_update="$ask_update removed=$skipped" |
Neels Hofmeyr | 3cf797d | 2018-04-05 16:56:38 +0200 | [diff] [blame] | 168 | if [ "x$allow_skip" = x0 ]; then |
| 169 | overall_verdict=4 |
Neels Hofmeyr | 3cf797d | 2018-04-05 16:56:38 +0200 | [diff] [blame] | 170 | fi |
| 171 | fi |
| 172 | |
| 173 | if [ "x$new" != x0 ]; then |
| 174 | echo "$new new" |
Neels Hofmeyr | 2068f43 | 2018-09-06 14:30:03 +0200 | [diff] [blame] | 175 | ask_update="$ask_update new=$new" |
Neels Hofmeyr | 3cf797d | 2018-04-05 16:56:38 +0200 | [diff] [blame] | 176 | if [ "x$allow_new" = x0 ]; then |
| 177 | overall_verdict=3 |
Neels Hofmeyr | 3cf797d | 2018-04-05 16:56:38 +0200 | [diff] [blame] | 178 | fi |
| 179 | fi |
| 180 | |
| 181 | if [ "x$more_successes" != x0 ]; then |
| 182 | echo "$more_successes pass unexpectedly" |
Neels Hofmeyr | 2068f43 | 2018-09-06 14:30:03 +0200 | [diff] [blame] | 183 | ask_update="$ask_update xpass=$more_successes" |
Neels Hofmeyr | 3cf797d | 2018-04-05 16:56:38 +0200 | [diff] [blame] | 184 | if [ "x$allow_xpass" = x0 ]; then |
| 185 | overall_verdict=2 |
Neels Hofmeyr | 3cf797d | 2018-04-05 16:56:38 +0200 | [diff] [blame] | 186 | fi |
| 187 | fi |
| 188 | |
| 189 | if [ "x$more_failures" != x0 ]; then |
| 190 | echo "$more_failures FAIL" |
| 191 | overall_verdict=1 |
| 192 | fi |
| 193 | |
Neels Hofmeyr | 2068f43 | 2018-09-06 14:30:03 +0200 | [diff] [blame] | 194 | if [ -n "$ask_update" ]; then |
| 195 | echo |
| 196 | echo "(Please update the expected results:$ask_update)" |
Neels Hofmeyr | 3cf797d | 2018-04-05 16:56:38 +0200 | [diff] [blame] | 197 | fi |
Neels Hofmeyr | 2068f43 | 2018-09-06 14:30:03 +0200 | [diff] [blame] | 198 | |
Neels Hofmeyr | 3cf797d | 2018-04-05 16:56:38 +0200 | [diff] [blame] | 199 | exit $overall_verdict |