1 # Copyright © 2012, 2020-2021, 2023-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 m4_define([LIBTOOL_VARS],
17 [eval `sed -n[]m4_foreach([var], m4_cdr($@), [ -e '/^var='/p]) <$1`])
19 dnl Verify that all symbols in the static library are properly prefixed.
20 AT_SETUP([libcdecl static symbol prefixes])
22 AT_CHECK([{ $LIBTOOL --config || exit 99; } >libtool.cfg])
23 LIBTOOL_VARS([libtool.cfg], [objdir], [build_old_libs])
24 AT_SKIP_IF([test x"$build_old_libs" = x"no"])
26 LIBTOOL_VARS([$builddir/libcdecl.la], [old_library])
27 archive="$builddir/$objdir/$old_library"
28 AT_CHECK([$SHELL "$builddir/exported.sh" "$archive" || exit 99], [0], [stdout])
29 AT_CHECK([sed '/^cdecl_/d' stdout])
33 dnl Verify that empty commands do nothing.
34 AT_SETUP([cdecl99 empty command])
36 AT_DATA([input], [[explain int x[42];
38 declare x as array 42 of int
44 AT_CHECK([cdecl99 -f input], [0], [[declare x as array 42 of int
51 dnl Verify that commands are not executed after "quit"
52 AT_SETUP([cdecl99 quit command])
54 AT_DATA([input], [[explain int;
56 explain this is a syntax error
59 AT_CHECK([cdecl99 -f input], [0], [type int
64 AT_SETUP([cdecl99 help command])
71 # Program to generate expected output based on src/execute.gperf
81 sed -f expout.sed "$srcdir/src/execute.gperf" >expout
83 # Program to filter the help output to extract the command list from "help"
84 # without any descriptions.
91 AT_CHECK([LC_ALL=C cdecl99 -f input >stdout && sed -f filter.sed stdout],
96 AT_SETUP([cdecl99 --execute option])
98 AT_CHECK([cdecl99 --execute 'explain int' --execute='declare x as int' \
99 --execute='simplify int (x)()'], [0],
107 AT_SETUP([cdecl99 --file error message])
109 AT_CHECK([cdecl99 --file nonexistent || exit 42], [42], [], [stderr])
110 AT_CHECK([grep -v nonexistent stderr || true])
114 AT_SETUP([cdecl99 command error messages])
116 # Extract progname from --help usage message
117 # This will only get the start of progname if it includes spaces;
118 # so we won't worry too hard about the exact format later.
119 AT_CHECK([LC_ALL=C cdecl99 --help], [0], [stdout])
120 progname=`$AWK 'NR == 1 { print $2; }' stdout`dnl'
122 # every line is erroneous
131 [[BEGIN { status=0; }
132 $1 == progname || $1 == (progname ":") { next; }
133 { status=1; print "unprefixed message on line", NR ":", $0; }
134 END { exit(status); }
137 AT_CHECK([LC_ALL=C cdecl99 --file=input || exit 42], [42], [], [stderr])
138 AT_CHECK([$AWK -f check.awk progname="$progname" stderr])
142 while read line <&3; do
143 set x "$@" "--execute=$line"; shift;
145 AT_CHECK([LC_ALL=C cdecl99 "$@" || exit 42], [42], [], [stderr])
146 AT_CHECK([$AWK f check.awk progname="$progname" stderr])
150 AT_SETUP([cdecl99 invalid character error messages])
154 print "explain \377";
158 }' >test.dat </dev/null
160 AT_CHECK([LC_ALL=C cdecl99 -f test.dat || exit 42], [42], [], [stderr])
161 AT_CHECK([$AWK '{ print $NF; }' stderr], [0],
171 dnl Ensure that parse error messages for misplaced keywords correctly
172 dnl include the keyword itself.
173 AT_SETUP([cdecl99 unexpected keyword error messages])
175 # We use the English syntax to reliably force a syntax error where we want
176 # it, as the "declare" form takes an identifier and not any other token,
178 [[declare signed as int
179 declare typedef as int
180 declare volatile as int
181 declare inline as int
186 for (i = 1; i <= $NF; i++) {
187 if ($i == "unexpected") {
188 sub(/,$/, "", $(i+1));
196 AT_CHECK([LC_ALL=C cdecl99 -f test.dat || exit 42], [42], [], [stderr])
197 AT_CHECK([$AWK -f test.awk stderr], [0],
206 AT_SETUP([cdecl99 interactive mode])
214 AT_CHECK([cdecl99 --quiet --interactive <test.dat], [0], [stdout], [ignore])
216 # If built with readline support, then the input commands (including their
217 # trailing newlines) will be captured by AT_CHECK. Otherwise, they are not:
218 # the output just directly follows the prompt, and the final prompt will
219 # not end with a newline. Attempt to paper over these differences.
228 AT_CHECK([echo >>stdout; sed -f check.sed stdout], [0],