1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
#!/bin/sh
# Copyright 2007 by Denys Vlasenko <vda.linux@googlemail.com>
# Licensed under GPL v2, see file LICENSE for details.
. ./testing.sh
# testing "description" "command" "result" "infile" "stdin"
testing "awk -F case 0" "awk -F '[#]' '{ print NF }'" "" "" ""
testing "awk -F case 1" "awk -F '[#]' '{ print NF }'" "0\n" "" "\n"
testing "awk -F case 2" "awk -F '[#]' '{ print NF }'" "2\n" "" "#\n"
testing "awk -F case 3" "awk -F '[#]' '{ print NF }'" "3\n" "" "#abc#\n"
testing "awk -F case 4" "awk -F '[#]' '{ print NF }'" "3\n" "" "#abc#zz\n"
testing "awk -F case 5" "awk -F '[#]' '{ print NF }'" "4\n" "" "#abc##zz\n"
testing "awk -F case 6" "awk -F '[#]' '{ print NF }'" "4\n" "" "z#abc##zz\n"
testing "awk -F case 7" "awk -F '[#]' '{ print NF }'" "5\n" "" "z##abc##zz\n"
# 4294967295 = 0xffffffff
testing "awk bitwise op" "awk '{ print or(4294967295,1) }'" "4.29497e+09\n" "" "\n"
testing "awk hex const 1" "awk '{ print or(0xffffffff,1) }'" "4.29497e+09\n" "" "\n"
testing "awk hex const 2" "awk '{ print or(0x80000000,1) }'" "2.14748e+09\n" "" "\n"
testing "awk oct const" "awk '{ print or(01234,1) }'" "669\n" "" "\n"
# long field seps requiring regex
testing "awk long field sep" "awk -F-- '{ print NF, length(\$NF), \$NF }'" \
"2 0 \n3 0 \n4 0 \n5 0 \n" \
"" \
"a--\na--b--\na--b--c--\na--b--c--d--"
# '@(samp|code|file)\{' is an invalid extended regex (unmatched '{'),
# but gawk 3.1.5 does not bail out on it.
testing "awk gsub falls back to non-extended-regex" \
"awk 'gsub(\"@(samp|code|file)\{\",\"\");'; echo \$?" "0\n" "" "Hi\n"
tar xjf awk_t1.tar.bz2
testing "awk 'gcc build bug'" \
"awk -f awk_t1_opt-functions.awk -f awk_t1_opth-gen.awk <awk_t1_input | md5sum" \
"f842e256461a5ab1ec60b58d16f1114f -\n" \
"" ""
rm -rf awk_t1_*
Q='":"'
testing "awk NF in BEGIN" \
"awk 'BEGIN { print ${Q} NF ${Q} \$0 ${Q} \$1 ${Q} \$2 ${Q} }'" \
":0::::\n" \
"" ""
prg='
function b(tmp) {
tmp = 0;
print "" tmp; #this line causes the bug
return tmp;
}
function c(tmpc) {
tmpc = b(); return tmpc;
}
BEGIN {
print (c() ? "string" : "number");
}'
testing "awk string cast (bug 725)" \
"awk '$prg'" \
"0\nnumber\n" \
"" ""
testing "awk handles whitespace before array subscript" \
"awk 'BEGIN { arr [3] = 1; print arr [3] }'" "1\n" "" ""
prg='
BEGIN {
v["q"]=1
v["w"]=1
v["e"]=1
for (l in v) {
print "outer1", l;
for (l in v) {
print " inner", l;
}
print "outer2", l;
}
print "end", l;
l="a"
exit;
}'
testing "awk nested loops with the same variable" \
"awk '$prg'" \
"\
outer1 e
inner e
inner q
inner w
outer2 w
outer1 q
inner e
inner q
inner w
outer2 w
outer1 w
inner e
inner q
inner w
outer2 w
end w
" \
"" ""
exit $FAILCOUNT
|