Denis Vlasenko | 960eca6 | 2007-07-18 18:33:18 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
Denis Vlasenko | 960eca6 | 2007-07-18 18:33:18 +0000 | [diff] [blame] | 3 | # Copyright 2007 by Denys Vlasenko <vda.linux@googlemail.com> |
| 4 | # Licensed under GPL v2, see file LICENSE for details. |
| 5 | |
Mike Frysinger | caa7940 | 2009-11-04 18:41:22 -0500 | [diff] [blame] | 6 | . ./testing.sh |
Denis Vlasenko | 960eca6 | 2007-07-18 18:33:18 +0000 | [diff] [blame] | 7 | |
Denis Vlasenko | bb13079 | 2008-07-15 06:45:14 +0000 | [diff] [blame] | 8 | # testing "description" "command" "result" "infile" "stdin" |
Denis Vlasenko | 960eca6 | 2007-07-18 18:33:18 +0000 | [diff] [blame] | 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 | |
Denis Vlasenko | 66496d7 | 2008-08-29 08:37:07 +0000 | [diff] [blame] | 19 | # 4294967295 = 0xffffffff |
| 20 | testing "awk bitwise op" "awk '{ print or(4294967295,1) }'" "4.29497e+09\n" "" "\n" |
| 21 | testing "awk hex const 1" "awk '{ print or(0xffffffff,1) }'" "4.29497e+09\n" "" "\n" |
| 22 | testing "awk hex const 2" "awk '{ print or(0x80000000,1) }'" "2.14748e+09\n" "" "\n" |
Denis Vlasenko | a2e1eea | 2008-09-02 09:00:23 +0000 | [diff] [blame] | 23 | testing "awk oct const" "awk '{ print or(01234,1) }'" "669\n" "" "\n" |
Denis Vlasenko | 66496d7 | 2008-08-29 08:37:07 +0000 | [diff] [blame] | 24 | |
Denis Vlasenko | 67b5eeb | 2009-04-12 13:54:13 +0000 | [diff] [blame] | 25 | # long field seps requiring regex |
| 26 | testing "awk long field sep" "awk -F-- '{ print NF, length(\$NF), \$NF }'" \ |
| 27 | "2 0 \n3 0 \n4 0 \n5 0 \n" \ |
| 28 | "" \ |
| 29 | "a--\na--b--\na--b--c--\na--b--c--d--" |
| 30 | |
Denis Vlasenko | 7a67664 | 2009-03-15 22:20:31 +0000 | [diff] [blame] | 31 | # '@(samp|code|file)\{' is an invalid extended regex (unmatched '{'), |
| 32 | # but gawk 3.1.5 does not bail out on it. |
| 33 | testing "awk gsub falls back to non-extended-regex" \ |
| 34 | "awk 'gsub(\"@(samp|code|file)\{\",\"\");'; echo \$?" "0\n" "" "Hi\n" |
| 35 | |
Denis Vlasenko | 3bb2bbd | 2008-07-01 01:57:36 +0000 | [diff] [blame] | 36 | tar xjf awk_t1.tar.bz2 |
| 37 | testing "awk 'gcc build bug'" \ |
| 38 | "awk -f awk_t1_opt-functions.awk -f awk_t1_opth-gen.awk <awk_t1_input | md5sum" \ |
| 39 | "f842e256461a5ab1ec60b58d16f1114f -\n" \ |
| 40 | "" "" |
| 41 | rm -rf awk_t1_* |
| 42 | |
Denis Vlasenko | 41d5ebe | 2009-01-25 01:00:15 +0000 | [diff] [blame] | 43 | Q='":"' |
| 44 | |
| 45 | testing "awk NF in BEGIN" \ |
| 46 | "awk 'BEGIN { print ${Q} NF ${Q} \$0 ${Q} \$1 ${Q} \$2 ${Q} }'" \ |
| 47 | ":0::::\n" \ |
| 48 | "" "" |
| 49 | |
Denys Vlasenko | 1284774 | 2009-11-30 01:15:04 +0100 | [diff] [blame] | 50 | prg=' |
| 51 | function b(tmp) { |
| 52 | tmp = 0; |
| 53 | print "" tmp; #this line causes the bug |
| 54 | return tmp; |
| 55 | } |
| 56 | function c(tmpc) { |
| 57 | tmpc = b(); return tmpc; |
| 58 | } |
| 59 | BEGIN { |
| 60 | print (c() ? "string" : "number"); |
| 61 | }' |
| 62 | testing "awk string cast (bug 725)" \ |
| 63 | "awk '$prg'" \ |
| 64 | "0\nnumber\n" \ |
| 65 | "" "" |
| 66 | |
Alexander Shishkin | d03cd3b | 2010-02-25 17:55:40 +0200 | [diff] [blame] | 67 | testing "awk handles whitespace before array subscript" \ |
| 68 | "awk 'BEGIN { arr [3] = 1; print arr [3] }'" "1\n" "" "" |
| 69 | |
Denys Vlasenko | 3cb60c3 | 2010-03-10 19:20:32 +0100 | [diff] [blame] | 70 | prg=' |
| 71 | BEGIN { |
Denys Vlasenko | 90f19fa | 2010-03-11 08:27:53 +0100 | [diff] [blame] | 72 | u["a"]=1 |
| 73 | u["b"]=1 |
| 74 | u["c"]=1 |
| 75 | v["d"]=1 |
Denys Vlasenko | 3cb60c3 | 2010-03-10 19:20:32 +0100 | [diff] [blame] | 76 | v["e"]=1 |
Denys Vlasenko | 90f19fa | 2010-03-11 08:27:53 +0100 | [diff] [blame] | 77 | v["f"]=1 |
| 78 | for (l in u) { |
Denys Vlasenko | 3cb60c3 | 2010-03-10 19:20:32 +0100 | [diff] [blame] | 79 | print "outer1", l; |
| 80 | for (l in v) { |
| 81 | print " inner", l; |
| 82 | } |
| 83 | print "outer2", l; |
| 84 | } |
| 85 | print "end", l; |
| 86 | l="a" |
| 87 | exit; |
| 88 | }' |
| 89 | testing "awk nested loops with the same variable" \ |
| 90 | "awk '$prg'" \ |
| 91 | "\ |
Denys Vlasenko | 90f19fa | 2010-03-11 08:27:53 +0100 | [diff] [blame] | 92 | outer1 a |
| 93 | inner d |
Denys Vlasenko | 3cb60c3 | 2010-03-10 19:20:32 +0100 | [diff] [blame] | 94 | inner e |
Denys Vlasenko | 90f19fa | 2010-03-11 08:27:53 +0100 | [diff] [blame] | 95 | inner f |
| 96 | outer2 f |
| 97 | outer1 b |
| 98 | inner d |
Denys Vlasenko | 3cb60c3 | 2010-03-10 19:20:32 +0100 | [diff] [blame] | 99 | inner e |
Denys Vlasenko | 90f19fa | 2010-03-11 08:27:53 +0100 | [diff] [blame] | 100 | inner f |
| 101 | outer2 f |
| 102 | outer1 c |
| 103 | inner d |
Denys Vlasenko | 3cb60c3 | 2010-03-10 19:20:32 +0100 | [diff] [blame] | 104 | inner e |
Denys Vlasenko | 90f19fa | 2010-03-11 08:27:53 +0100 | [diff] [blame] | 105 | inner f |
| 106 | outer2 f |
| 107 | end f |
| 108 | " \ |
| 109 | "" "" |
| 110 | |
| 111 | prg=' |
| 112 | BEGIN { |
| 113 | u["a"]=1 |
| 114 | u["b"]=1 |
| 115 | u["c"]=1 |
| 116 | v["d"]=1 |
| 117 | v["e"]=1 |
| 118 | v["f"]=1 |
| 119 | for (l in u) { |
| 120 | print "outer1", l; |
| 121 | for (l in v) { |
| 122 | print " inner", l; |
| 123 | break; |
| 124 | } |
| 125 | print "outer2", l; |
| 126 | } |
| 127 | print "end", l; |
| 128 | l="a" |
| 129 | exit; |
| 130 | }' |
| 131 | # It's not just buggy, it enters infinite loop. Thus disabled |
| 132 | false && test x"$SKIP_KNOWN_BUGS" = x"" && testing "awk nested loops with the same variable and break" \ |
| 133 | "awk '$prg'" \ |
| 134 | "\ |
| 135 | outer1 a |
| 136 | inner d |
| 137 | outer2 d |
| 138 | outer1 b |
| 139 | inner d |
| 140 | outer2 d |
| 141 | outer1 c |
| 142 | inner d |
| 143 | outer2 d |
| 144 | end d |
| 145 | " \ |
| 146 | "" "" |
| 147 | |
| 148 | prg=' |
| 149 | function f() { |
| 150 | for (l in v) { |
| 151 | print " inner", l; |
| 152 | return; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | BEGIN { |
| 157 | u["a"]=1 |
| 158 | u["b"]=1 |
| 159 | u["c"]=1 |
| 160 | v["d"]=1 |
| 161 | v["e"]=1 |
| 162 | v["f"]=1 |
| 163 | for (l in u) { |
| 164 | print "outer1", l; |
| 165 | f(); |
| 166 | print "outer2", l; |
| 167 | } |
| 168 | print "end", l; |
| 169 | l="a" |
| 170 | exit; |
| 171 | }' |
| 172 | # It's not just buggy, it enters infinite loop. Thus disabled |
| 173 | false && test x"$SKIP_KNOWN_BUGS" = x"" && testing "awk nested loops with the same variable and return" \ |
| 174 | "awk '$prg'" \ |
| 175 | "\ |
| 176 | outer1 a |
| 177 | inner d |
| 178 | outer2 d |
| 179 | outer1 b |
| 180 | inner d |
| 181 | outer2 d |
| 182 | outer1 c |
| 183 | inner d |
| 184 | outer2 d |
| 185 | end d |
Denys Vlasenko | 3cb60c3 | 2010-03-10 19:20:32 +0100 | [diff] [blame] | 186 | " \ |
| 187 | "" "" |
| 188 | |
Denis Vlasenko | 960eca6 | 2007-07-18 18:33:18 +0000 | [diff] [blame] | 189 | exit $FAILCOUNT |