VirtualBox

source: kBuild/trunk/src/grep/tests/status

Last change on this file was 3529, checked in by bird, 3 years ago

Imported grep 3.7 from grep-3.7.tar.gz (sha256: c22b0cf2d4f6bbe599c902387e8058990e1eee99aef333a203829e5fd3dbb342), applying minimal auto-props.

  • Property svn:executable set to *
File size: 2.2 KB
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# 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
16fail=0
17
18# should return 0 found a match
19echo "abcd" | grep -E -e 'abc' > /dev/null 2>&1
20if test $? -ne 0 ; then
21 echo "Status: Wrong status code, test \#1 failed"
22 fail=1
23fi
24
25# should return 1 found no match
26echo "abcd" | grep -E -e 'zbc' > /dev/null 2>&1
27if test $? -ne 1 ; then
28 echo "Status: Wrong status code, test \#2 failed"
29 fail=1
30fi
31
32# the filename MMMMMMMM.MMM should not exist hopefully
33if test -r MMMMMMMM.MMM; then
34 echo "Please remove MMMMMMMM.MMM to run check"
35else
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
71fi
72
73Exit $fail
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette