summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <meyering@fb.com>2018-11-24 12:17:05 -1000
committerJim Meyering <meyering@fb.com>2018-11-24 12:59:09 -1000
commit2725f1ee63e60da75a3884bcd6363ef6dbe9a39f (patch)
tree8bbf61d8b499f0732bc852c325b9c184f7c8cbfa
parent30e666ca22eaa7e69330ca46201e40f1cdb0f41e (diff)
downloadgrep-2725f1ee63e60da75a3884bcd6363ef6dbe9a39f.tar.gz
tests: stack-overflow: avoid false failure
* tests/stack-overflow: This test would fail to elicit a stack overflow diagnostic on some OS X systems. Rewrite to iterate, gradually increasing the size of the input regex, stopping when grep emits the desired diagnostic or the size reaches a reasonable limit.
-rwxr-xr-xtests/stack-overflow23
1 files changed, 16 insertions, 7 deletions
diff --git a/tests/stack-overflow b/tests/stack-overflow
index 2042ebc5..69220455 100755
--- a/tests/stack-overflow
+++ b/tests/stack-overflow
@@ -3,14 +3,23 @@
. "${srcdir=.}/init.sh"; path_prepend_ ../src
-# Too many open parentheses.
-printf %080000d 0|tr 0 '(' > in || framework_failure_
echo grep: stack overflow > exp || framework_failure_
+# grep attempts to detect overflow via gnulib's c-stack module.
+# Trigger that with an input regex composed solely of open parentheses,
+# increasing the size of that input until grep emits the expected diagnostic.
fail=0
-returns_ 2 grep -E -f in >out 2>err || fail=1
+for i in 1 3 5 10 20 30 40 50 100 200; do
+ # Create a file containing $i * 10000 open parentheses:
+ printf %0${i}0000d 0|tr 0 '(' > in || framework_failure_
+ grep -E -f in >out 2>err; st=$?
+ if grep -q 'stack overflow' err; then
+ test $st = 2 || fail=1
+ compare /dev/null out || fail=1
+ compare exp err || fail=1
+ test $fail = 0 && Exit 0
+ fail_ 'printed "stack overflow", but something else was wrong'
+ fi
+done
-compare /dev/null out || fail=1
-compare exp err || fail=1
-
-Exit $fail
+fail_ 'grep never printed "stack overflow"'