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" \ 84*a700bef1SMark Johnston grep -rS 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 492f823c6dcSKyle Evans atf_check -o file:test2 grep -vw -e "" test2 493a4f3f02bSEd Maste 494a4f3f02bSEd Maste atf_check -s exit:1 -o empty grep -w -e "" test3 495a4f3f02bSEd Maste 496f823c6dcSKyle Evans atf_check -o file:test4 grep -vw -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 atf_check -s exit:1 -o empty grep -x -e "" test1 50838325e2aSKyle Evans 50938325e2aSKyle Evans atf_check -o file:test2 grep -x -e "" test2 51038325e2aSKyle Evans 51138325e2aSKyle Evans atf_check -s exit:1 -o empty grep -x -e "" test3 51238325e2aSKyle Evans 51338325e2aSKyle Evans atf_check -s exit:1 -o empty grep -x -e "" test4 51438325e2aSKyle Evans 51538325e2aSKyle Evans total=$(wc -l /COPYRIGHT | sed 's/[^0-9]//g') 51638325e2aSKyle Evans 51738325e2aSKyle Evans # Simple checks that grep -x with an empty pattern isn't matching every 51838325e2aSKyle Evans # line. The exact counts aren't important, as long as they don't 51938325e2aSKyle Evans # match the total line count and as long as they don't match each other. 52038325e2aSKyle Evans atf_check -o save:xpositive.count grep -Fxc '' /COPYRIGHT 52138325e2aSKyle Evans atf_check -o save:xnegative.count grep -Fvxc '' /COPYRIGHT 52238325e2aSKyle Evans 52338325e2aSKyle Evans atf_check -o not-inline:"${total}" cat xpositive.count 52438325e2aSKyle Evans atf_check -o not-inline:"${total}" cat xnegative.count 52538325e2aSKyle Evans 52638325e2aSKyle Evans atf_check -o not-file:xnegative.count cat xpositive.count 52738325e2aSKyle Evans} 52838325e2aSKyle Evans 52938325e2aSKyle Evansatf_test_case xflag_emptypat_plus 53038325e2aSKyle Evansxflag_emptypat_plus_body() 53138325e2aSKyle Evans{ 53238325e2aSKyle Evans printf "foo\n\nbar\n\nbaz\n" > target 53338325e2aSKyle Evans printf "foo\n \nbar\n \nbaz\n" > target_spacelines 53438325e2aSKyle Evans printf "foo\nbar\nbaz\n" > matches 53538325e2aSKyle Evans printf " \n \n" > spacelines 53638325e2aSKyle Evans 53738325e2aSKyle Evans printf "foo\n\nbar\n\nbaz\n" > patlist1 53838325e2aSKyle Evans printf "foo\n\nba\n\nbaz\n" > patlist2 53938325e2aSKyle Evans 54038325e2aSKyle Evans sed -e '/bar/d' target > matches_not2 54138325e2aSKyle Evans 54238325e2aSKyle Evans # Normal handling first 54338325e2aSKyle Evans atf_check -o file:target grep -Fxf patlist1 target 54438325e2aSKyle Evans atf_check -o file:matches grep -Fxf patlist1 target_spacelines 54538325e2aSKyle Evans atf_check -o file:matches_not2 grep -Fxf patlist2 target 54638325e2aSKyle Evans 54738325e2aSKyle Evans # -v handling 54838325e2aSKyle Evans atf_check -s exit:1 -o empty grep -Fvxf patlist1 target 54938325e2aSKyle Evans atf_check -o file:spacelines grep -Fxvf patlist1 target_spacelines 55038325e2aSKyle Evans} 55138325e2aSKyle Evans 552f823c6dcSKyle Evansatf_test_case emptyfile 553f823c6dcSKyle Evansemptyfile_descr() 554f823c6dcSKyle Evans{ 555f823c6dcSKyle Evans atf_set "descr" "Check for proper handling of empty pattern files (PR 253209)" 556f823c6dcSKyle Evans} 557f823c6dcSKyle Evansemptyfile_body() 558f823c6dcSKyle Evans{ 559f823c6dcSKyle Evans :> epatfile 560f823c6dcSKyle Evans echo "blubb" > subj 561f823c6dcSKyle Evans 562f823c6dcSKyle Evans # From PR 253209, bsdgrep was short-circuiting completely on an empty 563f823c6dcSKyle Evans # file, but we should have still been processing lines. 564f823c6dcSKyle Evans atf_check -s exit:1 -o empty fgrep -f epatfile subj 565f823c6dcSKyle Evans atf_check -o file:subj fgrep -vf epatfile subj 566f823c6dcSKyle Evans} 567f823c6dcSKyle Evans 568fe8c9d5bSEd Masteatf_test_case excessive_matches 569fe8c9d5bSEd Masteexcessive_matches_head() 570fe8c9d5bSEd Maste{ 571fe8c9d5bSEd Maste atf_set "descr" "Check for proper handling of lines with excessive matches (PR 218811)" 572fe8c9d5bSEd Maste} 573fe8c9d5bSEd Masteexcessive_matches_body() 574fe8c9d5bSEd Maste{ 575fe8c9d5bSEd Maste grep_type 576fe8c9d5bSEd Maste if [ $? -eq $GREP_TYPE_GNU_FREEBSD ]; then 577fe8c9d5bSEd Maste atf_expect_fail "this test does not pass with GNU grep in base" 578fe8c9d5bSEd Maste fi 579fe8c9d5bSEd Maste 580fe8c9d5bSEd Maste for i in $(jot 4096); do 581fe8c9d5bSEd Maste printf "x" >> test.in 582fe8c9d5bSEd Maste done 583fe8c9d5bSEd Maste 584fe8c9d5bSEd Maste atf_check -s exit:0 -x '[ $(grep -o x test.in | wc -l) -eq 4096 ]' 5856d635d3bSEd Maste atf_check -s exit:1 -x 'grep -on x test.in | grep -v "1:x"' 586fe8c9d5bSEd Maste} 587fe8c9d5bSEd Maste 5885199917cSEnji Cooperatf_test_case fgrep_sanity 5895199917cSEnji Cooperfgrep_sanity_head() 5905199917cSEnji Cooper{ 5915199917cSEnji Cooper atf_set "descr" "Check for fgrep sanity, literal expressions only" 5925199917cSEnji Cooper} 5935199917cSEnji Cooperfgrep_sanity_body() 5945199917cSEnji Cooper{ 5955199917cSEnji Cooper printf "Foo" > test1 5965199917cSEnji Cooper 5975199917cSEnji Cooper atf_check -o inline:"Foo\n" fgrep -e "Foo" test1 5985199917cSEnji Cooper 5995199917cSEnji Cooper atf_check -s exit:1 -o empty fgrep -e "Fo." test1 6005199917cSEnji Cooper} 6015199917cSEnji Cooper 6025199917cSEnji Cooperatf_test_case egrep_sanity 6035199917cSEnji Cooperegrep_sanity_head() 6045199917cSEnji Cooper{ 6055199917cSEnji Cooper atf_set "descr" "Check for egrep sanity, EREs only" 6065199917cSEnji Cooper} 6075199917cSEnji Cooperegrep_sanity_body() 6085199917cSEnji Cooper{ 6095199917cSEnji Cooper printf "Foobar(ed)" > test1 6105199917cSEnji Cooper printf "M{1}" > test2 6115199917cSEnji Cooper 6125199917cSEnji Cooper atf_check -o inline:"Foo\n" egrep -o -e "F.." test1 6135199917cSEnji Cooper 6145199917cSEnji Cooper atf_check -o inline:"Foobar\n" egrep -o -e "F[a-z]*" test1 6155199917cSEnji Cooper 6165199917cSEnji Cooper atf_check -o inline:"Fo\n" egrep -o -e "F(o|p)" test1 6175199917cSEnji Cooper 6185199917cSEnji Cooper atf_check -o inline:"(ed)\n" egrep -o -e "\(ed\)" test1 6195199917cSEnji Cooper 6205199917cSEnji Cooper atf_check -o inline:"M\n" egrep -o -e "M{1}" test2 6215199917cSEnji Cooper 6225199917cSEnji Cooper atf_check -o inline:"M{1}\n" egrep -o -e "M\{1\}" test2 6235199917cSEnji Cooper} 6245199917cSEnji Cooper 6255199917cSEnji Cooperatf_test_case grep_sanity 6265199917cSEnji Coopergrep_sanity_head() 6275199917cSEnji Cooper{ 6285199917cSEnji Cooper atf_set "descr" "Check for basic grep sanity, BREs only" 6295199917cSEnji Cooper} 6305199917cSEnji Coopergrep_sanity_body() 6315199917cSEnji Cooper{ 6325199917cSEnji Cooper printf "Foobar(ed)" > test1 6335199917cSEnji Cooper printf "M{1}" > test2 6345199917cSEnji Cooper 6355199917cSEnji Cooper atf_check -o inline:"Foo\n" grep -o -e "F.." test1 6365199917cSEnji Cooper 6375199917cSEnji Cooper atf_check -o inline:"Foobar\n" grep -o -e "F[a-z]*" test1 6385199917cSEnji Cooper 6395199917cSEnji Cooper atf_check -o inline:"Fo\n" grep -o -e "F\(o\)" test1 6405199917cSEnji Cooper 6415199917cSEnji Cooper atf_check -o inline:"(ed)\n" grep -o -e "(ed)" test1 6425199917cSEnji Cooper 6435199917cSEnji Cooper atf_check -o inline:"M{1}\n" grep -o -e "M{1}" test2 6445199917cSEnji Cooper 6455199917cSEnji Cooper atf_check -o inline:"M\n" grep -o -e "M\{1\}" test2 6465199917cSEnji Cooper} 647945fc991SEd Maste 648945fc991SEd Masteatf_test_case wv_combo_break 649945fc991SEd Mastewv_combo_break_head() 650945fc991SEd Maste{ 651945fc991SEd Maste atf_set "descr" "Check for incorrectly matching lines with both -w and -v flags (PR 218467)" 652945fc991SEd Maste} 653945fc991SEd Mastewv_combo_break_body() 654945fc991SEd Maste{ 655945fc991SEd Maste printf "x xx\n" > test1 656945fc991SEd Maste printf "xx x\n" > test2 657945fc991SEd Maste 658945fc991SEd Maste atf_check -o file:test1 grep -w "x" test1 659945fc991SEd Maste atf_check -o file:test2 grep -w "x" test2 660945fc991SEd Maste 661945fc991SEd Maste atf_check -s exit:1 grep -v -w "x" test1 662945fc991SEd Maste atf_check -s exit:1 grep -v -w "x" test2 663945fc991SEd Maste} 664e2127de8SEd Maste 6656d635d3bSEd Masteatf_test_case ocolor_metadata 6666d635d3bSEd Masteocolor_metadata_head() 6676d635d3bSEd Maste{ 6686d635d3bSEd Maste atf_set "descr" "Check for -n/-b producing per-line metadata output" 6696d635d3bSEd Maste} 6706d635d3bSEd Masteocolor_metadata_body() 6716d635d3bSEd Maste{ 6726d635d3bSEd Maste grep_type 6736d635d3bSEd Maste if [ $? -eq $GREP_TYPE_GNU_FREEBSD ]; then 6746d635d3bSEd Maste atf_expect_fail "this test does not pass with GNU grep in base" 6756d635d3bSEd Maste fi 6766d635d3bSEd Maste 6776d635d3bSEd Maste printf "xxx\nyyyy\nzzz\nfoobarbaz\n" > test1 6786d635d3bSEd Maste check_expr="^[^:]*[0-9][^:]*:[^:]+$" 6796d635d3bSEd Maste 6806d635d3bSEd Maste atf_check -o inline:"1:1:xx\n" grep -bon "xx$" test1 6816d635d3bSEd Maste 6826d635d3bSEd Maste atf_check -o inline:"2:4:yyyy\n" grep -bn "yy" test1 6836d635d3bSEd Maste 6846d635d3bSEd Maste atf_check -o inline:"2:6:yy\n" grep -bon "yy$" test1 6856d635d3bSEd Maste 6866d635d3bSEd Maste # These checks ensure that grep isn't producing bogus line numbering 6876d635d3bSEd Maste # in the middle of a line. 6886d635d3bSEd Maste atf_check -s exit:1 -x \ 6896d635d3bSEd Maste "grep -Eon 'x|y|z|f' test1 | grep -Ev '${check_expr}'" 6906d635d3bSEd Maste 6916d635d3bSEd Maste atf_check -s exit:1 -x \ 6926d635d3bSEd Maste "grep -En 'x|y|z|f' --color=always test1 | grep -Ev '${check_expr}'" 6936d635d3bSEd Maste 6946d635d3bSEd Maste atf_check -s exit:1 -x \ 6956d635d3bSEd Maste "grep -Eon 'x|y|z|f' --color=always test1 | grep -Ev '${check_expr}'" 6966d635d3bSEd Maste} 6976d635d3bSEd Maste 698e2127de8SEd Masteatf_test_case grep_nomatch_flags 699e2127de8SEd Mastegrep_nomatch_flags_head() 700e2127de8SEd Maste{ 701e2127de8SEd Maste atf_set "descr" "Check for no match (-c, -l, -L, -q) flags not producing line matches or context (PR 219077)" 702e2127de8SEd Maste} 703e2127de8SEd Maste 704e2127de8SEd Mastegrep_nomatch_flags_body() 705e2127de8SEd Maste{ 70638325e2aSKyle Evans grep_type 70738325e2aSKyle Evans 70838325e2aSKyle Evans if [ $? -eq $GREP_TYPE_GNU_FREEBSD ]; then 70938325e2aSKyle Evans atf_expect_fail "this test does not pass with GNU grep in base" 71038325e2aSKyle Evans fi 71138325e2aSKyle Evans 712e2127de8SEd Maste printf "A\nB\nC\n" > test1 713e2127de8SEd Maste 714e2127de8SEd Maste atf_check -o inline:"1\n" grep -c -C 1 -e "B" test1 715e2127de8SEd Maste atf_check -o inline:"1\n" grep -c -B 1 -e "B" test1 716e2127de8SEd Maste atf_check -o inline:"1\n" grep -c -A 1 -e "B" test1 717e2127de8SEd Maste atf_check -o inline:"1\n" grep -c -C 1 -e "B" test1 718e2127de8SEd Maste 719e2127de8SEd Maste atf_check -o inline:"test1\n" grep -l -e "B" test1 720e2127de8SEd Maste atf_check -o inline:"test1\n" grep -l -B 1 -e "B" test1 721e2127de8SEd Maste atf_check -o inline:"test1\n" grep -l -A 1 -e "B" test1 722e2127de8SEd Maste atf_check -o inline:"test1\n" grep -l -C 1 -e "B" test1 723e2127de8SEd Maste 72438325e2aSKyle Evans atf_check -o inline:"test1\n" grep -L -e "D" test1 725e2127de8SEd Maste 726e2127de8SEd Maste atf_check -o empty grep -q -e "B" test1 727e2127de8SEd Maste atf_check -o empty grep -q -B 1 -e "B" test1 728e2127de8SEd Maste atf_check -o empty grep -q -A 1 -e "B" test1 729e2127de8SEd Maste atf_check -o empty grep -q -C 1 -e "B" test1 730e2127de8SEd Maste} 731b5fc583cSEd Maste 732b5fc583cSEd Masteatf_test_case badcontext 733b5fc583cSEd Mastebadcontext_head() 734b5fc583cSEd Maste{ 735b5fc583cSEd Maste atf_set "descr" "Check for handling of invalid context arguments" 736b5fc583cSEd Maste} 737b5fc583cSEd Mastebadcontext_body() 738b5fc583cSEd Maste{ 739b5fc583cSEd Maste printf "A\nB\nC\n" > test1 740b5fc583cSEd Maste 741b5fc583cSEd Maste atf_check -s not-exit:0 -e ignore grep -A "-1" "B" test1 742b5fc583cSEd Maste 743b5fc583cSEd Maste atf_check -s not-exit:0 -e ignore grep -B "-1" "B" test1 744b5fc583cSEd Maste 745b5fc583cSEd Maste atf_check -s not-exit:0 -e ignore grep -C "-1" "B" test1 746b5fc583cSEd Maste 747b5fc583cSEd Maste atf_check -s not-exit:0 -e ignore grep -A "B" "B" test1 748b5fc583cSEd Maste 749b5fc583cSEd Maste atf_check -s not-exit:0 -e ignore grep -B "B" "B" test1 750b5fc583cSEd Maste 751b5fc583cSEd Maste atf_check -s not-exit:0 -e ignore grep -C "B" "B" test1 752b5fc583cSEd Maste} 753f701bdc5SEd Maste 754f701bdc5SEd Masteatf_test_case binary_flags 755f701bdc5SEd Mastebinary_flags_head() 756f701bdc5SEd Maste{ 757f701bdc5SEd Maste atf_set "descr" "Check output for binary flags (-a, -I, -U, --binary-files)" 758f701bdc5SEd Maste} 759f701bdc5SEd Mastebinary_flags_body() 760f701bdc5SEd Maste{ 761f701bdc5SEd Maste printf "A\000B\000C" > test1 762f701bdc5SEd Maste printf "A\n\000B\n\000C" > test2 763f701bdc5SEd Maste binmatchtext="Binary file test1 matches\n" 764f701bdc5SEd Maste 765f701bdc5SEd Maste # Binaries not treated as text (default, -U) 766f701bdc5SEd Maste atf_check -o inline:"${binmatchtext}" grep 'B' test1 767f701bdc5SEd Maste atf_check -o inline:"${binmatchtext}" grep 'B' -C 1 test1 768f701bdc5SEd Maste 769f701bdc5SEd Maste atf_check -o inline:"${binmatchtext}" grep -U 'B' test1 770f701bdc5SEd Maste atf_check -o inline:"${binmatchtext}" grep -U 'B' -C 1 test1 771f701bdc5SEd Maste 772f701bdc5SEd Maste # Binary, -a, no newlines 773f701bdc5SEd Maste atf_check -o inline:"A\000B\000C\n" grep -a 'B' test1 774f701bdc5SEd Maste atf_check -o inline:"A\000B\000C\n" grep -a 'B' -C 1 test1 775f701bdc5SEd Maste 776f701bdc5SEd Maste # Binary, -a, newlines 777f701bdc5SEd Maste atf_check -o inline:"\000B\n" grep -a 'B' test2 778f701bdc5SEd Maste atf_check -o inline:"A\n\000B\n\000C\n" grep -a 'B' -C 1 test2 779f701bdc5SEd Maste 780f701bdc5SEd Maste # Binary files ignored 781f701bdc5SEd Maste atf_check -s exit:1 grep -I 'B' test2 782f701bdc5SEd Maste 783f701bdc5SEd Maste # --binary-files equivalence 784f701bdc5SEd Maste atf_check -o inline:"${binmatchtext}" grep --binary-files=binary 'B' test1 785f701bdc5SEd Maste atf_check -o inline:"A\000B\000C\n" grep --binary-files=text 'B' test1 786f701bdc5SEd Maste atf_check -s exit:1 grep --binary-files=without-match 'B' test2 787f701bdc5SEd Maste} 788d7b65474SEd Maste 789d7b65474SEd Masteatf_test_case mmap 790d7b65474SEd Mastemmap_head() 791d7b65474SEd Maste{ 792d7b65474SEd Maste atf_set "descr" "Check basic matching with --mmap flag" 793d7b65474SEd Maste} 794d7b65474SEd Mastemmap_body() 795d7b65474SEd Maste{ 796d7b65474SEd Maste grep_type 797d7b65474SEd Maste if [ $? -eq $GREP_TYPE_GNU ]; then 798d7b65474SEd Maste atf_expect_fail "gnu grep from ports has no --mmap option" 799d7b65474SEd Maste fi 800d7b65474SEd Maste 801d7b65474SEd Maste printf "A\nB\nC\n" > test1 802d7b65474SEd Maste 803d7b65474SEd Maste atf_check -s exit:0 -o inline:"B\n" grep --mmap -oe "B" test1 804d7b65474SEd Maste atf_check -s exit:1 grep --mmap -e "Z" test1 805d7b65474SEd Maste} 806d7b65474SEd Maste 8070e957942SKyle Evansatf_test_case matchall 8080e957942SKyle Evansmatchall_head() 8090e957942SKyle Evans{ 8100e957942SKyle Evans atf_set "descr" "Check proper behavior of matching all with an empty string" 8110e957942SKyle Evans} 8120e957942SKyle Evansmatchall_body() 8130e957942SKyle Evans{ 8140e957942SKyle Evans printf "" > test1 8150e957942SKyle Evans printf "A" > test2 8160e957942SKyle Evans printf "A\nB" > test3 8170e957942SKyle Evans 8180e957942SKyle Evans atf_check -o inline:"test2:A\ntest3:A\ntest3:B\n" grep "" test1 test2 test3 8190e957942SKyle Evans atf_check -o inline:"test3:A\ntest3:B\ntest2:A\n" grep "" test3 test1 test2 8200e957942SKyle Evans atf_check -o inline:"test2:A\ntest3:A\ntest3:B\n" grep "" test2 test3 test1 8210e957942SKyle Evans 8220e957942SKyle Evans atf_check -s exit:1 grep "" test1 8230e957942SKyle Evans} 824c552f48bSKyle Evans 825c552f48bSKyle Evansatf_test_case fgrep_multipattern 826c552f48bSKyle Evansfgrep_multipattern_head() 827c552f48bSKyle Evans{ 828c552f48bSKyle Evans atf_set "descr" "Check proper behavior with multiple patterns supplied to fgrep" 829c552f48bSKyle Evans} 830c552f48bSKyle Evansfgrep_multipattern_body() 831c552f48bSKyle Evans{ 832c552f48bSKyle Evans printf "Foo\nBar\nBaz" > test1 833c552f48bSKyle Evans 834c552f48bSKyle Evans atf_check -o inline:"Foo\nBaz\n" grep -F -e "Foo" -e "Baz" test1 835c552f48bSKyle Evans atf_check -o inline:"Foo\nBaz\n" grep -F -e "Baz" -e "Foo" test1 836c552f48bSKyle Evans atf_check -o inline:"Bar\nBaz\n" grep -F -e "Bar" -e "Baz" test1 837c552f48bSKyle Evans} 838c552f48bSKyle Evans 839c552f48bSKyle Evansatf_test_case fgrep_icase 840c552f48bSKyle Evansfgrep_icase_head() 841c552f48bSKyle Evans{ 842c552f48bSKyle Evans atf_set "descr" "Check proper handling of -i supplied to fgrep" 843c552f48bSKyle Evans} 844c552f48bSKyle Evansfgrep_icase_body() 845c552f48bSKyle Evans{ 846c552f48bSKyle Evans printf "Foo\nBar\nBaz" > test1 847c552f48bSKyle Evans 848c552f48bSKyle Evans atf_check -o inline:"Foo\nBaz\n" grep -Fi -e "foo" -e "baz" test1 849c552f48bSKyle Evans atf_check -o inline:"Foo\nBaz\n" grep -Fi -e "baz" -e "foo" test1 850c552f48bSKyle Evans atf_check -o inline:"Bar\nBaz\n" grep -Fi -e "bar" -e "baz" test1 851c552f48bSKyle Evans atf_check -o inline:"Bar\nBaz\n" grep -Fi -e "BAR" -e "bAz" test1 852c552f48bSKyle Evans} 853c552f48bSKyle Evans 854c552f48bSKyle Evansatf_test_case fgrep_oflag 855c552f48bSKyle Evansfgrep_oflag_head() 856c552f48bSKyle Evans{ 857c552f48bSKyle Evans atf_set "descr" "Check proper handling of -o supplied to fgrep" 858c552f48bSKyle Evans} 859c552f48bSKyle Evansfgrep_oflag_body() 860c552f48bSKyle Evans{ 861c552f48bSKyle Evans printf "abcdefghi\n" > test1 862c552f48bSKyle Evans 863c552f48bSKyle Evans atf_check -o inline:"a\n" grep -Fo "a" test1 864c552f48bSKyle Evans atf_check -o inline:"i\n" grep -Fo "i" test1 865c552f48bSKyle Evans atf_check -o inline:"abc\n" grep -Fo "abc" test1 866c552f48bSKyle Evans atf_check -o inline:"fgh\n" grep -Fo "fgh" test1 867c552f48bSKyle Evans atf_check -o inline:"cde\n" grep -Fo "cde" test1 868c552f48bSKyle Evans atf_check -o inline:"bcd\n" grep -Fo -e "bcd" -e "cde" test1 869c552f48bSKyle Evans atf_check -o inline:"bcd\nefg\n" grep -Fo -e "bcd" -e "efg" test1 870c552f48bSKyle Evans 871c552f48bSKyle Evans atf_check -s exit:1 grep -Fo "xabc" test1 872c552f48bSKyle Evans atf_check -s exit:1 grep -Fo "abcx" test1 873c552f48bSKyle Evans atf_check -s exit:1 grep -Fo "xghi" test1 874c552f48bSKyle Evans atf_check -s exit:1 grep -Fo "ghix" test1 875c552f48bSKyle Evans atf_check -s exit:1 grep -Fo "abcdefghiklmnopqrstuvwxyz" test1 876c552f48bSKyle Evans} 877ce024bdcSKyle Evans 878ce024bdcSKyle Evansatf_test_case cflag 879ce024bdcSKyle Evanscflag_head() 880ce024bdcSKyle Evans{ 881ce024bdcSKyle Evans atf_set "descr" "Check proper handling of -c" 882ce024bdcSKyle Evans} 883ce024bdcSKyle Evanscflag_body() 884ce024bdcSKyle Evans{ 885ce024bdcSKyle Evans printf "a\nb\nc\n" > test1 886ce024bdcSKyle Evans 887ce024bdcSKyle Evans atf_check -o inline:"1\n" grep -Ec "a" test1 888ce024bdcSKyle Evans atf_check -o inline:"2\n" grep -Ec "a|b" test1 889ce024bdcSKyle Evans atf_check -o inline:"3\n" grep -Ec "a|b|c" test1 890ce024bdcSKyle Evans 891ce024bdcSKyle Evans atf_check -o inline:"test1:2\n" grep -EHc "a|b" test1 892ce024bdcSKyle Evans} 89352cf8965SKyle Evans 89452cf8965SKyle Evansatf_test_case mflag 89552cf8965SKyle Evansmflag_head() 89652cf8965SKyle Evans{ 89752cf8965SKyle Evans atf_set "descr" "Check proper handling of -m" 89852cf8965SKyle Evans} 89952cf8965SKyle Evansmflag_body() 90052cf8965SKyle Evans{ 90152cf8965SKyle Evans printf "a\nb\nc\nd\ne\nf\n" > test1 90252cf8965SKyle Evans 90352cf8965SKyle Evans atf_check -o inline:"1\n" grep -m 1 -Ec "a" test1 90452cf8965SKyle Evans atf_check -o inline:"2\n" grep -m 2 -Ec "a|b" test1 90552cf8965SKyle Evans atf_check -o inline:"3\n" grep -m 3 -Ec "a|b|c|f" test1 90652cf8965SKyle Evans 90752cf8965SKyle Evans atf_check -o inline:"test1:2\n" grep -m 2 -EHc "a|b|e|f" test1 90852cf8965SKyle Evans} 90963c8336dSEric van Gyzen 9103e2d96acSKyle Evansatf_test_case mflag_trail_ctx 9113e2d96acSKyle Evansmflag_trail_ctx_head() 9123e2d96acSKyle Evans{ 9133e2d96acSKyle Evans atf_set "descr" "Check proper handling of -m with trailing context (PR 253350)" 9143e2d96acSKyle Evans} 9153e2d96acSKyle Evansmflag_trail_ctx_body() 9163e2d96acSKyle Evans{ 9173e2d96acSKyle Evans printf "foo\nfoo\nbar\nfoo\nbar\nfoo\nbar\n" > test1 9183e2d96acSKyle Evans 9193e2d96acSKyle Evans # Should pick up the next line after matching the first. 9203e2d96acSKyle Evans atf_check -o inline:"foo\nfoo\n" grep -A1 -m1 foo test1 9213e2d96acSKyle Evans 9223e2d96acSKyle Evans # Make sure the trailer is picked up as a non-match! 9233e2d96acSKyle Evans atf_check -o inline:"1:foo\n2-foo\n" grep -A1 -nm1 foo test1 9243e2d96acSKyle Evans} 9253e2d96acSKyle Evans 92663c8336dSEric van Gyzenatf_test_case zgrep_multiple_files 92763c8336dSEric van Gyzenzgrep_multiple_files_head() 92863c8336dSEric van Gyzen{ 92963c8336dSEric van Gyzen atf_set "descr" "Ensures that zgrep functions properly with multiple files" 93063c8336dSEric van Gyzen} 93163c8336dSEric van Gyzenzgrep_multiple_files_body() 93263c8336dSEric van Gyzen{ 93363c8336dSEric van Gyzen echo foo > test1 93463c8336dSEric van Gyzen echo foo > test2 93563c8336dSEric van Gyzen atf_check -o inline:"test1:foo\ntest2:foo\n" zgrep foo test1 test2 93663c8336dSEric van Gyzen 93763c8336dSEric van Gyzen echo bar > test1 93863c8336dSEric van Gyzen atf_check -o inline:"test2:foo\n" zgrep foo test1 test2 93963c8336dSEric van Gyzen 94063c8336dSEric van Gyzen echo bar > test2 94163c8336dSEric van Gyzen atf_check -s exit:1 zgrep foo test1 test2 94263c8336dSEric van Gyzen} 943799c5faaSEd Maste# End FreeBSD 94457718be8SEnji Cooper 94557718be8SEnji Cooperatf_init_test_cases() 94657718be8SEnji Cooper{ 94757718be8SEnji Cooper atf_add_test_case basic 94857718be8SEnji Cooper atf_add_test_case binary 94957718be8SEnji Cooper atf_add_test_case recurse 95057718be8SEnji Cooper atf_add_test_case recurse_symlink 95157718be8SEnji Cooper atf_add_test_case word_regexps 95257718be8SEnji Cooper atf_add_test_case begin_end 95357718be8SEnji Cooper atf_add_test_case ignore_case 95457718be8SEnji Cooper atf_add_test_case invert 95557718be8SEnji Cooper atf_add_test_case whole_line 95657718be8SEnji Cooper atf_add_test_case negative 95757718be8SEnji Cooper atf_add_test_case context 95857718be8SEnji Cooper atf_add_test_case file_exp 95957718be8SEnji Cooper atf_add_test_case egrep 96057718be8SEnji Cooper atf_add_test_case zgrep 961c4cbf1fbSCraig Leres atf_add_test_case zgrep_combined_flags 962c4cbf1fbSCraig Leres atf_add_test_case zgrep_eflag 963c4cbf1fbSCraig Leres atf_add_test_case zgrep_empty_eflag 964c4cbf1fbSCraig Leres atf_add_test_case zgrep_fflag 965c4cbf1fbSCraig Leres atf_add_test_case zgrep_long_eflag 966c4cbf1fbSCraig Leres atf_add_test_case zgrep_multiple_eflags 96757718be8SEnji Cooper atf_add_test_case nonexistent 96857718be8SEnji Cooper atf_add_test_case context2 969799c5faaSEd Maste# Begin FreeBSD 970799c5faaSEd Maste atf_add_test_case oflag_zerolen 971799c5faaSEd Maste atf_add_test_case xflag 972799c5faaSEd Maste atf_add_test_case color 973799c5faaSEd Maste atf_add_test_case f_file_empty 974799c5faaSEd Maste atf_add_test_case escmap 975799c5faaSEd Maste atf_add_test_case egrep_empty_invalid 976e06ffa32SEd Maste atf_add_test_case zerolen 977a4f3f02bSEd Maste atf_add_test_case wflag_emptypat 97838325e2aSKyle Evans atf_add_test_case xflag_emptypat 97938325e2aSKyle Evans atf_add_test_case xflag_emptypat_plus 980f823c6dcSKyle Evans atf_add_test_case emptyfile 981fe8c9d5bSEd Maste atf_add_test_case excessive_matches 982945fc991SEd Maste atf_add_test_case wv_combo_break 9835199917cSEnji Cooper atf_add_test_case fgrep_sanity 9845199917cSEnji Cooper atf_add_test_case egrep_sanity 9855199917cSEnji Cooper atf_add_test_case grep_sanity 9866d635d3bSEd Maste atf_add_test_case ocolor_metadata 987e2127de8SEd Maste atf_add_test_case grep_nomatch_flags 988f701bdc5SEd Maste atf_add_test_case binary_flags 989b5fc583cSEd Maste atf_add_test_case badcontext 990d7b65474SEd Maste atf_add_test_case mmap 9910e957942SKyle Evans atf_add_test_case matchall 992c552f48bSKyle Evans atf_add_test_case fgrep_multipattern 993c552f48bSKyle Evans atf_add_test_case fgrep_icase 994c552f48bSKyle Evans atf_add_test_case fgrep_oflag 995ce024bdcSKyle Evans atf_add_test_case cflag 99652cf8965SKyle Evans atf_add_test_case mflag 9973e2d96acSKyle Evans atf_add_test_case mflag_trail_ctx 99863c8336dSEric van Gyzen atf_add_test_case zgrep_multiple_files 999799c5faaSEd Maste# End FreeBSD 100057718be8SEnji Cooper} 1001