usleep tests: Avoid failure due to known Cygwin 3.5.3 bug.
[gnulib.git] / tests / test-yesno.sh
blob3f8f101ef32b6564b6d893ac53425859b2fd7569
1 #!/bin/sh
2 : "${srcdir=.}"
3 . "$srcdir/init.sh"; path_prepend_ .
5 # For now, only test with C locale
6 LC_ALL=C
7 export LC_ALL
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'
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
22 does not match either yesexpr or noexpr
24 EOF
26 cat <<EOF > xout.tmp
32 EOF
34 fail=0
35 (${CHECKER} test-yesno; ${CHECKER} 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
39 (${CHECKER} test-yesno 3; ${CHECKER} 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
43 # Test for behavior on pipe
44 cat <<EOF > xout.tmp
47 EOF
48 echo yes | ${CHECKER} 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
52 # Test for behavior with no EOL at EOF
53 cat <<EOF > xout.tmp
55 EOF
56 printf y | ${CHECKER} test-yesno 1 > 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
60 # Test for behavior on EOF
61 cat <<EOF > xout.tmp
63 EOF
64 ${CHECKER} test-yesno </dev/null > out1.tmp || fail=1
65 LC_ALL=C tr -d "$cr" < out1.tmp > out.tmp || fail=1
66 cmp xout.tmp out.tmp || fail=1
68 # Test for behavior when stdin is closed
69 ${CHECKER} test-yesno 0 <&- > out1.tmp 2> err.tmp && fail=1
70 LC_ALL=C tr -d "$cr" < out1.tmp > out.tmp || fail=1
71 cmp xout.tmp out.tmp || fail=1
72 test -s err.tmp || fail=1
74 Exit $fail