60ce07418035cf684382624d40d661238b2541e4
[platform/upstream/automake.git] / tests / test-driver-custom.test
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 # Custom test drivers: per-extension test drivers.
18
19 am_parallel_tests=yes
20 . ./defs || Exit 1
21
22 cat >> configure.ac << 'END'
23 AC_OUTPUT
24 END
25
26 cat > Makefile.am << 'END'
27 # Automake shouldn't match the '/test' in 'sub/test' as '.test' suffix.
28 TESTS = 1.chk 2.test 3 4.c.chk 5.suf sub/test
29
30 TEST_EXTENSIONS = .chk .test
31
32 CHK_LOG_DRIVER = ./chk-wrapper
33 TEST_LOG_DRIVER = $(SHELL) $(srcdir)/test-wrapper
34 LOG_DRIVER = noext-wrapper
35
36 AM_CHK_LOG_DRIVER_FLAGS = --am-chk
37 CHK_LOG_DRIVER_FLAGS = --chk
38 AM_TEST_LOG_DRIVER_FLAGS = -am-test
39 TEST_LOG_DRIVER_FLAGS = -test
40 AM_LOG_DRIVER_FLAGS = am
41 LOG_DRIVER_FLAGS = _
42 END
43
44 mkdir sub bin
45 PATH=`pwd`/bin$PATH_SEPARATOR$PATH; export PATH
46
47 cat > wrapper.skel <<'END'
48 #! /bin/sh
49 set -e
50
51 me=`echo "$0" | sed 's,^.*/,,'`
52 if test -z "$me"; then
53   echo "$0: cannot determine program name" >&2
54   exit 99
55 fi
56
57 am_log_wflags='@am_log_wflags@'
58 log_wflags='@log_wflags@'
59
60 test_name=INVALID
61 log_file=BAD.log
62 trs_file=BAD.trs
63 extra_opts=
64 while test $# -gt 0; do
65   case $1 in
66     --test-name) test_name=$2; shift;;
67     --log-file) log_file=$2; shift;;
68     --trs-file) trs_file=$2; shift;;
69     # Ignored.
70     --expect-failure) shift;;
71     --color-tests) shift;;
72     --enable-hard-errors) shift;;
73     # Remembered in the same order they're passed in.
74     $am_log_wflags|$log_wflags) extra_opts="$extra_opts $1";;
75     # Explicitly terminate option list.
76     --) shift; break;;
77     # Shouldn't happen
78     *) echo "$0: invalid option/argument: '$1'" >&2; exit 2;;
79   esac
80   shift
81 done
82
83 echo "$me" "$test_name" $extra_opts > "$log_file"
84 : > "$trs_file"
85
86 exec "$@"
87 exit 127
88 END
89
90 sed -e 's|@am_log_wflags@|--am-chk|' \
91     -e 's|@log_wflags@|--chk|' \
92     < wrapper.skel > chk-wrapper
93
94 sed -e 's|@am_log_wflags@|-am-test|' \
95     -e 's|@log_wflags@|-test|' \
96     < wrapper.skel > test-wrapper
97
98 sed -e 's|@am_log_wflags@|am|' \
99     -e 's|@log_wflags@|_|' \
100     < wrapper.skel > bin/noext-wrapper
101
102 # 'test-wrapper' is deliberately not made executable.
103 chmod a+x chk-wrapper bin/noext-wrapper
104
105 # Not needed anymore.
106 rm -f wrapper.skel
107
108 cat > 1.chk << 'END'
109 #! /bin/sh
110 exit 0
111 END
112 chmod a+x 1.chk
113 cp 1.chk 2.test
114 cp 1.chk 3
115 cp 1.chk 4.c.chk
116 cp 1.chk 5.suf
117 cp 1.chk sub/test
118
119 $ACLOCAL
120 $AUTOCONF
121 $AUTOMAKE
122
123 ./configure
124 $MAKE
125 VERBOSE=yes $MAKE check
126 ls -l . sub
127
128 test ! -r BAD.log
129 test ! -r BAD.trs
130
131 echo 'chk-wrapper 1.chk --am-chk --chk' > 1.exp
132 echo 'test-wrapper 2.test -am-test -test' > 2.exp
133 echo 'noext-wrapper 3 am _' > 3.exp
134 echo 'chk-wrapper 4.c.chk --am-chk --chk' > 4.c.exp
135 echo 'noext-wrapper 5.suf am _' > 5.suf.exp
136 echo 'noext-wrapper sub/test am _' > sub/test.exp
137
138 st=0
139 for x in 1 2 3 4.c 5.suf sub/test; do
140   cat $x.log
141   diff $x.exp $x.log || st=1
142 done
143
144 Exit $st