mount: fix the wrongly stored fs creation time
[platform/upstream/busybox.git] / testsuite / awk.tests
1 #!/bin/sh
2
3 # Copyright 2007 by Denys Vlasenko <vda.linux@googlemail.com>
4 # Licensed under GPLv2, see file LICENSE in this source tree.
5
6 . ./testing.sh
7
8 # testing "description" "command" "result" "infile" "stdin"
9
10 testing "awk -F case 0" "awk -F '[#]' '{ print NF }'" ""    "" ""
11 testing "awk -F case 1" "awk -F '[#]' '{ print NF }'" "0\n" "" "\n"
12 testing "awk -F case 2" "awk -F '[#]' '{ print NF }'" "2\n" "" "#\n"
13 testing "awk -F case 3" "awk -F '[#]' '{ print NF }'" "3\n" "" "#abc#\n"
14 testing "awk -F case 4" "awk -F '[#]' '{ print NF }'" "3\n" "" "#abc#zz\n"
15 testing "awk -F case 5" "awk -F '[#]' '{ print NF }'" "4\n" "" "#abc##zz\n"
16 testing "awk -F case 6" "awk -F '[#]' '{ print NF }'" "4\n" "" "z#abc##zz\n"
17 testing "awk -F case 7" "awk -F '[#]' '{ print NF }'" "5\n" "" "z##abc##zz\n"
18
19 # conditions and operators
20 testing "awk if operator == "  "awk 'BEGIN{if(23==23) print \"foo\"}'" "foo\n" "" ""
21 testing "awk if operator != "  "awk 'BEGIN{if(23!=23) print \"bar\"}'" ""      "" ""
22 testing "awk if operator >= "  "awk 'BEGIN{if(23>=23) print \"foo\"}'" "foo\n" "" ""
23 testing "awk if operator < "   "awk 'BEGIN{if(2 < 13) print \"foo\"}'" "foo\n" "" ""
24 testing "awk if string == "    "awk 'BEGIN{if(\"a\"==\"ab\") print \"bar\"}'" "" "" ""
25
26 # 4294967295 = 0xffffffff
27 testing "awk bitwise op"  "awk '{ print or(4294967295,1) }'" "4.29497e+09\n" "" "\n"
28 optional DESKTOP
29 testing "awk hex const 1" "awk '{ print or(0xffffffff,1) }'" "4.29497e+09\n" "" "\n"
30 testing "awk hex const 2" "awk '{ print or(0x80000000,1) }'" "2.14748e+09\n" "" "\n"
31 testing "awk oct const"   "awk '{ print or(01234,1) }'"      "669\n"         "" "\n"
32 SKIP=
33
34 # check that "hex/oct integer" heuristic doesn't kick in on 00NN.NNN
35 testing "awk floating const with leading zeroes" \
36         "awk '{ printf \"%f %f\n\", \"000.123\", \"009.123\" }'" \
37         "0.123000 9.123000\n" \
38         "" "\n"
39
40 # long field seps requiring regex
41 testing "awk long field sep" "awk -F-- '{ print NF, length(\$NF), \$NF }'" \
42         "2 0 \n3 0 \n4 0 \n5 0 \n" \
43         "" \
44         "a--\na--b--\na--b--c--\na--b--c--d--"
45
46 # '@(samp|code|file)\{' is an invalid extended regex (unmatched '{'),
47 # but gawk 3.1.5 does not bail out on it.
48 testing "awk gsub falls back to non-extended-regex" \
49         "awk 'gsub(\"@(samp|code|file)\{\",\"\");'; echo \$?" "0\n" "" "Hi\n"
50
51 optional TAR BUNZIP2 FEATURE_SEAMLESS_BZ2
52 test x"$SKIP" != x"1" && tar xjf awk_t1.tar.bz2
53 testing "awk 'gcc build bug'" \
54         "awk -f awk_t1_opt-functions.awk -f awk_t1_opth-gen.awk <awk_t1_input | md5sum" \
55         "f842e256461a5ab1ec60b58d16f1114f  -\n" \
56         "" ""
57 rm -rf awk_t1_* 2>/dev/null
58 SKIP=
59
60 Q='":"'
61
62 testing "awk NF in BEGIN" \
63         "awk 'BEGIN { print ${Q} NF ${Q} \$0 ${Q} \$1 ${Q} \$2 ${Q} }'" \
64         ":0::::\n" \
65         "" ""
66
67 prg='
68 function b(tmp) {
69         tmp = 0;
70         print "" tmp; #this line causes the bug
71         return tmp;
72 }
73 function c(tmpc) {
74         tmpc = b(); return tmpc;
75 }
76 BEGIN {
77         print (c() ? "string" : "number");
78 }'
79 testing "awk string cast (bug 725)" \
80         "awk '$prg'" \
81         "0\nnumber\n" \
82         "" ""
83
84 testing "awk handles whitespace before array subscript" \
85         "awk 'BEGIN { arr [3] = 1; print arr [3] }'" "1\n" "" ""
86
87 # GNU awk 3.1.5's "print ERRNO" prints "No such file or directory" instead of "2",
88 # do we need to emulate that as well?
89 testing "awk handles non-existing file correctly" \
90         "awk 'BEGIN { getline line <\"doesnt_exist\"; print ERRNO; ERRNO=0; close(\"doesnt_exist\"); print ERRNO; print \"Ok\" }'" \
91         "2\n0\nOk\n" "" ""
92
93 prg='
94 BEGIN {
95   u["a"]=1
96   u["b"]=1
97   u["c"]=1
98   v["d"]=1
99   v["e"]=1
100   v["f"]=1
101   for (l in u) {
102     print "outer1", l;
103     for (l in v) {
104       print " inner", l;
105     }
106     print "outer2", l;
107   }
108   print "end", l;
109   l="a"
110   exit;
111 }'
112 testing "awk nested loops with the same variable" \
113         "awk '$prg'" \
114         "\
115 outer1 a
116  inner d
117  inner e
118  inner f
119 outer2 f
120 outer1 b
121  inner d
122  inner e
123  inner f
124 outer2 f
125 outer1 c
126  inner d
127  inner e
128  inner f
129 outer2 f
130 end f
131 " \
132         "" ""
133
134 prg='
135 BEGIN {
136   u["a"]=1
137   u["b"]=1
138   u["c"]=1
139   v["d"]=1
140   v["e"]=1
141   v["f"]=1
142   for (l in u) {
143     print "outer1", l;
144     for (l in v) {
145       print " inner", l;
146       break;
147     }
148     print "outer2", l;
149   }
150   print "end", l;
151   l="a"
152   exit;
153 }'
154 # It's not just buggy, it enters infinite loop. Thus disabled
155 false && test x"$SKIP_KNOWN_BUGS" = x"" && testing "awk nested loops with the same variable and break" \
156         "awk '$prg'" \
157         "\
158 outer1 a
159  inner d
160 outer2 d
161 outer1 b
162  inner d
163 outer2 d
164 outer1 c
165  inner d
166 outer2 d
167 end d
168 " \
169         "" ""
170
171 prg='
172 function f() {
173   for (l in v) {
174     print " inner", l;
175     return;
176   }
177 }
178
179 BEGIN {
180   u["a"]=1
181   u["b"]=1
182   u["c"]=1
183   v["d"]=1
184   v["e"]=1
185   v["f"]=1
186   for (l in u) {
187     print "outer1", l;
188     f();
189     print "outer2", l;
190   }
191   print "end", l;
192   l="a"
193   exit;
194 }'
195 # It's not just buggy, it enters infinite loop. Thus disabled
196 false && test x"$SKIP_KNOWN_BUGS" = x"" && testing "awk nested loops with the same variable and return" \
197         "awk '$prg'" \
198         "\
199 outer1 a
200  inner d
201 outer2 d
202 outer1 b
203  inner d
204 outer2 d
205 outer1 c
206  inner d
207 outer2 d
208 end d
209 " \
210         "" ""
211
212 testing "awk handles empty ()" \
213         "awk 'BEGIN {print()}' 2>&1" "awk: cmd. line:1: Empty sequence\n" "" ""
214
215 exit $FAILCOUNT