Debian Codegraph @

tests/max-count-overread

raw
1 #!/bin/sh
2 # Ensure that -m1 stops reading after the first match.
3 # In grep-2.19, yes x|grep -m1 x would infloop.
4
5 . "${srcdir=.}/init.sh"; path_prepend_ ../src
6 require_timeout_
7
8 fail=0
9
10 echo x > exp || framework_failure_
11
12 yes x | timeout 10 grep -m1 x > out || fail=1
13 compare exp out || fail=1
14
15 # Make sure -m2 stops reading even when output is /dev/null.
16 # In grep 3.11, it would continue reading.
17 printf 'x\nx\nx\n' >in || framework_failure
18 (grep -m2 x >/dev/null && head -n1) <in >out || fail=1
19 compare exp out || fail=1
20
21 # The following two tests would fail before v3.11-70
22 echo x > in || framework_failure_
23 echo in > exp || framework_failure_
24 grep -l -m1 . in > out || fail=1
25 compare exp out || fail=1
26
27 # Ensure that this prints nothing and exits successfully.
28 grep -q -m1 . in > out || fail=1
29 compare /dev/null out || fail=1
30
31 Exit $fail