]> git.draconx.ca Git - cdecl99.git/blob - tests/general.at
Add test for interactive mode.
[cdecl99.git] / tests / general.at
1 # Copyright © 2012, 2020-2021, 2023 Nick Bowler
2 #
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.
7 #
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.
12 #
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/>.
15
16 m4_define([LIBTOOL_VARS],
17   [eval `sed -n[]m4_foreach([var], m4_cdr($@), [ -e '/^var='/p]) <$1`])
18
19 dnl Verify that all symbols in the static library are properly prefixed.
20 AT_SETUP([libcdecl static symbol prefixes])
21
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"])
25
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])
30
31 AT_CLEANUP
32
33 dnl Verify that empty commands do nothing.
34 AT_SETUP([cdecl99 empty command])
35
36 AT_DATA([input], [[explain int x[42];
37
38 declare x as array 42 of int
39
40 explain int
41
42 ]])
43
44 AT_CHECK([cdecl99 -f input], [0], [[declare x as array 42 of int
45 int x[42]
46 type int
47 ]])
48
49 AT_CLEANUP
50
51 dnl Verify that commands are not executed after "quit"
52 AT_SETUP([cdecl99 quit command])
53
54 AT_DATA([input], [[explain int;
55 quit
56 explain this is a syntax error
57 ]])
58
59 AT_CHECK([cdecl99 -f input], [0], [type int
60 ])
61
62 AT_CLEANUP
63
64 AT_SETUP([cdecl99 help command])
65
66 AT_DATA([input], [[help
67 explain int
68 ]])
69
70 AT_CHECK([cdecl99 -f input], [0], [stdout])
71 AT_CHECK([sed -n '$p' stdout], [0], [type int
72 ])
73
74 AT_CLEANUP
75
76 AT_SETUP([cdecl99 --execute option])
77
78 AT_CHECK([cdecl99 --execute 'explain int' --execute='declare x as int' \
79                   --execute='simplify int (x)()'], [0],
80 [[type int
81 int x
82 int x()
83 ]])
84
85 AT_CLEANUP
86
87 AT_SETUP([cdecl99 --file error message])
88
89 AT_CHECK([cdecl99 --file nonexistent || exit 42], [42], [], [stderr])
90 AT_CHECK([grep -v nonexistent stderr || true])
91
92 AT_CLEANUP
93
94 AT_SETUP([cdecl99 command error messages])
95
96 # Extract progname from --help usage message
97 # This will only get the start of progname if it includes spaces;
98 # so we won't worry too hard about the exact format later.
99 AT_CHECK([LC_ALL=C cdecl99 --help], [0], [stdout])
100 progname=`$AWK 'NR == 1 { print $2; }' stdout`dnl'
101
102 # every line is erroneous
103 AT_DATA([input],
104 [[explain int a b c
105 simplify int a b c
106 declare a as b c
107 ]])
108
109 AT_DATA([check.awk],
110 [[BEGIN { status=0; }
111 $1 == progname || $1 == (progname ":") { next; }
112 { status=1; print "unprefixed message on line", NR ":", $0; }
113 END { exit(status); }
114 ]])
115
116 AT_CHECK([LC_ALL=C cdecl99 --file=input || exit 42], [42], [], [stderr])
117 AT_CHECK([$AWK -v progname="$progname" -f check.awk stderr])
118
119 AT_CLEANUP
120
121 AT_SETUP([cdecl99 invalid character error messages])
122
123 $AWK -f - >test.dat <<'EOF'
124 BEGIN {
125   print "explain \1";
126   print "explain \377";
127   print "explain \a";
128   print "explain \b";
129   print "explain ?";
130 }
131 EOF
132
133 AT_CHECK([LC_ALL=C cdecl99 -f test.dat || exit 42], [42], [], [stderr])
134 AT_CHECK([$AWK '{ print $NF; }' stderr], [0],
135 [['\001'
136 '\377'
137 '\a'
138 '\b'
139 '?'
140 ]])
141
142 AT_CLEANUP
143
144 AT_SETUP([cdecl99 interactive mode])
145
146 AT_DATA([test.dat],
147 [[explain int x;
148 quit
149 ]])
150
151 AT_CHECK([cdecl99 --quiet --interactive <test.dat], [0], [stdout])
152 AT_CHECK([sed '/^>/d' stdout], [0], [declare x as int
153 ])
154
155 AT_CLEANUP