aboutsummaryrefslogtreecommitdiff
path: root/testsuite/awk.tests
blob: 7910c8875e0cd9223d1ad378a7c06703dabab176 (plain)
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
#!/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" \
	"" ""

exit $FAILCOUNT