source: branches/3.2/mindi-busybox/testsuite/awk.tests @ 3232

Last change on this file since 3232 was 3232, checked in by bruno, 5 years ago
  • Update mindi-busybox to 1.21.1
  • Property svn:executable set to *
File size: 5.2 KB
Line 
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
10testing "awk -F case 0" "awk -F '[#]' '{ print NF }'" ""    "" ""
11testing "awk -F case 1" "awk -F '[#]' '{ print NF }'" "0\n" "" "\n"
12testing "awk -F case 2" "awk -F '[#]' '{ print NF }'" "2\n" "" "#\n"
13testing "awk -F case 3" "awk -F '[#]' '{ print NF }'" "3\n" "" "#abc#\n"
14testing "awk -F case 4" "awk -F '[#]' '{ print NF }'" "3\n" "" "#abc#zz\n"
15testing "awk -F case 5" "awk -F '[#]' '{ print NF }'" "4\n" "" "#abc##zz\n"
16testing "awk -F case 6" "awk -F '[#]' '{ print NF }'" "4\n" "" "z#abc##zz\n"
17testing "awk -F case 7" "awk -F '[#]' '{ print NF }'" "5\n" "" "z##abc##zz\n"
18
19# conditions and operators
20testing "awk if operator == "  "awk 'BEGIN{if(23==23) print \"foo\"}'" "foo\n" "" ""
21testing "awk if operator != "  "awk 'BEGIN{if(23!=23) print \"bar\"}'" ""      "" ""
22testing "awk if operator >= "  "awk 'BEGIN{if(23>=23) print \"foo\"}'" "foo\n" "" ""
23testing "awk if operator < "   "awk 'BEGIN{if(2 < 13) print \"foo\"}'" "foo\n" "" ""
24testing "awk if string == "    "awk 'BEGIN{if(\"a\"==\"ab\") print \"bar\"}'" "" "" ""
25
26# 4294967295 = 0xffffffff
27testing "awk bitwise op"  "awk '{ print or(4294967295,1) }'" "4.29497e+09\n" "" "\n"
28optional DESKTOP
29testing "awk hex const 1" "awk '{ print or(0xffffffff,1) }'" "4.29497e+09\n" "" "\n"
30testing "awk hex const 2" "awk '{ print or(0x80000000,1) }'" "2.14748e+09\n" "" "\n"
31testing "awk oct const"   "awk '{ print or(01234,1) }'"      "669\n"         "" "\n"
32SKIP=
33
34# check that "hex/oct integer" heuristic doesn't kick in on 00NN.NNN
35testing "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
41testing "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
46testing "awk -F handles escapes" "awk -F'\\x21' '{print \$1}'" \
47    "a\n" \
48    "" \
49    "a!b\n"
50
51# '@(samp|code|file)\{' is an invalid extended regex (unmatched '{'),
52# but gawk 3.1.5 does not bail out on it.
53testing "awk gsub falls back to non-extended-regex" \
54    "awk 'gsub(\"@(samp|code|file)\{\",\"\");'; echo \$?" "0\n" "" "Hi\n"
55
56optional TAR BUNZIP2 FEATURE_SEAMLESS_BZ2
57test x"$SKIP" != x"1" && tar xjf awk_t1.tar.bz2
58testing "awk 'gcc build bug'" \
59    "awk -f awk_t1_opt-functions.awk -f awk_t1_opth-gen.awk <awk_t1_input | md5sum" \
60    "f842e256461a5ab1ec60b58d16f1114f  -\n" \
61    "" ""
62rm -rf awk_t1_* 2>/dev/null
63SKIP=
64
65Q='":"'
66
67testing "awk NF in BEGIN" \
68    "awk 'BEGIN { print ${Q} NF ${Q} \$0 ${Q} \$1 ${Q} \$2 ${Q} }'" \
69    ":0::::\n" \
70    "" ""
71
72prg='
73function b(tmp) {
74    tmp = 0;
75    print "" tmp; #this line causes the bug
76    return tmp;
77}
78function c(tmpc) {
79    tmpc = b(); return tmpc;
80}
81BEGIN {
82    print (c() ? "string" : "number");
83}'
84testing "awk string cast (bug 725)" \
85    "awk '$prg'" \
86    "0\nnumber\n" \
87    "" ""
88
89testing "awk handles whitespace before array subscript" \
90    "awk 'BEGIN { arr [3] = 1; print arr [3] }'" "1\n" "" ""
91
92# GNU awk 3.1.5's "print ERRNO" prints "No such file or directory" instead of "2",
93# do we need to emulate that as well?
94testing "awk handles non-existing file correctly" \
95    "awk 'BEGIN { getline line <\"doesnt_exist\"; print ERRNO; ERRNO=0; close(\"doesnt_exist\"); print ERRNO; print \"Ok\" }'" \
96    "2\n0\nOk\n" "" ""
97
98prg='
99BEGIN {
100  u["a"]=1
101  u["b"]=1
102  u["c"]=1
103  v["d"]=1
104  v["e"]=1
105  v["f"]=1
106  for (l in u) {
107    print "outer1", l;
108    for (l in v) {
109      print " inner", l;
110    }
111    print "outer2", l;
112  }
113  print "end", l;
114  l="a"
115  exit;
116}'
117testing "awk nested loops with the same variable" \
118    "awk '$prg'" \
119    "\
120outer1 a
121 inner d
122 inner e
123 inner f
124outer2 f
125outer1 b
126 inner d
127 inner e
128 inner f
129outer2 f
130outer1 c
131 inner d
132 inner e
133 inner f
134outer2 f
135end f
136" \
137    "" ""
138
139prg='
140BEGIN {
141  u["a"]=1
142  u["b"]=1
143  u["c"]=1
144  v["d"]=1
145  v["e"]=1
146  v["f"]=1
147  for (l in u) {
148    print "outer1", l;
149    for (l in v) {
150      print " inner", l;
151      break;
152    }
153    print "outer2", l;
154  }
155  print "end", l;
156  l="a"
157  exit;
158}'
159# It's not just buggy, it enters infinite loop. Thus disabled
160false && test x"$SKIP_KNOWN_BUGS" = x"" && testing "awk nested loops with the same variable and break" \
161    "awk '$prg'" \
162    "\
163outer1 a
164 inner d
165outer2 d
166outer1 b
167 inner d
168outer2 d
169outer1 c
170 inner d
171outer2 d
172end d
173" \
174    "" ""
175
176prg='
177function f() {
178  for (l in v) {
179    print " inner", l;
180    return;
181  }
182}
183
184BEGIN {
185  u["a"]=1
186  u["b"]=1
187  u["c"]=1
188  v["d"]=1
189  v["e"]=1
190  v["f"]=1
191  for (l in u) {
192    print "outer1", l;
193    f();
194    print "outer2", l;
195  }
196  print "end", l;
197  l="a"
198  exit;
199}'
200# It's not just buggy, it enters infinite loop. Thus disabled
201false && test x"$SKIP_KNOWN_BUGS" = x"" && testing "awk nested loops with the same variable and return" \
202    "awk '$prg'" \
203    "\
204outer1 a
205 inner d
206outer2 d
207outer1 b
208 inner d
209outer2 d
210outer1 c
211 inner d
212outer2 d
213end d
214" \
215    "" ""
216
217testing "awk handles empty ()" \
218    "awk 'BEGIN {print()}' 2>&1" "awk: cmd. line:1: Empty sequence\n" "" ""
219
220testing "awk FS assignment" "awk '{FS=\":\"; print \$1}'" \
221    "a:b\ne\n" \
222    "" \
223    "a:b c:d\ne:f g:h"
224
225# testing "description" "command" "result" "infile" "stdin"
226
227exit $FAILCOUNT
Note: See TracBrowser for help on using the repository browser.