From caa5a3b131137d1063ea466e57204b9375701499 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Wed, 13 Mar 2019 22:21:13 -0700 Subject: grep: use TOYFLAG_ARGFAIL for grep too. Also add a test, and add a test for timeout now it's been fixed. --- tests/grep.test | 2 ++ tests/timeout.test | 1 + toys/posix/grep.c | 8 ++++---- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/grep.test b/tests/grep.test index 05288983..cd1e1fda 100755 --- a/tests/grep.test +++ b/tests/grep.test @@ -154,3 +154,5 @@ testing "explicit ERE |" "grep -E 'uno|dos'" "uno\ndos\nuno|dos\n" \ testing "" "grep -o -e iss -e ipp" "iss\niss\nipp\n" "" "mississippi" testing "" "grep -o -e gum -e rgu" "rgu\n" "" "argument" + +testing "early failure" 'grep --what 2>/dev/null || echo $?' "2\n" "" "" diff --git a/tests/timeout.test b/tests/timeout.test index 5ca7cc90..189b592a 100644 --- a/tests/timeout.test +++ b/tests/timeout.test @@ -7,6 +7,7 @@ # timeout's exit value is complicated! testcmd "times out" '.1 sleep 100 ; echo $?' '124\n' '' '' testcmd "failure" '-s MONKEY .1 sleep 100 2>/dev/null ; echo $?' '125\n' '' '' +testcmd "early failure" '2>/dev/null ; echo $?' '125\n' '' '' testcmd "can't execute" '.1 / 2>/dev/null ; echo $?' '126\n' '' '' testcmd "can't find" '.1 /does/not/exist 2>/dev/null ; echo $?' '127\n' '' '' testcmd "custom signal" '-s 3 .1 sleep 100; echo $?' '124\n' '' '' diff --git a/toys/posix/grep.c b/toys/posix/grep.c index c9a30882..9239614f 100644 --- a/toys/posix/grep.c +++ b/toys/posix/grep.c @@ -10,9 +10,9 @@ * echo hello | grep -f