xref: /freebsd/contrib/one-true-awk/testdir/T.errmsg (revision dd78d987cb38ef162d40aad86229f1dc19884f78)
1echo T.errmsg:  check some error messages
2
3awk=${awk-../a.out}
4
5ls >glop
6awk=$awk awk  '
7{	pat = $0
8	prog = ""
9	while (getline x > 0 && x != "")
10		prog = prog "\n" x
11	print sprintf("\n%s '"'"'%s'"'"' <glop >>devnull 2>foo",
12		ENVIRON["awk"], prog)
13	print sprintf("grep '"'"'%s'"'"' foo >>devnull || echo '"'"'BAD: %s'"'"' failed", pat, pat)
14}
15' >foo.sh <<\!!!!
16illegal primary in regular expression
17/(/
18
19illegal break, continue, next or nextfile from BEGIN
20BEGIN { nextfile }
21
22illegal break, continue, next or nextfile from END
23END { nextfile }
24
25nextfile is illegal inside a function
26function foo() { nextfile }
27
28duplicate argument
29function f(i,j,i) { return i }
30
31nonterminated character class
32/[[/
33
34nonterminated character class
35/[]/
36
37nonterminated character class
38/[\
39
40nonterminated character class
41BEGIN { s = "[x"; if (1 ~ s) print "foo"}
42
43syntax error in regular expression
44BEGIN { if ("x" ~ /$^/) print "ugh" }
45
46syntax error in regular expression
47/((.)/
48
49division by zero
50BEGIN { print 1/0 }
51
52division by zero in /=
53BEGIN { x = 1; print x /= 0 }
54
55division by zero in %=
56BEGIN { x = 1; print x %= 0 }
57
58division by zero in mod
59BEGIN { print 1%0 }
60
61can.t read value.* array name.
62BEGIN { x[1] = 0; split("a b c", y, x) }
63
64can.t read value.* function
65function f(){}; {split($0, x, f)}
66
67can.t assign.* a function
68function f(){}; {f = split($0, x)}
69
70can.t assign to x; it.s an array name.
71{x = split($0, x)}
72
73is a function, not an array
74function f(){}; {split($0, f)}
75
76function f called with 1 args, uses only 0
77BEGIN { f(f) }
78function f() { print "x" }
79
80can.t use function f as argument in f
81BEGIN { f(f) }
82function f() { print "x" }
83
84x is an array, not a function
85{ split($0, x) }; function x() {}
86
87illegal nested function
88function x() { function g() {} }
89
90return not in function
91{ return }
92
93break illegal outside
94{ break }
95
96continue illegal outside
97{ continue }
98
99non-terminated string
100{ print "abc
101}
102
103next is illegal inside a function
104BEGIN { f() }
105function f() { next }
106
107not enough args in printf(%s)
108BEGIN { printf("%s") }
109
110weird printf conversion
111BEGIN { printf("%z", "foo")}
112
113function f has .* arguments, limit .*
114function f(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,
115	c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,d1,d2,d3,d4,d5,d6,d7,d8,d9,d10,
116	e1,e2,e3,e4,e5,e6,e7,e8,e9,e10,f1,f2,f3,f4,f5,f6,f7,f8,f9,f10) {}
117BEGIN { f(123) }
118
119bailing out
120])}
121
122bailing out
123{ print }}
124
125bailing out
126{ print }}}
127
128bailing out
129]
130
131bailing out
132[
133
134bailing out
135a & b
136
137extra )
138{ x = 1) }
139
140illegal statement
141{ print ))}
142
143illegal statement
144{{ print }
145
146illegal statement
147{{{ print }
148
149illegal .*next.* from BEGIN
150BEGIN { next }
151
152illegal .*next.* from END
153END {	next; print NR }
154
155can.t open file ./nonexistentdir/foo
156BEGIN { print "abc" >"./nonexistentdir/foo" }
157
158you can.t define function f more than once
159function f() { print 1 }
160function f() { print 2 }
161
162function mp called with 1 args, uses only 0
163function mp(){ cnt++;}
164BEGIN {	mp(xx) }
165
166index.*doesn.t permit regular expressions
167BEGIN { index("abc", /a/) }
168
169log argument out of domain
170BEGIN { print log(-1) }
171
172exp result out of range
173BEGIN {print exp(1000)}
174
175null file name in print or getline
176BEGIN { print >foo }
177
178function has too many arguments
179BEGIN { length("abc", "def") }
180
181calling undefined function foo
182BEGIN { foo() }
183
184this should print a BAD message
185BEGIN { print }
186!!!!
187
188
189echo '	running tests in foo.sh'
190sh foo.sh
191
192test -r core && echo BAD: someone dropped core 1>&2
193
194echo xxx >foo0
195$awk '{print x}' x='a
196b' foo0 >foo1 2>foo2
197grep 'newline in string' foo2 >/dev/null || echo 'BAD: T.errmsg newline in string'
198
199$awk -safe 'BEGIN{"date" | getline}' >foo 2>foo2
200grep 'cmd | getline is unsafe' foo2 >/dev/null || echo 'BAD: T.errmsg cmd|getline unsafe'
201
202$awk -safe 'BEGIN{print >"foo"}' >foo 2>foo2
203grep 'print > is unsafe' foo2 >/dev/null || echo 'BAD: T.errmsg print > unsafe'
204
205$awk -safe 'BEGIN{print >> "foo"}' >foo 2>foo2
206grep 'print >> is unsafe' foo2 >/dev/null || echo 'BAD: T.errmsg print >> unsafe'
207
208$awk -safe 'BEGIN{print | "foo"}' >foo 2>foo2
209grep 'print | is unsafe' foo2 >/dev/null || echo 'BAD: T.errmsg print | unsafe'
210
211$awk -safe 'BEGIN {system("date")}' >foo 2>foo2
212grep 'system is unsafe' foo2 >/dev/null || echo 'BAD: T.errmsg system unsafe'
213