1131554Stjr#!/bin/sh 253568Sobrien# Test for status code for GNU grep. 353568Sobrien# status code 453568Sobrien# 0 match found 553568Sobrien# 1 no match 653568Sobrien# 2 file not found 753568Sobrien 853568Sobrien: ${srcdir=.} 953568Sobrien 1053568Sobrienfailures=0 1153568Sobrien 1253568Sobrien# should return 0 found a match 1353568Sobrienecho "abcd" | ${GREP} -E -e 'abc' > /dev/null 2>&1 1453568Sobrienif test $? -ne 0 ; then 1553568Sobrien echo "Status: Wrong status code, test \#1 failed" 1653568Sobrien failures=1 1753568Sobrienfi 1853568Sobrien 1953568Sobrien# should return 1 found no match 2053568Sobrienecho "abcd" | ${GREP} -E -e 'zbc' > /dev/null 2>&1 2153568Sobrienif test $? -ne 1 ; then 2253568Sobrien echo "Status: Wrong status code, test \#2 failed" 2353568Sobrien failures=1 2453568Sobrienfi 2553568Sobrien 2653568Sobrien# the filename MMMMMMMM.MMM should not exist hopefully 27131554Stjrif test -r MMMMMMMM.MMM; then 2853568Sobrien echo "Please remove MMMMMMMM.MMM to run check" 2953568Sobrienelse 30131554Stjr # should return 2 file not found 31131554Stjr ${GREP} -E -e 'abc' MMMMMMMM.MMM > /dev/null 2>&1 3253568Sobrien if test $? -ne 2 ; then 3353568Sobrien echo "Status: Wrong status code, test \#3 failed" 3453568Sobrien failures=1 3553568Sobrien fi 36131554Stjr 37131554Stjr # should return 2 file not found 38131554Stjr ${GREP} -E -s -e 'abc' MMMMMMMM.MMM > /dev/null 2>&1 39131554Stjr if test $? -ne 2 ; then 40131554Stjr echo "Status: Wrong status code, test \#4 failed" 41131554Stjr failures=1 42131554Stjr fi 43131554Stjr 44131554Stjr # should return 0 found a match 45131554Stjr echo "abcd" | ${GREP} -E -q -s 'abc' MMMMMMMM.MMM - > /dev/null 2>&1 46131554Stjr if test $? -ne 0 ; then 47131554Stjr echo "Status: Wrong status code, test \#5 failed" 48131554Stjr failures=1 49131554Stjr fi 5053568Sobrienfi 5153568Sobrien 5253568Sobrienexit $failures 53