Blame tests/status

Packit 709fb3
#! /bin/sh
Packit 709fb3
# Test for status code for GNU grep.
Packit 709fb3
# status code
Packit 709fb3
#  0 match found
Packit 709fb3
#  1 no match
Packit 709fb3
#  2 file not found
Packit 709fb3
#
Packit 709fb3
# Copyright (C) 2001, 2006, 2009-2017 Free Software Foundation, Inc.
Packit 709fb3
#
Packit 709fb3
# Copying and distribution of this file, with or without modification,
Packit 709fb3
# are permitted in any medium without royalty provided the copyright
Packit 709fb3
# notice and this notice are preserved.
Packit 709fb3
Packit 709fb3
. "${srcdir=.}/init.sh"; path_prepend_ ../src
Packit 709fb3
Packit 709fb3
fail=0
Packit 709fb3
Packit 709fb3
# should return 0 found a match
Packit 709fb3
echo "abcd" | grep -E -e 'abc' > /dev/null 2>&1
Packit 709fb3
if test $? -ne 0 ; then
Packit 709fb3
        echo "Status: Wrong status code, test \#1 failed"
Packit 709fb3
        fail=1
Packit 709fb3
fi
Packit 709fb3
Packit 709fb3
# should return 1 found no match
Packit 709fb3
echo "abcd" | grep -E -e 'zbc' > /dev/null 2>&1
Packit 709fb3
if test $? -ne 1 ; then
Packit 709fb3
        echo "Status: Wrong status code, test \#2 failed"
Packit 709fb3
        fail=1
Packit 709fb3
fi
Packit 709fb3
Packit 709fb3
# the filename MMMMMMMM.MMM should not exist hopefully
Packit 709fb3
if test -r MMMMMMMM.MMM; then
Packit 709fb3
        echo "Please remove MMMMMMMM.MMM to run check"
Packit 709fb3
else
Packit 709fb3
        # should return 2 file not found
Packit 709fb3
        grep -E -e 'abc' MMMMMMMM.MMM > /dev/null 2>&1
Packit 709fb3
        if test $? -ne 2 ; then
Packit 709fb3
                echo "Status: Wrong status code, test \#3 failed"
Packit 709fb3
                fail=1
Packit 709fb3
        fi
Packit 709fb3
Packit 709fb3
        # should return 2 file not found
Packit 709fb3
        grep -E -s -e 'abc' MMMMMMMM.MMM > /dev/null 2>&1
Packit 709fb3
        if test $? -ne 2 ; then
Packit 709fb3
                echo "Status: Wrong status code, test \#4 failed"
Packit 709fb3
                fail=1
Packit 709fb3
        fi
Packit 709fb3
Packit 709fb3
        # should return 0 (found a match) or 2 (file not found)
Packit 709fb3
        echo "abcd" | grep -E -s 'abc' - MMMMMMMM.MMM > /dev/null 2>&1
Packit 709fb3
        status=$?
Packit 709fb3
        if test $status -ne 0 && test $status -ne 2 ; then
Packit 709fb3
                echo "Status: Wrong status code, test \#5 failed"
Packit 709fb3
                fail=1
Packit 709fb3
        fi
Packit 709fb3
Packit 709fb3
        # should return 0 found a match
Packit 709fb3
        echo "abcd" | grep -E -q -s 'abc' MMMMMMMM.MMM - > /dev/null 2>&1
Packit 709fb3
        if test $? -ne 0 ; then
Packit 709fb3
                echo "Status: Wrong status code, test \#6 failed"
Packit 709fb3
                fail=1
Packit 709fb3
        fi
Packit 709fb3
Packit 709fb3
        # should still return 0 found a match
Packit 709fb3
        echo "abcd" | grep -E -q 'abc' MMMMMMMM.MMM - > /dev/null 2>&1
Packit 709fb3
        if test $? -ne 0 ; then
Packit 709fb3
                echo "Status: Wrong status code, test \#7 failed"
Packit 709fb3
                fail=1
Packit 709fb3
        fi
Packit 709fb3
fi
Packit 709fb3
Packit 709fb3
Exit $fail