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