1 # $NetBSD: t_grep.sh,v 1.3 2017/01/14 20:43:52 christos Exp $
3 # Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 # POSSIBILITY OF SUCH DAMAGE.
31 atf_set "descr" "Checks basic functionality"
35 atf_check -o file:"$(atf_get_srcdir)/d_basic.out" -x \
36 'jot 10000 | grep 123'
42 atf_set "descr" "Checks handling of binary files"
46 dd if=/dev/zero count=1 of=test.file
47 echo -n "foobar" >> test.file
48 atf_check -o file:"$(atf_get_srcdir)/d_binary.out" grep foobar test.file
54 atf_set "descr" "Checks recursive searching"
58 mkdir -p recurse/a/f recurse/d
59 echo -e "cod\ndover sole\nhaddock\nhalibut\npilchard" > recurse/d/fish
60 echo -e "cod\nhaddock\nplaice" > recurse/a/f/favourite-fish
62 atf_check -o file:"$(atf_get_srcdir)/d_recurse.out" -x "grep -r haddock recurse | sort"
65 atf_test_case recurse_symlink
66 recurse_symlink_head()
68 atf_set "descr" "Checks symbolic link recursion"
70 recurse_symlink_body()
74 if [ $? -eq $GREP_TYPE_GNU ]; then
75 atf_expect_fail "this test doesn't pass with gnu grep from ports"
79 (cd test/c/d && ln -s ../d .)
80 echo "Test string" > test/c/match
82 atf_check -o file:"$(atf_get_srcdir)/d_recurse_symlink.out" \
83 -e file:"$(atf_get_srcdir)/d_recurse_symlink.err" \
87 atf_test_case word_regexps
90 atf_set "descr" "Checks word-regexps"
94 atf_check -o file:"$(atf_get_srcdir)/d_word_regexps.out" \
95 grep -w separated $(atf_get_srcdir)/d_input
98 printf "xmatch pmatch\n" > test1
100 atf_check -o inline:"pmatch\n" grep -Eow "(match )?pmatch" test1
104 atf_test_case begin_end
107 atf_set "descr" "Checks handling of line beginnings and ends"
111 atf_check -o file:"$(atf_get_srcdir)/d_begin_end_a.out" \
112 grep ^Front "$(atf_get_srcdir)/d_input"
114 atf_check -o file:"$(atf_get_srcdir)/d_begin_end_b.out" \
115 grep ending$ "$(atf_get_srcdir)/d_input"
118 atf_test_case ignore_case
121 atf_set "descr" "Checks ignore-case option"
125 atf_check -o file:"$(atf_get_srcdir)/d_ignore_case.out" \
126 grep -i Upper "$(atf_get_srcdir)/d_input"
132 atf_set "descr" "Checks selecting non-matching lines with -v option"
136 atf_check -o file:"$(atf_get_srcdir)/d_invert.out" \
137 grep -v fish "$(atf_get_srcdir)/d_invert.in"
140 atf_test_case whole_line
143 atf_set "descr" "Checks whole-line matching with -x flag"
147 atf_check -o file:"$(atf_get_srcdir)/d_whole_line.out" \
148 grep -x matchme "$(atf_get_srcdir)/d_input"
151 atf_test_case negative
154 atf_set "descr" "Checks handling of files with no matches"
158 atf_check -s ne:0 grep "not a hope in hell" "$(atf_get_srcdir)/d_input"
161 atf_test_case context
164 atf_set "descr" "Checks displaying context with -A, -B and -C flags"
168 cp $(atf_get_srcdir)/d_context_*.* .
170 atf_check -o file:d_context_a.out grep -C2 bamboo d_context_a.in
171 atf_check -o file:d_context_b.out grep -A3 tilt d_context_a.in
172 atf_check -o file:d_context_c.out grep -B4 Whig d_context_a.in
173 atf_check -o file:d_context_d.out grep -C1 pig d_context_a.in d_context_b.in
174 atf_check -o file:d_context_e.out \
175 grep -E -C1 '(banana|monkey)' d_context_e.in
176 atf_check -o file:d_context_f.out \
177 grep -Ev -B2 '(banana|monkey|fruit)' d_context_e.in
178 atf_check -o file:d_context_g.out \
179 grep -Ev -A1 '(banana|monkey|fruit)' d_context_e.in
182 atf_test_case file_exp
185 atf_set "descr" "Checks reading expressions from file"
189 atf_check -o file:"$(atf_get_srcdir)/d_file_exp.out" -x \
190 'jot 21 -1 1.00 | grep -f '"$(atf_get_srcdir)"'/d_file_exp.in'
196 atf_set "descr" "Checks matching special characters with egrep"
200 atf_check -o file:"$(atf_get_srcdir)/d_egrep.out" \
201 egrep '\?|\*$$' "$(atf_get_srcdir)/d_input"
207 atf_set "descr" "Checks handling of gzipped files with zgrep"
211 cp "$(atf_get_srcdir)/d_input" .
212 gzip d_input || atf_fail "gzip failed"
214 atf_check -o file:"$(atf_get_srcdir)/d_zgrep.out" zgrep -h line d_input.gz
217 atf_test_case zgrep_combined_flags
218 zgrep_combined_flags_head()
220 atf_set "descr" "Checks for zgrep wrapper problems with combined flags (PR 247126)"
222 zgrep_combined_flags_body()
224 atf_expect_fail "known but unsolved zgrep wrapper script regression"
226 echo 'foo bar' > test
228 atf_check -o inline:"foo bar\n" zgrep -we foo test
229 # Avoid hang on reading from stdin in the failure case
230 atf_check -o inline:"foo bar\n" zgrep -wefoo test < /dev/null
233 atf_test_case zgrep_eflag
236 atf_set "descr" "Checks for zgrep wrapper problems with -e PATTERN (PR 247126)"
240 echo 'foo bar' > test
242 # Avoid hang on reading from stdin in the failure case
243 atf_check -o inline:"foo bar\n" zgrep -e 'foo bar' test < /dev/null
244 atf_check -o inline:"foo bar\n" zgrep --regexp='foo bar' test < /dev/null
247 atf_test_case zgrep_fflag
250 atf_set "descr" "Checks for zgrep wrapper problems with -f FILE (PR 247126)"
257 # Avoid hang on reading from stdin in the failure case
258 atf_check -o inline:"foobar\n" zgrep -f pattern test </dev/null
259 atf_check -o inline:"foobar\n" zgrep --file=pattern test </dev/null
262 atf_test_case zgrep_long_eflag
263 zgrep_long_eflag_head()
265 atf_set "descr" "Checks for zgrep wrapper problems with --ignore-case reading from stdin (PR 247126)"
267 zgrep_long_eflag_body()
271 atf_check -o inline:"foobar\n" zgrep -e foo --ignore-case < test
274 atf_test_case zgrep_multiple_eflags
275 zgrep_multiple_eflags_head()
277 atf_set "descr" "Checks for zgrep wrapper problems with multiple -e flags (PR 247126)"
279 zgrep_multiple_eflags_body()
281 atf_expect_fail "known but unsolved zgrep wrapper script regression"
285 atf_check -o inline:"foobar\n" zgrep -e foo -e xxx test
288 atf_test_case zgrep_empty_eflag
289 zgrep_empty_eflag_head()
291 atf_set "descr" "Checks for zgrep wrapper problems with empty -e flags pattern (PR 247126)"
293 zgrep_empty_eflag_body()
297 atf_check -o inline:"foobar\n" zgrep -e '' test
300 atf_test_case nonexistent
303 atf_set "descr" "Checks that -s flag suppresses error" \
304 "messages about nonexistent files"
308 atf_check -s ne:0 grep -s foobar nonexistent
311 atf_test_case context2
314 atf_set "descr" "Checks displaying context with -z flag"
318 printf "haddock\000cod\000plaice\000" > test1
319 printf "mackeral\000cod\000crab\000" > test2
321 atf_check -o file:"$(atf_get_srcdir)/d_context2_a.out" \
322 grep -z -A1 cod test1 test2
324 atf_check -o file:"$(atf_get_srcdir)/d_context2_b.out" \
325 grep -z -B1 cod test1 test2
327 atf_check -o file:"$(atf_get_srcdir)/d_context2_c.out" \
328 grep -z -C1 cod test1 test2
332 # What grep(1) are we working with?
334 # - 1 : gnu grep 2.51 (base)
335 # - 2 : gnu grep (ports)
337 GREP_TYPE_GNU_FREEBSD=1
343 local grep_version=$(grep --version)
345 case "$grep_version" in
347 return $GREP_TYPE_BSD
350 case "$grep_version" in
352 return $GREP_TYPE_GNU_FREEBSD
355 return $GREP_TYPE_GNU
360 atf_fail "unknown grep type: $grep_version"
363 atf_test_case oflag_zerolen
366 atf_set "descr" "Check behavior of zero-length matches with -o flag (PR 195763)"
371 if [ $? -eq $GREP_TYPE_GNU_FREEBSD ]; then
372 atf_expect_fail "this test doesn't pass with gnu grep in base"
375 atf_check -o file:"$(atf_get_srcdir)/d_oflag_zerolen_a.out" \
376 grep -Eo '(^|:)0*' "$(atf_get_srcdir)/d_oflag_zerolen_a.in"
378 atf_check -o file:"$(atf_get_srcdir)/d_oflag_zerolen_b.out" \
379 grep -Eo '(^|:)0*' "$(atf_get_srcdir)/d_oflag_zerolen_b.in"
381 atf_check -o file:"$(atf_get_srcdir)/d_oflag_zerolen_c.out" \
382 grep -Eo '[[:alnum:]]*' "$(atf_get_srcdir)/d_oflag_zerolen_c.in"
384 atf_check -o empty grep -Eo '' "$(atf_get_srcdir)/d_oflag_zerolen_d.in"
386 atf_check -o file:"$(atf_get_srcdir)/d_oflag_zerolen_e.out" \
387 grep -o -e 'ab' -e 'bc' "$(atf_get_srcdir)/d_oflag_zerolen_e.in"
389 atf_check -o file:"$(atf_get_srcdir)/d_oflag_zerolen_e.out" \
390 grep -o -e 'bc' -e 'ab' "$(atf_get_srcdir)/d_oflag_zerolen_e.in"
396 atf_set "descr" "Check that we actually get a match with -x flag (PR 180990)"
400 echo 128 > match_file
401 seq 1 128 > pattern_file
402 grep -xf pattern_file match_file
408 atf_set "descr" "Check --color support"
413 if [ $? -eq $GREP_TYPE_GNU_FREEBSD ]; then
414 atf_expect_fail "this test doesn't pass with gnu grep in base"
417 echo 'abcd*' > grepfile
418 echo 'abc$' >> grepfile
419 echo '^abc' >> grepfile
421 atf_check -o file:"$(atf_get_srcdir)/d_color_a.out" \
422 grep --color=auto -e '.*' -e 'a' "$(atf_get_srcdir)/d_color_a.in"
424 atf_check -o file:"$(atf_get_srcdir)/d_color_b.out" \
425 grep --color=auto -f grepfile "$(atf_get_srcdir)/d_color_b.in"
427 atf_check -o file:"$(atf_get_srcdir)/d_color_c.out" \
428 grep --color=always -f grepfile "$(atf_get_srcdir)/d_color_b.in"
431 atf_test_case f_file_empty
434 atf_set "descr" "Check for handling of a null byte in empty file, specified by -f (PR 202022)"
438 printf "\0\n" > nulpat
440 atf_check -s exit:1 grep -f nulpat "$(atf_get_srcdir)/d_f_file_empty.in"
446 atf_set "descr" "Check proper handling of escaped vs. unescaped dot expressions (PR 175314)"
450 atf_check -s exit:1 grep -o 'f.o\.' "$(atf_get_srcdir)/d_escmap.in"
451 atf_check -o not-empty grep -o 'f.o.' "$(atf_get_srcdir)/d_escmap.in"
454 atf_test_case egrep_empty_invalid
455 egrep_empty_invalid_head()
457 atf_set "descr" "Check for handling of an invalid empty pattern (PR 194823)"
459 egrep_empty_invalid_body()
461 atf_check -e ignore -s not-exit:0 egrep '{' /dev/null
464 atf_test_case zerolen
467 atf_set "descr" "Check for successful zero-length matches with ^$"
471 printf "Eggs\n\nCheese" > test1
473 atf_check -o inline:"\n" grep -e "^$" test1
475 atf_check -o inline:"Eggs\nCheese\n" grep -v -e "^$" test1
478 atf_test_case wflag_emptypat
479 wflag_emptypat_head()
481 atf_set "descr" "Check for proper handling of -w with an empty pattern (PR 105221)"
483 wflag_emptypat_body()
488 printf " qaz\n" > test4
490 atf_check -s exit:1 -o empty grep -w -e "" test1
492 atf_check -o file:test2 grep -vw -e "" test2
494 atf_check -s exit:1 -o empty grep -w -e "" test3
496 atf_check -o file:test4 grep -vw -e "" test4
499 atf_test_case xflag_emptypat
500 xflag_emptypat_body()
505 printf " qaz\n" > test4
507 atf_check -s exit:1 -o empty grep -x -e "" test1
509 atf_check -o file:test2 grep -x -e "" test2
511 atf_check -s exit:1 -o empty grep -x -e "" test3
513 atf_check -s exit:1 -o empty grep -x -e "" test4
515 total=$(wc -l /COPYRIGHT | sed 's/[^0-9]//g')
517 # Simple checks that grep -x with an empty pattern isn't matching every
518 # line. The exact counts aren't important, as long as they don't
519 # match the total line count and as long as they don't match each other.
520 atf_check -o save:xpositive.count grep -Fxc '' /COPYRIGHT
521 atf_check -o save:xnegative.count grep -Fvxc '' /COPYRIGHT
523 atf_check -o not-inline:"${total}" cat xpositive.count
524 atf_check -o not-inline:"${total}" cat xnegative.count
526 atf_check -o not-file:xnegative.count cat xpositive.count
529 atf_test_case xflag_emptypat_plus
530 xflag_emptypat_plus_body()
532 printf "foo\n\nbar\n\nbaz\n" > target
533 printf "foo\n \nbar\n \nbaz\n" > target_spacelines
534 printf "foo\nbar\nbaz\n" > matches
535 printf " \n \n" > spacelines
537 printf "foo\n\nbar\n\nbaz\n" > patlist1
538 printf "foo\n\nba\n\nbaz\n" > patlist2
540 sed -e '/bar/d' target > matches_not2
542 # Normal handling first
543 atf_check -o file:target grep -Fxf patlist1 target
544 atf_check -o file:matches grep -Fxf patlist1 target_spacelines
545 atf_check -o file:matches_not2 grep -Fxf patlist2 target
548 atf_check -s exit:1 -o empty grep -Fvxf patlist1 target
549 atf_check -o file:spacelines grep -Fxvf patlist1 target_spacelines
552 atf_test_case emptyfile
555 atf_set "descr" "Check for proper handling of empty pattern files (PR 253209)"
562 # From PR 253209, bsdgrep was short-circuiting completely on an empty
563 # file, but we should have still been processing lines.
564 atf_check -s exit:1 -o empty fgrep -f epatfile subj
565 atf_check -o file:subj fgrep -vf epatfile subj
568 atf_test_case excessive_matches
569 excessive_matches_head()
571 atf_set "descr" "Check for proper handling of lines with excessive matches (PR 218811)"
573 excessive_matches_body()
576 if [ $? -eq $GREP_TYPE_GNU_FREEBSD ]; then
577 atf_expect_fail "this test does not pass with GNU grep in base"
580 for i in $(jot 4096); do
581 printf "x" >> test.in
584 atf_check -s exit:0 -x '[ $(grep -o x test.in | wc -l) -eq 4096 ]'
585 atf_check -s exit:1 -x 'grep -on x test.in | grep -v "1:x"'
588 atf_test_case fgrep_sanity
591 atf_set "descr" "Check for fgrep sanity, literal expressions only"
597 atf_check -o inline:"Foo\n" fgrep -e "Foo" test1
599 atf_check -s exit:1 -o empty fgrep -e "Fo." test1
602 atf_test_case egrep_sanity
605 atf_set "descr" "Check for egrep sanity, EREs only"
609 printf "Foobar(ed)" > test1
610 printf "M{1}" > test2
612 atf_check -o inline:"Foo\n" egrep -o -e "F.." test1
614 atf_check -o inline:"Foobar\n" egrep -o -e "F[a-z]*" test1
616 atf_check -o inline:"Fo\n" egrep -o -e "F(o|p)" test1
618 atf_check -o inline:"(ed)\n" egrep -o -e "\(ed\)" test1
620 atf_check -o inline:"M\n" egrep -o -e "M{1}" test2
622 atf_check -o inline:"M{1}\n" egrep -o -e "M\{1\}" test2
625 atf_test_case grep_sanity
628 atf_set "descr" "Check for basic grep sanity, BREs only"
632 printf "Foobar(ed)" > test1
633 printf "M{1}" > test2
635 atf_check -o inline:"Foo\n" grep -o -e "F.." test1
637 atf_check -o inline:"Foobar\n" grep -o -e "F[a-z]*" test1
639 atf_check -o inline:"Fo\n" grep -o -e "F\(o\)" test1
641 atf_check -o inline:"(ed)\n" grep -o -e "(ed)" test1
643 atf_check -o inline:"M{1}\n" grep -o -e "M{1}" test2
645 atf_check -o inline:"M\n" grep -o -e "M\{1\}" test2
648 atf_test_case wv_combo_break
649 wv_combo_break_head()
651 atf_set "descr" "Check for incorrectly matching lines with both -w and -v flags (PR 218467)"
653 wv_combo_break_body()
655 printf "x xx\n" > test1
656 printf "xx x\n" > test2
658 atf_check -o file:test1 grep -w "x" test1
659 atf_check -o file:test2 grep -w "x" test2
661 atf_check -s exit:1 grep -v -w "x" test1
662 atf_check -s exit:1 grep -v -w "x" test2
665 atf_test_case ocolor_metadata
666 ocolor_metadata_head()
668 atf_set "descr" "Check for -n/-b producing per-line metadata output"
670 ocolor_metadata_body()
673 if [ $? -eq $GREP_TYPE_GNU_FREEBSD ]; then
674 atf_expect_fail "this test does not pass with GNU grep in base"
677 printf "xxx\nyyyy\nzzz\nfoobarbaz\n" > test1
678 check_expr="^[^:]*[0-9][^:]*:[^:]+$"
680 atf_check -o inline:"1:1:xx\n" grep -bon "xx$" test1
682 atf_check -o inline:"2:4:yyyy\n" grep -bn "yy" test1
684 atf_check -o inline:"2:6:yy\n" grep -bon "yy$" test1
686 # These checks ensure that grep isn't producing bogus line numbering
687 # in the middle of a line.
688 atf_check -s exit:1 -x \
689 "grep -Eon 'x|y|z|f' test1 | grep -Ev '${check_expr}'"
691 atf_check -s exit:1 -x \
692 "grep -En 'x|y|z|f' --color=always test1 | grep -Ev '${check_expr}'"
694 atf_check -s exit:1 -x \
695 "grep -Eon 'x|y|z|f' --color=always test1 | grep -Ev '${check_expr}'"
698 atf_test_case grep_nomatch_flags
699 grep_nomatch_flags_head()
701 atf_set "descr" "Check for no match (-c, -l, -L, -q) flags not producing line matches or context (PR 219077)"
704 grep_nomatch_flags_body()
708 if [ $? -eq $GREP_TYPE_GNU_FREEBSD ]; then
709 atf_expect_fail "this test does not pass with GNU grep in base"
712 printf "A\nB\nC\n" > test1
714 atf_check -o inline:"1\n" grep -c -C 1 -e "B" test1
715 atf_check -o inline:"1\n" grep -c -B 1 -e "B" test1
716 atf_check -o inline:"1\n" grep -c -A 1 -e "B" test1
717 atf_check -o inline:"1\n" grep -c -C 1 -e "B" test1
719 atf_check -o inline:"test1\n" grep -l -e "B" test1
720 atf_check -o inline:"test1\n" grep -l -B 1 -e "B" test1
721 atf_check -o inline:"test1\n" grep -l -A 1 -e "B" test1
722 atf_check -o inline:"test1\n" grep -l -C 1 -e "B" test1
724 atf_check -o inline:"test1\n" grep -L -e "D" test1
726 atf_check -o empty grep -q -e "B" test1
727 atf_check -o empty grep -q -B 1 -e "B" test1
728 atf_check -o empty grep -q -A 1 -e "B" test1
729 atf_check -o empty grep -q -C 1 -e "B" test1
732 atf_test_case badcontext
735 atf_set "descr" "Check for handling of invalid context arguments"
739 printf "A\nB\nC\n" > test1
741 atf_check -s not-exit:0 -e ignore grep -A "-1" "B" test1
743 atf_check -s not-exit:0 -e ignore grep -B "-1" "B" test1
745 atf_check -s not-exit:0 -e ignore grep -C "-1" "B" test1
747 atf_check -s not-exit:0 -e ignore grep -A "B" "B" test1
749 atf_check -s not-exit:0 -e ignore grep -B "B" "B" test1
751 atf_check -s not-exit:0 -e ignore grep -C "B" "B" test1
754 atf_test_case binary_flags
757 atf_set "descr" "Check output for binary flags (-a, -I, -U, --binary-files)"
761 printf "A\000B\000C" > test1
762 printf "A\n\000B\n\000C" > test2
763 binmatchtext="Binary file test1 matches\n"
765 # Binaries not treated as text (default, -U)
766 atf_check -o inline:"${binmatchtext}" grep 'B' test1
767 atf_check -o inline:"${binmatchtext}" grep 'B' -C 1 test1
769 atf_check -o inline:"${binmatchtext}" grep -U 'B' test1
770 atf_check -o inline:"${binmatchtext}" grep -U 'B' -C 1 test1
772 # Binary, -a, no newlines
773 atf_check -o inline:"A\000B\000C\n" grep -a 'B' test1
774 atf_check -o inline:"A\000B\000C\n" grep -a 'B' -C 1 test1
776 # Binary, -a, newlines
777 atf_check -o inline:"\000B\n" grep -a 'B' test2
778 atf_check -o inline:"A\n\000B\n\000C\n" grep -a 'B' -C 1 test2
780 # Binary files ignored
781 atf_check -s exit:1 grep -I 'B' test2
783 # --binary-files equivalence
784 atf_check -o inline:"${binmatchtext}" grep --binary-files=binary 'B' test1
785 atf_check -o inline:"A\000B\000C\n" grep --binary-files=text 'B' test1
786 atf_check -s exit:1 grep --binary-files=without-match 'B' test2
792 atf_set "descr" "Check basic matching with --mmap flag"
797 if [ $? -eq $GREP_TYPE_GNU ]; then
798 atf_expect_fail "gnu grep from ports has no --mmap option"
801 printf "A\nB\nC\n" > test1
803 atf_check -s exit:0 -o inline:"B\n" grep --mmap -oe "B" test1
804 atf_check -s exit:1 grep --mmap -e "Z" test1
807 atf_test_case matchall
810 atf_set "descr" "Check proper behavior of matching all with an empty string"
816 printf "A\nB" > test3
818 atf_check -o inline:"test2:A\ntest3:A\ntest3:B\n" grep "" test1 test2 test3
819 atf_check -o inline:"test3:A\ntest3:B\ntest2:A\n" grep "" test3 test1 test2
820 atf_check -o inline:"test2:A\ntest3:A\ntest3:B\n" grep "" test2 test3 test1
822 atf_check -s exit:1 grep "" test1
825 atf_test_case fgrep_multipattern
826 fgrep_multipattern_head()
828 atf_set "descr" "Check proper behavior with multiple patterns supplied to fgrep"
830 fgrep_multipattern_body()
832 printf "Foo\nBar\nBaz" > test1
834 atf_check -o inline:"Foo\nBaz\n" grep -F -e "Foo" -e "Baz" test1
835 atf_check -o inline:"Foo\nBaz\n" grep -F -e "Baz" -e "Foo" test1
836 atf_check -o inline:"Bar\nBaz\n" grep -F -e "Bar" -e "Baz" test1
839 atf_test_case fgrep_icase
842 atf_set "descr" "Check proper handling of -i supplied to fgrep"
846 printf "Foo\nBar\nBaz" > test1
848 atf_check -o inline:"Foo\nBaz\n" grep -Fi -e "foo" -e "baz" test1
849 atf_check -o inline:"Foo\nBaz\n" grep -Fi -e "baz" -e "foo" test1
850 atf_check -o inline:"Bar\nBaz\n" grep -Fi -e "bar" -e "baz" test1
851 atf_check -o inline:"Bar\nBaz\n" grep -Fi -e "BAR" -e "bAz" test1
854 atf_test_case fgrep_oflag
857 atf_set "descr" "Check proper handling of -o supplied to fgrep"
861 printf "abcdefghi\n" > test1
863 atf_check -o inline:"a\n" grep -Fo "a" test1
864 atf_check -o inline:"i\n" grep -Fo "i" test1
865 atf_check -o inline:"abc\n" grep -Fo "abc" test1
866 atf_check -o inline:"fgh\n" grep -Fo "fgh" test1
867 atf_check -o inline:"cde\n" grep -Fo "cde" test1
868 atf_check -o inline:"bcd\n" grep -Fo -e "bcd" -e "cde" test1
869 atf_check -o inline:"bcd\nefg\n" grep -Fo -e "bcd" -e "efg" test1
871 atf_check -s exit:1 grep -Fo "xabc" test1
872 atf_check -s exit:1 grep -Fo "abcx" test1
873 atf_check -s exit:1 grep -Fo "xghi" test1
874 atf_check -s exit:1 grep -Fo "ghix" test1
875 atf_check -s exit:1 grep -Fo "abcdefghiklmnopqrstuvwxyz" test1
881 atf_set "descr" "Check proper handling of -c"
885 printf "a\nb\nc\n" > test1
887 atf_check -o inline:"1\n" grep -Ec "a" test1
888 atf_check -o inline:"2\n" grep -Ec "a|b" test1
889 atf_check -o inline:"3\n" grep -Ec "a|b|c" test1
891 atf_check -o inline:"test1:2\n" grep -EHc "a|b" test1
897 atf_set "descr" "Check proper handling of -m"
901 printf "a\nb\nc\nd\ne\nf\n" > test1
903 atf_check -o inline:"1\n" grep -m 1 -Ec "a" test1
904 atf_check -o inline:"2\n" grep -m 2 -Ec "a|b" test1
905 atf_check -o inline:"3\n" grep -m 3 -Ec "a|b|c|f" test1
907 atf_check -o inline:"test1:2\n" grep -m 2 -EHc "a|b|e|f" test1
910 atf_test_case mflag_trail_ctx
911 mflag_trail_ctx_head()
913 atf_set "descr" "Check proper handling of -m with trailing context (PR 253350)"
915 mflag_trail_ctx_body()
917 printf "foo\nfoo\nbar\nfoo\nbar\nfoo\nbar\n" > test1
919 # Should pick up the next line after matching the first.
920 atf_check -o inline:"foo\nfoo\n" grep -A1 -m1 foo test1
922 # Make sure the trailer is picked up as a non-match!
923 atf_check -o inline:"1:foo\n2-foo\n" grep -A1 -nm1 foo test1
926 atf_test_case zgrep_multiple_files
927 zgrep_multiple_files_head()
929 atf_set "descr" "Ensures that zgrep functions properly with multiple files"
931 zgrep_multiple_files_body()
935 atf_check -o inline:"test1:foo\ntest2:foo\n" zgrep foo test1 test2
938 atf_check -o inline:"test2:foo\n" zgrep foo test1 test2
941 atf_check -s exit:1 zgrep foo test1 test2
945 atf_init_test_cases()
947 atf_add_test_case basic
948 atf_add_test_case binary
949 atf_add_test_case recurse
950 atf_add_test_case recurse_symlink
951 atf_add_test_case word_regexps
952 atf_add_test_case begin_end
953 atf_add_test_case ignore_case
954 atf_add_test_case invert
955 atf_add_test_case whole_line
956 atf_add_test_case negative
957 atf_add_test_case context
958 atf_add_test_case file_exp
959 atf_add_test_case egrep
960 atf_add_test_case zgrep
961 atf_add_test_case zgrep_combined_flags
962 atf_add_test_case zgrep_eflag
963 atf_add_test_case zgrep_empty_eflag
964 atf_add_test_case zgrep_fflag
965 atf_add_test_case zgrep_long_eflag
966 atf_add_test_case zgrep_multiple_eflags
967 atf_add_test_case nonexistent
968 atf_add_test_case context2
970 atf_add_test_case oflag_zerolen
971 atf_add_test_case xflag
972 atf_add_test_case color
973 atf_add_test_case f_file_empty
974 atf_add_test_case escmap
975 atf_add_test_case egrep_empty_invalid
976 atf_add_test_case zerolen
977 atf_add_test_case wflag_emptypat
978 atf_add_test_case xflag_emptypat
979 atf_add_test_case xflag_emptypat_plus
980 atf_add_test_case emptyfile
981 atf_add_test_case excessive_matches
982 atf_add_test_case wv_combo_break
983 atf_add_test_case fgrep_sanity
984 atf_add_test_case egrep_sanity
985 atf_add_test_case grep_sanity
986 atf_add_test_case ocolor_metadata
987 atf_add_test_case grep_nomatch_flags
988 atf_add_test_case binary_flags
989 atf_add_test_case badcontext
990 atf_add_test_case mmap
991 atf_add_test_case matchall
992 atf_add_test_case fgrep_multipattern
993 atf_add_test_case fgrep_icase
994 atf_add_test_case fgrep_oflag
995 atf_add_test_case cflag
996 atf_add_test_case mflag
997 atf_add_test_case mflag_trail_ctx
998 atf_add_test_case zgrep_multiple_files