xref: /freebsd/contrib/netbsd-tests/usr.bin/grep/t_grep.sh (revision 38325e2ab8f0c7823e31df13bfc52e38e7f6d616)
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
21757718be8SEnji Cooperatf_test_case nonexistent
21857718be8SEnji Coopernonexistent_head()
21957718be8SEnji Cooper{
22057718be8SEnji Cooper	atf_set "descr" "Checks that -s flag suppresses error" \
22157718be8SEnji Cooper	                "messages about nonexistent files"
22257718be8SEnji Cooper}
22357718be8SEnji Coopernonexistent_body()
22457718be8SEnji Cooper{
22557718be8SEnji Cooper	atf_check -s ne:0 grep -s foobar nonexistent
22657718be8SEnji Cooper}
22757718be8SEnji Cooper
22857718be8SEnji Cooperatf_test_case context2
22957718be8SEnji Coopercontext2_head()
23057718be8SEnji Cooper{
23157718be8SEnji Cooper	atf_set "descr" "Checks displaying context with -z flag"
23257718be8SEnji Cooper}
23357718be8SEnji Coopercontext2_body()
23457718be8SEnji Cooper{
23557718be8SEnji Cooper	printf "haddock\000cod\000plaice\000" > test1
23657718be8SEnji Cooper	printf "mackeral\000cod\000crab\000" > test2
23757718be8SEnji Cooper
23857718be8SEnji Cooper	atf_check -o file:"$(atf_get_srcdir)/d_context2_a.out" \
23957718be8SEnji Cooper	    grep -z -A1 cod test1 test2
24057718be8SEnji Cooper
24157718be8SEnji Cooper	atf_check -o file:"$(atf_get_srcdir)/d_context2_b.out" \
24257718be8SEnji Cooper	    grep -z -B1 cod test1 test2
24357718be8SEnji Cooper
24457718be8SEnji Cooper	atf_check -o file:"$(atf_get_srcdir)/d_context2_c.out" \
24557718be8SEnji Cooper	    grep -z -C1 cod test1 test2
24657718be8SEnji Cooper}
247799c5faaSEd Maste# Begin FreeBSD
2489f67a481SEnji Cooper
2499f67a481SEnji Cooper# What grep(1) are we working with?
2509f67a481SEnji Cooper# - 0 : bsdgrep
2519f67a481SEnji Cooper# - 1 : gnu grep 2.51 (base)
2529f67a481SEnji Cooper# - 2 : gnu grep (ports)
2539f67a481SEnji CooperGREP_TYPE_BSD=0
2549f67a481SEnji CooperGREP_TYPE_GNU_FREEBSD=1
2559f67a481SEnji CooperGREP_TYPE_GNU=2
2569f67a481SEnji CooperGREP_TYPE_UNKNOWN=3
2579f67a481SEnji Cooper
2589f67a481SEnji Coopergrep_type()
2599f67a481SEnji Cooper{
2609f67a481SEnji Cooper	local grep_version=$(grep --version)
2619f67a481SEnji Cooper
2629f67a481SEnji Cooper	case "$grep_version" in
2639f67a481SEnji Cooper	*"BSD grep"*)
2649f67a481SEnji Cooper		return $GREP_TYPE_BSD
2659f67a481SEnji Cooper		;;
2669f67a481SEnji Cooper	*"GNU grep"*)
2679f67a481SEnji Cooper		case "$grep_version" in
2689f67a481SEnji Cooper		*2.5.1-FreeBSD*)
2699f67a481SEnji Cooper			return $GREP_TYPE_GNU_FREEBSD
2709f67a481SEnji Cooper			;;
2719f67a481SEnji Cooper		*)
2729f67a481SEnji Cooper			return $GREP_TYPE_GNU
2739f67a481SEnji Cooper			;;
2749f67a481SEnji Cooper		esac
2759f67a481SEnji Cooper		;;
2769f67a481SEnji Cooper	esac
2779f67a481SEnji Cooper	atf_fail "unknown grep type: $grep_version"
2789f67a481SEnji Cooper}
2799f67a481SEnji Cooper
280799c5faaSEd Masteatf_test_case oflag_zerolen
281799c5faaSEd Masteoflag_zerolen_head()
282799c5faaSEd Maste{
283799c5faaSEd Maste	atf_set "descr" "Check behavior of zero-length matches with -o flag (PR 195763)"
284799c5faaSEd Maste}
285799c5faaSEd Masteoflag_zerolen_body()
286799c5faaSEd Maste{
2879f67a481SEnji Cooper	grep_type
2889f67a481SEnji Cooper	if [ $? -eq $GREP_TYPE_GNU_FREEBSD ]; then
2899f67a481SEnji Cooper		atf_expect_fail "this test doesn't pass with gnu grep in base"
2909f67a481SEnji Cooper	fi
2919f67a481SEnji Cooper
292799c5faaSEd Maste	atf_check -o file:"$(atf_get_srcdir)/d_oflag_zerolen_a.out" \
293799c5faaSEd Maste	    grep -Eo '(^|:)0*' "$(atf_get_srcdir)/d_oflag_zerolen_a.in"
294799c5faaSEd Maste
295799c5faaSEd Maste	atf_check -o file:"$(atf_get_srcdir)/d_oflag_zerolen_b.out" \
296799c5faaSEd Maste	    grep -Eo '(^|:)0*' "$(atf_get_srcdir)/d_oflag_zerolen_b.in"
297799c5faaSEd Maste
298799c5faaSEd Maste	atf_check -o file:"$(atf_get_srcdir)/d_oflag_zerolen_c.out" \
299799c5faaSEd Maste	    grep -Eo '[[:alnum:]]*' "$(atf_get_srcdir)/d_oflag_zerolen_c.in"
300799c5faaSEd Maste
301799c5faaSEd Maste	atf_check -o empty grep -Eo '' "$(atf_get_srcdir)/d_oflag_zerolen_d.in"
302799c5faaSEd Maste
303799c5faaSEd Maste	atf_check -o file:"$(atf_get_srcdir)/d_oflag_zerolen_e.out" \
304799c5faaSEd Maste	    grep -o -e 'ab' -e 'bc' "$(atf_get_srcdir)/d_oflag_zerolen_e.in"
305799c5faaSEd Maste
306799c5faaSEd Maste	atf_check -o file:"$(atf_get_srcdir)/d_oflag_zerolen_e.out" \
307799c5faaSEd Maste	    grep -o -e 'bc' -e 'ab' "$(atf_get_srcdir)/d_oflag_zerolen_e.in"
308799c5faaSEd Maste}
309799c5faaSEd Maste
310799c5faaSEd Masteatf_test_case xflag
311799c5faaSEd Mastexflag_head()
312799c5faaSEd Maste{
313799c5faaSEd Maste	atf_set "descr" "Check that we actually get a match with -x flag (PR 180990)"
314799c5faaSEd Maste}
315799c5faaSEd Mastexflag_body()
316799c5faaSEd Maste{
317799c5faaSEd Maste	echo 128 > match_file
318799c5faaSEd Maste	seq 1 128 > pattern_file
319799c5faaSEd Maste	grep -xf pattern_file match_file
320799c5faaSEd Maste}
321799c5faaSEd Maste
322799c5faaSEd Masteatf_test_case color
323799c5faaSEd Mastecolor_head()
324799c5faaSEd Maste{
325799c5faaSEd Maste	atf_set "descr" "Check --color support"
326799c5faaSEd Maste}
327799c5faaSEd Mastecolor_body()
328799c5faaSEd Maste{
3299f67a481SEnji Cooper	grep_type
3309f67a481SEnji Cooper	if [ $? -eq $GREP_TYPE_GNU_FREEBSD ]; then
3319f67a481SEnji Cooper		atf_expect_fail "this test doesn't pass with gnu grep in base"
3329f67a481SEnji Cooper	fi
3339f67a481SEnji Cooper
334799c5faaSEd Maste	echo 'abcd*' > grepfile
335799c5faaSEd Maste	echo 'abc$' >> grepfile
336799c5faaSEd Maste	echo '^abc' >> grepfile
337799c5faaSEd Maste
338799c5faaSEd Maste	atf_check -o file:"$(atf_get_srcdir)/d_color_a.out" \
339799c5faaSEd Maste	    grep --color=auto -e '.*' -e 'a' "$(atf_get_srcdir)/d_color_a.in"
340799c5faaSEd Maste
341799c5faaSEd Maste	atf_check -o file:"$(atf_get_srcdir)/d_color_b.out" \
342799c5faaSEd Maste	    grep --color=auto -f grepfile "$(atf_get_srcdir)/d_color_b.in"
343799c5faaSEd Maste
344799c5faaSEd Maste	atf_check -o file:"$(atf_get_srcdir)/d_color_c.out" \
345799c5faaSEd Maste	    grep --color=always -f grepfile "$(atf_get_srcdir)/d_color_b.in"
346799c5faaSEd Maste}
347799c5faaSEd Maste
348799c5faaSEd Masteatf_test_case f_file_empty
349799c5faaSEd Mastef_file_empty_head()
350799c5faaSEd Maste{
351799c5faaSEd Maste	atf_set "descr" "Check for handling of a null byte in empty file, specified by -f (PR 202022)"
352799c5faaSEd Maste}
353799c5faaSEd Mastef_file_empty_body()
354799c5faaSEd Maste{
355799c5faaSEd Maste	printf "\0\n" > nulpat
356799c5faaSEd Maste
357799c5faaSEd Maste	atf_check -s exit:1 grep -f nulpat "$(atf_get_srcdir)/d_f_file_empty.in"
358799c5faaSEd Maste}
359799c5faaSEd Maste
360799c5faaSEd Masteatf_test_case escmap
361799c5faaSEd Masteescmap_head()
362799c5faaSEd Maste{
363799c5faaSEd Maste	atf_set "descr" "Check proper handling of escaped vs. unescaped dot expressions (PR 175314)"
364799c5faaSEd Maste}
365799c5faaSEd Masteescmap_body()
366799c5faaSEd Maste{
367799c5faaSEd Maste	atf_check -s exit:1 grep -o 'f.o\.' "$(atf_get_srcdir)/d_escmap.in"
368799c5faaSEd Maste	atf_check -o not-empty grep -o 'f.o.' "$(atf_get_srcdir)/d_escmap.in"
369799c5faaSEd Maste}
370799c5faaSEd Maste
371799c5faaSEd Masteatf_test_case egrep_empty_invalid
372799c5faaSEd Masteegrep_empty_invalid_head()
373799c5faaSEd Maste{
374799c5faaSEd Maste	atf_set "descr" "Check for handling of an invalid empty pattern (PR 194823)"
375799c5faaSEd Maste}
376799c5faaSEd Masteegrep_empty_invalid_body()
377799c5faaSEd Maste{
378befd089cSEd Maste	atf_check -e ignore -s not-exit:0 egrep '{' /dev/null
379799c5faaSEd Maste}
380e06ffa32SEd Maste
381e06ffa32SEd Masteatf_test_case zerolen
382e06ffa32SEd Mastezerolen_head()
383e06ffa32SEd Maste{
384e06ffa32SEd Maste	atf_set "descr" "Check for successful zero-length matches with ^$"
385e06ffa32SEd Maste}
386e06ffa32SEd Mastezerolen_body()
387e06ffa32SEd Maste{
388e06ffa32SEd Maste	printf "Eggs\n\nCheese" > test1
389e06ffa32SEd Maste
390e06ffa32SEd Maste	atf_check -o inline:"\n" grep -e "^$" test1
391e06ffa32SEd Maste
392e06ffa32SEd Maste	atf_check -o inline:"Eggs\nCheese\n" grep -v -e "^$" test1
393e06ffa32SEd Maste}
3945199917cSEnji Cooper
395a4f3f02bSEd Masteatf_test_case wflag_emptypat
396a4f3f02bSEd Mastewflag_emptypat_head()
397a4f3f02bSEd Maste{
398a4f3f02bSEd Maste	atf_set "descr" "Check for proper handling of -w with an empty pattern (PR 105221)"
399a4f3f02bSEd Maste}
400a4f3f02bSEd Mastewflag_emptypat_body()
401a4f3f02bSEd Maste{
402a4f3f02bSEd Maste	printf "" > test1
403a4f3f02bSEd Maste	printf "\n" > test2
404a4f3f02bSEd Maste	printf "qaz" > test3
405a4f3f02bSEd Maste	printf " qaz\n" > test4
406a4f3f02bSEd Maste
407a4f3f02bSEd Maste	atf_check -s exit:1 -o empty grep -w -e "" test1
408a4f3f02bSEd Maste
409a4f3f02bSEd Maste	atf_check -o file:test2 grep -w -e "" test2
410a4f3f02bSEd Maste
411a4f3f02bSEd Maste	atf_check -s exit:1 -o empty grep -w -e "" test3
412a4f3f02bSEd Maste
413a4f3f02bSEd Maste	atf_check -o file:test4 grep -w -e "" test4
414a4f3f02bSEd Maste}
415a4f3f02bSEd Maste
416*38325e2aSKyle Evansatf_test_case xflag_emptypat
417*38325e2aSKyle Evansxflag_emptypat_body()
418*38325e2aSKyle Evans{
419*38325e2aSKyle Evans	printf "" > test1
420*38325e2aSKyle Evans	printf "\n" > test2
421*38325e2aSKyle Evans	printf "qaz" > test3
422*38325e2aSKyle Evans	printf " qaz\n" > test4
423*38325e2aSKyle Evans
424*38325e2aSKyle Evans	# -x is whole-line, more strict than -w.
425*38325e2aSKyle Evans	atf_check -s exit:1 -o empty grep -x -e "" test1
426*38325e2aSKyle Evans
427*38325e2aSKyle Evans	atf_check -o file:test2 grep -x -e "" test2
428*38325e2aSKyle Evans
429*38325e2aSKyle Evans	atf_check -s exit:1 -o empty grep -x -e "" test3
430*38325e2aSKyle Evans
431*38325e2aSKyle Evans	atf_check -s exit:1 -o empty grep -x -e "" test4
432*38325e2aSKyle Evans
433*38325e2aSKyle Evans	total=$(wc -l /COPYRIGHT | sed 's/[^0-9]//g')
434*38325e2aSKyle Evans
435*38325e2aSKyle Evans	# Simple checks that grep -x with an empty pattern isn't matching every
436*38325e2aSKyle Evans	# line.  The exact counts aren't important, as long as they don't
437*38325e2aSKyle Evans	# match the total line count and as long as they don't match each other.
438*38325e2aSKyle Evans	atf_check -o save:xpositive.count grep -Fxc '' /COPYRIGHT
439*38325e2aSKyle Evans	atf_check -o save:xnegative.count grep -Fvxc '' /COPYRIGHT
440*38325e2aSKyle Evans
441*38325e2aSKyle Evans	atf_check -o not-inline:"${total}" cat xpositive.count
442*38325e2aSKyle Evans	atf_check -o not-inline:"${total}" cat xnegative.count
443*38325e2aSKyle Evans
444*38325e2aSKyle Evans	atf_check -o not-file:xnegative.count cat xpositive.count
445*38325e2aSKyle Evans}
446*38325e2aSKyle Evans
447*38325e2aSKyle Evansatf_test_case xflag_emptypat_plus
448*38325e2aSKyle Evansxflag_emptypat_plus_body()
449*38325e2aSKyle Evans{
450*38325e2aSKyle Evans	printf "foo\n\nbar\n\nbaz\n" > target
451*38325e2aSKyle Evans	printf "foo\n \nbar\n \nbaz\n" > target_spacelines
452*38325e2aSKyle Evans	printf "foo\nbar\nbaz\n" > matches
453*38325e2aSKyle Evans	printf " \n \n" > spacelines
454*38325e2aSKyle Evans
455*38325e2aSKyle Evans	printf "foo\n\nbar\n\nbaz\n" > patlist1
456*38325e2aSKyle Evans	printf "foo\n\nba\n\nbaz\n" > patlist2
457*38325e2aSKyle Evans
458*38325e2aSKyle Evans	sed -e '/bar/d' target > matches_not2
459*38325e2aSKyle Evans
460*38325e2aSKyle Evans	# Normal handling first
461*38325e2aSKyle Evans	atf_check -o file:target grep -Fxf patlist1 target
462*38325e2aSKyle Evans	atf_check -o file:matches grep -Fxf patlist1 target_spacelines
463*38325e2aSKyle Evans	atf_check -o file:matches_not2 grep -Fxf patlist2 target
464*38325e2aSKyle Evans
465*38325e2aSKyle Evans	# -v handling
466*38325e2aSKyle Evans	atf_check -s exit:1 -o empty grep -Fvxf patlist1 target
467*38325e2aSKyle Evans	atf_check -o file:spacelines grep -Fxvf patlist1 target_spacelines
468*38325e2aSKyle Evans}
469*38325e2aSKyle Evans
470fe8c9d5bSEd Masteatf_test_case excessive_matches
471fe8c9d5bSEd Masteexcessive_matches_head()
472fe8c9d5bSEd Maste{
473fe8c9d5bSEd Maste	atf_set "descr" "Check for proper handling of lines with excessive matches (PR 218811)"
474fe8c9d5bSEd Maste}
475fe8c9d5bSEd Masteexcessive_matches_body()
476fe8c9d5bSEd Maste{
477fe8c9d5bSEd Maste	grep_type
478fe8c9d5bSEd Maste	if [ $? -eq $GREP_TYPE_GNU_FREEBSD ]; then
479fe8c9d5bSEd Maste		atf_expect_fail "this test does not pass with GNU grep in base"
480fe8c9d5bSEd Maste	fi
481fe8c9d5bSEd Maste
482fe8c9d5bSEd Maste	for i in $(jot 4096); do
483fe8c9d5bSEd Maste		printf "x" >> test.in
484fe8c9d5bSEd Maste	done
485fe8c9d5bSEd Maste
486fe8c9d5bSEd Maste	atf_check -s exit:0 -x '[ $(grep -o x test.in | wc -l) -eq 4096 ]'
4876d635d3bSEd Maste	atf_check -s exit:1 -x 'grep -on x test.in | grep -v "1:x"'
488fe8c9d5bSEd Maste}
489fe8c9d5bSEd Maste
4905199917cSEnji Cooperatf_test_case fgrep_sanity
4915199917cSEnji Cooperfgrep_sanity_head()
4925199917cSEnji Cooper{
4935199917cSEnji Cooper	atf_set "descr" "Check for fgrep sanity, literal expressions only"
4945199917cSEnji Cooper}
4955199917cSEnji Cooperfgrep_sanity_body()
4965199917cSEnji Cooper{
4975199917cSEnji Cooper	printf "Foo" > test1
4985199917cSEnji Cooper
4995199917cSEnji Cooper	atf_check -o inline:"Foo\n" fgrep -e "Foo" test1
5005199917cSEnji Cooper
5015199917cSEnji Cooper	atf_check -s exit:1 -o empty fgrep -e "Fo." test1
5025199917cSEnji Cooper}
5035199917cSEnji Cooper
5045199917cSEnji Cooperatf_test_case egrep_sanity
5055199917cSEnji Cooperegrep_sanity_head()
5065199917cSEnji Cooper{
5075199917cSEnji Cooper	atf_set "descr" "Check for egrep sanity, EREs only"
5085199917cSEnji Cooper}
5095199917cSEnji Cooperegrep_sanity_body()
5105199917cSEnji Cooper{
5115199917cSEnji Cooper	printf "Foobar(ed)" > test1
5125199917cSEnji Cooper	printf "M{1}" > test2
5135199917cSEnji Cooper
5145199917cSEnji Cooper	atf_check -o inline:"Foo\n" egrep -o -e "F.." test1
5155199917cSEnji Cooper
5165199917cSEnji Cooper	atf_check -o inline:"Foobar\n" egrep -o -e "F[a-z]*" test1
5175199917cSEnji Cooper
5185199917cSEnji Cooper	atf_check -o inline:"Fo\n" egrep -o -e "F(o|p)" test1
5195199917cSEnji Cooper
5205199917cSEnji Cooper	atf_check -o inline:"(ed)\n" egrep -o -e "\(ed\)" test1
5215199917cSEnji Cooper
5225199917cSEnji Cooper	atf_check -o inline:"M\n" egrep -o -e "M{1}" test2
5235199917cSEnji Cooper
5245199917cSEnji Cooper	atf_check -o inline:"M{1}\n" egrep -o -e "M\{1\}" test2
5255199917cSEnji Cooper}
5265199917cSEnji Cooper
5275199917cSEnji Cooperatf_test_case grep_sanity
5285199917cSEnji Coopergrep_sanity_head()
5295199917cSEnji Cooper{
5305199917cSEnji Cooper	atf_set "descr" "Check for basic grep sanity, BREs only"
5315199917cSEnji Cooper}
5325199917cSEnji Coopergrep_sanity_body()
5335199917cSEnji Cooper{
5345199917cSEnji Cooper	printf "Foobar(ed)" > test1
5355199917cSEnji Cooper	printf "M{1}" > test2
5365199917cSEnji Cooper
5375199917cSEnji Cooper	atf_check -o inline:"Foo\n" grep -o -e "F.." test1
5385199917cSEnji Cooper
5395199917cSEnji Cooper	atf_check -o inline:"Foobar\n" grep -o -e "F[a-z]*" test1
5405199917cSEnji Cooper
5415199917cSEnji Cooper	atf_check -o inline:"Fo\n" grep -o -e "F\(o\)" test1
5425199917cSEnji Cooper
5435199917cSEnji Cooper	atf_check -o inline:"(ed)\n" grep -o -e "(ed)" test1
5445199917cSEnji Cooper
5455199917cSEnji Cooper	atf_check -o inline:"M{1}\n" grep -o -e "M{1}" test2
5465199917cSEnji Cooper
5475199917cSEnji Cooper	atf_check -o inline:"M\n" grep -o -e "M\{1\}" test2
5485199917cSEnji Cooper}
549945fc991SEd Maste
550945fc991SEd Masteatf_test_case wv_combo_break
551945fc991SEd Mastewv_combo_break_head()
552945fc991SEd Maste{
553945fc991SEd Maste	atf_set "descr" "Check for incorrectly matching lines with both -w and -v flags (PR 218467)"
554945fc991SEd Maste}
555945fc991SEd Mastewv_combo_break_body()
556945fc991SEd Maste{
557945fc991SEd Maste	printf "x xx\n" > test1
558945fc991SEd Maste	printf "xx x\n" > test2
559945fc991SEd Maste
560945fc991SEd Maste	atf_check -o file:test1 grep -w "x" test1
561945fc991SEd Maste	atf_check -o file:test2 grep -w "x" test2
562945fc991SEd Maste
563945fc991SEd Maste	atf_check -s exit:1 grep -v -w "x" test1
564945fc991SEd Maste	atf_check -s exit:1 grep -v -w "x" test2
565945fc991SEd Maste}
566e2127de8SEd Maste
5676d635d3bSEd Masteatf_test_case ocolor_metadata
5686d635d3bSEd Masteocolor_metadata_head()
5696d635d3bSEd Maste{
5706d635d3bSEd Maste	atf_set "descr" "Check for -n/-b producing per-line metadata output"
5716d635d3bSEd Maste}
5726d635d3bSEd Masteocolor_metadata_body()
5736d635d3bSEd Maste{
5746d635d3bSEd Maste	grep_type
5756d635d3bSEd Maste	if [ $? -eq $GREP_TYPE_GNU_FREEBSD ]; then
5766d635d3bSEd Maste		atf_expect_fail "this test does not pass with GNU grep in base"
5776d635d3bSEd Maste	fi
5786d635d3bSEd Maste
5796d635d3bSEd Maste	printf "xxx\nyyyy\nzzz\nfoobarbaz\n" > test1
5806d635d3bSEd Maste	check_expr="^[^:]*[0-9][^:]*:[^:]+$"
5816d635d3bSEd Maste
5826d635d3bSEd Maste	atf_check -o inline:"1:1:xx\n" grep -bon "xx$" test1
5836d635d3bSEd Maste
5846d635d3bSEd Maste	atf_check -o inline:"2:4:yyyy\n" grep -bn "yy" test1
5856d635d3bSEd Maste
5866d635d3bSEd Maste	atf_check -o inline:"2:6:yy\n" grep -bon "yy$" test1
5876d635d3bSEd Maste
5886d635d3bSEd Maste	# These checks ensure that grep isn't producing bogus line numbering
5896d635d3bSEd Maste	# in the middle of a line.
5906d635d3bSEd Maste	atf_check -s exit:1 -x \
5916d635d3bSEd Maste	    "grep -Eon 'x|y|z|f' test1 | grep -Ev '${check_expr}'"
5926d635d3bSEd Maste
5936d635d3bSEd Maste	atf_check -s exit:1 -x \
5946d635d3bSEd Maste	    "grep -En 'x|y|z|f' --color=always test1 | grep -Ev '${check_expr}'"
5956d635d3bSEd Maste
5966d635d3bSEd Maste	atf_check -s exit:1 -x \
5976d635d3bSEd Maste	    "grep -Eon 'x|y|z|f' --color=always test1 | grep -Ev '${check_expr}'"
5986d635d3bSEd Maste}
5996d635d3bSEd Maste
600e2127de8SEd Masteatf_test_case grep_nomatch_flags
601e2127de8SEd Mastegrep_nomatch_flags_head()
602e2127de8SEd Maste{
603e2127de8SEd Maste	atf_set "descr" "Check for no match (-c, -l, -L, -q) flags not producing line matches or context (PR 219077)"
604e2127de8SEd Maste}
605e2127de8SEd Maste
606e2127de8SEd Mastegrep_nomatch_flags_body()
607e2127de8SEd Maste{
608*38325e2aSKyle Evans	grep_type
609*38325e2aSKyle Evans
610*38325e2aSKyle Evans	if [ $? -eq $GREP_TYPE_GNU_FREEBSD ]; then
611*38325e2aSKyle Evans		atf_expect_fail "this test does not pass with GNU grep in base"
612*38325e2aSKyle Evans	fi
613*38325e2aSKyle Evans
614e2127de8SEd Maste	printf "A\nB\nC\n" > test1
615e2127de8SEd Maste
616e2127de8SEd Maste	atf_check -o inline:"1\n" grep -c -C 1 -e "B" test1
617e2127de8SEd Maste	atf_check -o inline:"1\n" grep -c -B 1 -e "B" test1
618e2127de8SEd Maste	atf_check -o inline:"1\n" grep -c -A 1 -e "B" test1
619e2127de8SEd Maste	atf_check -o inline:"1\n" grep -c -C 1 -e "B" test1
620e2127de8SEd Maste
621e2127de8SEd Maste	atf_check -o inline:"test1\n" grep -l -e "B" test1
622e2127de8SEd Maste	atf_check -o inline:"test1\n" grep -l -B 1 -e "B" test1
623e2127de8SEd Maste	atf_check -o inline:"test1\n" grep -l -A 1 -e "B" test1
624e2127de8SEd Maste	atf_check -o inline:"test1\n" grep -l -C 1 -e "B" test1
625e2127de8SEd Maste
626*38325e2aSKyle Evans	atf_check -o inline:"test1\n" grep -L -e "D" test1
627e2127de8SEd Maste
628e2127de8SEd Maste	atf_check -o empty grep -q -e "B" test1
629e2127de8SEd Maste	atf_check -o empty grep -q -B 1 -e "B" test1
630e2127de8SEd Maste	atf_check -o empty grep -q -A 1 -e "B" test1
631e2127de8SEd Maste	atf_check -o empty grep -q -C 1 -e "B" test1
632e2127de8SEd Maste}
633b5fc583cSEd Maste
634b5fc583cSEd Masteatf_test_case badcontext
635b5fc583cSEd Mastebadcontext_head()
636b5fc583cSEd Maste{
637b5fc583cSEd Maste	atf_set "descr" "Check for handling of invalid context arguments"
638b5fc583cSEd Maste}
639b5fc583cSEd Mastebadcontext_body()
640b5fc583cSEd Maste{
641b5fc583cSEd Maste	printf "A\nB\nC\n" > test1
642b5fc583cSEd Maste
643b5fc583cSEd Maste	atf_check -s not-exit:0 -e ignore grep -A "-1" "B" test1
644b5fc583cSEd Maste
645b5fc583cSEd Maste	atf_check -s not-exit:0 -e ignore grep -B "-1" "B" test1
646b5fc583cSEd Maste
647b5fc583cSEd Maste	atf_check -s not-exit:0 -e ignore grep -C "-1" "B" test1
648b5fc583cSEd Maste
649b5fc583cSEd Maste	atf_check -s not-exit:0 -e ignore grep -A "B" "B" test1
650b5fc583cSEd Maste
651b5fc583cSEd Maste	atf_check -s not-exit:0 -e ignore grep -B "B" "B" test1
652b5fc583cSEd Maste
653b5fc583cSEd Maste	atf_check -s not-exit:0 -e ignore grep -C "B" "B" test1
654b5fc583cSEd Maste}
655f701bdc5SEd Maste
656f701bdc5SEd Masteatf_test_case binary_flags
657f701bdc5SEd Mastebinary_flags_head()
658f701bdc5SEd Maste{
659f701bdc5SEd Maste	atf_set "descr" "Check output for binary flags (-a, -I, -U, --binary-files)"
660f701bdc5SEd Maste}
661f701bdc5SEd Mastebinary_flags_body()
662f701bdc5SEd Maste{
663f701bdc5SEd Maste	printf "A\000B\000C" > test1
664f701bdc5SEd Maste	printf "A\n\000B\n\000C" > test2
665f701bdc5SEd Maste	binmatchtext="Binary file test1 matches\n"
666f701bdc5SEd Maste
667f701bdc5SEd Maste	# Binaries not treated as text (default, -U)
668f701bdc5SEd Maste	atf_check -o inline:"${binmatchtext}" grep 'B' test1
669f701bdc5SEd Maste	atf_check -o inline:"${binmatchtext}" grep 'B' -C 1 test1
670f701bdc5SEd Maste
671f701bdc5SEd Maste	atf_check -o inline:"${binmatchtext}" grep -U 'B' test1
672f701bdc5SEd Maste	atf_check -o inline:"${binmatchtext}" grep -U 'B' -C 1 test1
673f701bdc5SEd Maste
674f701bdc5SEd Maste	# Binary, -a, no newlines
675f701bdc5SEd Maste	atf_check -o inline:"A\000B\000C\n" grep -a 'B' test1
676f701bdc5SEd Maste	atf_check -o inline:"A\000B\000C\n" grep -a 'B' -C 1 test1
677f701bdc5SEd Maste
678f701bdc5SEd Maste	# Binary, -a, newlines
679f701bdc5SEd Maste	atf_check -o inline:"\000B\n" grep -a 'B' test2
680f701bdc5SEd Maste	atf_check -o inline:"A\n\000B\n\000C\n" grep -a 'B' -C 1 test2
681f701bdc5SEd Maste
682f701bdc5SEd Maste	# Binary files ignored
683f701bdc5SEd Maste	atf_check -s exit:1 grep -I 'B' test2
684f701bdc5SEd Maste
685f701bdc5SEd Maste	# --binary-files equivalence
686f701bdc5SEd Maste	atf_check -o inline:"${binmatchtext}" grep --binary-files=binary 'B' test1
687f701bdc5SEd Maste	atf_check -o inline:"A\000B\000C\n" grep --binary-files=text 'B' test1
688f701bdc5SEd Maste	atf_check -s exit:1 grep --binary-files=without-match 'B' test2
689f701bdc5SEd Maste}
690d7b65474SEd Maste
691d7b65474SEd Masteatf_test_case mmap
692d7b65474SEd Mastemmap_head()
693d7b65474SEd Maste{
694d7b65474SEd Maste	atf_set "descr" "Check basic matching with --mmap flag"
695d7b65474SEd Maste}
696d7b65474SEd Mastemmap_body()
697d7b65474SEd Maste{
698d7b65474SEd Maste	grep_type
699d7b65474SEd Maste	if [ $? -eq $GREP_TYPE_GNU ]; then
700d7b65474SEd Maste		atf_expect_fail "gnu grep from ports has no --mmap option"
701d7b65474SEd Maste	fi
702d7b65474SEd Maste
703d7b65474SEd Maste	printf "A\nB\nC\n" > test1
704d7b65474SEd Maste
705d7b65474SEd Maste	atf_check -s exit:0 -o inline:"B\n" grep --mmap -oe "B" test1
706d7b65474SEd Maste	atf_check -s exit:1 grep --mmap -e "Z" test1
707d7b65474SEd Maste}
708d7b65474SEd Maste
7090e957942SKyle Evansatf_test_case matchall
7100e957942SKyle Evansmatchall_head()
7110e957942SKyle Evans{
7120e957942SKyle Evans	atf_set "descr" "Check proper behavior of matching all with an empty string"
7130e957942SKyle Evans}
7140e957942SKyle Evansmatchall_body()
7150e957942SKyle Evans{
7160e957942SKyle Evans	printf "" > test1
7170e957942SKyle Evans	printf "A" > test2
7180e957942SKyle Evans	printf "A\nB" > test3
7190e957942SKyle Evans
7200e957942SKyle Evans	atf_check -o inline:"test2:A\ntest3:A\ntest3:B\n" grep "" test1 test2 test3
7210e957942SKyle Evans	atf_check -o inline:"test3:A\ntest3:B\ntest2:A\n" grep "" test3 test1 test2
7220e957942SKyle Evans	atf_check -o inline:"test2:A\ntest3:A\ntest3:B\n" grep "" test2 test3 test1
7230e957942SKyle Evans
7240e957942SKyle Evans	atf_check -s exit:1 grep "" test1
7250e957942SKyle Evans}
726c552f48bSKyle Evans
727c552f48bSKyle Evansatf_test_case fgrep_multipattern
728c552f48bSKyle Evansfgrep_multipattern_head()
729c552f48bSKyle Evans{
730c552f48bSKyle Evans	atf_set "descr" "Check proper behavior with multiple patterns supplied to fgrep"
731c552f48bSKyle Evans}
732c552f48bSKyle Evansfgrep_multipattern_body()
733c552f48bSKyle Evans{
734c552f48bSKyle Evans	printf "Foo\nBar\nBaz" > test1
735c552f48bSKyle Evans
736c552f48bSKyle Evans	atf_check -o inline:"Foo\nBaz\n" grep -F -e "Foo" -e "Baz" test1
737c552f48bSKyle Evans	atf_check -o inline:"Foo\nBaz\n" grep -F -e "Baz" -e "Foo" test1
738c552f48bSKyle Evans	atf_check -o inline:"Bar\nBaz\n" grep -F -e "Bar" -e "Baz" test1
739c552f48bSKyle Evans}
740c552f48bSKyle Evans
741c552f48bSKyle Evansatf_test_case fgrep_icase
742c552f48bSKyle Evansfgrep_icase_head()
743c552f48bSKyle Evans{
744c552f48bSKyle Evans	atf_set "descr" "Check proper handling of -i supplied to fgrep"
745c552f48bSKyle Evans}
746c552f48bSKyle Evansfgrep_icase_body()
747c552f48bSKyle Evans{
748c552f48bSKyle Evans	printf "Foo\nBar\nBaz" > test1
749c552f48bSKyle Evans
750c552f48bSKyle Evans	atf_check -o inline:"Foo\nBaz\n" grep -Fi -e "foo" -e "baz" test1
751c552f48bSKyle Evans	atf_check -o inline:"Foo\nBaz\n" grep -Fi -e "baz" -e "foo" test1
752c552f48bSKyle Evans	atf_check -o inline:"Bar\nBaz\n" grep -Fi -e "bar" -e "baz" test1
753c552f48bSKyle Evans	atf_check -o inline:"Bar\nBaz\n" grep -Fi -e "BAR" -e "bAz" test1
754c552f48bSKyle Evans}
755c552f48bSKyle Evans
756c552f48bSKyle Evansatf_test_case fgrep_oflag
757c552f48bSKyle Evansfgrep_oflag_head()
758c552f48bSKyle Evans{
759c552f48bSKyle Evans	atf_set "descr" "Check proper handling of -o supplied to fgrep"
760c552f48bSKyle Evans}
761c552f48bSKyle Evansfgrep_oflag_body()
762c552f48bSKyle Evans{
763c552f48bSKyle Evans	printf "abcdefghi\n" > test1
764c552f48bSKyle Evans
765c552f48bSKyle Evans	atf_check -o inline:"a\n" grep -Fo "a" test1
766c552f48bSKyle Evans	atf_check -o inline:"i\n" grep -Fo "i" test1
767c552f48bSKyle Evans	atf_check -o inline:"abc\n" grep -Fo "abc" test1
768c552f48bSKyle Evans	atf_check -o inline:"fgh\n" grep -Fo "fgh" test1
769c552f48bSKyle Evans	atf_check -o inline:"cde\n" grep -Fo "cde" test1
770c552f48bSKyle Evans	atf_check -o inline:"bcd\n" grep -Fo -e "bcd" -e "cde" test1
771c552f48bSKyle Evans	atf_check -o inline:"bcd\nefg\n" grep -Fo -e "bcd" -e "efg" test1
772c552f48bSKyle Evans
773c552f48bSKyle Evans	atf_check -s exit:1 grep -Fo "xabc" test1
774c552f48bSKyle Evans	atf_check -s exit:1 grep -Fo "abcx" test1
775c552f48bSKyle Evans	atf_check -s exit:1 grep -Fo "xghi" test1
776c552f48bSKyle Evans	atf_check -s exit:1 grep -Fo "ghix" test1
777c552f48bSKyle Evans	atf_check -s exit:1 grep -Fo "abcdefghiklmnopqrstuvwxyz" test1
778c552f48bSKyle Evans}
779ce024bdcSKyle Evans
780ce024bdcSKyle Evansatf_test_case cflag
781ce024bdcSKyle Evanscflag_head()
782ce024bdcSKyle Evans{
783ce024bdcSKyle Evans	atf_set "descr" "Check proper handling of -c"
784ce024bdcSKyle Evans}
785ce024bdcSKyle Evanscflag_body()
786ce024bdcSKyle Evans{
787ce024bdcSKyle Evans	printf "a\nb\nc\n" > test1
788ce024bdcSKyle Evans
789ce024bdcSKyle Evans	atf_check -o inline:"1\n" grep -Ec "a" test1
790ce024bdcSKyle Evans	atf_check -o inline:"2\n" grep -Ec "a|b" test1
791ce024bdcSKyle Evans	atf_check -o inline:"3\n" grep -Ec "a|b|c" test1
792ce024bdcSKyle Evans
793ce024bdcSKyle Evans	atf_check -o inline:"test1:2\n" grep -EHc "a|b" test1
794ce024bdcSKyle Evans}
79552cf8965SKyle Evans
79652cf8965SKyle Evansatf_test_case mflag
79752cf8965SKyle Evansmflag_head()
79852cf8965SKyle Evans{
79952cf8965SKyle Evans	atf_set "descr" "Check proper handling of -m"
80052cf8965SKyle Evans}
80152cf8965SKyle Evansmflag_body()
80252cf8965SKyle Evans{
80352cf8965SKyle Evans	printf "a\nb\nc\nd\ne\nf\n" > test1
80452cf8965SKyle Evans
80552cf8965SKyle Evans	atf_check -o inline:"1\n" grep -m 1 -Ec "a" test1
80652cf8965SKyle Evans	atf_check -o inline:"2\n" grep -m 2 -Ec "a|b" test1
80752cf8965SKyle Evans	atf_check -o inline:"3\n" grep -m 3 -Ec "a|b|c|f" test1
80852cf8965SKyle Evans
80952cf8965SKyle Evans	atf_check -o inline:"test1:2\n" grep -m 2 -EHc "a|b|e|f" test1
81052cf8965SKyle Evans}
811799c5faaSEd Maste# End FreeBSD
81257718be8SEnji Cooper
81357718be8SEnji Cooperatf_init_test_cases()
81457718be8SEnji Cooper{
81557718be8SEnji Cooper	atf_add_test_case basic
81657718be8SEnji Cooper	atf_add_test_case binary
81757718be8SEnji Cooper	atf_add_test_case recurse
81857718be8SEnji Cooper	atf_add_test_case recurse_symlink
81957718be8SEnji Cooper	atf_add_test_case word_regexps
82057718be8SEnji Cooper	atf_add_test_case begin_end
82157718be8SEnji Cooper	atf_add_test_case ignore_case
82257718be8SEnji Cooper	atf_add_test_case invert
82357718be8SEnji Cooper	atf_add_test_case whole_line
82457718be8SEnji Cooper	atf_add_test_case negative
82557718be8SEnji Cooper	atf_add_test_case context
82657718be8SEnji Cooper	atf_add_test_case file_exp
82757718be8SEnji Cooper	atf_add_test_case egrep
82857718be8SEnji Cooper	atf_add_test_case zgrep
82957718be8SEnji Cooper	atf_add_test_case nonexistent
83057718be8SEnji Cooper	atf_add_test_case context2
831799c5faaSEd Maste# Begin FreeBSD
832799c5faaSEd Maste	atf_add_test_case oflag_zerolen
833799c5faaSEd Maste	atf_add_test_case xflag
834799c5faaSEd Maste	atf_add_test_case color
835799c5faaSEd Maste	atf_add_test_case f_file_empty
836799c5faaSEd Maste	atf_add_test_case escmap
837799c5faaSEd Maste	atf_add_test_case egrep_empty_invalid
838e06ffa32SEd Maste	atf_add_test_case zerolen
839a4f3f02bSEd Maste	atf_add_test_case wflag_emptypat
840*38325e2aSKyle Evans	atf_add_test_case xflag_emptypat
841*38325e2aSKyle Evans	atf_add_test_case xflag_emptypat_plus
842fe8c9d5bSEd Maste	atf_add_test_case excessive_matches
843945fc991SEd Maste	atf_add_test_case wv_combo_break
8445199917cSEnji Cooper	atf_add_test_case fgrep_sanity
8455199917cSEnji Cooper	atf_add_test_case egrep_sanity
8465199917cSEnji Cooper	atf_add_test_case grep_sanity
8476d635d3bSEd Maste	atf_add_test_case ocolor_metadata
848e2127de8SEd Maste	atf_add_test_case grep_nomatch_flags
849f701bdc5SEd Maste	atf_add_test_case binary_flags
850b5fc583cSEd Maste	atf_add_test_case badcontext
851d7b65474SEd Maste	atf_add_test_case mmap
8520e957942SKyle Evans	atf_add_test_case matchall
853c552f48bSKyle Evans	atf_add_test_case fgrep_multipattern
854c552f48bSKyle Evans	atf_add_test_case fgrep_icase
855c552f48bSKyle Evans	atf_add_test_case fgrep_oflag
856ce024bdcSKyle Evans	atf_add_test_case cflag
85752cf8965SKyle Evans	atf_add_test_case mflag
858799c5faaSEd Maste# End FreeBSD
85957718be8SEnji Cooper}
860