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 | # Copyright (C) 2001, 2006, 2009-2021 Free Software Foundation, Inc.
|
---|
9 | #
|
---|
10 | # Copying and distribution of this file, with or without modification,
|
---|
11 | # are permitted in any medium without royalty provided the copyright
|
---|
12 | # notice and this notice are preserved.
|
---|
13 |
|
---|
14 | . "${srcdir=.}/init.sh"; path_prepend_ ../src
|
---|
15 |
|
---|
16 | fail=0
|
---|
17 |
|
---|
18 | # should return 0 found a match
|
---|
19 | echo "abcd" | grep -E -e 'abc' > /dev/null 2>&1
|
---|
20 | if test $? -ne 0 ; then
|
---|
21 | echo "Status: Wrong status code, test \#1 failed"
|
---|
22 | fail=1
|
---|
23 | fi
|
---|
24 |
|
---|
25 | # should return 1 found no match
|
---|
26 | echo "abcd" | grep -E -e 'zbc' > /dev/null 2>&1
|
---|
27 | if test $? -ne 1 ; then
|
---|
28 | echo "Status: Wrong status code, test \#2 failed"
|
---|
29 | fail=1
|
---|
30 | fi
|
---|
31 |
|
---|
32 | # the filename MMMMMMMM.MMM should not exist hopefully
|
---|
33 | if test -r MMMMMMMM.MMM; then
|
---|
34 | echo "Please remove MMMMMMMM.MMM to run check"
|
---|
35 | else
|
---|
36 | # should return 2 file not found
|
---|
37 | grep -E -e 'abc' MMMMMMMM.MMM > /dev/null 2>&1
|
---|
38 | if test $? -ne 2 ; then
|
---|
39 | echo "Status: Wrong status code, test \#3 failed"
|
---|
40 | fail=1
|
---|
41 | fi
|
---|
42 |
|
---|
43 | # should return 2 file not found
|
---|
44 | grep -E -s -e 'abc' MMMMMMMM.MMM > /dev/null 2>&1
|
---|
45 | if test $? -ne 2 ; then
|
---|
46 | echo "Status: Wrong status code, test \#4 failed"
|
---|
47 | fail=1
|
---|
48 | fi
|
---|
49 |
|
---|
50 | # should return 0 (found a match) or 2 (file not found)
|
---|
51 | echo "abcd" | grep -E -s 'abc' - MMMMMMMM.MMM > /dev/null 2>&1
|
---|
52 | status=$?
|
---|
53 | if test $status -ne 0 && test $status -ne 2 ; then
|
---|
54 | echo "Status: Wrong status code, test \#5 failed"
|
---|
55 | fail=1
|
---|
56 | fi
|
---|
57 |
|
---|
58 | # should return 0 found a match
|
---|
59 | echo "abcd" | grep -E -q -s 'abc' MMMMMMMM.MMM - > /dev/null 2>&1
|
---|
60 | if test $? -ne 0 ; then
|
---|
61 | echo "Status: Wrong status code, test \#6 failed"
|
---|
62 | fail=1
|
---|
63 | fi
|
---|
64 |
|
---|
65 | # should still return 0 found a match
|
---|
66 | echo "abcd" | grep -E -q 'abc' MMMMMMMM.MMM - > /dev/null 2>&1
|
---|
67 | if test $? -ne 0 ; then
|
---|
68 | echo "Status: Wrong status code, test \#7 failed"
|
---|
69 | fail=1
|
---|
70 | fi
|
---|
71 | fi
|
---|
72 |
|
---|
73 | Exit $fail
|
---|