1# $OpenBSD: bksl-nl.t,v 1.1 2013/12/02 20:39:44 millert Exp $ 2 3# 4# These tests deal with how \newline is handled in various situations. The 5# first group of tests are places where it shouldn't be collapsed, the next 6# group of tests are places where it should be collapsed. 7# 8name: bksl-nl-ign-1 9description: 10 Check that \newline is not collasped after # 11stdin: 12 echo hi #there \ 13 echo folks 14expected-stdout: 15 hi 16 folks 17--- 18 19name: bksl-nl-ign-2 20description: 21 Check that \newline is not collasped inside single quotes 22stdin: 23 echo 'hi \ 24 there' 25 echo folks 26expected-stdout: 27 hi \ 28 there 29 folks 30--- 31 32name: bksl-nl-ign-3 33description: 34 Check that \newline is not collasped inside single quotes 35stdin: 36 cat << \EOF 37 hi \ 38 there 39 EOF 40expected-stdout: 41 hi \ 42 there 43--- 44 45name: blsk-nl-ign-4 46description: 47 Check interaction of aliases, single quotes and here-documents 48 with backslash-newline 49 (don't know what posix has to say about this) 50stdin: 51 a=2 52 alias x='echo hi 53 cat << "EOF" 54 foo\ 55 bar 56 some' 57 x 58 more\ 59 stuff$a 60 EOF 61expected-stdout: 62 hi 63 foo\ 64 bar 65 some 66 more\ 67 stuff$a 68--- 69 70name: blsk-nl-ign-5 71description: 72 Check what happens with backslash at end of input 73 (the old bourne shell trashes them; so do we) 74stdin: ! 75 echo `echo foo\\`bar 76 echo hi\ 77expected-stdout: 78 foobar 79 hi 80--- 81 82 83# 84# Places \newline should be collapsed 85# 86name: bksl-nl-1 87description: 88 Check that \newline is collasped before, in the middle of, and 89 after words 90stdin: 91 \ 92 echo hi\ 93 There, \ 94 folks 95expected-stdout: 96 hiThere, folks 97--- 98 99name: bksl-nl-2 100description: 101 Check that \newline is collasped in $ sequences 102 (ksh93 fails this) 103stdin: 104 a=12 105 ab=19 106 echo $\ 107 a 108 echo $a\ 109 b 110 echo $\ 111 {a} 112 echo ${a\ 113 b} 114 echo ${ab\ 115 } 116expected-stdout: 117 12 118 19 119 12 120 19 121 19 122--- 123 124name: bksl-nl-3 125description: 126 Check that \newline is collasped in $(..) and `...` sequences 127 (ksh93 fails this) 128stdin: 129 echo $\ 130 (echo foobar1) 131 echo $(\ 132 echo foobar2) 133 echo $(echo foo\ 134 bar3) 135 echo $(echo foobar4\ 136 ) 137 echo ` 138 echo stuff1` 139 echo `echo st\ 140 uff2` 141expected-stdout: 142 foobar1 143 foobar2 144 foobar3 145 foobar4 146 stuff1 147 stuff2 148--- 149 150name: bksl-nl-4 151description: 152 Check that \newline is collasped in $((..)) sequences 153 (ksh93 fails this) 154stdin: 155 echo $\ 156 ((1+2)) 157 echo $(\ 158 (1+2+3)) 159 echo $((\ 160 1+2+3+4)) 161 echo $((1+\ 162 2+3+4+5)) 163 echo $((1+2+3+4+5+6)\ 164 ) 165expected-stdout: 166 3 167 6 168 10 169 15 170 21 171--- 172 173name: bksl-nl-5 174description: 175 Check that \newline is collasped in double quoted strings 176stdin: 177 echo "\ 178 hi" 179 echo "foo\ 180 bar" 181 echo "folks\ 182 " 183expected-stdout: 184 hi 185 foobar 186 folks 187--- 188 189name: bksl-nl-6 190description: 191 Check that \newline is collasped in here document delimiters 192 (ksh93 fails second part of this) 193stdin: 194 a=12 195 cat << EO\ 196 F 197 a=$a 198 foo\ 199 bar 200 EOF 201 cat << E_O_F 202 foo 203 E_O_\ 204 F 205 echo done 206expected-stdout: 207 a=12 208 foobar 209 foo 210 done 211--- 212 213name: bksl-nl-7 214description: 215 Check that \newline is collasped in double-quoted here-document 216 delimiter. 217stdin: 218 a=12 219 cat << "EO\ 220 F" 221 a=$a 222 foo\ 223 bar 224 EOF 225 echo done 226expected-stdout: 227 a=$a 228 foo\ 229 bar 230 done 231--- 232 233name: bksl-nl-8 234description: 235 Check that \newline is collasped in various 2+ character tokens 236 delimiter. 237 (ksh93 fails this) 238stdin: 239 echo hi &\ 240 & echo there 241 echo foo |\ 242 | echo bar 243 cat <\ 244 < EOF 245 stuff 246 EOF 247 cat <\ 248 <\ 249 - EOF 250 more stuff 251 EOF 252 cat <<\ 253 EOF 254 abcdef 255 EOF 256 echo hi >\ 257 > /dev/null 258 echo $? 259 i=1 260 case $i in 261 (\ 262 x|\ 263 1\ 264 ) echo hi;\ 265 ; 266 (*) echo oops 267 esac 268expected-stdout: 269 hi 270 there 271 foo 272 stuff 273 more stuff 274 abcdef 275 0 276 hi 277--- 278 279name: blsk-nl-9 280description: 281 Check that \ at the end of an alias is collapsed when followed 282 by a newline 283 (don't know what posix has to say about this) 284stdin: 285 alias x='echo hi\' 286 x 287 echo there 288expected-stdout: 289 hiecho there 290--- 291 292name: blsk-nl-10 293description: 294 Check that \newline in a keyword is collapsed 295stdin: 296 i\ 297 f true; then\ 298 echo pass; el\ 299 se echo fail; fi 300expected-stdout: 301 pass 302--- 303 304# 305# Places \newline should be collapsed (ksh extensions) 306# 307 308name: blsk-nl-ksh-1 309description: 310 Check that \newline is collapsed in extended globbing 311 (ksh93 fails this) 312stdin: 313 xxx=foo 314 case $xxx in 315 (f*\ 316 (\ 317 o\ 318 )\ 319 ) echo ok ;; 320 *) echo bad 321 esac 322expected-stdout: 323 ok 324--- 325 326name: blsk-nl-ksh-2 327description: 328 Check that \newline is collapsed in ((...)) expressions 329 (ksh93 fails this) 330stdin: 331 i=1 332 (\ 333 (\ 334 i=i+2\ 335 )\ 336 ) 337 echo $i 338expected-stdout: 339 3 340--- 341 342