aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2021-02-04 21:26:45 +0000
committerKyle Evans <kevans@FreeBSD.org>2021-02-05 02:59:42 +0000
commitf823c6dc730b0dd08b54a53be1d8fd587eee7021 (patch)
tree57d87d3dd9fc780d7aa70852d0b0cd56b9c932ea /contrib
parent856789c123d69de86684c5aa1ad8a53427dd47fc (diff)
downloadsrc-f823c6dc730b0dd08b54a53be1d8fd587eee7021.tar.gz
src-f823c6dc730b0dd08b54a53be1d8fd587eee7021.zip
grep: fix null pattern and empty pattern file behavior
The null pattern semantics were terrible because I tried to match gnugrep, but I got it wrong. Let's unwind that: - The null pattern should match every line if neither -w nor -x. - The null pattern should match empty lines if -x. - The null pattern should not match any lines if -w. The first two will stop processing (shortcut) even if additional patterns are specified. In any other case, we will continue processing other patterns. If no other patterns are specified beside a null pattern, then we match if neither -w nor -x or set and do not match if either of those are specified. The justification for -w is that it should match on a whole word, but the null pattern deos not have a whole word to match on. Empty pattern files should never match anything, and more importantly, -v should cause everything to be written. PR: 253209 MFC-after: 4 days
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/netbsd-tests/usr.bin/grep/t_grep.sh22
1 files changed, 19 insertions, 3 deletions
diff --git a/contrib/netbsd-tests/usr.bin/grep/t_grep.sh b/contrib/netbsd-tests/usr.bin/grep/t_grep.sh
index e094b15c6d67..ef3f0617465e 100755
--- a/contrib/netbsd-tests/usr.bin/grep/t_grep.sh
+++ b/contrib/netbsd-tests/usr.bin/grep/t_grep.sh
@@ -489,11 +489,11 @@ wflag_emptypat_body()
atf_check -s exit:1 -o empty grep -w -e "" test1
- atf_check -o file:test2 grep -w -e "" test2
+ atf_check -o file:test2 grep -vw -e "" test2
atf_check -s exit:1 -o empty grep -w -e "" test3
- atf_check -o file:test4 grep -w -e "" test4
+ atf_check -o file:test4 grep -vw -e "" test4
}
atf_test_case xflag_emptypat
@@ -504,7 +504,6 @@ xflag_emptypat_body()
printf "qaz" > test3
printf " qaz\n" > test4
- # -x is whole-line, more strict than -w.
atf_check -s exit:1 -o empty grep -x -e "" test1
atf_check -o file:test2 grep -x -e "" test2
@@ -550,6 +549,22 @@ xflag_emptypat_plus_body()
atf_check -o file:spacelines grep -Fxvf patlist1 target_spacelines
}
+atf_test_case emptyfile
+emptyfile_descr()
+{
+ atf_set "descr" "Check for proper handling of empty pattern files (PR 253209)"
+}
+emptyfile_body()
+{
+ :> epatfile
+ echo "blubb" > subj
+
+ # From PR 253209, bsdgrep was short-circuiting completely on an empty
+ # file, but we should have still been processing lines.
+ atf_check -s exit:1 -o empty fgrep -f epatfile subj
+ atf_check -o file:subj fgrep -vf epatfile subj
+}
+
atf_test_case excessive_matches
excessive_matches_head()
{
@@ -946,6 +961,7 @@ atf_init_test_cases()
atf_add_test_case wflag_emptypat
atf_add_test_case xflag_emptypat
atf_add_test_case xflag_emptypat_plus
+ atf_add_test_case emptyfile
atf_add_test_case excessive_matches
atf_add_test_case wv_combo_break
atf_add_test_case fgrep_sanity