pty: Activate the signature wrapper of forkpty.
[gnulib.git] / tests / test-yesno.sh
1 #!/bin/sh
2 : ${srcdir=.}
3 . "$srcdir/init.sh"; path_prepend_ .
4
5 # For now, only test with C locale
6 LC_ALL=C
7 export LC_ALL
8
9 # Find out how to remove carriage returns from output. Solaris /usr/ucb/tr
10 # does not understand '\r'.
11 if echo solaris | tr -d '\r' | grep solais > /dev/null; then
12   cr='\015'
13 else
14   cr='\r'
15 fi
16
17 # Test with seekable stdin; the follow-on process must see remaining data.
18 tr @ '\177' <<EOF > in.tmp
19 nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn - entire line consumed
20 y@n - backspace does not change result
21 y
22 does not match either yesexpr or noexpr
23 n
24 EOF
25
26 cat <<EOF > xout.tmp
27 N
28 Y
29 Y
30 N
31 n
32 EOF
33
34 fail=0
35 (test-yesno; test-yesno 3; cat) < in.tmp > out1.tmp || fail=1
36 LC_ALL=C tr -d "$cr" < out1.tmp > out.tmp || fail=1
37 cmp xout.tmp out.tmp || fail=1
38
39 (test-yesno 3; test-yesno; cat) < in.tmp > out1.tmp || fail=1
40 LC_ALL=C tr -d "$cr" < out1.tmp > out.tmp || fail=1
41 cmp xout.tmp out.tmp || fail=1
42
43 # Test for behavior on pipe
44 cat <<EOF > xout.tmp
45 Y
46 N
47 EOF
48 echo yes | test-yesno 2 > out1.tmp || fail=1
49 LC_ALL=C tr -d "$cr" < out1.tmp > out.tmp || fail=1
50 cmp xout.tmp out.tmp || fail=1
51
52 # Test for behavior on EOF
53 cat <<EOF > xout.tmp
54 N
55 EOF
56 test-yesno </dev/null > out1.tmp || fail=1
57 LC_ALL=C tr -d "$cr" < out1.tmp > out.tmp || fail=1
58 cmp xout.tmp out.tmp || fail=1
59
60 # Test for behavior when stdin is closed
61 test-yesno 0 <&- > out1.tmp 2> err.tmp && fail=1
62 LC_ALL=C tr -d "$cr" < out1.tmp > out.tmp || fail=1
63 cmp xout.tmp out.tmp || fail=1
64 test -s err.tmp || fail=1
65
66 Exit $fail