| 1 | ## our_shell: ysh
|
| 2 | ## oils_failures_allowed: 4
|
| 3 |
|
| 4 | #### fastlex: NUL byte not allowed inside char literal #' '
|
| 5 |
|
| 6 | echo $'var x = #\'\x00\'; echo x=$x' > tmp.oil
|
| 7 | $[ENV.SH] tmp.oil
|
| 8 |
|
| 9 | echo $'var x = #\' ' > incomplete.oil
|
| 10 | $[ENV.SH] incomplete.oil
|
| 11 |
|
| 12 | ## status: 2
|
| 13 | ## STDOUT:
|
| 14 | ## END
|
| 15 |
|
| 16 | #### fastlex: NUL byte inside shebang line
|
| 17 |
|
| 18 | # Hm this test doesn't really tickle the bug
|
| 19 |
|
| 20 | echo $'#! /usr/bin/env \x00 sh \necho hi' > tmp.oil
|
| 21 | env OILS_HIJACK_SHEBANG=1 $[ENV.SH] tmp.oil
|
| 22 |
|
| 23 | ## STDOUT:
|
| 24 | hi
|
| 25 | ## END
|
| 26 |
|
| 27 | #### Tea keywords don't interfere with YSH expressions
|
| 28 |
|
| 29 | var d = {data: 'foo'}
|
| 30 |
|
| 31 | echo $[d.data]
|
| 32 |
|
| 33 | var e = {enum: 1, class: 2, import: 3, const: 4, var: 5, set: 6}
|
| 34 | echo $[len(e)]
|
| 35 |
|
| 36 | ## STDOUT:
|
| 37 | foo
|
| 38 | 6
|
| 39 | ## END
|
| 40 |
|
| 41 | #### Catch AttributeError
|
| 42 |
|
| 43 | var s = 'foo'
|
| 44 | echo s=$s
|
| 45 | var t = s.bad()
|
| 46 | echo 'should not get here'
|
| 47 |
|
| 48 | ## status: 3
|
| 49 | ## STDOUT:
|
| 50 | s=foo
|
| 51 | ## END
|
| 52 |
|
| 53 |
|
| 54 | #### Command sub paren parsing bug (#1387)
|
| 55 |
|
| 56 | write $(if (true) { write true })
|
| 57 |
|
| 58 | const a = $(write $[len('foo')])
|
| 59 | echo $a
|
| 60 |
|
| 61 | const b = $(write $[5 ** 3])
|
| 62 | echo $b
|
| 63 |
|
| 64 | const c = $(
|
| 65 | write $[6 + 7]
|
| 66 | )
|
| 67 | echo $c
|
| 68 |
|
| 69 | ## STDOUT:
|
| 70 | true
|
| 71 | 3
|
| 72 | 125
|
| 73 | 13
|
| 74 | ## END
|
| 75 |
|
| 76 |
|
| 77 | #### More Command sub paren parsing
|
| 78 |
|
| 79 | write $( var mylist = ['for']; for x in (mylist) { echo $x } )
|
| 80 |
|
| 81 | write $( echo while; while (false) { write hi } )
|
| 82 |
|
| 83 | write $( if (true) { write 'if' } )
|
| 84 |
|
| 85 | write $( if (false) { write 'if' } elif (true) { write 'elif' } )
|
| 86 |
|
| 87 | ## STDOUT:
|
| 88 | for
|
| 89 | while
|
| 90 | if
|
| 91 | elif
|
| 92 | ## END
|
| 93 |
|
| 94 | #### don't execute empty command
|
| 95 |
|
| 96 | shopt --set ysh:all
|
| 97 |
|
| 98 | set -x
|
| 99 |
|
| 100 | try {
|
| 101 | type -a ''
|
| 102 | }
|
| 103 | echo "type -a returned $_status"
|
| 104 |
|
| 105 | $(true)
|
| 106 | echo nope
|
| 107 |
|
| 108 | ## status: 127
|
| 109 | ## STDOUT:
|
| 110 | type -a returned 1
|
| 111 | ## END
|
| 112 |
|
| 113 |
|
| 114 | #### Do && || with YSH constructs make sense/
|
| 115 |
|
| 116 | # I guess there's nothing wrong with this?
|
| 117 | #
|
| 118 | # But I generally feel && || are only for
|
| 119 | #
|
| 120 | # test --file x && test --file y
|
| 121 |
|
| 122 | var x = []
|
| 123 | true && call x->append(42)
|
| 124 | false && call x->append(43)
|
| 125 | pp test_ (x)
|
| 126 |
|
| 127 | func amp() {
|
| 128 | true && return (42)
|
| 129 | }
|
| 130 |
|
| 131 | func pipe() {
|
| 132 | false || return (42)
|
| 133 | }
|
| 134 |
|
| 135 | pp test_ (amp())
|
| 136 | pp test_ (pipe())
|
| 137 |
|
| 138 | ## STDOUT:
|
| 139 | ## END
|
| 140 |
|
| 141 |
|
| 142 | #### shvar then replace - bug #1986 context manager crash
|
| 143 |
|
| 144 | shvar FOO=bar {
|
| 145 | for x in (1 ..< 500) {
|
| 146 | var Q = "hello"
|
| 147 | setvar Q = Q=>replace("hello","world")
|
| 148 | }
|
| 149 | }
|
| 150 | #echo $Q
|
| 151 | echo hi
|
| 152 |
|
| 153 | ## STDOUT:
|
| 154 | hi
|
| 155 | ## END
|
| 156 |
|
| 157 |
|
| 158 | #### Parsing crash - bug #2003
|
| 159 |
|
| 160 | set +o errexit
|
| 161 |
|
| 162 | $[ENV.SH] -c 'proc y (;x) { return = x }'
|
| 163 | echo status=$?
|
| 164 |
|
| 165 | $[ENV.SH] -c 'func y (;x) { return = x }'
|
| 166 | echo status=$?
|
| 167 |
|
| 168 | ## STDOUT:
|
| 169 | status=2
|
| 170 | status=2
|
| 171 | ## END
|
| 172 |
|
| 173 |
|
| 174 | #### proc with IFS= read -r line - dynamic scope - issue #2012
|
| 175 |
|
| 176 | # 2024-10 - FIXED by the new Env Obj! Because in YSH, 'line' is NOT created in
|
| 177 | # TEMP stack frame - we use the ENCLOSED frame, and it fixes it.
|
| 178 |
|
| 179 | proc p {
|
| 180 | read -r line
|
| 181 | write $line
|
| 182 | }
|
| 183 |
|
| 184 | proc p-ifs {
|
| 185 | IFS= read -r line
|
| 186 | write $line
|
| 187 | }
|
| 188 |
|
| 189 | #set -x
|
| 190 |
|
| 191 | echo zz | p
|
| 192 |
|
| 193 | echo yy | p-ifs
|
| 194 |
|
| 195 | ## STDOUT:
|
| 196 | zz
|
| 197 | yy
|
| 198 | ## END
|
| 199 |
|
| 200 | #### func call inside proc call - error message attribution
|
| 201 |
|
| 202 | try 2> foo {
|
| 203 | $[ENV.SH] -c '
|
| 204 | func ident(x) {
|
| 205 | return (x)
|
| 206 | }
|
| 207 |
|
| 208 | proc p (; x) {
|
| 209 | echo $x
|
| 210 | }
|
| 211 |
|
| 212 | # BUG: it points to ( in ident(
|
| 213 | # should point to ( in eval (
|
| 214 |
|
| 215 | eval (ident([1,2,3]))
|
| 216 | '
|
| 217 | }
|
| 218 |
|
| 219 | cat foo
|
| 220 |
|
| 221 | ## STDOUT:
|
| 222 | ## END
|
| 223 |
|
| 224 |
|
| 225 | #### Crash in parsing case on EOF condition - issue #2037
|
| 226 |
|
| 227 | var WEIGHT = ${1:-}
|
| 228 | case (WEIGHT) {
|
| 229 | "-" { echo "got nothing" }
|
| 230 | (else) { echo $WEIGHT
|
| 231 | }
|
| 232 |
|
| 233 | ## status: 2
|
| 234 | ## STDOUT:
|
| 235 | ## END
|
| 236 |
|
| 237 | #### Crash due to incorrect of context manager rooting - issue #1986
|
| 238 |
|
| 239 | proc p {
|
| 240 | var s = "hi"
|
| 241 | for q in (1..<50) {
|
| 242 | shvar Q="whatever" {
|
| 243 | setvar s = "." ++ s
|
| 244 | }
|
| 245 | }
|
| 246 | }
|
| 247 |
|
| 248 | for i in (1..<10) {
|
| 249 | p
|
| 250 | }
|
| 251 |
|
| 252 | if false {
|
| 253 | echo 'testing for longer'
|
| 254 | for i in (1 ..< 1000) {
|
| 255 | p
|
| 256 | }
|
| 257 | }
|
| 258 |
|
| 259 | ## STDOUT:
|
| 260 | ## END
|
| 261 |
|
| 262 |
|
| 263 | #### crash due to arbitrary PNode limit - issue #2078
|
| 264 |
|
| 265 | #!/usr/bin/env ysh
|
| 266 | var DelegatedCompName = {
|
| 267 | "llvm" : "x_project",
|
| 268 | "rocprofiler_register" : "x_rocprofiler_register",
|
| 269 | "roct_thunk_interface" : "x_roct",
|
| 270 | "rocr_runtime" : "x_rocr",
|
| 271 | "openmp" : "x_openmp",
|
| 272 | "offload" : "x_offload",
|
| 273 | "aomp_extras" : "x_extras",
|
| 274 | "comgr" : "x_comgr",
|
| 275 | "rocminfo" : "x_rocminfo",
|
| 276 | "rocsmilib" : "x_rocm_smi_lib",
|
| 277 | "amdsmi" : "x_amdsmi",
|
| 278 | "flang_legacy" : "x_flang_legacy",
|
| 279 | "pgmath" : "x_pgmath",
|
| 280 | "flang" : "x_flang",
|
| 281 | "flang_runtime" : "x_flang_runtime",
|
| 282 | "hipcc" : "x_hipcc",
|
| 283 | "hipamd" : "x_hipamd",
|
| 284 | "rocm_dbgapi" : "x_rocdbgapi",
|
| 285 | "rocgdb" : "x_rocgdb",
|
| 286 | "roctracer" : "x_roctracer",
|
| 287 | "rocprofiler" : "x_rocprofiler"
|
| 288 | }
|
| 289 |
|
| 290 | echo $[len(DelegatedCompName)]
|
| 291 |
|
| 292 | ## STDOUT:
|
| 293 | 21
|
| 294 | ## END
|
| 295 |
|
| 296 | #### bad assertion when pretty printing
|
| 297 |
|
| 298 | pp value (__builtins__) > /dev/null
|
| 299 | echo status=$?
|
| 300 |
|
| 301 | ## STDOUT:
|
| 302 | status=0
|
| 303 | ## END
|
| 304 |
|
| 305 | #### Another "stealing stdin" issue with spec tests
|
| 306 |
|
| 307 | proc where2(; pred) {
|
| 308 | for line in (io.stdin) {
|
| 309 | pp test_ (line)
|
| 310 | }
|
| 311 | }
|
| 312 |
|
| 313 | seq 5 | where2 [_line ~== 2 or _line ~== 4]
|
| 314 |
|
| 315 | #{ echo 1; echo 2; } | where2 [_line ~== 2 or _line ~== 4]
|
| 316 |
|
| 317 | # empty lines here get put on stdin
|
| 318 |
|
| 319 | ## STDOUT:
|
| 320 | (Str) "1"
|
| 321 | (Str) "2"
|
| 322 | (Str) "3"
|
| 323 | (Str) "4"
|
| 324 | (Str) "5"
|
| 325 | ## END
|
| 326 |
|
| 327 | #### Long boolean flags can't have attached values
|
| 328 |
|
| 329 | # This currently works, but I think --json and --j8 are enough?
|
| 330 |
|
| 331 | write --json=0 hi
|
| 332 | write --json=F hi
|
| 333 | write --json=False hi
|
| 334 | write --json=false hi
|
| 335 | echo
|
| 336 |
|
| 337 | write --json=1 hi
|
| 338 | write --json=T hi
|
| 339 | write --json=True hi
|
| 340 | write --json=true hi
|
| 341 |
|
| 342 | # typo bug
|
| 343 | write --json=Talse hi
|
| 344 |
|
| 345 | ## status: 1
|
| 346 | ## STDOUT:
|
| 347 | ## END
|
| 348 |
|
| 349 | #### Bug: rooting of pgen2::PNode
|
| 350 |
|
| 351 | # manifests with _bin/cxx-asan+gcalways/ysh, after turning on VALIDATE_ROOTS
|
| 352 |
|
| 353 | var x = 42
|
| 354 | echo $x
|
| 355 |
|
| 356 | #var y = 'foo-' ++ $(var y = 42; echo $y)
|
| 357 |
|
| 358 | ## STDOUT:
|
| 359 | 42
|
| 360 | ## END
|