| Line | |
|---|
| 1 | #!/bin/sh
|
|---|
| 2 | # Test for status code for GNU grep.
|
|---|
| 3 | # status code
|
|---|
| 4 | # 0 match found
|
|---|
| 5 | # 1 no match
|
|---|
| 6 | # 2 file not found
|
|---|
| 7 |
|
|---|
| 8 | : ${srcdir=.}
|
|---|
| 9 |
|
|---|
| 10 | failures=0
|
|---|
| 11 |
|
|---|
| 12 | # should return 0 found a match
|
|---|
| 13 | echo "abcd" | ${GREP} -E -e 'abc' > /dev/null 2>&1
|
|---|
| 14 | if test $? -ne 0 ; then
|
|---|
| 15 | echo "Status: Wrong status code, test \#1 failed"
|
|---|
| 16 | failures=1
|
|---|
| 17 | fi
|
|---|
| 18 |
|
|---|
| 19 | # should return 1 found no match
|
|---|
| 20 | echo "abcd" | ${GREP} -E -e 'zbc' > /dev/null 2>&1
|
|---|
| 21 | if test $? -ne 1 ; then
|
|---|
| 22 | echo "Status: Wrong status code, test \#2 failed"
|
|---|
| 23 | failures=1
|
|---|
| 24 | fi
|
|---|
| 25 |
|
|---|
| 26 | # the filename MMMMMMMM.MMM should not exist hopefully
|
|---|
| 27 | if test -r MMMMMMMM.MMM; then
|
|---|
| 28 | echo "Please remove MMMMMMMM.MMM to run check"
|
|---|
| 29 | else
|
|---|
| 30 | # should return 2 file not found
|
|---|
| 31 | ${GREP} -E -e 'abc' MMMMMMMM.MMM > /dev/null 2>&1
|
|---|
| 32 | if test $? -ne 2 ; then
|
|---|
| 33 | echo "Status: Wrong status code, test \#3 failed"
|
|---|
| 34 | failures=1
|
|---|
| 35 | fi
|
|---|
| 36 |
|
|---|
| 37 | # should return 2 file not found
|
|---|
| 38 | ${GREP} -E -s -e 'abc' MMMMMMMM.MMM > /dev/null 2>&1
|
|---|
| 39 | if test $? -ne 2 ; then
|
|---|
| 40 | echo "Status: Wrong status code, test \#4 failed"
|
|---|
| 41 | failures=1
|
|---|
| 42 | fi
|
|---|
| 43 |
|
|---|
| 44 | # should return 0 found a match
|
|---|
| 45 | echo "abcd" | ${GREP} -E -q -s 'abc' MMMMMMMM.MMM - > /dev/null 2>&1
|
|---|
| 46 | if test $? -ne 0 ; then
|
|---|
| 47 | echo "Status: Wrong status code, test \#5 failed"
|
|---|
| 48 | failures=1
|
|---|
| 49 | fi
|
|---|
| 50 | fi
|
|---|
| 51 |
|
|---|
| 52 | exit $failures
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.