summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <meyering@fb.com>2016-10-30 18:51:34 (GMT)
committerJim Meyering <meyering@fb.com>2016-11-15 03:12:22 (GMT)
commit1569ee170b8eb3e5a03ca3d7d53e71fd05fd08e5 (patch)
treeda31c08048a0f959ab8bd0ab7503264a8d3fc69c
parent735085b7935ef12a9e6b7c42a99450f9e5497491 (diff)
downloadgrep-1569ee170b8eb3e5a03ca3d7d53e71fd05fd08e5.zip
grep-1569ee170b8eb3e5a03ca3d7d53e71fd05fd08e5.tar.gz
grep-1569ee170b8eb3e5a03ca3d7d53e71fd05fd08e5.tar.bz2
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.
-rwxr-xr-xtests/backref-multibyte-slow4
-rwxr-xr-xtests/char-class-multibyte3
-rwxr-xr-xtests/dfa-heap-overrun3
-rwxr-xr-xtests/encoding-error3
-rwxr-xr-xtests/euc-mb7
-rwxr-xr-xtests/fedora10
-rwxr-xr-xtests/grep-dev-null16
-rw-r--r--tests/init.cfg2
-rwxr-xr-xtests/kwset-abuse5
-rwxr-xr-xtests/mb-non-UTF8-overrun3
-rwxr-xr-xtests/multibyte-white-space6
-rwxr-xr-xtests/pcre-abort3
-rwxr-xr-xtests/pcre-infloop4
-rwxr-xr-xtests/pcre-jitstack4
-rwxr-xr-xtests/repetition-overflow4
-rwxr-xr-xtests/reversed-range-endpoints3
-rwxr-xr-xtests/sjis-mb8
-rwxr-xr-xtests/surrogate-pair3
-rwxr-xr-xtests/warn-char-classes24
19 files changed, 47 insertions, 68 deletions
diff --git a/tests/backref-multibyte-slow b/tests/backref-multibyte-slow
index fb012a6..9c4fe06 100755
--- a/tests/backref-multibyte-slow
+++ b/tests/backref-multibyte-slow
@@ -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
diff --git a/tests/char-class-multibyte b/tests/char-class-multibyte
index 459d10c..6bff4b3 100755
--- a/tests/char-class-multibyte
+++ b/tests/char-class-multibyte
@@ -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
diff --git a/tests/dfa-heap-overrun b/tests/dfa-heap-overrun
index 874dea2..c8bb185 100755
--- a/tests/dfa-heap-overrun
+++ b/tests/dfa-heap-overrun
@@ -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
diff --git a/tests/encoding-error b/tests/encoding-error
index 0cbeffc..5f5a09d 100755
--- a/tests/encoding-error
+++ b/tests/encoding-error
@@ -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
diff --git a/tests/euc-mb b/tests/euc-mb
index b625046..06e72cd 100755
--- a/tests/euc-mb
+++ b/tests/euc-mb
@@ -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
diff --git a/tests/fedora b/tests/fedora
index e7e7463..43650f3 100755
--- a/tests/fedora
+++ b/tests/fedora
@@ -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
diff --git a/tests/grep-dev-null b/tests/grep-dev-null
index e649be0..49a9385 100755
--- a/tests/grep-dev-null
+++ b/tests/grep-dev-null
@@ -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
diff --git a/tests/init.cfg b/tests/init.cfg
index bc62c32..1677ec5 100644
--- a/tests/init.cfg
+++ b/tests/init.cfg
@@ -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
}
diff --git a/tests/kwset-abuse b/tests/kwset-abuse
index 84e9416..a8680f8 100755
--- a/tests/kwset-abuse
+++ b/tests/kwset-abuse
@@ -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
diff --git a/tests/mb-non-UTF8-overrun b/tests/mb-non-UTF8-overrun
index 69335d3..7743029 100755
--- a/tests/mb-non-UTF8-overrun
+++ b/tests/mb-non-UTF8-overrun
@@ -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
diff --git a/tests/multibyte-white-space b/tests/multibyte-white-space
index 24b14cb..7c0d0b7 100755
--- a/tests/multibyte-white-space
+++ b/tests/multibyte-white-space
@@ -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
diff --git a/tests/pcre-abort b/tests/pcre-abort
index 5e9fdf2..83c90e4 100755
--- a/tests/pcre-abort
+++ b/tests/pcre-abort
@@ -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
diff --git a/tests/pcre-infloop b/tests/pcre-infloop
index 179bf86..ce6cd7a 100755
--- a/tests/pcre-infloop
+++ b/tests/pcre-infloop
@@ -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
diff --git a/tests/pcre-jitstack b/tests/pcre-jitstack
index b473b12..a7bca79 100755
--- a/tests/pcre-jitstack
+++ b/tests/pcre-jitstack
@@ -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
diff --git a/tests/repetition-overflow b/tests/repetition-overflow
index 35d928b..38a652d 100755
--- a/tests/repetition-overflow
+++ b/tests/repetition-overflow
@@ -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
diff --git a/tests/reversed-range-endpoints b/tests/reversed-range-endpoints
index faa33f4..0737447 100755
--- a/tests/reversed-range-endpoints
+++ b/tests/reversed-range-endpoints
@@ -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
diff --git a/tests/sjis-mb b/tests/sjis-mb
index db147fd..fb6dcf7 100755
--- a/tests/sjis-mb
+++ b/tests/sjis-mb
@@ -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() {
diff --git a/tests/surrogate-pair b/tests/surrogate-pair
index 93eeb5a..38a2a55 100755
--- a/tests/surrogate-pair
+++ b/tests/surrogate-pair
@@ -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
diff --git a/tests/warn-char-classes b/tests/warn-char-classes
index 1069059..1a64073 100755
--- a/tests/warn-char-classes
+++ b/tests/warn-char-classes
@@ -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