Merge branch 'master' into test-protocols
[platform/upstream/automake.git] / tests / test-metadata-results.test
1 #! /bin/sh
2 # Copyright (C) 2011 Free Software Foundation, Inc.
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2, or (at your option)
7 # any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 # Parallel testsuite harness: check APIs for the registering of test
18 # results in `*.trs' files, as documented in the automake manual.
19
20 parallel_tests=yes
21 . ./defs || Exit 1
22
23 cat >> configure.in << 'END'
24 AC_OUTPUT
25 END
26
27 cat > Makefile.am << 'END'
28 TEST_LOG_DRIVER = ./dummy-driver
29 TESTS = foo.test bar.test
30 END
31
32 cat > dummy-driver <<'END'
33 #! /bin/sh
34 set -e; set -u
35 while test $# -gt 0; do
36   case $1 in
37     --log-file) log_file=$2; shift;;
38     --trs-file) trs_file=$2; shift;;
39     --test-name) test_name=$2; shift;;
40     --expect-failure|--color-tests|--enable-hard-errors) shift;;
41     --) shift; break;;
42      *) echo "$0: invalid option/argument: '$1'" >&2; exit 2;;
43   esac
44   shift
45 done
46 : > $log_file
47 cp $1 $trs_file
48 END
49 chmod a+x dummy-driver
50
51 mk_check ()
52 {
53   st=0
54   $MAKE check >stdout || st=$?
55   cat stdout
56   # Our dummy driver make no testsuite progress report.
57   grep ': .*\.test' stdout && Exit 1
58   # Nor it writes to the log files.
59   test -s foo.log && Exit 1
60   test -s bar.log && Exit 1
61   return $st
62 }
63
64 # This must be different from the one defined in `test/defs', as that
65 # assumes that the driver does proper testsuite progress reporting.
66 count_test_results ()
67 {
68   total=ERR pass=ERR fail=ERR xpass=ERR xfail=ERR skip=ERR error=ERR
69   eval "$@"
70   st=0
71   grep "^# TOTAL:  *$total$" stdout || rc=1
72   grep "^# PASS:  *$pass$"   stdout || rc=1
73   grep "^# XFAIL:  *$xfail$" stdout || rc=1
74   grep "^# SKIP:  *$skip$"   stdout || rc=1
75   grep "^# FAIL:  *$fail$"   stdout || rc=1
76   grep "^# XPASS:  *$xpass$" stdout || rc=1
77   grep "^# ERROR:  *$error$" stdout || rc=1
78   test $st -eq 0 || Exit 1
79 }
80
81 $ACLOCAL
82 $AUTOCONF
83 $AUTOMAKE
84
85 ./configure
86
87 # Basic checks.  Also that that "old-style" directives with format
88 # "RESULT: test-name" are be ignored now.
89
90 cat > foo.test <<END
91 FAIL: foo.test
92 :test-result: PASS
93 END
94 echo ERROR: bar.test > bar.test
95 mk_check
96 count_test_results total=1 pass=1 fail=0 xpass=0 xfail=0 skip=0 error=0
97
98 cat > foo.test <<END
99 PASS: foo.test
100 :test-result: FAIL
101 END
102 echo SKIP: bar.test > bar.test
103 : > bar.test
104 mk_check && Exit 1
105 count_test_results total=1 pass=0 fail=1 xpass=0 xfail=0 skip=0 error=0
106
107 cat > foo.test <<END
108 PASS: foo.test
109 :test-result: FAIL
110 END
111 cat > bar.test <<END
112 ERROR: foo.test
113 :test-result: SKIP
114 END
115 mk_check && Exit 1
116 count_test_results total=2 pass=0 fail=1 xpass=0 xfail=0 skip=1 error=0
117
118 cat > foo.test <<END
119 :test-result: XFAIL
120 :test-result: PASS
121 :test-result: SKIP
122 END
123 cat > bar.test <<END
124 :test-result: SKIP
125 :test-result: PASS
126 :test-result: SKIP
127 :test-result: PASS
128 :test-result: PASS
129 END
130 mk_check
131 count_test_results total=8 pass=4 fail=0 xpass=0 xfail=1 skip=3 error=0
132
133 # Check that all results expected to be supported are *really* supported.
134
135 cat > foo.test <<END
136 :test-result: PASS
137 :test-result: SKIP
138 :test-result: XFAIL
139 :test-result: FAIL
140 :test-result: XPASS
141 :test-result: ERROR
142 END
143 : > bar.test
144 mk_check && Exit 1
145 count_test_results total=6 pass=1 fail=1 xpass=1 xfail=1 skip=1 error=1
146
147 cp foo.test bar.test
148 mk_check && Exit 1
149 count_test_results total=12 pass=2 fail=2 xpass=2 xfail=2 skip=2 error=2
150
151 # Check that we are liberal w.r.t. whitespace use.
152
153 : > foo.test
154 : > bar.test
155 for RESULT in PASS FAIL XPASS XFAIL SKIP ERROR; do
156   sed -e 's/^ *//' -e 's/|//g' >> foo.test <<END
157     |:test-result:$RESULT|
158     |:test-result: $tab  $RESULT|
159     |:test-result:$RESULT  $tab|
160     |:test-result:$tab$tab  $RESULT$tab  $tab |
161 END
162   echo "  $tab $tab$tab   :test-result: $RESULT" >> bar.test
163 done
164 cat foo.test # For debugging.
165 cat bar.test # Likewise.
166 mk_check && Exit 1
167 count_test_results total=30 pass=5 fail=5 xpass=5 xfail=5 skip=5 error=5
168
169 :