xref: /openbsd-src/regress/bin/ksh/read.t (revision 8534e72e04570d018bd86f47004261768cc2901d)
1#	$OpenBSD: read.t,v 1.2 2022/10/16 12:34:13 kn Exp $
2
3#
4# To test:
5#   POSIX:
6#	- if no -r, \ is escape character
7#	    - \newline disappear
8#	    - \<IFS> -> don't break here
9#	    - \<anything-else> -> <anything-else>
10#	- if -r, backslash is not special
11#	- if stdin is tty and shell interactive
12#	    - prompt for continuation if \newline (prompt to stderr)
13#	    - a here-document isn't terminated after newline ????
14#	- remaining vars set to empty string (not null)
15#	- check field splitting
16#	- left over fields and their separators assigned to last var
17#	- exit status is normally 0
18#	- exit status is > 0 on eof
19#	- exit status > 0 on error
20#	- signals interrupt reads
21#   extra:
22#	- can't change read-only variables
23#	- error if var name bogus
24#	- set -o allexport effects read
25# ksh:
26#	x check default variable: REPLY
27#	- check -p, -s, -u options
28#	- check var?prompt stuff
29#	- "echo a b | read x y" sets x,y in parent shell (at&t)
30#
31name: read-IFS-1
32description:
33	Simple test, default IFS
34stdin:
35	echo "A B " > IN
36	unset x y z
37	read x y z < IN
38	echo 1: "x[$x] y[$y] z[$z]"
39	echo 1a: ${z-z not set}
40	read x < IN
41	echo 2: "x[$x]"
42expected-stdout:
43	1: x[A] y[B] z[]
44	1a:
45	2: x[A B]
46---
47
48name: read-ksh-1
49description:
50	If no var specified, REPLY is used
51stdin:
52	echo "abc" > IN
53	read < IN
54	echo "[$REPLY]";
55expected-stdout:
56	[abc]
57---
58
59name: signal-aborts-endless-read
60description:
61	Check that an endless read can be interrupted.
62# XXX ^C does nothing, needs uncatchable SIGKILL to stop
63expected-fail: yes
64stdin:
65	exec timeout --preserve-status -s INT -k 0.5s -- 0.1s $PROG -c '
66		read < /dev/zero
67	'
68# 2/9 == INT/KILL
69# XXX using signal expressions like 's == 2' only works with ksh
70expected-exit: e == 128 + 2
71---
72