xref: /illumos-gate/usr/src/test/util-tests/tests/grep_xpg4/grep_test.ksh (revision 8a2b682e57a046b828f37bcde1776f131ef4629f)
1#! /usr/bin/ksh
2#
3#
4# This file and its contents are supplied under the terms of the
5# Common Development and Distribution License ("CDDL"), version 1.0.
6# You may only use this file in accordance with the terms of version
7# 1.0 of the CDDL.
8#
9# A full copy of the text of the CDDL should have accompanied this
10# source.  A copy of the CDDL is also available via the Internet at
11# http://www.illumos.org/license/CDDL.
12#
13
14#
15# Copyright 2017 Nexenta Systems, Inc. All rights reserved.
16#
17
18XGREP=${XGREP:=/usr/bin/grep}
19FILEDIR=$MY_TESTS/tests/files
20
21fail() {
22	echo $1
23	exit -1
24}
25
26FLAGLIST="
27-n
28-c
29-q
30-v
31-nv
32-vc
33-A 5
34-nA 5
35-cA 5
36-qA 5
37-vA 5
38-nvA 5
39-vcA 5
40-B 5
41-nB 5
42-cB 5
43-qB 5
44-vB 5
45-nvB 5
46-vcB 5
47-C 5
48-nC 5
49-cC 5
50-qC 5
51-vC 5
52-nvC 5
53-vcC 5
54-B 5 -A 2
55-nB 5 -A 2
56-cB 5 -A 2
57-qB 5 -A 2
58-vB 5 -A 2
59-nvB 5 -A 2
60-vcB 5 -A 2
61-B 5 -A 2 -C 5
62-nB 5 -A 2 -C 5
63-cB 5 -A 2 -C 5
64-qB 5 -A 2 -C 5
65-vB 5 -A 2 -C 5
66-nvB 5 -A 2 -C 5
67-vcB 5 -A 2 -C 5
68-5
69-n -5
70-c -5
71-q -5
72-v -5
73-nv -5
74-vc -5
75-50000
76-n -50000
77-c -50000
78-q -50000
79-v -50000
80-nv -50000
81-vc -50000
82-C 5 -B 4 -A 2
83-nC 5 -B 4 -A 2
84-cC 5 -B 4 -A 2
85-qC 5 -B 4 -A 2
86-vC 5 -B 4 -A 2
87-nvC 5 -B 4 -A 2
88-vcC 5 -B 4 -A 2"
89
90echo "$FLAGLIST" > /tmp/flags
91
92cd $FILEDIR
93
94i=0
95while read flags; do
96	print -n "test $i: grep $flags: "
97	$XGREP $flags a test0 test1 test2 \
98	    test3 test4 test5 test6 \
99	    test7 > out
100	err="$?"
101	if [[ $err -ne 0 ]]; then
102		fail "failed on exit: $err"
103	elif [ -n "$(diff out gout$i)" ]; then
104		print "$(diff out gout$i)"
105		fail "output is different"
106	fi
107	echo "passed"
108	((i++))
109done < /tmp/flags
110
111FLAGS2="-nE"
112
113echo "$FLAGS2" > /tmp/flags
114
115while read flags; do
116	print -n "test $i: grep $flags: "
117	$XGREP $flags ".*" testnl > out
118	err="$?"
119	if [[ $err -ne 0 ]]; then
120		fail "failed on exit: $err"
121	elif [ -n "$(diff out gout$i)" ]; then
122		print "$(diff out gout$i)"
123		fail "output is different"
124	fi
125	echo "passed"
126	((i++))
127done < /tmp/flags
128
129FLAGS3="-B 1
130-vA 1
131-vB 1"
132
133echo "$FLAGS3" > /tmp/flags
134
135while read flags; do
136	print -n "test $i: grep $flags: "
137	$XGREP $flags a testnl > out
138	err="$?"
139	if [[ $err -ne 0 ]]; then
140		fail "failed on exit: $err"
141	elif [ -n "$(diff out gout$i)" ]; then
142		print "$(diff out gout$i)"
143		fail "output is different"
144	fi
145	echo "passed"
146	((i++))
147done < /tmp/flags
148