Contents of /trunk/mkinitrd-magellan/busybox/testsuite/awk.tests
Parent Directory | Revision Log
Revision 1123 -
(show annotations)
(download)
Wed Aug 18 21:56:57 2010 UTC (14 years, 1 month ago) by niro
File size: 3963 byte(s)
Wed Aug 18 21:56:57 2010 UTC (14 years, 1 month ago) by niro
File size: 3963 byte(s)
-updated to busybox-1.17.1
1 | #!/bin/sh |
2 | |
3 | # Copyright 2007 by Denys Vlasenko <vda.linux@googlemail.com> |
4 | # Licensed under GPL v2, see file LICENSE for details. |
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 | # 4294967295 = 0xffffffff |
20 | testing "awk bitwise op" "awk '{ print or(4294967295,1) }'" "4.29497e+09\n" "" "\n" |
21 | optional DESKTOP |
22 | testing "awk hex const 1" "awk '{ print or(0xffffffff,1) }'" "4.29497e+09\n" "" "\n" |
23 | testing "awk hex const 2" "awk '{ print or(0x80000000,1) }'" "2.14748e+09\n" "" "\n" |
24 | testing "awk oct const" "awk '{ print or(01234,1) }'" "669\n" "" "\n" |
25 | SKIP= |
26 | |
27 | # long field seps requiring regex |
28 | testing "awk long field sep" "awk -F-- '{ print NF, length(\$NF), \$NF }'" \ |
29 | "2 0 \n3 0 \n4 0 \n5 0 \n" \ |
30 | "" \ |
31 | "a--\na--b--\na--b--c--\na--b--c--d--" |
32 | |
33 | # '@(samp|code|file)\{' is an invalid extended regex (unmatched '{'), |
34 | # but gawk 3.1.5 does not bail out on it. |
35 | testing "awk gsub falls back to non-extended-regex" \ |
36 | "awk 'gsub(\"@(samp|code|file)\{\",\"\");'; echo \$?" "0\n" "" "Hi\n" |
37 | |
38 | optional TAR BUNZIP2 FEATURE_SEAMLESS_BZ2 |
39 | test x"$SKIP" != x"1" && tar xjf awk_t1.tar.bz2 |
40 | testing "awk 'gcc build bug'" \ |
41 | "awk -f awk_t1_opt-functions.awk -f awk_t1_opth-gen.awk <awk_t1_input | md5sum" \ |
42 | "f842e256461a5ab1ec60b58d16f1114f -\n" \ |
43 | "" "" |
44 | rm -rf awk_t1_* 2>/dev/null |
45 | SKIP= |
46 | |
47 | Q='":"' |
48 | |
49 | testing "awk NF in BEGIN" \ |
50 | "awk 'BEGIN { print ${Q} NF ${Q} \$0 ${Q} \$1 ${Q} \$2 ${Q} }'" \ |
51 | ":0::::\n" \ |
52 | "" "" |
53 | |
54 | prg=' |
55 | function b(tmp) { |
56 | tmp = 0; |
57 | print "" tmp; #this line causes the bug |
58 | return tmp; |
59 | } |
60 | function c(tmpc) { |
61 | tmpc = b(); return tmpc; |
62 | } |
63 | BEGIN { |
64 | print (c() ? "string" : "number"); |
65 | }' |
66 | testing "awk string cast (bug 725)" \ |
67 | "awk '$prg'" \ |
68 | "0\nnumber\n" \ |
69 | "" "" |
70 | |
71 | testing "awk handles whitespace before array subscript" \ |
72 | "awk 'BEGIN { arr [3] = 1; print arr [3] }'" "1\n" "" "" |
73 | |
74 | prg=' |
75 | BEGIN { |
76 | u["a"]=1 |
77 | u["b"]=1 |
78 | u["c"]=1 |
79 | v["d"]=1 |
80 | v["e"]=1 |
81 | v["f"]=1 |
82 | for (l in u) { |
83 | print "outer1", l; |
84 | for (l in v) { |
85 | print " inner", l; |
86 | } |
87 | print "outer2", l; |
88 | } |
89 | print "end", l; |
90 | l="a" |
91 | exit; |
92 | }' |
93 | testing "awk nested loops with the same variable" \ |
94 | "awk '$prg'" \ |
95 | "\ |
96 | outer1 a |
97 | inner d |
98 | inner e |
99 | inner f |
100 | outer2 f |
101 | outer1 b |
102 | inner d |
103 | inner e |
104 | inner f |
105 | outer2 f |
106 | outer1 c |
107 | inner d |
108 | inner e |
109 | inner f |
110 | outer2 f |
111 | end f |
112 | " \ |
113 | "" "" |
114 | |
115 | prg=' |
116 | BEGIN { |
117 | u["a"]=1 |
118 | u["b"]=1 |
119 | u["c"]=1 |
120 | v["d"]=1 |
121 | v["e"]=1 |
122 | v["f"]=1 |
123 | for (l in u) { |
124 | print "outer1", l; |
125 | for (l in v) { |
126 | print " inner", l; |
127 | break; |
128 | } |
129 | print "outer2", l; |
130 | } |
131 | print "end", l; |
132 | l="a" |
133 | exit; |
134 | }' |
135 | # It's not just buggy, it enters infinite loop. Thus disabled |
136 | false && test x"$SKIP_KNOWN_BUGS" = x"" && testing "awk nested loops with the same variable and break" \ |
137 | "awk '$prg'" \ |
138 | "\ |
139 | outer1 a |
140 | inner d |
141 | outer2 d |
142 | outer1 b |
143 | inner d |
144 | outer2 d |
145 | outer1 c |
146 | inner d |
147 | outer2 d |
148 | end d |
149 | " \ |
150 | "" "" |
151 | |
152 | prg=' |
153 | function f() { |
154 | for (l in v) { |
155 | print " inner", l; |
156 | return; |
157 | } |
158 | } |
159 | |
160 | BEGIN { |
161 | u["a"]=1 |
162 | u["b"]=1 |
163 | u["c"]=1 |
164 | v["d"]=1 |
165 | v["e"]=1 |
166 | v["f"]=1 |
167 | for (l in u) { |
168 | print "outer1", l; |
169 | f(); |
170 | print "outer2", l; |
171 | } |
172 | print "end", l; |
173 | l="a" |
174 | exit; |
175 | }' |
176 | # It's not just buggy, it enters infinite loop. Thus disabled |
177 | false && test x"$SKIP_KNOWN_BUGS" = x"" && testing "awk nested loops with the same variable and return" \ |
178 | "awk '$prg'" \ |
179 | "\ |
180 | outer1 a |
181 | inner d |
182 | outer2 d |
183 | outer1 b |
184 | inner d |
185 | outer2 d |
186 | outer1 c |
187 | inner d |
188 | outer2 d |
189 | end d |
190 | " \ |
191 | "" "" |
192 | |
193 | exit $FAILCOUNT |