File: test-closein.sh

package info (click to toggle)
m4 1.4.16-3
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 10,204 kB
  • sloc: ansic: 69,401; sh: 7,576; cpp: 1,030; lisp: 243; makefile: 161
file content (38 lines) | stat: -rwxr-xr-x 1,076 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/sh

tmpfiles=
trap 'rm -fr $tmpfiles' 1 2 3 15

p=t-closein-
tmpfiles="${p}in.tmp ${p}xout.tmp ${p}out1.tmp ${p}out2.tmp"

echo Hello world > ${p}in.tmp
echo world > ${p}xout.tmp

# Test with seekable stdin; followon process must see remaining data
(./test-closein${EXEEXT}; cat) < ${p}in.tmp > ${p}out1.tmp || exit 1
cmp ${p}out1.tmp ${p}in.tmp || exit 1

(./test-closein${EXEEXT} consume; cat) < ${p}in.tmp > ${p}out2.tmp || exit 1
cmp ${p}out2.tmp ${p}xout.tmp || exit 1

# Test for lack of error on pipe.  Ignore any EPIPE failures from cat.
cat ${p}in.tmp 2>/dev/null | ./test-closein${EXEEXT} || exit 1

cat ${p}in.tmp 2>/dev/null | ./test-closein${EXEEXT} consume || exit 1

# Test for lack of error when nothing is read
./test-closein${EXEEXT} </dev/null || exit 1

./test-closein${EXEEXT} <&- || exit 1

# Test for no error when EOF is read early
./test-closein${EXEEXT} consume </dev/null || exit 1

# Test for error when read fails because no file available
./test-closein${EXEEXT} consume close <&- 2>/dev/null && exit 1

# Cleanup
rm -fr $tmpfiles

exit 0