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