xref: /freebsd/contrib/netbsd-tests/usr.bin/grep/t_grep.sh (revision 63c8336d4de15085d50c9d8c855cdc97ee018a04)
1f40f3adcSEnji Cooper# $NetBSD: t_grep.sh,v 1.3 2017/01/14 20:43:52 christos Exp $
257718be8SEnji Cooper#
357718be8SEnji Cooper# Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
457718be8SEnji Cooper# All rights reserved.
557718be8SEnji Cooper#
657718be8SEnji Cooper# Redistribution and use in source and binary forms, with or without
757718be8SEnji Cooper# modification, are permitted provided that the following conditions
857718be8SEnji Cooper# are met:
957718be8SEnji Cooper# 1. Redistributions of source code must retain the above copyright
1057718be8SEnji Cooper#    notice, this list of conditions and the following disclaimer.
1157718be8SEnji Cooper# 2. Redistributions in binary form must reproduce the above copyright
1257718be8SEnji Cooper#    notice, this list of conditions and the following disclaimer in the
1357718be8SEnji Cooper#    documentation and/or other materials provided with the distribution.
1457718be8SEnji Cooper#
1557718be8SEnji Cooper# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1657718be8SEnji Cooper# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1757718be8SEnji Cooper# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1857718be8SEnji Cooper# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
1957718be8SEnji Cooper# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2057718be8SEnji Cooper# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2157718be8SEnji Cooper# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2257718be8SEnji Cooper# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2357718be8SEnji Cooper# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2457718be8SEnji Cooper# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2557718be8SEnji Cooper# POSSIBILITY OF SUCH DAMAGE.
2657718be8SEnji Cooper#
2757718be8SEnji Cooper
2857718be8SEnji Cooperatf_test_case basic
2957718be8SEnji Cooperbasic_head()
3057718be8SEnji Cooper{
3157718be8SEnji Cooper	atf_set "descr" "Checks basic functionality"
3257718be8SEnji Cooper}
3357718be8SEnji Cooperbasic_body()
3457718be8SEnji Cooper{
3557718be8SEnji Cooper	atf_check -o file:"$(atf_get_srcdir)/d_basic.out" -x \
3657718be8SEnji Cooper	    'jot 10000 | grep 123'
3757718be8SEnji Cooper}
3857718be8SEnji Cooper
3957718be8SEnji Cooperatf_test_case binary
4057718be8SEnji Cooperbinary_head()
4157718be8SEnji Cooper{
4257718be8SEnji Cooper	atf_set "descr" "Checks handling of binary files"
4357718be8SEnji Cooper}
4457718be8SEnji Cooperbinary_body()
4557718be8SEnji Cooper{
461115e598SEnji Cooper	dd if=/dev/zero count=1 of=test.file
471115e598SEnji Cooper	echo -n "foobar" >> test.file
481115e598SEnji Cooper	atf_check -o file:"$(atf_get_srcdir)/d_binary.out" grep foobar test.file
4957718be8SEnji Cooper}
5057718be8SEnji Cooper
5157718be8SEnji Cooperatf_test_case recurse
5257718be8SEnji Cooperrecurse_head()
5357718be8SEnji Cooper{
5457718be8SEnji Cooper	atf_set "descr" "Checks recursive searching"
5557718be8SEnji Cooper}
5657718be8SEnji Cooperrecurse_body()
5757718be8SEnji Cooper{
5857718be8SEnji Cooper	mkdir -p recurse/a/f recurse/d
5957718be8SEnji Cooper	echo -e "cod\ndover sole\nhaddock\nhalibut\npilchard" > recurse/d/fish
6057718be8SEnji Cooper	echo -e "cod\nhaddock\nplaice" > recurse/a/f/favourite-fish
6157718be8SEnji Cooper
62eaae77f8SAlan Somers	atf_check -o file:"$(atf_get_srcdir)/d_recurse.out" -x "grep -r haddock recurse | sort"
6357718be8SEnji Cooper}
6457718be8SEnji Cooper
6557718be8SEnji Cooperatf_test_case recurse_symlink
6657718be8SEnji Cooperrecurse_symlink_head()
6757718be8SEnji Cooper{
6857718be8SEnji Cooper	atf_set "descr" "Checks symbolic link recursion"
6957718be8SEnji Cooper}
7057718be8SEnji Cooperrecurse_symlink_body()
7157718be8SEnji Cooper{
729f67a481SEnji Cooper	# Begin FreeBSD
739f67a481SEnji Cooper	grep_type
749f67a481SEnji Cooper	if [ $? -eq $GREP_TYPE_GNU ]; then
759f67a481SEnji Cooper		atf_expect_fail "this test doesn't pass with gnu grep from ports"
769f67a481SEnji Cooper	fi
779f67a481SEnji Cooper	# End FreeBSD
7857718be8SEnji Cooper	mkdir -p test/c/d
7957718be8SEnji Cooper	(cd test/c/d && ln -s ../d .)
8057718be8SEnji Cooper	echo "Test string" > test/c/match
8157718be8SEnji Cooper
8257718be8SEnji Cooper	atf_check -o file:"$(atf_get_srcdir)/d_recurse_symlink.out" \
8357718be8SEnji Cooper	    -e file:"$(atf_get_srcdir)/d_recurse_symlink.err" \
8457718be8SEnji Cooper	    grep -r string test
8557718be8SEnji Cooper}
8657718be8SEnji Cooper
8757718be8SEnji Cooperatf_test_case word_regexps
8857718be8SEnji Cooperword_regexps_head()
8957718be8SEnji Cooper{
9057718be8SEnji Cooper	atf_set "descr" "Checks word-regexps"
9157718be8SEnji Cooper}
9257718be8SEnji Cooperword_regexps_body()
9357718be8SEnji Cooper{
9457718be8SEnji Cooper	atf_check -o file:"$(atf_get_srcdir)/d_word_regexps.out" \
9557718be8SEnji Cooper	    grep -w separated $(atf_get_srcdir)/d_input
96945fc991SEd Maste
97945fc991SEd Maste	# Begin FreeBSD
98945fc991SEd Maste	printf "xmatch pmatch\n" > test1
99945fc991SEd Maste
100945fc991SEd Maste	atf_check -o inline:"pmatch\n" grep -Eow "(match )?pmatch" test1
101945fc991SEd Maste	# End FreeBSD
10257718be8SEnji Cooper}
10357718be8SEnji Cooper
10457718be8SEnji Cooperatf_test_case begin_end
10557718be8SEnji Cooperbegin_end_head()
10657718be8SEnji Cooper{
10757718be8SEnji Cooper	atf_set "descr" "Checks handling of line beginnings and ends"
10857718be8SEnji Cooper}
10957718be8SEnji Cooperbegin_end_body()
11057718be8SEnji Cooper{
11157718be8SEnji Cooper	atf_check -o file:"$(atf_get_srcdir)/d_begin_end_a.out" \
11257718be8SEnji Cooper	    grep ^Front "$(atf_get_srcdir)/d_input"
11357718be8SEnji Cooper
11457718be8SEnji Cooper	atf_check -o file:"$(atf_get_srcdir)/d_begin_end_b.out" \
11557718be8SEnji Cooper	    grep ending$ "$(atf_get_srcdir)/d_input"
11657718be8SEnji Cooper}
11757718be8SEnji Cooper
11857718be8SEnji Cooperatf_test_case ignore_case
11957718be8SEnji Cooperignore_case_head()
12057718be8SEnji Cooper{
12157718be8SEnji Cooper	atf_set "descr" "Checks ignore-case option"
12257718be8SEnji Cooper}
12357718be8SEnji Cooperignore_case_body()
12457718be8SEnji Cooper{
12557718be8SEnji Cooper	atf_check -o file:"$(atf_get_srcdir)/d_ignore_case.out" \
12657718be8SEnji Cooper	    grep -i Upper "$(atf_get_srcdir)/d_input"
12757718be8SEnji Cooper}
12857718be8SEnji Cooper
12957718be8SEnji Cooperatf_test_case invert
13057718be8SEnji Cooperinvert_head()
13157718be8SEnji Cooper{
13257718be8SEnji Cooper	atf_set "descr" "Checks selecting non-matching lines with -v option"
13357718be8SEnji Cooper}
13457718be8SEnji Cooperinvert_body()
13557718be8SEnji Cooper{
13657718be8SEnji Cooper	atf_check -o file:"$(atf_get_srcdir)/d_invert.out" \
13757718be8SEnji Cooper	    grep -v fish "$(atf_get_srcdir)/d_invert.in"
13857718be8SEnji Cooper}
13957718be8SEnji Cooper
14057718be8SEnji Cooperatf_test_case whole_line
14157718be8SEnji Cooperwhole_line_head()
14257718be8SEnji Cooper{
14357718be8SEnji Cooper	atf_set "descr" "Checks whole-line matching with -x flag"
14457718be8SEnji Cooper}
14557718be8SEnji Cooperwhole_line_body()
14657718be8SEnji Cooper{
14757718be8SEnji Cooper	atf_check -o file:"$(atf_get_srcdir)/d_whole_line.out" \
14857718be8SEnji Cooper	    grep -x matchme "$(atf_get_srcdir)/d_input"
14957718be8SEnji Cooper}
15057718be8SEnji Cooper
15157718be8SEnji Cooperatf_test_case negative
15257718be8SEnji Coopernegative_head()
15357718be8SEnji Cooper{
15457718be8SEnji Cooper	atf_set "descr" "Checks handling of files with no matches"
15557718be8SEnji Cooper}
15657718be8SEnji Coopernegative_body()
15757718be8SEnji Cooper{
15857718be8SEnji Cooper	atf_check -s ne:0 grep "not a hope in hell" "$(atf_get_srcdir)/d_input"
15957718be8SEnji Cooper}
16057718be8SEnji Cooper
16157718be8SEnji Cooperatf_test_case context
16257718be8SEnji Coopercontext_head()
16357718be8SEnji Cooper{
16457718be8SEnji Cooper	atf_set "descr" "Checks displaying context with -A, -B and -C flags"
16557718be8SEnji Cooper}
16657718be8SEnji Coopercontext_body()
16757718be8SEnji Cooper{
16857718be8SEnji Cooper	cp $(atf_get_srcdir)/d_context_*.* .
16957718be8SEnji Cooper
17057718be8SEnji Cooper	atf_check -o file:d_context_a.out grep -C2 bamboo d_context_a.in
17157718be8SEnji Cooper	atf_check -o file:d_context_b.out grep -A3 tilt d_context_a.in
17257718be8SEnji Cooper	atf_check -o file:d_context_c.out grep -B4 Whig d_context_a.in
17357718be8SEnji Cooper	atf_check -o file:d_context_d.out grep -C1 pig d_context_a.in d_context_b.in
174a4f3f02bSEd Maste	atf_check -o file:d_context_e.out \
175a4f3f02bSEd Maste	    grep -E -C1 '(banana|monkey)' d_context_e.in
176a4f3f02bSEd Maste	atf_check -o file:d_context_f.out \
177a4f3f02bSEd Maste	    grep -Ev -B2 '(banana|monkey|fruit)' d_context_e.in
178a4f3f02bSEd Maste	atf_check -o file:d_context_g.out \
179a4f3f02bSEd Maste	    grep -Ev -A1 '(banana|monkey|fruit)' d_context_e.in
18057718be8SEnji Cooper}
18157718be8SEnji Cooper
18257718be8SEnji Cooperatf_test_case file_exp
18357718be8SEnji Cooperfile_exp_head()
18457718be8SEnji Cooper{
18557718be8SEnji Cooper	atf_set "descr" "Checks reading expressions from file"
18657718be8SEnji Cooper}
18757718be8SEnji Cooperfile_exp_body()
18857718be8SEnji Cooper{
18957718be8SEnji Cooper	atf_check -o file:"$(atf_get_srcdir)/d_file_exp.out" -x \
19057718be8SEnji Cooper	    'jot 21 -1 1.00 | grep -f '"$(atf_get_srcdir)"'/d_file_exp.in'
19157718be8SEnji Cooper}
19257718be8SEnji Cooper
19357718be8SEnji Cooperatf_test_case egrep
19457718be8SEnji Cooperegrep_head()
19557718be8SEnji Cooper{
19657718be8SEnji Cooper	atf_set "descr" "Checks matching special characters with egrep"
19757718be8SEnji Cooper}
19857718be8SEnji Cooperegrep_body()
19957718be8SEnji Cooper{
20057718be8SEnji Cooper	atf_check -o file:"$(atf_get_srcdir)/d_egrep.out" \
20157718be8SEnji Cooper		egrep '\?|\*$$' "$(atf_get_srcdir)/d_input"
20257718be8SEnji Cooper}
20357718be8SEnji Cooper
20457718be8SEnji Cooperatf_test_case zgrep
20557718be8SEnji Cooperzgrep_head()
20657718be8SEnji Cooper{
20757718be8SEnji Cooper	atf_set "descr" "Checks handling of gzipped files with zgrep"
20857718be8SEnji Cooper}
20957718be8SEnji Cooperzgrep_body()
21057718be8SEnji Cooper{
21157718be8SEnji Cooper	cp "$(atf_get_srcdir)/d_input" .
21257718be8SEnji Cooper	gzip d_input || atf_fail "gzip failed"
21357718be8SEnji Cooper
21457718be8SEnji Cooper	atf_check -o file:"$(atf_get_srcdir)/d_zgrep.out" zgrep -h line d_input.gz
21557718be8SEnji Cooper}
21657718be8SEnji Cooper
217c4cbf1fbSCraig Leresatf_test_case zgrep_combined_flags
218c4cbf1fbSCraig Lereszgrep_combined_flags_head()
219c4cbf1fbSCraig Leres{
220c4cbf1fbSCraig Leres	atf_set "descr" "Checks for zgrep wrapper problems with combined flags (PR 247126)"
221c4cbf1fbSCraig Leres}
222c4cbf1fbSCraig Lereszgrep_combined_flags_body()
223c4cbf1fbSCraig Leres{
224c4cbf1fbSCraig Leres	atf_expect_fail "known but unsolved zgrep wrapper script regression"
225c4cbf1fbSCraig Leres
226c4cbf1fbSCraig Leres	echo 'foo bar' > test
227c4cbf1fbSCraig Leres
228c4cbf1fbSCraig Leres	atf_check -o inline:"foo bar\n" zgrep -we foo test
229c4cbf1fbSCraig Leres	# Avoid hang on reading from stdin in the failure case
230c4cbf1fbSCraig Leres	atf_check -o inline:"foo bar\n" zgrep -wefoo test < /dev/null
231c4cbf1fbSCraig Leres}
232c4cbf1fbSCraig Leres
233c4cbf1fbSCraig Leresatf_test_case zgrep_eflag
234c4cbf1fbSCraig Lereszgrep_eflag_head()
235c4cbf1fbSCraig Leres{
236c4cbf1fbSCraig Leres	atf_set "descr" "Checks for zgrep wrapper problems with -e PATTERN (PR 247126)"
237c4cbf1fbSCraig Leres}
238c4cbf1fbSCraig Lereszgrep_eflag_body()
239c4cbf1fbSCraig Leres{
240c4cbf1fbSCraig Leres	echo 'foo bar' > test
241c4cbf1fbSCraig Leres
242c4cbf1fbSCraig Leres	# Avoid hang on reading from stdin in the failure case
243c4cbf1fbSCraig Leres	atf_check -o inline:"foo bar\n" zgrep -e 'foo bar' test < /dev/null
244c4cbf1fbSCraig Leres	atf_check -o inline:"foo bar\n" zgrep --regexp='foo bar' test < /dev/null
245c4cbf1fbSCraig Leres}
246c4cbf1fbSCraig Leres
247c4cbf1fbSCraig Leresatf_test_case zgrep_fflag
248c4cbf1fbSCraig Lereszgrep_fflag_head()
249c4cbf1fbSCraig Leres{
250c4cbf1fbSCraig Leres	atf_set "descr" "Checks for zgrep wrapper problems with -f FILE (PR 247126)"
251c4cbf1fbSCraig Leres}
252c4cbf1fbSCraig Lereszgrep_fflag_body()
253c4cbf1fbSCraig Leres{
254c4cbf1fbSCraig Leres	echo foo > pattern
255c4cbf1fbSCraig Leres	echo foobar > test
256c4cbf1fbSCraig Leres
257c4cbf1fbSCraig Leres	# Avoid hang on reading from stdin in the failure case
258c4cbf1fbSCraig Leres	atf_check -o inline:"foobar\n" zgrep -f pattern test </dev/null
259c4cbf1fbSCraig Leres	atf_check -o inline:"foobar\n" zgrep --file=pattern test </dev/null
260c4cbf1fbSCraig Leres}
261c4cbf1fbSCraig Leres
262c4cbf1fbSCraig Leresatf_test_case zgrep_long_eflag
263c4cbf1fbSCraig Lereszgrep_long_eflag_head()
264c4cbf1fbSCraig Leres{
265c4cbf1fbSCraig Leres	atf_set "descr" "Checks for zgrep wrapper problems with --ignore-case reading from stdin (PR 247126)"
266c4cbf1fbSCraig Leres}
267c4cbf1fbSCraig Lereszgrep_long_eflag_body()
268c4cbf1fbSCraig Leres{
269c4cbf1fbSCraig Leres	echo foobar > test
270c4cbf1fbSCraig Leres
271c4cbf1fbSCraig Leres	atf_check -o inline:"foobar\n" zgrep -e foo --ignore-case < test
272c4cbf1fbSCraig Leres}
273c4cbf1fbSCraig Leres
274c4cbf1fbSCraig Leresatf_test_case zgrep_multiple_eflags
275c4cbf1fbSCraig Lereszgrep_multiple_eflags_head()
276c4cbf1fbSCraig Leres{
277c4cbf1fbSCraig Leres	atf_set "descr" "Checks for zgrep wrapper problems with multiple -e flags (PR 247126)"
278c4cbf1fbSCraig Leres}
279c4cbf1fbSCraig Lereszgrep_multiple_eflags_body()
280c4cbf1fbSCraig Leres{
281c4cbf1fbSCraig Leres	atf_expect_fail "known but unsolved zgrep wrapper script regression"
282c4cbf1fbSCraig Leres
283c4cbf1fbSCraig Leres	echo foobar > test
284c4cbf1fbSCraig Leres
285c4cbf1fbSCraig Leres	atf_check -o inline:"foobar\n" zgrep -e foo -e xxx test
286c4cbf1fbSCraig Leres}
287c4cbf1fbSCraig Leres
288c4cbf1fbSCraig Leresatf_test_case zgrep_empty_eflag
289c4cbf1fbSCraig Lereszgrep_empty_eflag_head()
290c4cbf1fbSCraig Leres{
291c4cbf1fbSCraig Leres	atf_set "descr" "Checks for zgrep wrapper problems with empty -e flags pattern (PR 247126)"
292c4cbf1fbSCraig Leres}
293c4cbf1fbSCraig Lereszgrep_empty_eflag_body()
294c4cbf1fbSCraig Leres{
295c4cbf1fbSCraig Leres	echo foobar > test
296c4cbf1fbSCraig Leres
297c4cbf1fbSCraig Leres	atf_check -o inline:"foobar\n" zgrep -e '' test
298c4cbf1fbSCraig Leres}
299c4cbf1fbSCraig Leres
30057718be8SEnji Cooperatf_test_case nonexistent
30157718be8SEnji Coopernonexistent_head()
30257718be8SEnji Cooper{
30357718be8SEnji Cooper	atf_set "descr" "Checks that -s flag suppresses error" \
30457718be8SEnji Cooper	                "messages about nonexistent files"
30557718be8SEnji Cooper}
30657718be8SEnji Coopernonexistent_body()
30757718be8SEnji Cooper{
30857718be8SEnji Cooper	atf_check -s ne:0 grep -s foobar nonexistent
30957718be8SEnji Cooper}
31057718be8SEnji Cooper
31157718be8SEnji Cooperatf_test_case context2
31257718be8SEnji Coopercontext2_head()
31357718be8SEnji Cooper{
31457718be8SEnji Cooper	atf_set "descr" "Checks displaying context with -z flag"
31557718be8SEnji Cooper}
31657718be8SEnji Coopercontext2_body()
31757718be8SEnji Cooper{
31857718be8SEnji Cooper	printf "haddock\000cod\000plaice\000" > test1
31957718be8SEnji Cooper	printf "mackeral\000cod\000crab\000" > test2
32057718be8SEnji Cooper
32157718be8SEnji Cooper	atf_check -o file:"$(atf_get_srcdir)/d_context2_a.out" \
32257718be8SEnji Cooper	    grep -z -A1 cod test1 test2
32357718be8SEnji Cooper
32457718be8SEnji Cooper	atf_check -o file:"$(atf_get_srcdir)/d_context2_b.out" \
32557718be8SEnji Cooper	    grep -z -B1 cod test1 test2
32657718be8SEnji Cooper
32757718be8SEnji Cooper	atf_check -o file:"$(atf_get_srcdir)/d_context2_c.out" \
32857718be8SEnji Cooper	    grep -z -C1 cod test1 test2
32957718be8SEnji Cooper}
330799c5faaSEd Maste# Begin FreeBSD
3319f67a481SEnji Cooper
3329f67a481SEnji Cooper# What grep(1) are we working with?
3339f67a481SEnji Cooper# - 0 : bsdgrep
3349f67a481SEnji Cooper# - 1 : gnu grep 2.51 (base)
3359f67a481SEnji Cooper# - 2 : gnu grep (ports)
3369f67a481SEnji CooperGREP_TYPE_BSD=0
3379f67a481SEnji CooperGREP_TYPE_GNU_FREEBSD=1
3389f67a481SEnji CooperGREP_TYPE_GNU=2
3399f67a481SEnji CooperGREP_TYPE_UNKNOWN=3
3409f67a481SEnji Cooper
3419f67a481SEnji Coopergrep_type()
3429f67a481SEnji Cooper{
3439f67a481SEnji Cooper	local grep_version=$(grep --version)
3449f67a481SEnji Cooper
3459f67a481SEnji Cooper	case "$grep_version" in
3469f67a481SEnji Cooper	*"BSD grep"*)
3479f67a481SEnji Cooper		return $GREP_TYPE_BSD
3489f67a481SEnji Cooper		;;
3499f67a481SEnji Cooper	*"GNU grep"*)
3509f67a481SEnji Cooper		case "$grep_version" in
3519f67a481SEnji Cooper		*2.5.1-FreeBSD*)
3529f67a481SEnji Cooper			return $GREP_TYPE_GNU_FREEBSD
3539f67a481SEnji Cooper			;;
3549f67a481SEnji Cooper		*)
3559f67a481SEnji Cooper			return $GREP_TYPE_GNU
3569f67a481SEnji Cooper			;;
3579f67a481SEnji Cooper		esac
3589f67a481SEnji Cooper		;;
3599f67a481SEnji Cooper	esac
3609f67a481SEnji Cooper	atf_fail "unknown grep type: $grep_version"
3619f67a481SEnji Cooper}
3629f67a481SEnji Cooper
363799c5faaSEd Masteatf_test_case oflag_zerolen
364799c5faaSEd Masteoflag_zerolen_head()
365799c5faaSEd Maste{
366799c5faaSEd Maste	atf_set "descr" "Check behavior of zero-length matches with -o flag (PR 195763)"
367799c5faaSEd Maste}
368799c5faaSEd Masteoflag_zerolen_body()
369799c5faaSEd Maste{
3709f67a481SEnji Cooper	grep_type
3719f67a481SEnji Cooper	if [ $? -eq $GREP_TYPE_GNU_FREEBSD ]; then
3729f67a481SEnji Cooper		atf_expect_fail "this test doesn't pass with gnu grep in base"
3739f67a481SEnji Cooper	fi
3749f67a481SEnji Cooper
375799c5faaSEd Maste	atf_check -o file:"$(atf_get_srcdir)/d_oflag_zerolen_a.out" \
376799c5faaSEd Maste	    grep -Eo '(^|:)0*' "$(atf_get_srcdir)/d_oflag_zerolen_a.in"
377799c5faaSEd Maste
378799c5faaSEd Maste	atf_check -o file:"$(atf_get_srcdir)/d_oflag_zerolen_b.out" \
379799c5faaSEd Maste	    grep -Eo '(^|:)0*' "$(atf_get_srcdir)/d_oflag_zerolen_b.in"
380799c5faaSEd Maste
381799c5faaSEd Maste	atf_check -o file:"$(atf_get_srcdir)/d_oflag_zerolen_c.out" \
382799c5faaSEd Maste	    grep -Eo '[[:alnum:]]*' "$(atf_get_srcdir)/d_oflag_zerolen_c.in"
383799c5faaSEd Maste
384799c5faaSEd Maste	atf_check -o empty grep -Eo '' "$(atf_get_srcdir)/d_oflag_zerolen_d.in"
385799c5faaSEd Maste
386799c5faaSEd Maste	atf_check -o file:"$(atf_get_srcdir)/d_oflag_zerolen_e.out" \
387799c5faaSEd Maste	    grep -o -e 'ab' -e 'bc' "$(atf_get_srcdir)/d_oflag_zerolen_e.in"
388799c5faaSEd Maste
389799c5faaSEd Maste	atf_check -o file:"$(atf_get_srcdir)/d_oflag_zerolen_e.out" \
390799c5faaSEd Maste	    grep -o -e 'bc' -e 'ab' "$(atf_get_srcdir)/d_oflag_zerolen_e.in"
391799c5faaSEd Maste}
392799c5faaSEd Maste
393799c5faaSEd Masteatf_test_case xflag
394799c5faaSEd Mastexflag_head()
395799c5faaSEd Maste{
396799c5faaSEd Maste	atf_set "descr" "Check that we actually get a match with -x flag (PR 180990)"
397799c5faaSEd Maste}
398799c5faaSEd Mastexflag_body()
399799c5faaSEd Maste{
400799c5faaSEd Maste	echo 128 > match_file
401799c5faaSEd Maste	seq 1 128 > pattern_file
402799c5faaSEd Maste	grep -xf pattern_file match_file
403799c5faaSEd Maste}
404799c5faaSEd Maste
405799c5faaSEd Masteatf_test_case color
406799c5faaSEd Mastecolor_head()
407799c5faaSEd Maste{
408799c5faaSEd Maste	atf_set "descr" "Check --color support"
409799c5faaSEd Maste}
410799c5faaSEd Mastecolor_body()
411799c5faaSEd Maste{
4129f67a481SEnji Cooper	grep_type
4139f67a481SEnji Cooper	if [ $? -eq $GREP_TYPE_GNU_FREEBSD ]; then
4149f67a481SEnji Cooper		atf_expect_fail "this test doesn't pass with gnu grep in base"
4159f67a481SEnji Cooper	fi
4169f67a481SEnji Cooper
417799c5faaSEd Maste	echo 'abcd*' > grepfile
418799c5faaSEd Maste	echo 'abc$' >> grepfile
419799c5faaSEd Maste	echo '^abc' >> grepfile
420799c5faaSEd Maste
421799c5faaSEd Maste	atf_check -o file:"$(atf_get_srcdir)/d_color_a.out" \
422799c5faaSEd Maste	    grep --color=auto -e '.*' -e 'a' "$(atf_get_srcdir)/d_color_a.in"
423799c5faaSEd Maste
424799c5faaSEd Maste	atf_check -o file:"$(atf_get_srcdir)/d_color_b.out" \
425799c5faaSEd Maste	    grep --color=auto -f grepfile "$(atf_get_srcdir)/d_color_b.in"
426799c5faaSEd Maste
427799c5faaSEd Maste	atf_check -o file:"$(atf_get_srcdir)/d_color_c.out" \
428799c5faaSEd Maste	    grep --color=always -f grepfile "$(atf_get_srcdir)/d_color_b.in"
429799c5faaSEd Maste}
430799c5faaSEd Maste
431799c5faaSEd Masteatf_test_case f_file_empty
432799c5faaSEd Mastef_file_empty_head()
433799c5faaSEd Maste{
434799c5faaSEd Maste	atf_set "descr" "Check for handling of a null byte in empty file, specified by -f (PR 202022)"
435799c5faaSEd Maste}
436799c5faaSEd Mastef_file_empty_body()
437799c5faaSEd Maste{
438799c5faaSEd Maste	printf "\0\n" > nulpat
439799c5faaSEd Maste
440799c5faaSEd Maste	atf_check -s exit:1 grep -f nulpat "$(atf_get_srcdir)/d_f_file_empty.in"
441799c5faaSEd Maste}
442799c5faaSEd Maste
443799c5faaSEd Masteatf_test_case escmap
444799c5faaSEd Masteescmap_head()
445799c5faaSEd Maste{
446799c5faaSEd Maste	atf_set "descr" "Check proper handling of escaped vs. unescaped dot expressions (PR 175314)"
447799c5faaSEd Maste}
448799c5faaSEd Masteescmap_body()
449799c5faaSEd Maste{
450799c5faaSEd Maste	atf_check -s exit:1 grep -o 'f.o\.' "$(atf_get_srcdir)/d_escmap.in"
451799c5faaSEd Maste	atf_check -o not-empty grep -o 'f.o.' "$(atf_get_srcdir)/d_escmap.in"
452799c5faaSEd Maste}
453799c5faaSEd Maste
454799c5faaSEd Masteatf_test_case egrep_empty_invalid
455799c5faaSEd Masteegrep_empty_invalid_head()
456799c5faaSEd Maste{
457799c5faaSEd Maste	atf_set "descr" "Check for handling of an invalid empty pattern (PR 194823)"
458799c5faaSEd Maste}
459799c5faaSEd Masteegrep_empty_invalid_body()
460799c5faaSEd Maste{
461befd089cSEd Maste	atf_check -e ignore -s not-exit:0 egrep '{' /dev/null
462799c5faaSEd Maste}
463e06ffa32SEd Maste
464e06ffa32SEd Masteatf_test_case zerolen
465e06ffa32SEd Mastezerolen_head()
466e06ffa32SEd Maste{
467e06ffa32SEd Maste	atf_set "descr" "Check for successful zero-length matches with ^$"
468e06ffa32SEd Maste}
469e06ffa32SEd Mastezerolen_body()
470e06ffa32SEd Maste{
471e06ffa32SEd Maste	printf "Eggs\n\nCheese" > test1
472e06ffa32SEd Maste
473e06ffa32SEd Maste	atf_check -o inline:"\n" grep -e "^$" test1
474e06ffa32SEd Maste
475e06ffa32SEd Maste	atf_check -o inline:"Eggs\nCheese\n" grep -v -e "^$" test1
476e06ffa32SEd Maste}
4775199917cSEnji Cooper
478a4f3f02bSEd Masteatf_test_case wflag_emptypat
479a4f3f02bSEd Mastewflag_emptypat_head()
480a4f3f02bSEd Maste{
481a4f3f02bSEd Maste	atf_set "descr" "Check for proper handling of -w with an empty pattern (PR 105221)"
482a4f3f02bSEd Maste}
483a4f3f02bSEd Mastewflag_emptypat_body()
484a4f3f02bSEd Maste{
485a4f3f02bSEd Maste	printf "" > test1
486a4f3f02bSEd Maste	printf "\n" > test2
487a4f3f02bSEd Maste	printf "qaz" > test3
488a4f3f02bSEd Maste	printf " qaz\n" > test4
489a4f3f02bSEd Maste
490a4f3f02bSEd Maste	atf_check -s exit:1 -o empty grep -w -e "" test1
491a4f3f02bSEd Maste
492a4f3f02bSEd Maste	atf_check -o file:test2 grep -w -e "" test2
493a4f3f02bSEd Maste
494a4f3f02bSEd Maste	atf_check -s exit:1 -o empty grep -w -e "" test3
495a4f3f02bSEd Maste
496a4f3f02bSEd Maste	atf_check -o file:test4 grep -w -e "" test4
497a4f3f02bSEd Maste}
498a4f3f02bSEd Maste
49938325e2aSKyle Evansatf_test_case xflag_emptypat
50038325e2aSKyle Evansxflag_emptypat_body()
50138325e2aSKyle Evans{
50238325e2aSKyle Evans	printf "" > test1
50338325e2aSKyle Evans	printf "\n" > test2
50438325e2aSKyle Evans	printf "qaz" > test3
50538325e2aSKyle Evans	printf " qaz\n" > test4
50638325e2aSKyle Evans
50738325e2aSKyle Evans	# -x is whole-line, more strict than -w.
50838325e2aSKyle Evans	atf_check -s exit:1 -o empty grep -x -e "" test1
50938325e2aSKyle Evans
51038325e2aSKyle Evans	atf_check -o file:test2 grep -x -e "" test2
51138325e2aSKyle Evans
51238325e2aSKyle Evans	atf_check -s exit:1 -o empty grep -x -e "" test3
51338325e2aSKyle Evans
51438325e2aSKyle Evans	atf_check -s exit:1 -o empty grep -x -e "" test4
51538325e2aSKyle Evans
51638325e2aSKyle Evans	total=$(wc -l /COPYRIGHT | sed 's/[^0-9]//g')
51738325e2aSKyle Evans
51838325e2aSKyle Evans	# Simple checks that grep -x with an empty pattern isn't matching every
51938325e2aSKyle Evans	# line.  The exact counts aren't important, as long as they don't
52038325e2aSKyle Evans	# match the total line count and as long as they don't match each other.
52138325e2aSKyle Evans	atf_check -o save:xpositive.count grep -Fxc '' /COPYRIGHT
52238325e2aSKyle Evans	atf_check -o save:xnegative.count grep -Fvxc '' /COPYRIGHT
52338325e2aSKyle Evans
52438325e2aSKyle Evans	atf_check -o not-inline:"${total}" cat xpositive.count
52538325e2aSKyle Evans	atf_check -o not-inline:"${total}" cat xnegative.count
52638325e2aSKyle Evans
52738325e2aSKyle Evans	atf_check -o not-file:xnegative.count cat xpositive.count
52838325e2aSKyle Evans}
52938325e2aSKyle Evans
53038325e2aSKyle Evansatf_test_case xflag_emptypat_plus
53138325e2aSKyle Evansxflag_emptypat_plus_body()
53238325e2aSKyle Evans{
53338325e2aSKyle Evans	printf "foo\n\nbar\n\nbaz\n" > target
53438325e2aSKyle Evans	printf "foo\n \nbar\n \nbaz\n" > target_spacelines
53538325e2aSKyle Evans	printf "foo\nbar\nbaz\n" > matches
53638325e2aSKyle Evans	printf " \n \n" > spacelines
53738325e2aSKyle Evans
53838325e2aSKyle Evans	printf "foo\n\nbar\n\nbaz\n" > patlist1
53938325e2aSKyle Evans	printf "foo\n\nba\n\nbaz\n" > patlist2
54038325e2aSKyle Evans
54138325e2aSKyle Evans	sed -e '/bar/d' target > matches_not2
54238325e2aSKyle Evans
54338325e2aSKyle Evans	# Normal handling first
54438325e2aSKyle Evans	atf_check -o file:target grep -Fxf patlist1 target
54538325e2aSKyle Evans	atf_check -o file:matches grep -Fxf patlist1 target_spacelines
54638325e2aSKyle Evans	atf_check -o file:matches_not2 grep -Fxf patlist2 target
54738325e2aSKyle Evans
54838325e2aSKyle Evans	# -v handling
54938325e2aSKyle Evans	atf_check -s exit:1 -o empty grep -Fvxf patlist1 target
55038325e2aSKyle Evans	atf_check -o file:spacelines grep -Fxvf patlist1 target_spacelines
55138325e2aSKyle Evans}
55238325e2aSKyle Evans
553fe8c9d5bSEd Masteatf_test_case excessive_matches
554fe8c9d5bSEd Masteexcessive_matches_head()
555fe8c9d5bSEd Maste{
556fe8c9d5bSEd Maste	atf_set "descr" "Check for proper handling of lines with excessive matches (PR 218811)"
557fe8c9d5bSEd Maste}
558fe8c9d5bSEd Masteexcessive_matches_body()
559fe8c9d5bSEd Maste{
560fe8c9d5bSEd Maste	grep_type
561fe8c9d5bSEd Maste	if [ $? -eq $GREP_TYPE_GNU_FREEBSD ]; then
562fe8c9d5bSEd Maste		atf_expect_fail "this test does not pass with GNU grep in base"
563fe8c9d5bSEd Maste	fi
564fe8c9d5bSEd Maste
565fe8c9d5bSEd Maste	for i in $(jot 4096); do
566fe8c9d5bSEd Maste		printf "x" >> test.in
567fe8c9d5bSEd Maste	done
568fe8c9d5bSEd Maste
569fe8c9d5bSEd Maste	atf_check -s exit:0 -x '[ $(grep -o x test.in | wc -l) -eq 4096 ]'
5706d635d3bSEd Maste	atf_check -s exit:1 -x 'grep -on x test.in | grep -v "1:x"'
571fe8c9d5bSEd Maste}
572fe8c9d5bSEd Maste
5735199917cSEnji Cooperatf_test_case fgrep_sanity
5745199917cSEnji Cooperfgrep_sanity_head()
5755199917cSEnji Cooper{
5765199917cSEnji Cooper	atf_set "descr" "Check for fgrep sanity, literal expressions only"
5775199917cSEnji Cooper}
5785199917cSEnji Cooperfgrep_sanity_body()
5795199917cSEnji Cooper{
5805199917cSEnji Cooper	printf "Foo" > test1
5815199917cSEnji Cooper
5825199917cSEnji Cooper	atf_check -o inline:"Foo\n" fgrep -e "Foo" test1
5835199917cSEnji Cooper
5845199917cSEnji Cooper	atf_check -s exit:1 -o empty fgrep -e "Fo." test1
5855199917cSEnji Cooper}
5865199917cSEnji Cooper
5875199917cSEnji Cooperatf_test_case egrep_sanity
5885199917cSEnji Cooperegrep_sanity_head()
5895199917cSEnji Cooper{
5905199917cSEnji Cooper	atf_set "descr" "Check for egrep sanity, EREs only"
5915199917cSEnji Cooper}
5925199917cSEnji Cooperegrep_sanity_body()
5935199917cSEnji Cooper{
5945199917cSEnji Cooper	printf "Foobar(ed)" > test1
5955199917cSEnji Cooper	printf "M{1}" > test2
5965199917cSEnji Cooper
5975199917cSEnji Cooper	atf_check -o inline:"Foo\n" egrep -o -e "F.." test1
5985199917cSEnji Cooper
5995199917cSEnji Cooper	atf_check -o inline:"Foobar\n" egrep -o -e "F[a-z]*" test1
6005199917cSEnji Cooper
6015199917cSEnji Cooper	atf_check -o inline:"Fo\n" egrep -o -e "F(o|p)" test1
6025199917cSEnji Cooper
6035199917cSEnji Cooper	atf_check -o inline:"(ed)\n" egrep -o -e "\(ed\)" test1
6045199917cSEnji Cooper
6055199917cSEnji Cooper	atf_check -o inline:"M\n" egrep -o -e "M{1}" test2
6065199917cSEnji Cooper
6075199917cSEnji Cooper	atf_check -o inline:"M{1}\n" egrep -o -e "M\{1\}" test2
6085199917cSEnji Cooper}
6095199917cSEnji Cooper
6105199917cSEnji Cooperatf_test_case grep_sanity
6115199917cSEnji Coopergrep_sanity_head()
6125199917cSEnji Cooper{
6135199917cSEnji Cooper	atf_set "descr" "Check for basic grep sanity, BREs only"
6145199917cSEnji Cooper}
6155199917cSEnji Coopergrep_sanity_body()
6165199917cSEnji Cooper{
6175199917cSEnji Cooper	printf "Foobar(ed)" > test1
6185199917cSEnji Cooper	printf "M{1}" > test2
6195199917cSEnji Cooper
6205199917cSEnji Cooper	atf_check -o inline:"Foo\n" grep -o -e "F.." test1
6215199917cSEnji Cooper
6225199917cSEnji Cooper	atf_check -o inline:"Foobar\n" grep -o -e "F[a-z]*" test1
6235199917cSEnji Cooper
6245199917cSEnji Cooper	atf_check -o inline:"Fo\n" grep -o -e "F\(o\)" test1
6255199917cSEnji Cooper
6265199917cSEnji Cooper	atf_check -o inline:"(ed)\n" grep -o -e "(ed)" test1
6275199917cSEnji Cooper
6285199917cSEnji Cooper	atf_check -o inline:"M{1}\n" grep -o -e "M{1}" test2
6295199917cSEnji Cooper
6305199917cSEnji Cooper	atf_check -o inline:"M\n" grep -o -e "M\{1\}" test2
6315199917cSEnji Cooper}
632945fc991SEd Maste
633945fc991SEd Masteatf_test_case wv_combo_break
634945fc991SEd Mastewv_combo_break_head()
635945fc991SEd Maste{
636945fc991SEd Maste	atf_set "descr" "Check for incorrectly matching lines with both -w and -v flags (PR 218467)"
637945fc991SEd Maste}
638945fc991SEd Mastewv_combo_break_body()
639945fc991SEd Maste{
640945fc991SEd Maste	printf "x xx\n" > test1
641945fc991SEd Maste	printf "xx x\n" > test2
642945fc991SEd Maste
643945fc991SEd Maste	atf_check -o file:test1 grep -w "x" test1
644945fc991SEd Maste	atf_check -o file:test2 grep -w "x" test2
645945fc991SEd Maste
646945fc991SEd Maste	atf_check -s exit:1 grep -v -w "x" test1
647945fc991SEd Maste	atf_check -s exit:1 grep -v -w "x" test2
648945fc991SEd Maste}
649e2127de8SEd Maste
6506d635d3bSEd Masteatf_test_case ocolor_metadata
6516d635d3bSEd Masteocolor_metadata_head()
6526d635d3bSEd Maste{
6536d635d3bSEd Maste	atf_set "descr" "Check for -n/-b producing per-line metadata output"
6546d635d3bSEd Maste}
6556d635d3bSEd Masteocolor_metadata_body()
6566d635d3bSEd Maste{
6576d635d3bSEd Maste	grep_type
6586d635d3bSEd Maste	if [ $? -eq $GREP_TYPE_GNU_FREEBSD ]; then
6596d635d3bSEd Maste		atf_expect_fail "this test does not pass with GNU grep in base"
6606d635d3bSEd Maste	fi
6616d635d3bSEd Maste
6626d635d3bSEd Maste	printf "xxx\nyyyy\nzzz\nfoobarbaz\n" > test1
6636d635d3bSEd Maste	check_expr="^[^:]*[0-9][^:]*:[^:]+$"
6646d635d3bSEd Maste
6656d635d3bSEd Maste	atf_check -o inline:"1:1:xx\n" grep -bon "xx$" test1
6666d635d3bSEd Maste
6676d635d3bSEd Maste	atf_check -o inline:"2:4:yyyy\n" grep -bn "yy" test1
6686d635d3bSEd Maste
6696d635d3bSEd Maste	atf_check -o inline:"2:6:yy\n" grep -bon "yy$" test1
6706d635d3bSEd Maste
6716d635d3bSEd Maste	# These checks ensure that grep isn't producing bogus line numbering
6726d635d3bSEd Maste	# in the middle of a line.
6736d635d3bSEd Maste	atf_check -s exit:1 -x \
6746d635d3bSEd Maste	    "grep -Eon 'x|y|z|f' test1 | grep -Ev '${check_expr}'"
6756d635d3bSEd Maste
6766d635d3bSEd Maste	atf_check -s exit:1 -x \
6776d635d3bSEd Maste	    "grep -En 'x|y|z|f' --color=always test1 | grep -Ev '${check_expr}'"
6786d635d3bSEd Maste
6796d635d3bSEd Maste	atf_check -s exit:1 -x \
6806d635d3bSEd Maste	    "grep -Eon 'x|y|z|f' --color=always test1 | grep -Ev '${check_expr}'"
6816d635d3bSEd Maste}
6826d635d3bSEd Maste
683e2127de8SEd Masteatf_test_case grep_nomatch_flags
684e2127de8SEd Mastegrep_nomatch_flags_head()
685e2127de8SEd Maste{
686e2127de8SEd Maste	atf_set "descr" "Check for no match (-c, -l, -L, -q) flags not producing line matches or context (PR 219077)"
687e2127de8SEd Maste}
688e2127de8SEd Maste
689e2127de8SEd Mastegrep_nomatch_flags_body()
690e2127de8SEd Maste{
69138325e2aSKyle Evans	grep_type
69238325e2aSKyle Evans
69338325e2aSKyle Evans	if [ $? -eq $GREP_TYPE_GNU_FREEBSD ]; then
69438325e2aSKyle Evans		atf_expect_fail "this test does not pass with GNU grep in base"
69538325e2aSKyle Evans	fi
69638325e2aSKyle Evans
697e2127de8SEd Maste	printf "A\nB\nC\n" > test1
698e2127de8SEd Maste
699e2127de8SEd Maste	atf_check -o inline:"1\n" grep -c -C 1 -e "B" test1
700e2127de8SEd Maste	atf_check -o inline:"1\n" grep -c -B 1 -e "B" test1
701e2127de8SEd Maste	atf_check -o inline:"1\n" grep -c -A 1 -e "B" test1
702e2127de8SEd Maste	atf_check -o inline:"1\n" grep -c -C 1 -e "B" test1
703e2127de8SEd Maste
704e2127de8SEd Maste	atf_check -o inline:"test1\n" grep -l -e "B" test1
705e2127de8SEd Maste	atf_check -o inline:"test1\n" grep -l -B 1 -e "B" test1
706e2127de8SEd Maste	atf_check -o inline:"test1\n" grep -l -A 1 -e "B" test1
707e2127de8SEd Maste	atf_check -o inline:"test1\n" grep -l -C 1 -e "B" test1
708e2127de8SEd Maste
70938325e2aSKyle Evans	atf_check -o inline:"test1\n" grep -L -e "D" test1
710e2127de8SEd Maste
711e2127de8SEd Maste	atf_check -o empty grep -q -e "B" test1
712e2127de8SEd Maste	atf_check -o empty grep -q -B 1 -e "B" test1
713e2127de8SEd Maste	atf_check -o empty grep -q -A 1 -e "B" test1
714e2127de8SEd Maste	atf_check -o empty grep -q -C 1 -e "B" test1
715e2127de8SEd Maste}
716b5fc583cSEd Maste
717b5fc583cSEd Masteatf_test_case badcontext
718b5fc583cSEd Mastebadcontext_head()
719b5fc583cSEd Maste{
720b5fc583cSEd Maste	atf_set "descr" "Check for handling of invalid context arguments"
721b5fc583cSEd Maste}
722b5fc583cSEd Mastebadcontext_body()
723b5fc583cSEd Maste{
724b5fc583cSEd Maste	printf "A\nB\nC\n" > test1
725b5fc583cSEd Maste
726b5fc583cSEd Maste	atf_check -s not-exit:0 -e ignore grep -A "-1" "B" test1
727b5fc583cSEd Maste
728b5fc583cSEd Maste	atf_check -s not-exit:0 -e ignore grep -B "-1" "B" test1
729b5fc583cSEd Maste
730b5fc583cSEd Maste	atf_check -s not-exit:0 -e ignore grep -C "-1" "B" test1
731b5fc583cSEd Maste
732b5fc583cSEd Maste	atf_check -s not-exit:0 -e ignore grep -A "B" "B" test1
733b5fc583cSEd Maste
734b5fc583cSEd Maste	atf_check -s not-exit:0 -e ignore grep -B "B" "B" test1
735b5fc583cSEd Maste
736b5fc583cSEd Maste	atf_check -s not-exit:0 -e ignore grep -C "B" "B" test1
737b5fc583cSEd Maste}
738f701bdc5SEd Maste
739f701bdc5SEd Masteatf_test_case binary_flags
740f701bdc5SEd Mastebinary_flags_head()
741f701bdc5SEd Maste{
742f701bdc5SEd Maste	atf_set "descr" "Check output for binary flags (-a, -I, -U, --binary-files)"
743f701bdc5SEd Maste}
744f701bdc5SEd Mastebinary_flags_body()
745f701bdc5SEd Maste{
746f701bdc5SEd Maste	printf "A\000B\000C" > test1
747f701bdc5SEd Maste	printf "A\n\000B\n\000C" > test2
748f701bdc5SEd Maste	binmatchtext="Binary file test1 matches\n"
749f701bdc5SEd Maste
750f701bdc5SEd Maste	# Binaries not treated as text (default, -U)
751f701bdc5SEd Maste	atf_check -o inline:"${binmatchtext}" grep 'B' test1
752f701bdc5SEd Maste	atf_check -o inline:"${binmatchtext}" grep 'B' -C 1 test1
753f701bdc5SEd Maste
754f701bdc5SEd Maste	atf_check -o inline:"${binmatchtext}" grep -U 'B' test1
755f701bdc5SEd Maste	atf_check -o inline:"${binmatchtext}" grep -U 'B' -C 1 test1
756f701bdc5SEd Maste
757f701bdc5SEd Maste	# Binary, -a, no newlines
758f701bdc5SEd Maste	atf_check -o inline:"A\000B\000C\n" grep -a 'B' test1
759f701bdc5SEd Maste	atf_check -o inline:"A\000B\000C\n" grep -a 'B' -C 1 test1
760f701bdc5SEd Maste
761f701bdc5SEd Maste	# Binary, -a, newlines
762f701bdc5SEd Maste	atf_check -o inline:"\000B\n" grep -a 'B' test2
763f701bdc5SEd Maste	atf_check -o inline:"A\n\000B\n\000C\n" grep -a 'B' -C 1 test2
764f701bdc5SEd Maste
765f701bdc5SEd Maste	# Binary files ignored
766f701bdc5SEd Maste	atf_check -s exit:1 grep -I 'B' test2
767f701bdc5SEd Maste
768f701bdc5SEd Maste	# --binary-files equivalence
769f701bdc5SEd Maste	atf_check -o inline:"${binmatchtext}" grep --binary-files=binary 'B' test1
770f701bdc5SEd Maste	atf_check -o inline:"A\000B\000C\n" grep --binary-files=text 'B' test1
771f701bdc5SEd Maste	atf_check -s exit:1 grep --binary-files=without-match 'B' test2
772f701bdc5SEd Maste}
773d7b65474SEd Maste
774d7b65474SEd Masteatf_test_case mmap
775d7b65474SEd Mastemmap_head()
776d7b65474SEd Maste{
777d7b65474SEd Maste	atf_set "descr" "Check basic matching with --mmap flag"
778d7b65474SEd Maste}
779d7b65474SEd Mastemmap_body()
780d7b65474SEd Maste{
781d7b65474SEd Maste	grep_type
782d7b65474SEd Maste	if [ $? -eq $GREP_TYPE_GNU ]; then
783d7b65474SEd Maste		atf_expect_fail "gnu grep from ports has no --mmap option"
784d7b65474SEd Maste	fi
785d7b65474SEd Maste
786d7b65474SEd Maste	printf "A\nB\nC\n" > test1
787d7b65474SEd Maste
788d7b65474SEd Maste	atf_check -s exit:0 -o inline:"B\n" grep --mmap -oe "B" test1
789d7b65474SEd Maste	atf_check -s exit:1 grep --mmap -e "Z" test1
790d7b65474SEd Maste}
791d7b65474SEd Maste
7920e957942SKyle Evansatf_test_case matchall
7930e957942SKyle Evansmatchall_head()
7940e957942SKyle Evans{
7950e957942SKyle Evans	atf_set "descr" "Check proper behavior of matching all with an empty string"
7960e957942SKyle Evans}
7970e957942SKyle Evansmatchall_body()
7980e957942SKyle Evans{
7990e957942SKyle Evans	printf "" > test1
8000e957942SKyle Evans	printf "A" > test2
8010e957942SKyle Evans	printf "A\nB" > test3
8020e957942SKyle Evans
8030e957942SKyle Evans	atf_check -o inline:"test2:A\ntest3:A\ntest3:B\n" grep "" test1 test2 test3
8040e957942SKyle Evans	atf_check -o inline:"test3:A\ntest3:B\ntest2:A\n" grep "" test3 test1 test2
8050e957942SKyle Evans	atf_check -o inline:"test2:A\ntest3:A\ntest3:B\n" grep "" test2 test3 test1
8060e957942SKyle Evans
8070e957942SKyle Evans	atf_check -s exit:1 grep "" test1
8080e957942SKyle Evans}
809c552f48bSKyle Evans
810c552f48bSKyle Evansatf_test_case fgrep_multipattern
811c552f48bSKyle Evansfgrep_multipattern_head()
812c552f48bSKyle Evans{
813c552f48bSKyle Evans	atf_set "descr" "Check proper behavior with multiple patterns supplied to fgrep"
814c552f48bSKyle Evans}
815c552f48bSKyle Evansfgrep_multipattern_body()
816c552f48bSKyle Evans{
817c552f48bSKyle Evans	printf "Foo\nBar\nBaz" > test1
818c552f48bSKyle Evans
819c552f48bSKyle Evans	atf_check -o inline:"Foo\nBaz\n" grep -F -e "Foo" -e "Baz" test1
820c552f48bSKyle Evans	atf_check -o inline:"Foo\nBaz\n" grep -F -e "Baz" -e "Foo" test1
821c552f48bSKyle Evans	atf_check -o inline:"Bar\nBaz\n" grep -F -e "Bar" -e "Baz" test1
822c552f48bSKyle Evans}
823c552f48bSKyle Evans
824c552f48bSKyle Evansatf_test_case fgrep_icase
825c552f48bSKyle Evansfgrep_icase_head()
826c552f48bSKyle Evans{
827c552f48bSKyle Evans	atf_set "descr" "Check proper handling of -i supplied to fgrep"
828c552f48bSKyle Evans}
829c552f48bSKyle Evansfgrep_icase_body()
830c552f48bSKyle Evans{
831c552f48bSKyle Evans	printf "Foo\nBar\nBaz" > test1
832c552f48bSKyle Evans
833c552f48bSKyle Evans	atf_check -o inline:"Foo\nBaz\n" grep -Fi -e "foo" -e "baz" test1
834c552f48bSKyle Evans	atf_check -o inline:"Foo\nBaz\n" grep -Fi -e "baz" -e "foo" test1
835c552f48bSKyle Evans	atf_check -o inline:"Bar\nBaz\n" grep -Fi -e "bar" -e "baz" test1
836c552f48bSKyle Evans	atf_check -o inline:"Bar\nBaz\n" grep -Fi -e "BAR" -e "bAz" test1
837c552f48bSKyle Evans}
838c552f48bSKyle Evans
839c552f48bSKyle Evansatf_test_case fgrep_oflag
840c552f48bSKyle Evansfgrep_oflag_head()
841c552f48bSKyle Evans{
842c552f48bSKyle Evans	atf_set "descr" "Check proper handling of -o supplied to fgrep"
843c552f48bSKyle Evans}
844c552f48bSKyle Evansfgrep_oflag_body()
845c552f48bSKyle Evans{
846c552f48bSKyle Evans	printf "abcdefghi\n" > test1
847c552f48bSKyle Evans
848c552f48bSKyle Evans	atf_check -o inline:"a\n" grep -Fo "a" test1
849c552f48bSKyle Evans	atf_check -o inline:"i\n" grep -Fo "i" test1
850c552f48bSKyle Evans	atf_check -o inline:"abc\n" grep -Fo "abc" test1
851c552f48bSKyle Evans	atf_check -o inline:"fgh\n" grep -Fo "fgh" test1
852c552f48bSKyle Evans	atf_check -o inline:"cde\n" grep -Fo "cde" test1
853c552f48bSKyle Evans	atf_check -o inline:"bcd\n" grep -Fo -e "bcd" -e "cde" test1
854c552f48bSKyle Evans	atf_check -o inline:"bcd\nefg\n" grep -Fo -e "bcd" -e "efg" test1
855c552f48bSKyle Evans
856c552f48bSKyle Evans	atf_check -s exit:1 grep -Fo "xabc" test1
857c552f48bSKyle Evans	atf_check -s exit:1 grep -Fo "abcx" test1
858c552f48bSKyle Evans	atf_check -s exit:1 grep -Fo "xghi" test1
859c552f48bSKyle Evans	atf_check -s exit:1 grep -Fo "ghix" test1
860c552f48bSKyle Evans	atf_check -s exit:1 grep -Fo "abcdefghiklmnopqrstuvwxyz" test1
861c552f48bSKyle Evans}
862ce024bdcSKyle Evans
863ce024bdcSKyle Evansatf_test_case cflag
864ce024bdcSKyle Evanscflag_head()
865ce024bdcSKyle Evans{
866ce024bdcSKyle Evans	atf_set "descr" "Check proper handling of -c"
867ce024bdcSKyle Evans}
868ce024bdcSKyle Evanscflag_body()
869ce024bdcSKyle Evans{
870ce024bdcSKyle Evans	printf "a\nb\nc\n" > test1
871ce024bdcSKyle Evans
872ce024bdcSKyle Evans	atf_check -o inline:"1\n" grep -Ec "a" test1
873ce024bdcSKyle Evans	atf_check -o inline:"2\n" grep -Ec "a|b" test1
874ce024bdcSKyle Evans	atf_check -o inline:"3\n" grep -Ec "a|b|c" test1
875ce024bdcSKyle Evans
876ce024bdcSKyle Evans	atf_check -o inline:"test1:2\n" grep -EHc "a|b" test1
877ce024bdcSKyle Evans}
87852cf8965SKyle Evans
87952cf8965SKyle Evansatf_test_case mflag
88052cf8965SKyle Evansmflag_head()
88152cf8965SKyle Evans{
88252cf8965SKyle Evans	atf_set "descr" "Check proper handling of -m"
88352cf8965SKyle Evans}
88452cf8965SKyle Evansmflag_body()
88552cf8965SKyle Evans{
88652cf8965SKyle Evans	printf "a\nb\nc\nd\ne\nf\n" > test1
88752cf8965SKyle Evans
88852cf8965SKyle Evans	atf_check -o inline:"1\n" grep -m 1 -Ec "a" test1
88952cf8965SKyle Evans	atf_check -o inline:"2\n" grep -m 2 -Ec "a|b" test1
89052cf8965SKyle Evans	atf_check -o inline:"3\n" grep -m 3 -Ec "a|b|c|f" test1
89152cf8965SKyle Evans
89252cf8965SKyle Evans	atf_check -o inline:"test1:2\n" grep -m 2 -EHc "a|b|e|f" test1
89352cf8965SKyle Evans}
894*63c8336dSEric van Gyzen
895*63c8336dSEric van Gyzenatf_test_case zgrep_multiple_files
896*63c8336dSEric van Gyzenzgrep_multiple_files_head()
897*63c8336dSEric van Gyzen{
898*63c8336dSEric van Gyzen	atf_set "descr" "Ensures that zgrep functions properly with multiple files"
899*63c8336dSEric van Gyzen}
900*63c8336dSEric van Gyzenzgrep_multiple_files_body()
901*63c8336dSEric van Gyzen{
902*63c8336dSEric van Gyzen	echo foo > test1
903*63c8336dSEric van Gyzen	echo foo > test2
904*63c8336dSEric van Gyzen	atf_check -o inline:"test1:foo\ntest2:foo\n" zgrep foo test1 test2
905*63c8336dSEric van Gyzen
906*63c8336dSEric van Gyzen	echo bar > test1
907*63c8336dSEric van Gyzen	atf_check -o inline:"test2:foo\n" zgrep foo test1 test2
908*63c8336dSEric van Gyzen
909*63c8336dSEric van Gyzen	echo bar > test2
910*63c8336dSEric van Gyzen	atf_check -s exit:1 zgrep foo test1 test2
911*63c8336dSEric van Gyzen}
912799c5faaSEd Maste# End FreeBSD
91357718be8SEnji Cooper
91457718be8SEnji Cooperatf_init_test_cases()
91557718be8SEnji Cooper{
91657718be8SEnji Cooper	atf_add_test_case basic
91757718be8SEnji Cooper	atf_add_test_case binary
91857718be8SEnji Cooper	atf_add_test_case recurse
91957718be8SEnji Cooper	atf_add_test_case recurse_symlink
92057718be8SEnji Cooper	atf_add_test_case word_regexps
92157718be8SEnji Cooper	atf_add_test_case begin_end
92257718be8SEnji Cooper	atf_add_test_case ignore_case
92357718be8SEnji Cooper	atf_add_test_case invert
92457718be8SEnji Cooper	atf_add_test_case whole_line
92557718be8SEnji Cooper	atf_add_test_case negative
92657718be8SEnji Cooper	atf_add_test_case context
92757718be8SEnji Cooper	atf_add_test_case file_exp
92857718be8SEnji Cooper	atf_add_test_case egrep
92957718be8SEnji Cooper	atf_add_test_case zgrep
930c4cbf1fbSCraig Leres	atf_add_test_case zgrep_combined_flags
931c4cbf1fbSCraig Leres	atf_add_test_case zgrep_eflag
932c4cbf1fbSCraig Leres	atf_add_test_case zgrep_empty_eflag
933c4cbf1fbSCraig Leres	atf_add_test_case zgrep_fflag
934c4cbf1fbSCraig Leres	atf_add_test_case zgrep_long_eflag
935c4cbf1fbSCraig Leres	atf_add_test_case zgrep_multiple_eflags
93657718be8SEnji Cooper	atf_add_test_case nonexistent
93757718be8SEnji Cooper	atf_add_test_case context2
938799c5faaSEd Maste# Begin FreeBSD
939799c5faaSEd Maste	atf_add_test_case oflag_zerolen
940799c5faaSEd Maste	atf_add_test_case xflag
941799c5faaSEd Maste	atf_add_test_case color
942799c5faaSEd Maste	atf_add_test_case f_file_empty
943799c5faaSEd Maste	atf_add_test_case escmap
944799c5faaSEd Maste	atf_add_test_case egrep_empty_invalid
945e06ffa32SEd Maste	atf_add_test_case zerolen
946a4f3f02bSEd Maste	atf_add_test_case wflag_emptypat
94738325e2aSKyle Evans	atf_add_test_case xflag_emptypat
94838325e2aSKyle Evans	atf_add_test_case xflag_emptypat_plus
949fe8c9d5bSEd Maste	atf_add_test_case excessive_matches
950945fc991SEd Maste	atf_add_test_case wv_combo_break
9515199917cSEnji Cooper	atf_add_test_case fgrep_sanity
9525199917cSEnji Cooper	atf_add_test_case egrep_sanity
9535199917cSEnji Cooper	atf_add_test_case grep_sanity
9546d635d3bSEd Maste	atf_add_test_case ocolor_metadata
955e2127de8SEd Maste	atf_add_test_case grep_nomatch_flags
956f701bdc5SEd Maste	atf_add_test_case binary_flags
957b5fc583cSEd Maste	atf_add_test_case badcontext
958d7b65474SEd Maste	atf_add_test_case mmap
9590e957942SKyle Evans	atf_add_test_case matchall
960c552f48bSKyle Evans	atf_add_test_case fgrep_multipattern
961c552f48bSKyle Evans	atf_add_test_case fgrep_icase
962c552f48bSKyle Evans	atf_add_test_case fgrep_oflag
963ce024bdcSKyle Evans	atf_add_test_case cflag
96452cf8965SKyle Evans	atf_add_test_case mflag
965*63c8336dSEric van Gyzen	atf_add_test_case zgrep_multiple_files
966799c5faaSEd Maste# End FreeBSD
96757718be8SEnji Cooper}
968