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 <dgk@research.att.com> # 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 25function err_exit 26{ 27 print -u2 -n "\t" 28 print -u2 -r ${Command}[$1]: "${@:2}" 29 (( Errors++ )) 30} 31 32alias err_exit='err_exit $lineno' 33 34Command=${0##*/} 35integer Errors=0 lineno=1 36 37whence -q pty || { lineno=$LINENO; err_exit "pty command not found -- tests skipped"; exit 0; } 38 39bintrue=$(whence -p true) 40 41x=$( $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 55if [[ -o xtrace ]] 56then debug=--debug=1 57else debug= 58fi 59 60function 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 75export PS1=':test-!: ' PS2='> ' PS4=': ' ENV= EXINIT= HISTFILE= TERM=dumb VISUAL=vi LC_ALL=C 76 77if ! pty $bintrue < /dev/null 78then err_exit pty command hangs on $bintrue -- tests skipped 79 exit 0 80fi 81 82# err_exit # 83tst $LINENO <<"!" 84L 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 91I ^\r?\n$ 92p :test-1: 93w sleep 60 & 94u [[:digit:]]\r?\n$ 95s 100 96p :test-2: 97w kill -TSTP $! 98u (Stopped|Suspended) 99p :test-3: 100w kill -KILL $! 101w wait 102u (Killed|Done) 103! 104 105# err_exit # 106tst $LINENO <<"!" 107L 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 114I ^\r?\n$ 115p :test-1: 116w sleep 60 & 117u [[:digit:]]\r?\n$ 118s 100 119p :test-2: 120w kill -TTIN $! 121u (Stopped|Suspended) \(SIGTTIN\) 122p :test-3: 123w kill -KILL $! 124w wait 125u (Killed|Done) 126! 127 128# err_exit # 129tst $LINENO <<"!" 130L 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 137I ^\r?\n$ 138p :test-1: 139w sleep 60 & 140u [[:digit:]]\r?\n$ 141s 100 142p :test-2: 143w kill -TTOU $! 144u (Stopped|Suspended) \(SIGTTOU\) 145p :test-3: 146w kill -KILL $! 147w wait 148u (Killed|Done) 149! 150 151# err_exit # 152tst $LINENO <<"!" 153L 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 161c echo h 162c ell 163w o 164u ^hello\r?\n$ 165! 166 167# err_exit # 168tst $LINENO <<"!" 169L 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 175w echo hello 176u ^hello\r?\n$ 177c echo goo 178c dby 179w e 180u ^goodbye\r?\n$ 181! 182 183# err_exit # 184tst $LINENO <<"!" 185L 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 191c echo he\E 192s 400 193w allo 194u ^hello\r?\n$ 195! 196 197# err_exit # 198tst $LINENO <<"!" 199L 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 208I ^\r?\n$ 209p :test-1: 210w echo first 211p :test-2: 212w stty intr ^C 213p :test-3: 214c echo bad\E 215s 400 216c \cC 217w echo scrambled 218p :test-4: 219w history 220u echo first 221r stty intr \^C 222r echo 223r history 224! 225 226# err_exit # 227tst $LINENO <<"!" 228L 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 234c echo ok\n 235u ^ok\r?\n$ 236! 237 238# err_exit # 239tst $LINENO <<"!" 240L 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 249I ^\r?\n$ 250p :test-1: 251w echo first 252u ^first 253p :test-2: 254w stty intr ^C 255r 256p :test-3: 257c echo bad\cC 258w echo last 259p :test-4: 260w history 261u echo first 262r stty intr \^C 263r echo last 264r history 265! 266 267# err_exit # 268tst $LINENO <<"!" 269L 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 275p :test-1: 276w stty kill ^X 277p :test-2: 278c echo bad\cX 279w echo ok 280u ^ok\r?\n$ 281! 282 283# err_exit # 284tst $LINENO <<"!" 285L 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 296d 10 297p :test-1: 298w stty erase ^H intr ^C kill ^X 299p :test-2: 300w echo erase=:\cV\cH: 301u ^erase=:\r?\n$ 302p :test-3: 303w echo kill=:\cV\cX: 304u ^kill=:\cX:\r?\n$ 305p :test-4: 306w echo control-V=:\cV\cV: 307u ^control-V=:\cV:\r?\n$ 308p :test-5: 309w echo control-W:\cV\cW: 310u ^control-W:\cW:\r?\n$ 311p :test-6: 312w echo EOF=:\cV\cD: 313u ^EOF=:\004:\r?\n$ 314p :test-7: 315w echo backslash-erase=:\\\cH: 316u ^backslash-erase=:\r?\n$ 317p :test-8: 318w echo backslash-kill=:\\\cX: 319u ^backslash-kill=:\cX:\r?\n$ 320p :test-9: 321w echo ESC=:\cV\E: 322u ^ESC=:\E:\r?\n$ 323p :test-10: 324w echo interrupt=:\cV\cC: 325u ^interrupt=:\cC:\r?\n$ 326! 327 328# err_exit # 329tst $LINENO <<"!" 330L 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 337p :test-1: 338w trap 'echo done >&2' EXIT 339p :test-2: 340s 100 341c \cD 342u ^done\r?\n$ 343! 344 345# err_exit # 346tst $LINENO <<"!" 347L 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 355p :test-1: 356c echo save\E 357s 400 358c # 359p :test-2: 360w history 361u #echo save 362r history 363! 364 365# err_exit # 366tst $LINENO <<"!" 367L 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 375p :test-1: 376c echo hello\E 377s 400 378c v 379u /tmp/ 380c A world\E 381s 400 382w :wq 383u ^hello world\r?\n$ 384! 385 386# err_exit # 387tst $LINENO <<"!" 388L 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 395p :test-1: 396w echo repeat-1 397u ^repeat-1\r?\n$ 398p :test-2: 399w echo repeat-2 400u ^repeat-2\r?\n$ 401p :test-3: 402s 100 403c \E 404s 400 405w /rep 406u echo repeat-2 407c n 408r echo repeat-1 409c N 410r echo repeat-2 411w dd 412p :test-3: 413w echo repeat-3 414u ^repeat-3\r?\n$ 415p :test-4: 416s 100 417c \E 418s 400 419w ?rep 420r echo repeat-2 421c N 422r echo repeat-1 423c n 424r echo repeat-2 425c n 426r echo repeat-3 427! 428 429# err_exit # 430whence -q less && 431TERM=vt100 tst $LINENO <<"!" 432L process/terminal group exercise 433 434w m=yes; while true; do echo $m-$m; done | less 435u :$|:\E|lines 436c \cZ 437r Stopped 438w fg 439u yes-yes 440! 441 442exit $((Errors<125?Errors:125)) 443