tests: use "returns_" rather than explicit comparison with "$?"

* tests/sjis-mb (encode): Rearrange to emit desired input into
a file, rather than piping directly into grep.  That permits
the use of returns_ 1 to verify timeout's exit status.
* tests/euc-mb: Use "returns_ 1" rather than testing $? = 1
* tests/char-class-multibyte: Likewise.
* tests/dfa-heap-overrun: Likewise.
* tests/encoding-error: Likewise.
* tests/fedora: Likewise.
* tests/grep-dev-null: Likewise.
* tests/init.cfg (envvar_check_fail): Likewise.
* tests/kwset-abuse: Likewise.
* tests/mb-non-UTF8-overrun: Likewise.
* tests/multibyte-white-space: Likewise.
* tests/pcre-infloop: Likewise.
* tests/surrogate-pair: Likewise.
* tests/warn-char-classes: Likewise.
Do the same for other values:
* tests/backref-multibyte-slow: Likewise.
* tests/euc-mb: Likewise.
* tests/pcre-abort: Likewise.
* tests/pcre-jitstack: Likewise.
* tests/repetition-overflow: Likewise.
* tests/reversed-range-endpoints: Likewise.
* tests/warn-char-classes: Likewise.
This commit is contained in:
Jim Meyering 2016-10-30 11:51:34 -07:00
parent 735085b793
commit 1569ee170b
19 changed files with 47 additions and 68 deletions

View File

@ -25,8 +25,8 @@ test $max_seconds = 1 && max_seconds=5
for LOC in en_US.UTF-8; do
out=out-$LOC
LC_ALL=$LOC timeout ${max_seconds}s grep -aE '^([a-z]).\1$' in > $out 2>&1
test $? = 0 || fail=1
LC_ALL=$LOC timeout ${max_seconds}s grep -aE '^([a-z]).\1$' in > $out 2>&1 \
|| fail=1
compare $out in || fail=1
done

View File

@ -24,8 +24,7 @@ done
for LOC in en_US.UTF-8 $LOCALE_FR_UTF8; do
out=out3-$LOC
printf '\303\n' | LC_ALL=$LOC grep '[é]' > $out
test $? = 1 || fail=1
printf '\303\n' | LC_ALL=$LOC returns_ 1 grep '[é]' > $out || fail=1
done
Exit $fail

View File

@ -20,7 +20,6 @@
fail=0
grep -E '(^| )*(a|b)*(c|d)*( |$)' < /dev/null
test $? = 1 || fail=1
returns_ 1 grep -E '(^| )*(a|b)*(c|d)*( |$)' < /dev/null || fail=1
Exit $fail

View File

@ -31,8 +31,7 @@ compare exp out || fail=1
grep '^J' in >out || fail=1
compare j out || fail=1
grep '^X' in >out
test $? = 1 || fail=1
returns_ 1 grep '^X' in >out || fail=1
compare /dev/null out || fail=1
grep . in >out || fail=1

View File

@ -38,11 +38,10 @@ make_input BABA |euc_grep AB && fail=1
make_input BABAAB |euc_grep AB > out || fail=1
make_input BABAAB > exp || framework_failure_
compare exp out || fail=1
make_input BABABA |euc_grep AB; test $? = 1 || fail=1
make_input BABABA |euc_grep '^x\|AB'; test $? = 1 || fail=1
make_input BABABA |returns_ 1 euc_grep AB || fail=1
make_input BABABA |returns_ 1 euc_grep '^x\|AB' || fail=1
# -P supports only unibyte and UTF-8 locales.
LC_ALL=$locale grep -P x /dev/null
test $? = 2 || fail=1
LC_ALL=$locale returns_ 2 grep -P x /dev/null || fail=1
Exit $fail

View File

@ -52,18 +52,16 @@ if ( timeout --version ) > /dev/null 2>&1; then
U=https://bugzilla.redhat.com/show_bug.cgi?id=189580
printf 'grep -D skip opening a special file: '
timeout 10 grep -D skip foo /dev/zero
test $? = 124 && fail || ok
returns_ 124 timeout 10 grep -D skip foo /dev/zero && fail || ok
U=https://bugzilla.redhat.com/show_bug.cgi?id=169524
printf 'grep -Fw looping infinitely: '
echo foobar | timeout 10 grep -Fw ""
test $? = 124 && fail || ok
echo foobar | returns_ 124 timeout 10 grep -Fw "" && fail || ok
U=https://bugzilla.redhat.com/show_bug.cgi?id=140781
printf 'fgrep hangs on binary files: '
timeout 10 grep -F grep "$abs_top_builddir/src/grep" >/dev/null
test $? = 124 && fail || ok
returns_ 124 timeout 10 grep -F grep "$abs_top_builddir/src/grep" \
> /dev/null && fail || ok
fi

View File

@ -7,14 +7,14 @@ require_en_utf8_locale_
LC_ALL=en_US.UTF-8
export LC_ALL
echo x | grep -f /dev/null; test $? = 1 || fail=1
echo x | grep -if /dev/null; test $? = 1 || fail=1
echo x | grep -Ff /dev/null; test $? = 1 || fail=1
echo x | grep -Fif /dev/null; test $? = 1 || fail=1
echo x | returns_ 1 grep -f /dev/null || fail=1
echo x | returns_ 1 grep -if /dev/null || fail=1
echo x | returns_ 1 grep -Ff /dev/null || fail=1
echo x | returns_ 1 grep -Fif /dev/null || fail=1
grep -f /dev/null < /dev/null; test $? = 1 || fail=1
grep -if /dev/null < /dev/null; test $? = 1 || fail=1
grep -Ff /dev/null < /dev/null; test $? = 1 || fail=1
grep -Fif /dev/null < /dev/null; test $? = 1 || fail=1
returns_ 1 grep -f /dev/null < /dev/null || fail=1
returns_ 1 grep -if /dev/null < /dev/null || fail=1
returns_ 1 grep -Ff /dev/null < /dev/null || fail=1
returns_ 1 grep -Fif /dev/null < /dev/null || fail=1
Exit $fail

View File

@ -41,7 +41,7 @@ require_timeout_()
{
( timeout 10s true ) > /dev/null 2>&1 \
|| skip_ your system lacks the timeout program
timeout 10s false; test $? = 1 \
returns_ 1 timeout 10s false \
|| skip_ your system has a non-GNU timeout program
}

View File

@ -25,8 +25,7 @@ fail=0
# with gdb showed a reallocation slightly larger than that in fillbuf.
# To reach the buggy code, the needle must have length < 1/11 that of
# the haystack, and 10,000 is a nice round number that fits the bill.
printf '%0260000dXy\n' 0 | grep -F $(printf %010000dy 0)
test $? = 1 || fail=1
printf '%0260000dXy\n' 0 | returns_ 1 grep -F $(printf %010000dy 0) \
|| fail=1
Exit $fail

View File

@ -24,7 +24,6 @@ fail=0
# This would fail when running an ASAN-enabled binary, or when run via
# valgrind, accessing one byte beyond the end of an input buffer.
grep -z . < /dev/null
test $? = 1 || fail=1
returns_ 1 grep -z . < /dev/null || fail=1
Exit $fail

View File

@ -83,8 +83,7 @@ for i in $utf8_space_characters; do
hex_printf_ "$i" | grep -q '^\s$' \
|| { warn_ " $m: \\s failed to match $i in the $LC_ALL locale"; fail; }
hex_printf_ "$i" | grep -q '\S'
test $? = 1 \
hex_printf_ "$i" | returns_ 1 grep -q '\S' \
|| { warn_ " $m: \\S mistakenly matched $i in the $LC_ALL locale"; fail; }
done
@ -94,8 +93,7 @@ done
# match_mb_charset function) that would have otherwise been untouched.
# However, as of the change-set adding this new test, match_mb_charset
# is unreachable via grep.
printf '\0' | grep -aE '^\s?$' > out 2>&1
test $? = 1 || fail=1
printf '\0' | returns_ 1 grep -aE '^\s?$' > out 2>&1 || fail=1
compare /dev/null out
Exit $fail

View File

@ -14,8 +14,7 @@ require_pcre_
fail=0
echo aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab > in || framework_failure_
grep -P '((a+)*)+$' in > out
test $? = 2 || fail=1
returns_ 2 grep -P '((a+)*)+$' in > out || fail=1
compare /dev/null out || fail=1
Exit $fail

View File

@ -27,7 +27,7 @@ printf 'a\201b\r' > in || framework_failure_
fail=0
LC_ALL=en_US.UTF-8 timeout 10 grep -P 'a.?..b' in
test $? = 1 || fail_ "libpcre's match function appears to infloop"
LC_ALL=en_US.UTF-8 returns_ 1 timeout 10 grep -P 'a.?..b' in \
|| fail_ "libpcre's match function appears to infloop"
Exit $fail

View File

@ -52,8 +52,8 @@ if test $? != 1; then
# Rerun that same test, but now with no limit on stack size:
(ulimit -s unlimited;
LC_ALL=C grep -P -n '^([/](?!/)|[^/])*~/.*' pcrejit.txt)
test $? = 1 || fail=1
LC_ALL=C returns_ 1 grep -P -n '^([/](?!/)|[^/])*~/.*' pcrejit.txt) \
|| fail=1
fi
Exit $fail

View File

@ -11,9 +11,9 @@ fail=0
# range of "unsigned int" would silently wrap around. Hence, 2^32+1
# would be treated just like "1", and both of these would mistakenly match.
echo abc | grep -E "b{$xp1}" > out 2> /dev/null; test $? = 2 || fail=1
echo abc | returns_ 2 grep -E "b{$xp1}" > out 2> /dev/null || fail=1
compare /dev/null out || fail=1
echo abbc | grep -E "b{1,$xp2}" > out 2> /dev/null; test $? = 2 || fail=1
echo abbc | returns_ 2 grep -E "b{1,$xp2}" > out 2> /dev/null || fail=1
compare /dev/null out || fail=1
Exit $fail

View File

@ -6,9 +6,8 @@ fail=0
printf 'Invalid range end\n' > exp
for prog in grep 'grep -E'; do
$prog '[b-a]' < /dev/null > out 2>&1
# exit status must be 2, not 1
test $? = 2 || fail=1
returns_ 2 $prog '[b-a]' < /dev/null > out 2>&1 || fail=1
# Remove "$prog: " prefix from actual output.
sed 's/^[grep]*: //' out > k && mv k out

View File

@ -29,10 +29,10 @@ test -n "$locale" || skip_ 'SJIS locale not found'
k=0
test_grep_reject() {
k=$(expr $k + 1)
encode "$2" | \
LC_ALL=$locale \
timeout 10s grep $1 $(encode "$3") > out$k 2>&1
test $? = 1 && compare /dev/null out$k
encode "$2" > in || return 1
LC_ALL=$locale \
returns_ 1 timeout 10s grep $1 $(encode "$3") in >out$k 2>&1 \
&& compare /dev/null out$k
}
test_grep() {

View File

@ -29,9 +29,8 @@ LC_ALL=en_US.UTF-8
export LC_ALL
# On Cygwin, before grep-2.15, this would segfault.
grep -i anything-else in > out 2>&1
# Require not just non-zero exit status, but exactly 1.
test $? = 1 || fail=1
returns_ 1 grep -i anything-else in > out 2>&1 || fail=1
# Expect no output.
compare /dev/null out || fail=1

View File

@ -10,38 +10,30 @@ printf 'grep: character class syntax is [[:space:]], not [:space:]\n' \
# basic cases
grep '[:space:]' x 2> err
test $? = 2 || fail=1
returns_ 2 grep '[:space:]' x 2> err || fail=1
sed 's/^\([A-Za-z]:\)\{0,1\}[^: ]*: /grep: /' err > err1 && mv err1 err
compare exp-err err || fail=1
grep '[[:space:]]' x 2> err
test $? = 1 || fail=1
returns_ 1 grep '[[:space:]]' x 2> err || fail=1
test -s err && fail=1
# disabled by POSIXLY_CORRECT
POSIXLY_CORRECT=yes grep '[:space:]' x 2> err
test $? = 1 || fail=1
POSIXLY_CORRECT=yes returns_ 1 grep '[:space:]' x 2> err || fail=1
test -s err && fail=1
# patterns that are considered valid
grep '[::]' x 2> err
test $? = 1 || fail=1
returns_ 1 grep '[::]' x 2> err || fail=1
test -s err && fail=1
grep '[:space]' x 2> err
test $? = 1 || fail=1
returns_ 1 grep '[:space]' x 2> err || fail=1
test -s err && fail=1
grep '[:space:wxyz]' x 2> err
test $? = 1 || fail=1
returns_ 1 grep '[:space:wxyz]' x 2> err || fail=1
test -s err && fail=1
grep '[:space[:space:]:]' x 2> err
test $? = 1 || fail=1
returns_ 1 grep '[:space[:space:]:]' x 2> err || fail=1
test -s err && fail=1
grep '[:spac-e:]' x 2> err
test $? = 1 || fail=1
returns_ 1 grep '[:spac-e:]' x 2> err || fail=1
test -s err && fail=1
Exit $fail