From 799c5faa8b6fe27c7dfdf573a59496a4eca0b997 Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Wed, 5 Apr 2017 18:41:44 +0000 Subject: [PATCH] bsdgrep: create additional tests for coverage on recent fixes Create additional tests to cover regressions that were discovered by PRs linked to reviews D10098, D10102, and D10104. It is worth noting that neither bsdgrep(1) nor gnugrep(1) in the base system currently pass all of these tests, and gnugrep(1) not quite being up to snuff was also noted in at least one of the PRs. PR: 175314 202022 195763 180990 197555 197531 181263 209116 Submitted by: Kyle Evans Reviewed by: cem, ngie, emaste MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D10112 --- .../netbsd-tests/usr.bin/grep/d_color_a.in | 1 + .../netbsd-tests/usr.bin/grep/d_color_a.out | 1 + .../netbsd-tests/usr.bin/grep/d_color_b.in | 5 + .../netbsd-tests/usr.bin/grep/d_color_b.out | 3 + .../netbsd-tests/usr.bin/grep/d_color_c.out | 3 + contrib/netbsd-tests/usr.bin/grep/d_escmap.in | 1 + .../usr.bin/grep/d_f_file_empty.in | 2 + .../usr.bin/grep/d_oflag_zerolen_a.in | 1 + .../usr.bin/grep/d_oflag_zerolen_a.out | 3 + .../usr.bin/grep/d_oflag_zerolen_b.in | 1 + .../usr.bin/grep/d_oflag_zerolen_b.out | 2 + .../usr.bin/grep/d_oflag_zerolen_c.in | 1 + .../usr.bin/grep/d_oflag_zerolen_c.out | 2 + .../usr.bin/grep/d_oflag_zerolen_d.in | 3 + .../usr.bin/grep/d_oflag_zerolen_e.in | 1 + .../usr.bin/grep/d_oflag_zerolen_e.out | 1 + contrib/netbsd-tests/usr.bin/grep/t_grep.sh | 102 +++++++++++++++++- usr.bin/grep/tests/Makefile | 16 +++ 18 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 contrib/netbsd-tests/usr.bin/grep/d_color_a.in create mode 100644 contrib/netbsd-tests/usr.bin/grep/d_color_a.out create mode 100644 contrib/netbsd-tests/usr.bin/grep/d_color_b.in create mode 100644 contrib/netbsd-tests/usr.bin/grep/d_color_b.out create mode 100644 contrib/netbsd-tests/usr.bin/grep/d_color_c.out create mode 100644 contrib/netbsd-tests/usr.bin/grep/d_escmap.in create mode 100644 contrib/netbsd-tests/usr.bin/grep/d_f_file_empty.in create mode 100644 contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_a.in create mode 100644 contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_a.out create mode 100644 contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_b.in create mode 100644 contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_b.out create mode 100644 contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_c.in create mode 100644 contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_c.out create mode 100644 contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_d.in create mode 100644 contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_e.in create mode 100644 contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_e.out diff --git a/contrib/netbsd-tests/usr.bin/grep/d_color_a.in b/contrib/netbsd-tests/usr.bin/grep/d_color_a.in new file mode 100644 index 000000000000..a1e432252d25 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/grep/d_color_a.in @@ -0,0 +1 @@ +abcd* diff --git a/contrib/netbsd-tests/usr.bin/grep/d_color_a.out b/contrib/netbsd-tests/usr.bin/grep/d_color_a.out new file mode 100644 index 000000000000..a1e432252d25 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/grep/d_color_a.out @@ -0,0 +1 @@ +abcd* diff --git a/contrib/netbsd-tests/usr.bin/grep/d_color_b.in b/contrib/netbsd-tests/usr.bin/grep/d_color_b.in new file mode 100644 index 000000000000..83409d744b2f --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/grep/d_color_b.in @@ -0,0 +1,5 @@ +fojeiwuroiuwet +ljfajsljkfabcdddjlfkajlkj +abcaaa +zzzabc + diff --git a/contrib/netbsd-tests/usr.bin/grep/d_color_b.out b/contrib/netbsd-tests/usr.bin/grep/d_color_b.out new file mode 100644 index 000000000000..83db20cb2f59 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/grep/d_color_b.out @@ -0,0 +1,3 @@ +ljfajsljkfabcdddjlfkajlkj +abcaaa +zzzabc diff --git a/contrib/netbsd-tests/usr.bin/grep/d_color_c.out b/contrib/netbsd-tests/usr.bin/grep/d_color_c.out new file mode 100644 index 000000000000..30fd9e5b3b4d --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/grep/d_color_c.out @@ -0,0 +1,3 @@ +ljfajsljkfabcdddjlfkajlkj +abcaaa +zzzabc diff --git a/contrib/netbsd-tests/usr.bin/grep/d_escmap.in b/contrib/netbsd-tests/usr.bin/grep/d_escmap.in new file mode 100644 index 000000000000..ef045756ac50 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/grep/d_escmap.in @@ -0,0 +1 @@ +f.oo diff --git a/contrib/netbsd-tests/usr.bin/grep/d_f_file_empty.in b/contrib/netbsd-tests/usr.bin/grep/d_f_file_empty.in new file mode 100644 index 000000000000..58d8e574add0 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/grep/d_f_file_empty.in @@ -0,0 +1,2 @@ +Fish zebra monkey suits + diff --git a/contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_a.in b/contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_a.in new file mode 100644 index 000000000000..7d00c34c16fe --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_a.in @@ -0,0 +1 @@ +01:1:01 diff --git a/contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_a.out b/contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_a.out new file mode 100644 index 000000000000..fb4c91278b1c --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_a.out @@ -0,0 +1,3 @@ +0 +: +:0 diff --git a/contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_b.in b/contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_b.in new file mode 100644 index 000000000000..6c793401d047 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_b.in @@ -0,0 +1 @@ +1:1:01 diff --git a/contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_b.out b/contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_b.out new file mode 100644 index 000000000000..221f334d0d99 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_b.out @@ -0,0 +1,2 @@ +: +:0 diff --git a/contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_c.in b/contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_c.in new file mode 100644 index 000000000000..b72e7d487723 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_c.in @@ -0,0 +1 @@ +bla bla diff --git a/contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_c.out b/contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_c.out new file mode 100644 index 000000000000..167a17b76c72 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_c.out @@ -0,0 +1,2 @@ +bla +bla diff --git a/contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_d.in b/contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_d.in new file mode 100644 index 000000000000..c2057f88aca0 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_d.in @@ -0,0 +1,3 @@ +bla +bla + diff --git a/contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_e.in b/contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_e.in new file mode 100644 index 000000000000..0373d9336f8c --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_e.in @@ -0,0 +1 @@ +abcdef diff --git a/contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_e.out b/contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_e.out new file mode 100644 index 000000000000..81bf39695611 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/grep/d_oflag_zerolen_e.out @@ -0,0 +1 @@ +ab diff --git a/contrib/netbsd-tests/usr.bin/grep/t_grep.sh b/contrib/netbsd-tests/usr.bin/grep/t_grep.sh index 558b074ad4b3..b8d2a398c8dc 100755 --- a/contrib/netbsd-tests/usr.bin/grep/t_grep.sh +++ b/contrib/netbsd-tests/usr.bin/grep/t_grep.sh @@ -226,10 +226,102 @@ context2_body() atf_check -o file:"$(atf_get_srcdir)/d_context2_c.out" \ grep -z -C1 cod test1 test2 } +# Begin FreeBSD +atf_test_case oflag_zerolen +oflag_zerolen_head() +{ + atf_set "descr" "Check behavior of zero-length matches with -o flag (PR 195763)" +} +oflag_zerolen_body() +{ + atf_check -o file:"$(atf_get_srcdir)/d_oflag_zerolen_a.out" \ + grep -Eo '(^|:)0*' "$(atf_get_srcdir)/d_oflag_zerolen_a.in" + + atf_check -o file:"$(atf_get_srcdir)/d_oflag_zerolen_b.out" \ + grep -Eo '(^|:)0*' "$(atf_get_srcdir)/d_oflag_zerolen_b.in" + + atf_check -o file:"$(atf_get_srcdir)/d_oflag_zerolen_c.out" \ + grep -Eo '[[:alnum:]]*' "$(atf_get_srcdir)/d_oflag_zerolen_c.in" + + atf_check -o empty grep -Eo '' "$(atf_get_srcdir)/d_oflag_zerolen_d.in" + + atf_check -o file:"$(atf_get_srcdir)/d_oflag_zerolen_e.out" \ + grep -o -e 'ab' -e 'bc' "$(atf_get_srcdir)/d_oflag_zerolen_e.in" + + atf_check -o file:"$(atf_get_srcdir)/d_oflag_zerolen_e.out" \ + grep -o -e 'bc' -e 'ab' "$(atf_get_srcdir)/d_oflag_zerolen_e.in" +} + +atf_test_case xflag +xflag_head() +{ + atf_set "descr" "Check that we actually get a match with -x flag (PR 180990)" +} +xflag_body() +{ + echo 128 > match_file + seq 1 128 > pattern_file + grep -xf pattern_file match_file +} + +atf_test_case color +color_head() +{ + atf_set "descr" "Check --color support" +} +color_body() +{ + echo 'abcd*' > grepfile + echo 'abc$' >> grepfile + echo '^abc' >> grepfile + + atf_check -o file:"$(atf_get_srcdir)/d_color_a.out" \ + grep --color=auto -e '.*' -e 'a' "$(atf_get_srcdir)/d_color_a.in" + + atf_check -o file:"$(atf_get_srcdir)/d_color_b.out" \ + grep --color=auto -f grepfile "$(atf_get_srcdir)/d_color_b.in" + + atf_check -o file:"$(atf_get_srcdir)/d_color_c.out" \ + grep --color=always -f grepfile "$(atf_get_srcdir)/d_color_b.in" +} + +atf_test_case f_file_empty +f_file_empty_head() +{ + atf_set "descr" "Check for handling of a null byte in empty file, specified by -f (PR 202022)" +} +f_file_empty_body() +{ + printf "\0\n" > nulpat + + atf_check -s exit:1 grep -f nulpat "$(atf_get_srcdir)/d_f_file_empty.in" +} + +atf_test_case escmap +escmap_head() +{ + atf_set "descr" "Check proper handling of escaped vs. unescaped dot expressions (PR 175314)" +} +escmap_body() +{ + atf_check -s exit:1 grep -o 'f.o\.' "$(atf_get_srcdir)/d_escmap.in" + atf_check -o not-empty grep -o 'f.o.' "$(atf_get_srcdir)/d_escmap.in" +} + +atf_test_case egrep_empty_invalid +egrep_empty_invalid_head() +{ + atf_set "descr" "Check for handling of an invalid empty pattern (PR 194823)" +} +egrep_empty_invalid_body() +{ + atf_check -s exit:1 egrep '{' /dev/null +} +# End FreeBSD atf_init_test_cases() { - atf_add_test_case basic + atf_add_test_case basic atf_add_test_case binary atf_add_test_case recurse atf_add_test_case recurse_symlink @@ -245,4 +337,12 @@ atf_init_test_cases() atf_add_test_case zgrep atf_add_test_case nonexistent atf_add_test_case context2 +# Begin FreeBSD + atf_add_test_case oflag_zerolen + atf_add_test_case xflag + atf_add_test_case color + atf_add_test_case f_file_empty + atf_add_test_case escmap + atf_add_test_case egrep_empty_invalid +# End FreeBSD } diff --git a/usr.bin/grep/tests/Makefile b/usr.bin/grep/tests/Makefile index 041259b0144e..51c2deb4cc61 100644 --- a/usr.bin/grep/tests/Makefile +++ b/usr.bin/grep/tests/Makefile @@ -8,6 +8,11 @@ ${PACKAGE}FILES+= d_basic.out ${PACKAGE}FILES+= d_begin_end_a.out ${PACKAGE}FILES+= d_begin_end_b.out ${PACKAGE}FILES+= d_binary.out +${PACKAGE}FILES+= d_color_a.in +${PACKAGE}FILES+= d_color_a.out +${PACKAGE}FILES+= d_color_b.in +${PACKAGE}FILES+= d_color_b.out +${PACKAGE}FILES+= d_color_c.out ${PACKAGE}FILES+= d_context2_a.out ${PACKAGE}FILES+= d_context2_b.out ${PACKAGE}FILES+= d_context2_c.out @@ -18,12 +23,23 @@ ${PACKAGE}FILES+= d_context_b.out ${PACKAGE}FILES+= d_context_c.out ${PACKAGE}FILES+= d_context_d.out ${PACKAGE}FILES+= d_egrep.out +${PACKAGE}FILES+= d_escmap.in +${PACKAGE}FILES+= d_f_file_empty.in ${PACKAGE}FILES+= d_file_exp.in ${PACKAGE}FILES+= d_file_exp.out ${PACKAGE}FILES+= d_ignore_case.out ${PACKAGE}FILES+= d_input ${PACKAGE}FILES+= d_invert.in ${PACKAGE}FILES+= d_invert.out +${PACKAGE}FILES+= d_oflag_zerolen_a.in +${PACKAGE}FILES+= d_oflag_zerolen_a.out +${PACKAGE}FILES+= d_oflag_zerolen_b.in +${PACKAGE}FILES+= d_oflag_zerolen_b.out +${PACKAGE}FILES+= d_oflag_zerolen_c.in +${PACKAGE}FILES+= d_oflag_zerolen_c.out +${PACKAGE}FILES+= d_oflag_zerolen_d.in +${PACKAGE}FILES+= d_oflag_zerolen_e.in +${PACKAGE}FILES+= d_oflag_zerolen_e.out ${PACKAGE}FILES+= d_recurse.out ${PACKAGE}FILES+= d_recurse_symlink.err ${PACKAGE}FILES+= d_recurse_symlink.out