tests: use 'parallel-tests' Automake option by default
[platform/upstream/automake.git] / t / test-metadata-results.sh
1 #! /bin/sh
2 # Copyright (C) 2011-2012 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 . ./defs || Exit 1
21
22 cat >> configure.ac << 'END'
23 AC_OUTPUT
24 END
25
26 cat > Makefile.am << 'END'
27 TEST_LOG_DRIVER = ./dummy-driver
28 TESTS = foo.test bar.test
29 END
30
31 cat > dummy-driver <<'END'
32 #! /bin/sh
33 set -e; set -u
34 while test $# -gt 0; do
35   case $1 in
36     --log-file) log_file=$2; shift;;
37     --trs-file) trs_file=$2; shift;;
38     --test-name) test_name=$2; shift;;
39     --expect-failure|--color-tests|--enable-hard-errors) shift;;
40     --) shift; break;;
41      *) echo "$0: invalid option/argument: '$1'" >&2; exit 2;;
42   esac
43   shift
44 done
45 : > $log_file
46 cp $1 $trs_file
47 END
48 chmod a+x dummy-driver
49
50 mk_check ()
51 {
52   st=0
53   $MAKE check >stdout || st=$?
54   cat stdout
55   # Our dummy driver make no testsuite progress report.
56   grep ': .*\.test' stdout && Exit 1
57   # Nor it writes to the log files.
58   test -s foo.log && Exit 1
59   test -s bar.log && Exit 1
60   return $st
61 }
62
63 # This must be different from the one defined in 'test/defs', as that
64 # assumes that the driver does proper testsuite progress reporting.
65 count_test_results ()
66 {
67   total=ERR pass=ERR fail=ERR xpass=ERR xfail=ERR skip=ERR error=ERR
68   eval "$@"
69   st=0
70   grep "^# TOTAL:  *$total$" stdout || rc=1
71   grep "^# PASS:  *$pass$"   stdout || rc=1
72   grep "^# XFAIL:  *$xfail$" stdout || rc=1
73   grep "^# SKIP:  *$skip$"   stdout || rc=1
74   grep "^# FAIL:  *$fail$"   stdout || rc=1
75   grep "^# XPASS:  *$xpass$" stdout || rc=1
76   grep "^# ERROR:  *$error$" stdout || rc=1
77   test $st -eq 0 || Exit 1
78 }
79
80 $ACLOCAL
81 $AUTOCONF
82 $AUTOMAKE
83
84 ./configure
85
86 # Basic checks.  Also that that ':global-test-result:' fields and
87 # "old-style" directives with format "RESULT: test-name" are now ignored.
88
89 : > foo.test
90 echo blah blah blah > bar.test
91 mk_check
92 count_test_results total=0 pass=0 fail=0 xpass=0 xfail=0 skip=0 error=0
93
94 cat > foo.test <<END
95 :test-global-result: PASS
96 :test-result: FAIL
97 END
98 cat > bar.test <<END
99 :test-result: SKIP
100 :test-global-result: ERROR
101 END
102 mk_check && Exit 1
103 count_test_results total=2 pass=0 fail=1 xpass=0 xfail=0 skip=1 error=0
104
105 cat > foo.test <<END
106 FAIL: foo.test
107 :test-result: PASS
108 :test-global-result: XPASS
109 END
110 echo ERROR: bar.test > bar.test
111 mk_check
112 count_test_results total=1 pass=1 fail=0 xpass=0 xfail=0 skip=0 error=0
113
114 cat > foo.test <<END
115 :test-global-result: SKIP
116 :test-result: FAIL
117 END
118 cat > bar.test <<END
119 :test-global-result: PASS
120 END
121 mk_check && Exit 1
122 count_test_results total=1 pass=0 fail=1 xpass=0 xfail=0 skip=0 error=0
123
124 cat > foo.test <<END
125 :test-result: XFAIL
126 :test-result: PASS
127 :test-result: SKIP
128 END
129 cat > bar.test <<END
130 :test-result: SKIP
131 :test-result: PASS
132 :test-result: SKIP
133 :test-result: PASS
134 :test-result: PASS
135 END
136 mk_check
137 count_test_results total=8 pass=4 fail=0 xpass=0 xfail=1 skip=3 error=0
138
139 # Check that all results expected to be supported are *really* supported.
140
141 cat > foo.test <<END
142 :test-result: PASS
143 :test-result: SKIP
144 :test-result: XFAIL
145 :test-result: FAIL
146 :test-result: XPASS
147 :test-result: ERROR
148 END
149 : > bar.test
150 mk_check && Exit 1
151 count_test_results total=6 pass=1 fail=1 xpass=1 xfail=1 skip=1 error=1
152
153 cp foo.test bar.test
154 mk_check && Exit 1
155 count_test_results total=12 pass=2 fail=2 xpass=2 xfail=2 skip=2 error=2
156
157 # Check that we are liberal w.r.t. whitespace use.
158
159 : > foo.test
160 : > bar.test
161 for RESULT in PASS FAIL XPASS XFAIL SKIP ERROR; do
162   sed -e 's/^ *//' -e 's/|//g' >> foo.test <<END
163     |:test-result:$RESULT|
164     |:test-result: $tab  $RESULT|
165     |:test-result:$RESULT  $tab|
166     |:test-result:$tab$tab  $RESULT$tab  $tab |
167 END
168   echo "  $tab $tab$tab   :test-result: $RESULT" >> bar.test
169 done
170 cat foo.test # For debugging.
171 cat bar.test # Likewise.
172 mk_check && Exit 1
173 count_test_results total=30 pass=5 fail=5 xpass=5 xfail=5 skip=5 error=5
174
175 :