Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/ksh93/tests/pty.sh
1810 views
1
########################################################################
2
# #
3
# This software is part of the ast package #
4
# Copyright (c) 1982-2012 AT&T Intellectual Property #
5
# and is licensed under the #
6
# Eclipse Public License, Version 1.0 #
7
# by AT&T Intellectual Property #
8
# #
9
# A copy of the License is available at #
10
# http://www.eclipse.org/org/documents/epl-v10.html #
11
# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
12
# #
13
# Information and Software Systems Research #
14
# AT&T Research #
15
# Florham Park NJ #
16
# #
17
# David Korn <[email protected]> #
18
# #
19
########################################################################
20
: : generated by mkptytests from "posix-sh-*-c.pty" : :
21
22
# the trickiest part of the tests is avoiding typeahead
23
# in the pty dialogue
24
25
function err_exit
26
{
27
print -u2 -n "\t"
28
print -u2 -r ${Command}[$1]: "${@:2}"
29
(( Errors++ ))
30
}
31
32
alias err_exit='err_exit $lineno'
33
34
Command=${0##*/}
35
integer Errors=0 lineno=1
36
37
whence -q pty || { lineno=$LINENO; err_exit "pty command not found -- tests skipped"; exit 0; }
38
39
bintrue=$(whence -p true)
40
41
x=$( $SHELL <<- \EOF
42
trap 'exit 0' EXIT
43
bintrue=$(whence -p true)
44
set -o monitor
45
{
46
eval $'set -o vi\npty $bintrue'
47
} < /dev/null & pid=$!
48
#sleep 1
49
jobs
50
kill $$
51
EOF
52
)
53
[[ $x == *Stop* ]] && err_exit 'monitor mode enabled incorrectly causes job to stop'
54
55
if [[ -o xtrace ]]
56
then debug=--debug=1
57
else debug=
58
fi
59
60
function tst
61
{
62
integer lineno=$1 offset
63
typeset text
64
65
pty $debug --dialogue --messages='/dev/fd/1' $SHELL |
66
while read -r text
67
do if [[ $text == *debug* ]]
68
then print -u2 -r -- "$text"
69
else offset=${text/*: line +([[:digit:]]):*/\1}
70
err_exit "${text/: line $offset:/: line $(( lineno + offset)):}"
71
fi
72
done
73
}
74
75
export PS1=':test-!: ' PS2='> ' PS4=': ' ENV= EXINIT= HISTFILE= TERM=dumb VISUAL=vi LC_ALL=C
76
77
if ! pty $bintrue < /dev/null
78
then err_exit pty command hangs on $bintrue -- tests skipped
79
exit 0
80
fi
81
82
# err_exit #
83
tst $LINENO <<"!"
84
L POSIX sh 026(C)
85
86
# If the User Portability Utilities Option is supported: When the
87
# POSIX locale is specified and a background job is suspended by a
88
# SIGTSTP signal then the <state> field in the output message is set to
89
# Stopped, Suspended, Stopped(SIGTSTP) or Suspended(SIGTSTP).
90
91
I ^\r?\n$
92
p :test-1:
93
w sleep 60 &
94
u [[:digit:]]\r?\n$
95
s 100
96
p :test-2:
97
w kill -TSTP $!
98
u (Stopped|Suspended)
99
p :test-3:
100
w kill -KILL $!
101
w wait
102
u (Killed|Done)
103
!
104
105
# err_exit #
106
tst $LINENO <<"!"
107
L POSIX sh 028(C)
108
109
# If the User Portability Utilities Option is supported: When the
110
# POSIX locale is specified and a background job is suspended by a
111
# SIGTTIN signal then the <state> field in the output message is set to
112
# Stopped(SIGTTIN) or Suspended(SIGTTIN).
113
114
I ^\r?\n$
115
p :test-1:
116
w sleep 60 &
117
u [[:digit:]]\r?\n$
118
s 100
119
p :test-2:
120
w kill -TTIN $!
121
u (Stopped|Suspended) \(SIGTTIN\)
122
p :test-3:
123
w kill -KILL $!
124
w wait
125
u (Killed|Done)
126
!
127
128
# err_exit #
129
tst $LINENO <<"!"
130
L POSIX sh 029(C)
131
132
# If the User Portability Utilities Option is supported: When the
133
# POSIX locale is specified and a background job is suspended by a
134
# SIGTTOU signal then the <state> field in the output message is set to
135
# Stopped(SIGTTOU) or Suspended(SIGTTOU).
136
137
I ^\r?\n$
138
p :test-1:
139
w sleep 60 &
140
u [[:digit:]]\r?\n$
141
s 100
142
p :test-2:
143
w kill -TTOU $!
144
u (Stopped|Suspended) \(SIGTTOU\)
145
p :test-3:
146
w kill -KILL $!
147
w wait
148
u (Killed|Done)
149
!
150
151
# err_exit #
152
tst $LINENO <<"!"
153
L POSIX sh 091(C)
154
155
# If the User Portability Utilities Option is supported and shell
156
# command line editing is supported: When in insert mode an entered
157
# character other than <newline>, erase, interrupt, kill, control-V,
158
# control-W, backslash \ (followed by erase or kill), end-of-file and
159
# <ESC> is inserted in the current command line.
160
161
c echo h
162
c ell
163
w o
164
u ^hello\r?\n$
165
!
166
167
# err_exit #
168
tst $LINENO <<"!"
169
L POSIX sh 093(C)
170
171
# If the User Portability Utilities Option is supported and shell
172
# command line editing is supported: After termination of a previous
173
# command, sh is entered in insert mode.
174
175
w echo hello
176
u ^hello\r?\n$
177
c echo goo
178
c dby
179
w e
180
u ^goodbye\r?\n$
181
!
182
183
# err_exit #
184
tst $LINENO <<"!"
185
L POSIX sh 094(C)
186
187
# If the User Portability Utilities Option is supported and shell
188
# command line editing is supported: When in insert mode an <ESC>
189
# switches sh into command mode.
190
191
c echo he\E
192
s 400
193
w allo
194
u ^hello\r?\n$
195
!
196
197
# err_exit #
198
tst $LINENO <<"!"
199
L POSIX sh 096(C)
200
201
# If the User Portability Utilities Option is supported and shell
202
# command line editing is supported: When in command mode the
203
# interrupt character causes sh to terminate command line editing on
204
# the current command line, re-issue the prompt on the next line of the
205
# terminal and to reset the command history so that the command that
206
# was interrupted is not entered in the history.
207
208
I ^\r?\n$
209
p :test-1:
210
w echo first
211
p :test-2:
212
w stty intr ^C
213
p :test-3:
214
c echo bad\E
215
s 400
216
c \cC
217
w echo scrambled
218
p :test-4:
219
w history
220
u echo first
221
r stty intr \^C
222
r echo
223
r history
224
!
225
226
# err_exit #
227
tst $LINENO <<"!"
228
L POSIX sh 097(C)
229
230
# If the User Portability Utilities Option is supported and shell
231
# command line editing is supported: When in insert mode a <newline>
232
# causes the current command line to be executed.
233
234
c echo ok\n
235
u ^ok\r?\n$
236
!
237
238
# err_exit #
239
tst $LINENO <<"!"
240
L POSIX sh 099(C)
241
242
# If the User Portability Utilities Option is supported and shell
243
# command line editing is supported: When in insert mode the interrupt
244
# character causes sh to terminate command line editing on the current
245
# command line, re-issue the prompt on the next line of the terminal
246
# and to reset the command history so that the command that was
247
# interrupted is not entered in the history.
248
249
I ^\r?\n$
250
p :test-1:
251
w echo first
252
u ^first
253
p :test-2:
254
w stty intr ^C
255
r
256
p :test-3:
257
c echo bad\cC
258
w echo last
259
p :test-4:
260
w history
261
u echo first
262
r stty intr \^C
263
r echo last
264
r history
265
!
266
267
# err_exit #
268
tst $LINENO <<"!"
269
L POSIX sh 100(C)
270
271
# If the User Portability Utilities Option is supported and shell
272
# command line editing is supported: When in insert mode the kill
273
# character clears all the characters from the input line.
274
275
p :test-1:
276
w stty kill ^X
277
p :test-2:
278
c echo bad\cX
279
w echo ok
280
u ^ok\r?\n$
281
!
282
283
# err_exit #
284
tst $LINENO <<"!"
285
L POSIX sh 101(C)
286
287
# If the User Portability Utilities Option is supported and shell
288
# command line editing is supported: When in insert mode a control-V
289
# causes the next character to be inserted even in the case that the
290
# character is a special insert mode character.
291
# Testing Requirements: The assertion must be tested with at least the
292
# following set of characters: <newline>, erase, interrupt, kill,
293
# control-V, control-W, end-of-file, backslash \ (followed by erase or
294
# kill) and <ESC>.
295
296
d 10
297
p :test-1:
298
w stty erase ^H intr ^C kill ^X
299
p :test-2:
300
w echo erase=:\cV\cH:
301
u ^erase=:\r?\n$
302
p :test-3:
303
w echo kill=:\cV\cX:
304
u ^kill=:\cX:\r?\n$
305
p :test-4:
306
w echo control-V=:\cV\cV:
307
u ^control-V=:\cV:\r?\n$
308
p :test-5:
309
w echo control-W:\cV\cW:
310
u ^control-W:\cW:\r?\n$
311
p :test-6:
312
w echo EOF=:\cV\cD:
313
u ^EOF=:\004:\r?\n$
314
p :test-7:
315
w echo backslash-erase=:\\\cH:
316
u ^backslash-erase=:\r?\n$
317
p :test-8:
318
w echo backslash-kill=:\\\cX:
319
u ^backslash-kill=:\cX:\r?\n$
320
p :test-9:
321
w echo ESC=:\cV\E:
322
u ^ESC=:\E:\r?\n$
323
p :test-10:
324
w echo interrupt=:\cV\cC:
325
u ^interrupt=:\cC:\r?\n$
326
!
327
328
# err_exit #
329
tst $LINENO <<"!"
330
L POSIX sh 104(C)
331
332
# If the User Portability Utilities Option is supported and shell
333
# command line editing is supported: When in insert mode an
334
# end-of-file at the beginning of an input line is interpreted as the
335
# end of input.
336
337
p :test-1:
338
w trap 'echo done >&2' EXIT
339
p :test-2:
340
s 100
341
c \cD
342
u ^done\r?\n$
343
!
344
345
# err_exit #
346
tst $LINENO <<"!"
347
L POSIX sh 111(C)
348
349
# If the User Portability Utilities Option is supported and shell
350
# command line editing is supported: When in command mode, # inserts
351
# the character # at the beginning of the command line and causes the
352
# line to be treated as a comment and the line is entered in the
353
# command history.
354
355
p :test-1:
356
c echo save\E
357
s 400
358
c #
359
p :test-2:
360
w history
361
u #echo save
362
r history
363
!
364
365
# err_exit #
366
tst $LINENO <<"!"
367
L POSIX sh 137(C)
368
369
# If the User Portability Utilities Option is supported and shell
370
# command line editing is supported: When in command mode, then v
371
# invokes the vi editor to edit the current command line in a temporary
372
# file. When the editor exits, the commands in the temporary file are
373
# executed.
374
375
p :test-1:
376
c echo hello\E
377
s 400
378
c v
379
u /tmp/
380
c A world\E
381
s 400
382
w :wq
383
u ^hello world\r?\n$
384
!
385
386
# err_exit #
387
tst $LINENO <<"!"
388
L POSIX sh 251(C)
389
390
# If the User Portability Utilities Option is supported and shell
391
# command line editing is supported: When in command mode, then the
392
# command N repeats the most recent / or ? command, reversing the
393
# direction of the search.
394
395
p :test-1:
396
w echo repeat-1
397
u ^repeat-1\r?\n$
398
p :test-2:
399
w echo repeat-2
400
u ^repeat-2\r?\n$
401
p :test-3:
402
s 100
403
c \E
404
s 400
405
w /rep
406
u echo repeat-2
407
c n
408
r echo repeat-1
409
c N
410
r echo repeat-2
411
w dd
412
p :test-3:
413
w echo repeat-3
414
u ^repeat-3\r?\n$
415
p :test-4:
416
s 100
417
c \E
418
s 400
419
w ?rep
420
r echo repeat-2
421
c N
422
r echo repeat-1
423
c n
424
r echo repeat-2
425
c n
426
r echo repeat-3
427
!
428
429
# err_exit #
430
whence -q less &&
431
TERM=vt100 tst $LINENO <<"!"
432
L process/terminal group exercise
433
434
w m=yes; while true; do echo $m-$m; done | less
435
u :$|:\E|lines
436
c \cZ
437
r Stopped
438
w fg
439
u yes-yes
440
!
441
442
exit $((Errors<125?Errors:125))
443
444