1# alias-y.tst: yash-specific test of aliases 2 3setup 'set -e' 4 5test_OE -e 0 'yash has no predefined aliases' 6alias 7__IN__ 8 9test_oE 'multi-line alias' 10alias e='echo 1 11echo 2' 12e 3 13__IN__ 141 152 3 16__OUT__ 17 18test_oE 'alias in command substitution' 19alias e=: 20func() { 21 alias e=echo 22 echo "$(e not_printed)" 23} 24func 25__IN__ 26 27__OUT__ 28 29test_Oe -e 2 'semicolon after newline (for)' 30alias -g s=';' 31for i 32s do :; done 33__IN__ 34syntax error: `;' cannot appear on a new line 35__ERR__ 36#' 37#` 38 39( 40posix="true" 41 42test_Oe -e 2 'reserved word esac as pattern (-o POSIX)' 43alias CASE='case esac in ( ' ESAC='Esac' Esac='esac' 44CASE ESAC ) echo not reached; esac 45__IN__ 46syntax error: an unquoted `esac' cannot be the first case pattern 47__ERR__ 48#' 49#` 50 51) 52 53( 54if ! testee -c 'command -v [[' >/dev/null; then 55 skip="true" 56fi 57 58test_OE -e 0 'alias substitution after [[' 59# "!" is not keyword between "[[" and "]]" 60alias -g != 61[[ ! ! ! foo ]] && [[ ! foo = foo ]] && [[ ! -n foo ]] && 62 [[ ! ( ! foo ! = ! foo ! ) ! && ! foo ! ]] && [[ ! '' ! || ! foo ! ]] 63__IN__ 64 65) 66 67test_oE 'alias substitution after function keyword' 68alias fn='function ' f=g 69fn f { echo F; } 70g 71__IN__ 72F 73__OUT__ 74 75test_oE 'alias substitution after function name with grouping' 76alias fn='function f ' p='()' g='{ echo G; }' 77fn p { echo F; } 78f 79fn g 80f 81__IN__ 82F 83G 84__OUT__ 85 86test_oE 'alias substitution after function name with empty parentheses body' 87alias fn='function f ' p='() ' 88fn p p 89{ echo this is not function body; } 90__IN__ 91this is not function body 92__OUT__ 93 94test_oE 'alias substitution after function open parenthesis' 95alias fn='function f (' p=')' 96fn p { echo F; } 97f 98__IN__ 99F 100__OUT__ 101 102test_oE 'alias substitution after function parentheses' 103alias fn='function f() ' g='{ echo G; }' 104fn g 105f 106__IN__ 107G 108__OUT__ 109 110test_oE -e 0 'global aliases' 111alias -g A=a B=b C=c -- ---=- 112echo C B A -A- -B- -C- \A "B" 'C' --- 113__IN__ 114c b a -A- -B- -C- A B C - 115__OUT__ 116 117test_oE -e 0 'global alias (substituting to line continuation)' 118alias --global eeee='echo\ 119' 120eeee eeee 121__IN__ 122echo 123__OUT__ 124 125test_oE -e 0 'global alias (substituting to single-quotation)' 126alias --global sq="'" 127printf '[%s]\n' sq A ' sq;' 128__IN__ 129[ A ] 130[;] 131__OUT__ 132 133test_oE -e 0 'global alias (substituting to pipeline)' 134alias -g pipe_cat='| cat' 135echo A pipe_cat - 136__IN__ 137A 138__OUT__ 139 140test_oE -e 0 'global alias (substituting to semicolon)' 141alias -g semicolon=';' 142echo A semicolon echo A 143__IN__ 144A 145A 146__OUT__ 147 148test_oE -e 0 'global alias (substituting to parenthesis)' 149alias -g l='(' r=')' 150l echo A r 151__IN__ 152A 153__OUT__ 154 155test_OE -e 0 'global alias (substituting to redirection)' 156alias -g I='</dev/null' O='>/dev/null' 157echo 1 O 158echo 2 | cat I 159(echo 3) O 160{ echo 4; } O 161if :; then echo 5; fi O 162if if :; then :; fi then if :; then echo 6; fi fi O 163if if :; then :; fi then if :; then echo 7; fi O fi 164if if echo 8; then :; fi O then if :; then :; fi fi 165__IN__ 166 167test_oE -e 0 'global alias (ending with blank)' 168alias a=unexpected_substitution 169alias -g echo='echo ' 170echo a 171__IN__ 172a 173__OUT__ 174 175test_oE -e 0 'global aliases are ignored in POSIX mode' 176alias -g a=unexpected_substitution 177set -o posix 178echo a 179__IN__ 180a 181__OUT__ 182 183test_oE -e 0 'global aliases apply just once' 184alias -g a='a a ' 185echo a 186alias echo='echo ' 187echo a 188__IN__ 189a a 190a a 191__OUT__ 192 193test_oE -e 0 'printing all aliases (without -p)' 194alias a=A b=B c=C 195alias -g x=X y=Y z=Z 196alias 197__IN__ 198a=A 199b=B 200c=C 201x=X 202y=Y 203z=Z 204__OUT__ 205 206test_oE -e 0 'printing all aliases (hyphen & quotation, without -p)' 207alias -- -="'" 208alias -g -- ---='"' 209alias 210__IN__ 211-=\' 212---='"' 213__OUT__ 214 215test_oE -e 0 'printing all aliases (with -p)' 216alias a=A b=B c=C 217alias -g x=X y=Y z=Z 218alias -p 219__IN__ 220alias a=A 221alias b=B 222alias c=C 223alias -g x=X 224alias -g y=Y 225alias -g z=Z 226__OUT__ 227 228test_oE -e 0 'printing all aliases (with --prefix)' 229alias a=A b=B c=C 230alias -g x=X y=Y z=Z 231alias --prefix 232__IN__ 233alias a=A 234alias b=B 235alias c=C 236alias -g x=X 237alias -g y=Y 238alias -g z=Z 239__OUT__ 240 241test_oE -e 0 'printing all aliases (hyphen & quotation, with -p)' 242alias -- -="'" 243alias -g -- ---='"' 244alias -p 245__IN__ 246alias -- -=\' 247alias -g -- ---='"' 248__OUT__ 249 250( 251setup - <<\END 252alias -- e=echo echo='echo a' 253alias -g -- a=A ---=----- 254END 255 256test_oE -e 0 'printing specific global alias (without -p)' 257alias \a e 258__IN__ 259a=A 260e=echo 261__OUT__ 262 263test_oE -e 0 'printing specific global alias (with -p)' 264alias -p \a e 265__IN__ 266alias -g a=A 267alias e=echo 268__OUT__ 269 270test_OE -e 0 '"unalias -a" removes global aliases' 271unalias -a 272alias 273__IN__ 274 275test_Oe -e n 'alias built-in invalid option' 276alias --no-such-option 277__IN__ 278alias: `--no-such-option' is not a valid option 279__ERR__ 280#' 281#` 282 283test_Oe -e n 'alias built-in printing non-existing alias' 284alias no_such_alias 285__IN__ 286alias: no such alias `no_such_alias' 287__ERR__ 288#' 289#` 290 291test_O -d -e n 'alias built-in printing to closed stream without operands' 292alias >&- 293__IN__ 294 295test_O -d -e n 'alias built-in printing to closed stream with operands' 296alias \a e >&- 297__IN__ 298 299test_O -d -e n 'alias built-in printing to closed stream with -p' 300alias -p >&- 301__IN__ 302 303test_O -d -e n 'alias built-in printing to closed stream with -p & operands' 304alias -p \a e >&- 305__IN__ 306 307test_Oe -e n 'unalias built-in invalid option' 308unalias --no-such-option 309__IN__ 310unalias: `--no-such-option' is not a valid option 311__ERR__ 312#' 313#` 314 315test_Oe -e n 'unalias built-in invalid combination of -a and operands' 316unalias -a e 317__IN__ 318unalias: no operand is expected 319__ERR__ 320 321test_Oe -e n 'unalias built-in missing operand' 322unalias 323__IN__ 324unalias: this command requires an operand 325__ERR__ 326 327test_Oe -e n 'unalias built-in printing non-existing alias' 328unalias no_such_alias 329__IN__ 330unalias: no such alias `no_such_alias' 331__ERR__ 332#' 333#` 334 335) 336 337# vim: set ft=sh ts=8 sts=4 sw=4 noet: 338