randomconfig fixes
[platform/upstream/busybox.git] / testsuite / grep.tests
index b2de2af..ffce033 100755 (executable)
@@ -1,11 +1,11 @@
 #!/bin/sh
 
 # Copyright 2005 by Rob Landley <rob@landley.net>
-# Licensed under GPL v2, see file LICENSE for details.
+# Licensed under GPLv2, see file LICENSE in this source tree.
 
 # AUDIT:
 
-. testing.sh
+. ./testing.sh
 
 # testing "test name" "options" "expected result" "file input" "stdin"
 #   file input will be file called "input"
@@ -62,21 +62,21 @@ testing "grep -s nofile - (stdin and nonexisting file, match)" \
        "grep -s domatch nonexistent - ; echo \$?" \
        "(standard input):domatch\n2\n" "" "nomatch\ndomatch\nend\n"
 
-# This doesn't match GNU behaviour (Binary file input matches)
-# acts like GNU grep -a
-testing "grep handles binary files" "grep foo input" "foo\n" "\0foo\n\n" ""
-# This doesn't match GNU behaviour (Binary file (standard input) matches)
-# acts like GNU grep -a
-testing "grep handles binary stdin" "grep foo" "foo\n" "" "\0foo\n\n"
+optional EXTRA_COMPAT
+testing "grep handles NUL in files" "grep -a foo input" "\0foo\n" "\0foo\n\n" ""
+testing "grep handles NUL on stdin" "grep -a foo" "\0foo\n" "" "\0foo\n\n"
 
 testing "grep matches NUL" "grep . input > /dev/null 2>&1 ; echo \$?" \
        "0\n" "\0\n" ""
+SKIP=
 
 # -e regex
 testing "grep handles multiple regexps" "grep -e one -e two input ; echo \$?" \
        "one\ntwo\n0\n" "one\ntwo\n" ""
 testing "grep -F handles multiple expessions" "grep -F -e one -e two input ; echo \$?" \
        "one\ntwo\n0\n" "one\ntwo\n" ""
+testing "grep -F handles -i" "grep -F -i foo input ; echo \$?" \
+       "FOO\n0\n" "FOO\n" ""
 
 # -f file/-
 testing "grep can read regexps from stdin" "grep -f - input ; echo \$?" \
@@ -88,5 +88,19 @@ testing "grep -E supports extended regexps" "grep -E fo+" "foo\n" "" \
 testing "grep is also egrep" "egrep foo" "foo\n" "" "foo\nbar\n"
 testing "egrep is not case insensitive" \
        "egrep foo ; [ \$? -ne 0 ] && echo yes" "yes\n" "" "FOO\n"
+testing "grep -E -o prints all matches" \
+       "grep -E -o '([[:xdigit:]]{2}[:-]){5}[[:xdigit:]]{2}'" \
+       "00:19:3E:00:AA:5E\n00:1D:60:3D:3A:FB\n00:22:43:49:FB:AA\n" \
+       "" "00:19:3E:00:AA:5E 00:1D:60:3D:3A:FB 00:22:43:49:FB:AA\n"
+SKIP=
+
+testing "grep -o does not loop forever" \
+       'grep -o "[^/]*$"' \
+       "test\n" \
+       "" "/var/test\n"
+testing "grep -o does not loop forever on zero-length match" \
+       'grep -o "" | head -n1' \
+       "" \
+       "" "test\n"
 
 exit $FAILCOUNT