xref: /freebsd/contrib/one-true-awk/testdir/T.errmsg (revision 23f24377b1a9ab6677f00f2302484d6658d94cab)
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
103illegal field $(foo)
104BEGIN { print $"foo" }
105
106next is illegal inside a function
107BEGIN { f() }
108function f() { next }
109
110not enough args in printf(%s)
111BEGIN { printf("%s") }
112
113weird printf conversion
114BEGIN { printf("%z", "foo")}
115
116function f has .* arguments, limit .*
117function f(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,
118	c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,d1,d2,d3,d4,d5,d6,d7,d8,d9,d10,
119	e1,e2,e3,e4,e5,e6,e7,e8,e9,e10,f1,f2,f3,f4,f5,f6,f7,f8,f9,f10) {}
120BEGIN { f(123) }
121
122bailing out
123])}
124
125bailing out
126{ print }}
127
128bailing out
129{ print }}}
130
131bailing out
132]
133
134bailing out
135[
136
137bailing out
138a & b
139
140extra )
141{ x = 1) }
142
143illegal statement
144{ print ))}
145
146illegal statement
147{{ print }
148
149illegal statement
150{{{ print }
151
152illegal .*next.* from BEGIN
153BEGIN { next }
154
155illegal .*next.* from END
156END {	next; print NR }
157
158can.t open file ./nonexistentdir/foo
159BEGIN { print "abc" >"./nonexistentdir/foo" }
160
161you can.t define function f more than once
162function f() { print 1 }
163function f() { print 2 }
164
165function mp called with 1 args, uses only 0
166function mp(){ cnt++;}
167BEGIN {	mp(xx) }
168
169index.*doesn.t permit regular expressions
170BEGIN { index("abc", /a/) }
171
172log argument out of domain
173BEGIN { print log(-1) }
174
175exp result out of range
176BEGIN {print exp(1000)}
177
178null file name in print or getline
179BEGIN { print >foo }
180
181function has too many arguments
182BEGIN { length("abc", "def") }
183
184calling undefined function foo
185BEGIN { foo() }
186
187this should print a BAD message
188BEGIN { print }
189!!!!
190
191
192echo '	running tests in foo.sh'
193sh foo.sh
194
195test -r core && echo BAD: someone dropped core 1>&2
196
197echo xxx >foo0
198$awk '{print x}' x='a
199b' foo0 >foo1 2>foo2
200grep 'newline in string' foo2 >/dev/null || echo 'BAD: T.errmsg newline in string'
201
202$awk -safe 'BEGIN{"date" | getline}' >foo 2>foo2
203grep 'cmd | getline is unsafe' foo2 >/dev/null || echo 'BAD: T.errmsg cmd|getline 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{print | "foo"}' >foo 2>foo2
212grep 'print | is unsafe' foo2 >/dev/null || echo 'BAD: T.errmsg print | unsafe'
213
214$awk -safe 'BEGIN {system("date")}' >foo 2>foo2
215grep 'system is unsafe' foo2 >/dev/null || echo 'BAD: T.errmsg system unsafe'
216