3c4623715b7191585fb3e4c85be4165d907f6306
[platform/upstream/automake.git] / tests / test-driver-custom-xfail-tests.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 # Custom test drivers: "abstract" XFAIL_TESTS support.
18
19 am_parallel_tests=yes
20 . ./defs || Exit 1
21
22 cat >> configure.in <<'END'
23 AC_SUBST([nihil], [])
24 AC_SUBST([ac_xfail_tests], ['x5.test x6$(test_suffix)'])
25 AC_CONFIG_FILES([sub1/Makefile sub2/Makefile])
26 AC_OUTPUT
27 END
28
29 cat > Makefile.am <<'END'
30 SUBDIRS = . sub1 sub2
31 TEST_LOG_DRIVER = $(srcdir)/td
32 TESTS = pass.test xfail.test
33 XFAIL_TESTS = xfail.test
34 END
35
36 mkdir sub1 sub2
37
38 cat > sub1/Makefile.am <<END
39 empty =
40
41 TEST_LOG_DRIVER = \$(top_srcdir)/td
42
43 # XFAIL_TESTS should gracefully handle TAB characters, and multiple
44 # whitespaces.
45 XFAIL_TESTS =\$(empty)${tab}x1.test x2.test${tab}x3.test${tab}\
46 x4.test ${tab} x5.test              x6.test${tab}\$(empty)
47
48 TESTS = pass.test x1.test x2.test x3.test x4.test x5.test x6.test
49 END
50
51 cat > sub2/Makefile.am <<'END'
52 AUTOMAKE_OPTIONS = -Wno-portability-recursive
53
54 TEST_LOG_DRIVER = $(srcdir)/../td
55
56 # XFAIL_TESTS should gracefully AC_SUBST @substitution@ and
57 # make variables indirections.
58 an_xfail_test = x1.test
59 test_suffix = .test
60 v0 = x3.test
61 v1 = v
62 v2 = 0
63 XFAIL_TESTS = $(an_xfail_test) x2.test @nihil@ x3${test_suffix}
64 XFAIL_TESTS += $($(v1)$(v2)) x4.test @ac_xfail_tests@
65
66 TESTS = pass.test x1.test x2.test x3.test x4.test x5.test x6.test
67 END
68
69 cat > pass.test <<'END'
70 #!/bin/sh
71 exit 0
72 END
73
74 cat > xfail.test <<'END'
75 #!/bin/sh
76 exit 1
77 END
78
79 chmod a+x pass.test xfail.test
80
81 cp pass.test sub1/pass.test
82 cp pass.test sub2/pass.test
83
84 for i in 1 2 3 4 5 6; do
85   cp xfail.test sub1/x$i.test
86   cp xfail.test sub2/x$i.test
87 done
88
89 cat > td <<'END'
90 #! /bin/sh
91 set -e; set -u
92 test_name=INVALID
93 log_file=/dev/null
94 trs_file=/dev/null
95 expect_failure=no
96 while test $# -gt 0; do
97   case $1 in
98     --test-name) test_name=$2; shift;;
99     --expect-failure) expect_failure=$2; shift;;
100     --log-file) log_file=$2; shift;;
101     --trs-file) trs_file=$2; shift;;
102     # Ignored.
103     --color-tests) shift;;
104     --enable-hard-errors) shift;;
105     # Explicitly terminate option list.
106     --) shift; break;;
107     # Shouldn't happen
108     *) echo "$0: invalid option/argument: '$1'" >&2; exit 2;;
109   esac
110   shift
111 done
112 st=0
113 "$@" || st=$?
114 case $st,$expect_failure in
115   0,no)
116     echo "PASS: $test_name" | tee "$log_file"
117     echo ":test-result: PASS" > "$trs_file"
118     ;;
119   1,no)
120     echo "FAIL: $test_name" | tee "$log_file"
121     echo ":test-result: FAIL" > "$trs_file"
122     ;;
123   0,yes)
124     echo "XPASS: $test_name" | tee "$log_file"
125     echo ":test-result: XPASS" > "$trs_file"
126     ;;
127   1,yes)
128     echo "XFAIL: $test_name" | tee "$log_file"
129     echo ":test-result: XFAIL" > "$trs_file"
130     ;;
131   *)
132     echo "INTERNAL ERROR" >&2
133     exit 99
134     ;;
135 esac
136 END
137 chmod a+x td
138
139 $ACLOCAL
140 $AUTOCONF
141 $AUTOMAKE
142
143 ./configure
144
145 $MAKE check >stdout || { cat stdout; Exit 1; }
146 cat stdout
147 test `grep -c '^PASS:'  stdout` -eq 3
148 test `grep -c '^XFAIL:' stdout` -eq 13
149
150 for dir in sub1 sub2; do
151   cd $dir
152   cp pass.test x1.test
153   cp x2.test pass.test
154   $MAKE check >stdout && { cat stdout; Exit 1; }
155   cat stdout
156   test "`cat pass.trs`" = ":test-result: FAIL"
157   test "`cat x1.trs`"   = ":test-result: XPASS"
158   test "`cat x2.trs`"   = ":test-result: XFAIL"
159   grep '^FAIL: pass\.test$' stdout
160   grep '^XPASS: x1\.test$'  stdout
161   grep '^XFAIL: x2\.test$'  stdout
162   count_test_results total=7 pass=0 xpass=1 fail=1 xfail=5 skip=0 error=0
163   cd ..
164 done
165
166 :