diff options
-rwxr-xr-x | tests/grep.test | 2 | ||||
-rw-r--r-- | tests/timeout.test | 1 | ||||
-rw-r--r-- | 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 </dev/null * -USE_GREP(NEWTOY(grep, "(color):;S(exclude)*M(include)*ZzEFHIab(byte-offset)h(no-filename)ino(only-matching)rsvwcl(files-with-matches)q(quiet)(silent)e*f*C#B#A#m#x[!wx][!EFw]", TOYFLAG_BIN)) -USE_EGREP(OLDTOY(egrep, grep, TOYFLAG_BIN)) -USE_FGREP(OLDTOY(fgrep, grep, TOYFLAG_BIN)) +USE_GREP(NEWTOY(grep, "(color):;S(exclude)*M(include)*ZzEFHIab(byte-offset)h(no-filename)ino(only-matching)rsvwcl(files-with-matches)q(quiet)(silent)e*f*C#B#A#m#x[!wx][!EFw]", TOYFLAG_BIN|TOYFLAG_ARGFAIL(2))) +USE_EGREP(OLDTOY(egrep, grep, TOYFLAG_BIN|TOYFLAG_ARGFAIL(2))) +USE_FGREP(OLDTOY(fgrep, grep, TOYFLAG_BIN|TOYFLAG_ARGFAIL(2))) config GREP bool "grep" @@ -22,7 +22,7 @@ config GREP Show lines matching regular expressions. If no -e, first argument is regular expression to match. With no files (or "-" filename) read stdin. - Returns 0 if matched, 1 if no match found. + Returns 0 if matched, 1 if no match found, 2 for command errors. -e Regex to match. (May be repeated.) -f File listing regular expressions to match. |