1 # Copyright © 2020-2024 Nick Bowler
3 # This program is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation, either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16 AT_BANNER([Program tests])
18 dnl TEST_PATH_LOOKUP(var, program, [abspath=`pwd`/bin])
20 dnl If "command -v program" returns abspath/program, then set var=program.
21 dnl Otherwise, set var=abspath/program. This helps compute the expected
22 dnl program name from path lookups as certain older shells (e.g., Solaris
23 dnl 10 /bin/sh) do not implement "command".
24 m4_define([TEST_PATH_LOOKUP],
25 [AS_VAR_SET([$1], [$2])
26 val=`$TEST_SHELL -c 'command -v $2'`
27 AS_IF([test x"$val" != x"m4_default([$3], [`pwd`/bin])/$2"],
28 [AS_VAR_SET([$1], [m4_default([$3], [`pwd`/bin])/$2])])])
30 m4_define([TEST_SIMPLE_PROGRAM_PROBES],
31 [TEST_SIMPLE_PROGRAM_PROBES_([$1], m4_toupper($1))])
32 m4_define([TEST_SIMPLE_PROGRAM_PROBES_],
33 [AT_SETUP([$1 probes])
34 AT_KEYWORDS([DX_PROG_$2 program])dnl
35 AT_CAPTURE_FILE([config.log])dnl
38 cp -P "$srcdir/t/$1.sh" bin/$1
46 TEST_CONFIGURE_AC([[DX_PROG_$2([], [HAVE_$2=yes], [HAVE_$2=no])
50 set x conftest*; shift
52 AC_MSG_ERROR([$[]1 left behind by [D@@&t@&t@X_PROG_$2]])
55 AC_CONFIG_FILES([test])
59 # Check the search via path lookup
61 PATH=`pwd`/bin${PATH:+":$PATH"}
63 TEST_PATH_LOOKUP([expected], [$1])
65 AT_CHECK_UNQUOTED([cat test], [0], [yes
70 # Check the search via user override
71 TEST_CONFIGURE([$2="$srcdir/t/$1.sh"])
72 AT_CHECK_UNQUOTED([cat test], [0], [yes
76 # Check that a bogus program doesn't come back as valid.
77 TEST_CONFIGURE([$2=true])
78 AT_CHECK_UNQUOTED([cat test], [0], [no
83 mv configure.ac configure.old
84 sed ['s/\(DX_PROG_$2(\)\[\]/\1[2.1.3]/'] configure.old >configure.ac
87 TEST_CONFIGURE([FAKE_$2_VERSION=2.0.0 $2="$srcdir/t/$1.sh"])
88 AT_CHECK_UNQUOTED([cat test], [0], [no
92 TEST_CONFIGURE([FAKE_$2_VERSION=3.0.0 $2="$srcdir/t/$1.sh"])
93 AT_CHECK_UNQUOTED([cat test], [0], [yes
97 TEST_CONFIGURE([FAKE_$2_VERSION=2.5.0 $2="$srcdir/t/$1.sh"])
98 AT_CHECK_UNQUOTED([cat test], [0], [yes
102 TEST_CONFIGURE([FAKE_$2_VERSION=2.1.2 $2="$srcdir/t/$1.sh"])
103 AT_CHECK_UNQUOTED([cat test], [0], [no
107 TEST_CONFIGURE([FAKE_$2_VERSION=2.1.3 $2="$srcdir/t/$1.sh"])
108 AT_CHECK_UNQUOTED([cat test], [0], [yes
115 TEST_SIMPLE_PROGRAM_PROBES([gob2])
116 TEST_SIMPLE_PROGRAM_PROBES([flex])
117 TEST_SIMPLE_PROGRAM_PROBES([bison])
119 AT_SETUP([md5 probes])
120 AT_KEYWORDS([DX_PROG_MD5 program])
121 AT_CAPTURE_FILE([config.log])
124 cp -P "$srcdir/t/md5.sh" bin/md5sum
128 dx_cv_md5_works=@dx_cv_md5_works@
129 dx_cv_md5_outpos=@dx_cv_md5_outpos@
132 TEST_CONFIGURE_AC([[DX_PROG_MD5
133 AC_SUBST([dx_cv_md5_works])
134 AC_SUBST([dx_cv_md5_outpos])
136 set x conftest*; shift
137 if test -f $[]1; then
138 AC_MSG_ERROR([$[]1 left behind by [D@@&t@&t@X_PROG_MD5]])
141 AC_CONFIG_FILES([test])
145 # Check the search via path lookup
147 PATH=`pwd`/bin${PATH:+":$PATH"}
149 TEST_PATH_LOOKUP([expected], [md5sum])
151 AT_CHECK_UNQUOTED([cat test], [0], [MD5=$expected
153 dx_cv_md5_outpos=front
156 mv bin/md5sum bin/md5
157 TEST_PATH_LOOKUP([expected], [md5])
158 TEST_CONFIGURE([MD5_DIRECTION=reverse])
159 AT_CHECK_UNQUOTED([cat test], [0], [MD5=$expected -r
161 dx_cv_md5_outpos=front
164 mv bin/md5 bin/openssl
165 TEST_PATH_LOOKUP([expected], [openssl])
166 TEST_CONFIGURE([MD5_DIRECTION=reverse MD5_NO_R=true])
167 AT_CHECK_UNQUOTED([cat test], [0], [MD5=$expected md5
169 dx_cv_md5_outpos=back
174 # Check the search via user override
175 TEST_CONFIGURE([MD5_DIRECTION=reverse MD5="$srcdir/t/md5.sh"])
176 AT_CHECK_UNQUOTED([cat test], [0], [MD5=$srcdir/t/md5.sh
178 dx_cv_md5_outpos=back
181 # Check that a bogus program doesn't come back as valid.
182 TEST_CONFIGURE([MD5=true])
183 AT_CHECK([grep dx_cv_md5_works test], [0], [dx_cv_md5_works=no
188 AT_SETUP([join probes])
192 dx_cv_join_works=@dx_cv_join_works@
195 TEST_CONFIGURE_AC([[DX_PROG_JOIN
196 AC_SUBST([dx_cv_join_works])
198 set x conftest*; shift
199 if test -f $[]1; then
200 AC_MSG_ERROR([$[]1 left behind by [D@@&t@&t@X_PROG_JOIN]])
203 AC_CONFIG_FILES([test])
207 TEST_CONFIGURE([JOIN=true AWK="$AWK"])
208 AT_CHECK_UNQUOTED([$AWK '{ print $1 }' test], [0],
214 IFS='='; read x JOIN <test
230 AT_CHECK([$JOIN a b], [0], [[b
235 TEST_CONFIGURE([JOIN="$JOIN"])
236 AT_CHECK_UNQUOTED([cat test], [0],
243 AT_SETUP([autotest probes])
244 AT_KEYWORDS([DX_PROG_AUTOTEST program])dnl
248 @dx_cv_autotest_works@
251 TEST_CONFIGURE_AC([[DX_PROG_AUTOTEST
252 AC_SUBST([dx_cv_autotest_works])
254 set x conftest*; shift
255 if test -f $[]1; then
256 AC_MSG_ERROR([$[]1 left behind by [D@@&t@&t@X_PROG_AUTOTEST]])
258 AC_CONFIG_FILES([test])]])
261 # Check the search via path lookup for autom4te
263 cp -P "$srcdir/t/autotest.sh" bin/autom4te
266 PATH=`pwd`/bin${PATH:+":$PATH"}
270 AT_CHECK([cat test], [0], [[autom4te -l autotest
274 # Check that we can assign AUTOTEST directly
275 TEST_CONFIGURE([AUTOTEST="$srcdir/t/autotest.sh"])
276 AT_CHECK_UNQUOTED([cat test], [0], [[$srcdir/t/autotest.sh
280 # Check that we can assign AUTOM4TE directly
281 TEST_CONFIGURE([AUTOM4TE="$srcdir/t/autotest.sh"])
282 AT_CHECK_UNQUOTED([cat test], [0], [[$srcdir/t/autotest.sh -l autotest
286 # Check that a bogus program doesn't come back as valid
287 TEST_CONFIGURE([AUTOTEST=true])
288 AT_CHECK([cat test], [0], [[true