* tests/test-yesno.sh: Silence stderr during test.
[gnulib.git] / tests / test-yesno.sh
1 #!/bin/sh
2
3 tmpfiles=
4 trap 'rm -fr $tmpfiles' 1 2 3 15
5
6 p=t-yesno-
7 tmpfiles="${p}in.tmp ${p}xout.tmp ${p}out.tmp ${p}err.tmp"
8
9 # For now, only test with C locale
10 LC_ALL=C
11 export LC_ALL
12
13 # Test with seekable stdin; followon process must see remaining data
14 cat <<EOF > ${p}in.tmp
15 nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn - entire line consumed
16 y\7fn - backspace does not change result
17 y
18 does not match either yesexpr or noexpr
19 n
20 EOF
21 cat <<EOF > ${p}xout.tmp
22 N
23 Y
24 Y
25 N
26 n
27 EOF
28 (./test-yesno${EXEEXT}; ./test-yesno${EXEEXT} 3; cat) \
29   < ${p}in.tmp > ${p}out.tmp || exit 1
30 cmp ${p}xout.tmp ${p}out.tmp || exit 1
31
32 (./test-yesno${EXEEXT} 3; ./test-yesno${EXEEXT}; cat) \
33   < ${p}in.tmp > ${p}out.tmp || exit 1
34 cmp ${p}xout.tmp ${p}out.tmp || exit 1
35
36 # Test for behavior on pipe
37 cat <<EOF > ${p}xout.tmp
38 Y
39 N
40 EOF
41 echo yes | ./test-yesno${EXEEXT} 2 > ${p}out.tmp || exit 1
42 cmp ${p}xout.tmp ${p}out.tmp || exit 1
43
44 # Test for behavior on EOF
45 cat <<EOF > ${p}xout.tmp
46 N
47 EOF
48 ./test-yesno${EXEEXT} </dev/null > ${p}out.tmp || exit 1
49 cmp ${p}xout.tmp ${p}out.tmp || exit 1
50
51 # Test for behavior when stdin is closed
52 ./test-yesno${EXEEXT} 0 <&- > ${p}out.tmp 2> ${p}err.tmp && exit 1
53 cmp ${p}xout.tmp ${p}out.tmp || exit 1
54 test -s ${p}err.tmp || exit 1
55
56 # Cleanup
57 rm -fr $tmpfiles
58
59 exit 0