blob: 2c7642ce0b79097ac3f27e07473d20c149d4a985 [file] [log] [blame]
Denis Vlasenko960eca62007-07-18 18:33:18 +00001#!/bin/sh
2
Denis Vlasenko960eca62007-07-18 18:33:18 +00003# Copyright 2007 by Denys Vlasenko <vda.linux@googlemail.com>
4# Licensed under GPL v2, see file LICENSE for details.
5
Mike Frysingercaa79402009-11-04 18:41:22 -05006. ./testing.sh
Denis Vlasenko960eca62007-07-18 18:33:18 +00007
Denis Vlasenkobb130792008-07-15 06:45:14 +00008# testing "description" "command" "result" "infile" "stdin"
Denis Vlasenko960eca62007-07-18 18:33:18 +00009
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
Denis Vlasenko66496d72008-08-29 08:37:07 +000019# 4294967295 = 0xffffffff
20testing "awk bitwise op" "awk '{ print or(4294967295,1) }'" "4.29497e+09\n" "" "\n"
21testing "awk hex const 1" "awk '{ print or(0xffffffff,1) }'" "4.29497e+09\n" "" "\n"
22testing "awk hex const 2" "awk '{ print or(0x80000000,1) }'" "2.14748e+09\n" "" "\n"
Denis Vlasenkoa2e1eea2008-09-02 09:00:23 +000023testing "awk oct const" "awk '{ print or(01234,1) }'" "669\n" "" "\n"
Denis Vlasenko66496d72008-08-29 08:37:07 +000024
Denis Vlasenko67b5eeb2009-04-12 13:54:13 +000025# long field seps requiring regex
26testing "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 Vlasenko7a676642009-03-15 22:20:31 +000031# '@(samp|code|file)\{' is an invalid extended regex (unmatched '{'),
32# but gawk 3.1.5 does not bail out on it.
33testing "awk gsub falls back to non-extended-regex" \
34 "awk 'gsub(\"@(samp|code|file)\{\",\"\");'; echo \$?" "0\n" "" "Hi\n"
35
Denis Vlasenko3bb2bbd2008-07-01 01:57:36 +000036tar xjf awk_t1.tar.bz2
37testing "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 "" ""
41rm -rf awk_t1_*
42
Denis Vlasenko41d5ebe2009-01-25 01:00:15 +000043Q='":"'
44
45testing "awk NF in BEGIN" \
46 "awk 'BEGIN { print ${Q} NF ${Q} \$0 ${Q} \$1 ${Q} \$2 ${Q} }'" \
47 ":0::::\n" \
48 "" ""
49
Denis Vlasenko960eca62007-07-18 18:33:18 +000050exit $FAILCOUNT