svn commit: r318317 - head/contrib/netbsd-tests/usr.bin/grep

Ed Maste emaste at FreeBSD.org
Mon May 15 20:41:30 UTC 2017


Author: emaste
Date: Mon May 15 20:41:29 2017
New Revision: 318317
URL: https://svnweb.freebsd.org/changeset/base/318317

Log:
  bsdgrep: add more tests for different binary flags
  
  The existing 'binary' test in netbsd-tests/ does a basic check of the
  default treatment for binary behavior, but not much more than that.
  Given some opportunity for breakage recently that did not trigger any
  failures, add some tests to cover the three different binary file
  behaviors (a, -I, -U) and their --binary-files= equivalent values.
  
  Submitted by:	Kyle Evans <kevans91 at ksu.edu>
  Reviewed by:	cem, ngie
  Differential Revision:	https://reviews.freebsd.org/D10620

Modified:
  head/contrib/netbsd-tests/usr.bin/grep/t_grep.sh

Modified: head/contrib/netbsd-tests/usr.bin/grep/t_grep.sh
==============================================================================
--- head/contrib/netbsd-tests/usr.bin/grep/t_grep.sh	Mon May 15 20:18:14 2017	(r318316)
+++ head/contrib/netbsd-tests/usr.bin/grep/t_grep.sh	Mon May 15 20:41:29 2017	(r318317)
@@ -539,6 +539,41 @@ badcontext_body()
 
 	atf_check -s not-exit:0 -e ignore grep -C "B" "B" test1
 }
+
+atf_test_case binary_flags
+binary_flags_head()
+{
+	atf_set "descr" "Check output for binary flags (-a, -I, -U, --binary-files)"
+}
+binary_flags_body()
+{
+	printf "A\000B\000C" > test1
+	printf "A\n\000B\n\000C" > test2
+	binmatchtext="Binary file test1 matches\n"
+
+	# Binaries not treated as text (default, -U)
+	atf_check -o inline:"${binmatchtext}" grep 'B' test1
+	atf_check -o inline:"${binmatchtext}" grep 'B' -C 1 test1
+
+	atf_check -o inline:"${binmatchtext}" grep -U 'B' test1
+	atf_check -o inline:"${binmatchtext}" grep -U 'B' -C 1 test1
+
+	# Binary, -a, no newlines
+	atf_check -o inline:"A\000B\000C\n" grep -a 'B' test1
+	atf_check -o inline:"A\000B\000C\n" grep -a 'B' -C 1 test1
+
+	# Binary, -a, newlines
+	atf_check -o inline:"\000B\n" grep -a 'B' test2
+	atf_check -o inline:"A\n\000B\n\000C\n" grep -a 'B' -C 1 test2
+
+	# Binary files ignored
+	atf_check -s exit:1 grep -I 'B' test2
+
+	# --binary-files equivalence
+	atf_check -o inline:"${binmatchtext}" grep --binary-files=binary 'B' test1
+	atf_check -o inline:"A\000B\000C\n" grep --binary-files=text 'B' test1
+	atf_check -s exit:1 grep --binary-files=without-match 'B' test2
+}
 # End FreeBSD
 
 atf_init_test_cases()
@@ -573,6 +608,7 @@ atf_init_test_cases()
 	atf_add_test_case egrep_sanity
 	atf_add_test_case grep_sanity
 	atf_add_test_case grep_nomatch_flags
+	atf_add_test_case binary_flags
 	atf_add_test_case badcontext
 # End FreeBSD
 }


More information about the svn-src-head mailing list