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 grep_type 403a4f3f02bSEd Maste if [ $? -eq $GREP_TYPE_GNU_FREEBSD ]; then 404a4f3f02bSEd Maste atf_expect_fail "this test does not pass with GNU grep in base" 405a4f3f02bSEd Maste fi 406a4f3f02bSEd Maste 407a4f3f02bSEd Maste printf "" > test1 408a4f3f02bSEd Maste printf "\n" > test2 409a4f3f02bSEd Maste printf "qaz" > test3 410a4f3f02bSEd Maste printf " qaz\n" > test4 411a4f3f02bSEd Maste 412a4f3f02bSEd Maste atf_check -s exit:1 -o empty grep -w -e "" test1 413a4f3f02bSEd Maste 414a4f3f02bSEd Maste atf_check -o file:test2 grep -w -e "" test2 415a4f3f02bSEd Maste 416a4f3f02bSEd Maste atf_check -s exit:1 -o empty grep -w -e "" test3 417a4f3f02bSEd Maste 418a4f3f02bSEd Maste atf_check -o file:test4 grep -w -e "" test4 419a4f3f02bSEd Maste} 420a4f3f02bSEd Maste 4215199917cSEnji Cooperatf_test_case fgrep_sanity 4225199917cSEnji Cooperfgrep_sanity_head() 4235199917cSEnji Cooper{ 4245199917cSEnji Cooper atf_set "descr" "Check for fgrep sanity, literal expressions only" 4255199917cSEnji Cooper} 4265199917cSEnji Cooperfgrep_sanity_body() 4275199917cSEnji Cooper{ 4285199917cSEnji Cooper printf "Foo" > test1 4295199917cSEnji Cooper 4305199917cSEnji Cooper atf_check -o inline:"Foo\n" fgrep -e "Foo" test1 4315199917cSEnji Cooper 4325199917cSEnji Cooper atf_check -s exit:1 -o empty fgrep -e "Fo." test1 4335199917cSEnji Cooper} 4345199917cSEnji Cooper 4355199917cSEnji Cooperatf_test_case egrep_sanity 4365199917cSEnji Cooperegrep_sanity_head() 4375199917cSEnji Cooper{ 4385199917cSEnji Cooper atf_set "descr" "Check for egrep sanity, EREs only" 4395199917cSEnji Cooper} 4405199917cSEnji Cooperegrep_sanity_body() 4415199917cSEnji Cooper{ 4425199917cSEnji Cooper printf "Foobar(ed)" > test1 4435199917cSEnji Cooper printf "M{1}" > test2 4445199917cSEnji Cooper 4455199917cSEnji Cooper atf_check -o inline:"Foo\n" egrep -o -e "F.." test1 4465199917cSEnji Cooper 4475199917cSEnji Cooper atf_check -o inline:"Foobar\n" egrep -o -e "F[a-z]*" test1 4485199917cSEnji Cooper 4495199917cSEnji Cooper atf_check -o inline:"Fo\n" egrep -o -e "F(o|p)" test1 4505199917cSEnji Cooper 4515199917cSEnji Cooper atf_check -o inline:"(ed)\n" egrep -o -e "\(ed\)" test1 4525199917cSEnji Cooper 4535199917cSEnji Cooper atf_check -o inline:"M\n" egrep -o -e "M{1}" test2 4545199917cSEnji Cooper 4555199917cSEnji Cooper atf_check -o inline:"M{1}\n" egrep -o -e "M\{1\}" test2 4565199917cSEnji Cooper} 4575199917cSEnji Cooper 4585199917cSEnji Cooperatf_test_case grep_sanity 4595199917cSEnji Coopergrep_sanity_head() 4605199917cSEnji Cooper{ 4615199917cSEnji Cooper atf_set "descr" "Check for basic grep sanity, BREs only" 4625199917cSEnji Cooper} 4635199917cSEnji Coopergrep_sanity_body() 4645199917cSEnji Cooper{ 4655199917cSEnji Cooper printf "Foobar(ed)" > test1 4665199917cSEnji Cooper printf "M{1}" > test2 4675199917cSEnji Cooper 4685199917cSEnji Cooper atf_check -o inline:"Foo\n" grep -o -e "F.." test1 4695199917cSEnji Cooper 4705199917cSEnji Cooper atf_check -o inline:"Foobar\n" grep -o -e "F[a-z]*" test1 4715199917cSEnji Cooper 4725199917cSEnji Cooper atf_check -o inline:"Fo\n" grep -o -e "F\(o\)" test1 4735199917cSEnji Cooper 4745199917cSEnji Cooper atf_check -o inline:"(ed)\n" grep -o -e "(ed)" test1 4755199917cSEnji Cooper 4765199917cSEnji Cooper atf_check -o inline:"M{1}\n" grep -o -e "M{1}" test2 4775199917cSEnji Cooper 4785199917cSEnji Cooper atf_check -o inline:"M\n" grep -o -e "M\{1\}" test2 4795199917cSEnji Cooper} 480945fc991SEd Maste 481945fc991SEd Masteatf_test_case wv_combo_break 482945fc991SEd Mastewv_combo_break_head() 483945fc991SEd Maste{ 484945fc991SEd Maste atf_set "descr" "Check for incorrectly matching lines with both -w and -v flags (PR 218467)" 485945fc991SEd Maste} 486945fc991SEd Mastewv_combo_break_body() 487945fc991SEd Maste{ 488945fc991SEd Maste printf "x xx\n" > test1 489945fc991SEd Maste printf "xx x\n" > test2 490945fc991SEd Maste 491945fc991SEd Maste atf_check -o file:test1 grep -w "x" test1 492945fc991SEd Maste atf_check -o file:test2 grep -w "x" test2 493945fc991SEd Maste 494945fc991SEd Maste atf_check -s exit:1 grep -v -w "x" test1 495945fc991SEd Maste atf_check -s exit:1 grep -v -w "x" test2 496945fc991SEd Maste} 497*e2127de8SEd Maste 498*e2127de8SEd Masteatf_test_case grep_nomatch_flags 499*e2127de8SEd Mastegrep_nomatch_flags_head() 500*e2127de8SEd Maste{ 501*e2127de8SEd Maste atf_set "descr" "Check for no match (-c, -l, -L, -q) flags not producing line matches or context (PR 219077)" 502*e2127de8SEd Maste} 503*e2127de8SEd Maste 504*e2127de8SEd Mastegrep_nomatch_flags_body() 505*e2127de8SEd Maste{ 506*e2127de8SEd Maste printf "A\nB\nC\n" > test1 507*e2127de8SEd Maste 508*e2127de8SEd Maste atf_check -o inline:"1\n" grep -c -C 1 -e "B" test1 509*e2127de8SEd Maste atf_check -o inline:"1\n" grep -c -B 1 -e "B" test1 510*e2127de8SEd Maste atf_check -o inline:"1\n" grep -c -A 1 -e "B" test1 511*e2127de8SEd Maste atf_check -o inline:"1\n" grep -c -C 1 -e "B" test1 512*e2127de8SEd Maste 513*e2127de8SEd Maste atf_check -o inline:"test1\n" grep -l -e "B" test1 514*e2127de8SEd Maste atf_check -o inline:"test1\n" grep -l -B 1 -e "B" test1 515*e2127de8SEd Maste atf_check -o inline:"test1\n" grep -l -A 1 -e "B" test1 516*e2127de8SEd Maste atf_check -o inline:"test1\n" grep -l -C 1 -e "B" test1 517*e2127de8SEd Maste 518*e2127de8SEd Maste atf_check -s exit:1 -o inline:"test1\n" grep -L -e "D" test1 519*e2127de8SEd Maste 520*e2127de8SEd Maste atf_check -o empty grep -q -e "B" test1 521*e2127de8SEd Maste atf_check -o empty grep -q -B 1 -e "B" test1 522*e2127de8SEd Maste atf_check -o empty grep -q -A 1 -e "B" test1 523*e2127de8SEd Maste atf_check -o empty grep -q -C 1 -e "B" test1 524*e2127de8SEd Maste} 525799c5faaSEd Maste# End FreeBSD 52657718be8SEnji Cooper 52757718be8SEnji Cooperatf_init_test_cases() 52857718be8SEnji Cooper{ 52957718be8SEnji Cooper atf_add_test_case basic 53057718be8SEnji Cooper atf_add_test_case binary 53157718be8SEnji Cooper atf_add_test_case recurse 53257718be8SEnji Cooper atf_add_test_case recurse_symlink 53357718be8SEnji Cooper atf_add_test_case word_regexps 53457718be8SEnji Cooper atf_add_test_case begin_end 53557718be8SEnji Cooper atf_add_test_case ignore_case 53657718be8SEnji Cooper atf_add_test_case invert 53757718be8SEnji Cooper atf_add_test_case whole_line 53857718be8SEnji Cooper atf_add_test_case negative 53957718be8SEnji Cooper atf_add_test_case context 54057718be8SEnji Cooper atf_add_test_case file_exp 54157718be8SEnji Cooper atf_add_test_case egrep 54257718be8SEnji Cooper atf_add_test_case zgrep 54357718be8SEnji Cooper atf_add_test_case nonexistent 54457718be8SEnji Cooper atf_add_test_case context2 545799c5faaSEd Maste# Begin FreeBSD 546799c5faaSEd Maste atf_add_test_case oflag_zerolen 547799c5faaSEd Maste atf_add_test_case xflag 548799c5faaSEd Maste atf_add_test_case color 549799c5faaSEd Maste atf_add_test_case f_file_empty 550799c5faaSEd Maste atf_add_test_case escmap 551799c5faaSEd Maste atf_add_test_case egrep_empty_invalid 552e06ffa32SEd Maste atf_add_test_case zerolen 553a4f3f02bSEd Maste atf_add_test_case wflag_emptypat 554945fc991SEd Maste atf_add_test_case wv_combo_break 5555199917cSEnji Cooper atf_add_test_case fgrep_sanity 5565199917cSEnji Cooper atf_add_test_case egrep_sanity 5575199917cSEnji Cooper atf_add_test_case grep_sanity 558*e2127de8SEd Maste atf_add_test_case grep_nomatch_flags 559799c5faaSEd Maste# End FreeBSD 56057718be8SEnji Cooper} 561