summaryrefslogtreecommitdiffstats
path: root/src/grep/tests/grep-dir
blob: 49475121e166b9e617b92d7bb90b96047ee1ff4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/sh
# Case-insensitive grep with a 0-size input file would fail in grep up to 2.6.3
. "${srcdir=.}/init.sh"; path_prepend_ ../src

mkdir a || framework_failure

# Lower and upper bound of valid exit status for "grep -f DIR",
# when reading from empty and nonempty files, respectively.
if cat a >acopy 2>&1 && cmp a acopy; then
  l=1 u=1 L=0 U=1
else
  l=2 u=127 L=2 U=127
fi

status_range ()
{
  status=$?
  { test $1 -le $status && test $status -le $2; } || fail=1
}

echo x | grep -f a/; status_range $L $U
echo x | grep -if a/; status_range $L $U
echo x | grep -Ff a/; status_range $L $U
echo x | grep -Fif a/; status_range $L $U

grep -f a/ < /dev/null; status_range $l $u
grep -if a/ < /dev/null; status_range $l $u
grep -Ff a/ < /dev/null; status_range $l $u
grep -Fif a/ < /dev/null; status_range $l $u

Exit $fail