Make test-yesno.sh work on mingw.
[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}out1.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 # Find out how to remove carriage returns from output. Solaris /usr/ucb/tr
14 # does not understand '\r'.
15 if echo solaris | tr -d '\r' | grep solais > /dev/null; then
16   cr='\015'
17 else
18   cr='\r'
19 fi
20
21 # Test with seekable stdin; the followon process must see remaining data.
22 cat <<EOF > ${p}in.tmp
23 nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn - entire line consumed
24 y\7fn - backspace does not change result
25 y
26 does not match either yesexpr or noexpr
27 n
28 EOF
29
30 cat <<EOF > ${p}xout.tmp
31 N
32 Y
33 Y
34 N
35 n
36 EOF
37
38 (./test-yesno${EXEEXT}; ./test-yesno${EXEEXT} 3; cat) \
39   < ${p}in.tmp > ${p}out1.tmp || exit 1
40 LC_ALL=C tr -d "$cr" < ${p}out1.tmp > ${p}out.tmp || exit 1
41 cmp ${p}xout.tmp ${p}out.tmp || exit 1
42
43 (./test-yesno${EXEEXT} 3; ./test-yesno${EXEEXT}; cat) \
44   < ${p}in.tmp > ${p}out1.tmp || exit 1
45 LC_ALL=C tr -d "$cr" < ${p}out1.tmp > ${p}out.tmp || exit 1
46 cmp ${p}xout.tmp ${p}out.tmp || exit 1
47
48 # Test for behavior on pipe
49 cat <<EOF > ${p}xout.tmp
50 Y
51 N
52 EOF
53 echo yes | ./test-yesno${EXEEXT} 2 > ${p}out1.tmp || exit 1
54 LC_ALL=C tr -d "$cr" < ${p}out1.tmp > ${p}out.tmp || exit 1
55 cmp ${p}xout.tmp ${p}out.tmp || exit 1
56
57 # Test for behavior on EOF
58 cat <<EOF > ${p}xout.tmp
59 N
60 EOF
61 ./test-yesno${EXEEXT} </dev/null > ${p}out1.tmp || exit 1
62 LC_ALL=C tr -d "$cr" < ${p}out1.tmp > ${p}out.tmp || exit 1
63 cmp ${p}xout.tmp ${p}out.tmp || exit 1
64
65 # Test for behavior when stdin is closed
66 ./test-yesno${EXEEXT} 0 <&- > ${p}out1.tmp 2> ${p}err.tmp && exit 1
67 LC_ALL=C tr -d "$cr" < ${p}out1.tmp > ${p}out.tmp || exit 1
68 cmp ${p}xout.tmp ${p}out.tmp || exit 1
69 test -s ${p}err.tmp || exit 1
70
71 # Cleanup
72 rm -fr $tmpfiles
73
74 exit 0