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@ksu.edu> Reviewed by: cem, ngie Differential Revision: https://reviews.freebsd.org/D10620
This commit is contained in:
parent
fdf3f96c49
commit
65df1ed6c9
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user