| 1 | ## oils_failures_allowed: 1
|
| 2 | ## our_shell: ysh
|
| 3 |
|
| 4 | #### getFrame()
|
| 5 |
|
| 6 | var fr = vm.getFrame(0)
|
| 7 | pp test_ (fr)
|
| 8 | var d = dict(fr)
|
| 9 | pp test_ (d.ARGV)
|
| 10 | echo
|
| 11 |
|
| 12 | proc p1 {
|
| 13 | var p1_var = 'x'
|
| 14 | p2
|
| 15 | }
|
| 16 |
|
| 17 | proc p2 {
|
| 18 | echo 'p2 frame -1'
|
| 19 | var fr = vm.getFrame(-1)
|
| 20 | var d = dict(fr)
|
| 21 |
|
| 22 | pp test_ (fr)
|
| 23 | pp test_ (d)
|
| 24 | pp test_ (keys(d))
|
| 25 | echo
|
| 26 |
|
| 27 | echo 'p2 frame -2'
|
| 28 | setvar fr = vm.getFrame(-2)
|
| 29 | setvar d = dict(fr)
|
| 30 |
|
| 31 | pp test_ (fr)
|
| 32 | pp test_ (keys(d))
|
| 33 | echo
|
| 34 | }
|
| 35 |
|
| 36 | p1
|
| 37 |
|
| 38 | var fr = vm.getFrame(99) # fails
|
| 39 |
|
| 40 | ## status: 3
|
| 41 | ## STDOUT:
|
| 42 | <Frame>
|
| 43 | (List) []
|
| 44 |
|
| 45 | p2 frame -1
|
| 46 | <Frame>
|
| 47 | (Dict) {"__E__":<Frame>,"ARGV":[],"fr":<Frame>}
|
| 48 | (List) ["__E__","ARGV","fr"]
|
| 49 |
|
| 50 | p2 frame -2
|
| 51 | <Frame>
|
| 52 | (List) ["__E__","ARGV","p1_var"]
|
| 53 |
|
| 54 | ## END
|
| 55 |
|
| 56 |
|
| 57 | #### bindFrame()
|
| 58 |
|
| 59 | var frag = ^(echo $i)
|
| 60 |
|
| 61 | # TODO: should be fragment
|
| 62 | pp test_ (frag)
|
| 63 |
|
| 64 | var cmd = bindFrame(frag, vm.getFrame(0))
|
| 65 |
|
| 66 | pp test_ (cmd)
|
| 67 |
|
| 68 | ## STDOUT:
|
| 69 | ## END
|
| 70 |
|
| 71 | #### vm.getDebugStack()
|
| 72 |
|
| 73 | proc p {
|
| 74 | echo $[len(vm.getDebugStack())]
|
| 75 | }
|
| 76 |
|
| 77 | proc p2 {
|
| 78 | p
|
| 79 | }
|
| 80 |
|
| 81 | p
|
| 82 | p2
|
| 83 |
|
| 84 | ## STDOUT:
|
| 85 | 1
|
| 86 | 2
|
| 87 | ## END
|
| 88 |
|
| 89 | #### DebugFrame.toString() running file
|
| 90 |
|
| 91 | $[ENV.SH] $[ENV.REPO_ROOT]/spec/testdata/debug-frame-main.ysh |
|
| 92 | sed -e "s;$[ENV.REPO_ROOT];MYROOT;g" -e 's;#;%;g'
|
| 93 |
|
| 94 | ## STDOUT:
|
| 95 | %1 MYROOT/spec/testdata/debug-frame-main.ysh:4
|
| 96 | print-stack
|
| 97 | ^~~~~~~~~~~
|
| 98 |
|
| 99 | %1 MYROOT/spec/testdata/debug-frame-main.ysh:7
|
| 100 | my-proc
|
| 101 | ^~~~~~~
|
| 102 | %2 MYROOT/spec/testdata/debug-frame-lib.ysh:15
|
| 103 | print-stack
|
| 104 | ^~~~~~~~~~~
|
| 105 | ## END
|
| 106 |
|
| 107 |
|
| 108 | #### DebugFrame.toString() running stdin and -c
|
| 109 |
|
| 110 | # stdin
|
| 111 | echo 'source $[ENV.REPO_ROOT]/spec/testdata/debug-frame-lib.ysh; my-proc' |
|
| 112 | $[ENV.SH] |
|
| 113 | sed -e "s;$[ENV.REPO_ROOT];MYROOT;g" -e 's;#;%;g'
|
| 114 | echo
|
| 115 |
|
| 116 | # -c
|
| 117 | $[ENV.SH] -c 'source $[ENV.REPO_ROOT]/spec/testdata/debug-frame-lib.ysh; my-proc' |
|
| 118 | sed -e "s;$[ENV.REPO_ROOT];MYROOT;g" -e 's;#;%;g'
|
| 119 |
|
| 120 | ## STDOUT:
|
| 121 | %1 [ stdin ]:1
|
| 122 | source $[ENV.REPO_ROOT]/spec/testdata/debug-frame-lib.ysh; my-proc
|
| 123 | ^~~~~~~
|
| 124 | %2 MYROOT/spec/testdata/debug-frame-lib.ysh:15
|
| 125 | print-stack
|
| 126 | ^~~~~~~~~~~
|
| 127 |
|
| 128 | %1 [ -c flag ]:1
|
| 129 | source $[ENV.REPO_ROOT]/spec/testdata/debug-frame-lib.ysh; my-proc
|
| 130 | ^~~~~~~
|
| 131 | %2 MYROOT/spec/testdata/debug-frame-lib.ysh:15
|
| 132 | print-stack
|
| 133 | ^~~~~~~~~~~
|
| 134 | ## END
|
| 135 |
|
| 136 | #### DebugFrame.toString() running eval
|
| 137 |
|
| 138 | # -c and eval
|
| 139 | $[ENV.SH] -c 'source $[ENV.REPO_ROOT]/spec/testdata/debug-frame-lib.ysh; eval "my-proc a b"' |
|
| 140 | sed -e "s;$[ENV.REPO_ROOT];MYROOT;g" -e 's;#;%;g'
|
| 141 | echo
|
| 142 |
|
| 143 | # eval
|
| 144 | $[ENV.SH] -c 'source $[ENV.REPO_ROOT]/spec/testdata/debug-frame-eval.ysh' |
|
| 145 | sed -e "s;$[ENV.REPO_ROOT];MYROOT;g" -e 's;#;%;g'
|
| 146 |
|
| 147 | ## STDOUT:
|
| 148 | %1 [ -c flag ]:1
|
| 149 | source $[ENV.REPO_ROOT]/spec/testdata/debug-frame-lib.ysh; eval "my-proc a b"
|
| 150 | ^
|
| 151 | %2 [ eval arg at line 1 of [ -c flag ] ]:1
|
| 152 | my-proc a b
|
| 153 | ^~~~~~~
|
| 154 | %3 MYROOT/spec/testdata/debug-frame-lib.ysh:15
|
| 155 | print-stack
|
| 156 | ^~~~~~~~~~~
|
| 157 |
|
| 158 | %1 [ -c flag ]:1
|
| 159 | source $[ENV.REPO_ROOT]/spec/testdata/debug-frame-eval.ysh
|
| 160 | ^~~~~~
|
| 161 | %2 MYROOT/spec/testdata/debug-frame-eval.ysh:7
|
| 162 | p3
|
| 163 | ^~
|
| 164 | %3 MYROOT/spec/testdata/debug-frame-eval.ysh:4
|
| 165 | eval 'my-proc x y'
|
| 166 | ^
|
| 167 | %4 [ eval arg at line 4 of MYROOT/spec/testdata/debug-frame-eval.ysh ]:1
|
| 168 | my-proc x y
|
| 169 | ^~~~~~~
|
| 170 | %5 MYROOT/spec/testdata/debug-frame-lib.ysh:15
|
| 171 | print-stack
|
| 172 | ^~~~~~~~~~~
|
| 173 | ## END
|
| 174 |
|
| 175 | #### DebugFrame.toString() running io->eval() on command
|
| 176 | $[ENV.SH] -c '
|
| 177 | source $[ENV.REPO_ROOT]/spec/testdata/debug-frame-lib.ysh
|
| 178 | var b = ^(my-proc a b)
|
| 179 | proc p {
|
| 180 | call io->eval(b)
|
| 181 | }
|
| 182 | p
|
| 183 | ' | sed -e "s;$[ENV.REPO_ROOT];MYROOT;g" -e 's;#;%;g'
|
| 184 |
|
| 185 | ## STDOUT:
|
| 186 | %1 [ -c flag ]:7
|
| 187 | p
|
| 188 | ^
|
| 189 | %2 [ -c flag ]:5
|
| 190 | call io->eval(b)
|
| 191 | ^
|
| 192 | %3 [ -c flag ]:3
|
| 193 | var b = ^(my-proc a b)
|
| 194 | ^~~~~~~
|
| 195 | %4 MYROOT/spec/testdata/debug-frame-lib.ysh:15
|
| 196 | print-stack
|
| 197 | ^~~~~~~~~~~
|
| 198 | ## END
|
| 199 |
|
| 200 | #### DebugFrame.toString() running io->evalExpr()
|
| 201 |
|
| 202 | $[ENV.SH] -c '
|
| 203 | source $[ENV.REPO_ROOT]/spec/testdata/debug-frame-lib.ysh
|
| 204 |
|
| 205 | proc print-num {
|
| 206 | print-stack > stack-trace.txt
|
| 207 | echo 42
|
| 208 | }
|
| 209 |
|
| 210 | var e = ^[2 + $(print-num)]
|
| 211 |
|
| 212 | proc p {
|
| 213 | call io->evalExpr(e)
|
| 214 | }
|
| 215 |
|
| 216 | p
|
| 217 | '
|
| 218 |
|
| 219 | sed 's;#;%;g' stack-trace.txt
|
| 220 |
|
| 221 | ## STDOUT:
|
| 222 | %1 [ -c flag ]:15
|
| 223 | p
|
| 224 | ^
|
| 225 | %2 [ -c flag ]:12
|
| 226 | call io->evalExpr(e)
|
| 227 | ^
|
| 228 | %3 [ -c flag ]:9
|
| 229 | var e = ^[2 + $(print-num)]
|
| 230 | ^~~~~~~~~
|
| 231 | %4 [ -c flag ]:5
|
| 232 | print-stack > stack-trace.txt
|
| 233 | ^~~~~~~~~~~
|
| 234 | ## END
|
| 235 |
|
| 236 | #### DebugFrame.toString() running YSH functions
|
| 237 |
|
| 238 | # functions
|
| 239 | $[ENV.SH] -c 'source $[ENV.REPO_ROOT]/spec/testdata/debug-frame-lib.ysh; call-func' |
|
| 240 | sed -e "s;$[ENV.REPO_ROOT];MYROOT;g" -e 's;#;%;g'
|
| 241 |
|
| 242 | ## STDOUT:
|
| 243 | %1 [ -c flag ]:1
|
| 244 | source $[ENV.REPO_ROOT]/spec/testdata/debug-frame-lib.ysh; call-func
|
| 245 | ^~~~~~~~~
|
| 246 | %2 MYROOT/spec/testdata/debug-frame-lib.ysh:32
|
| 247 | var x = myfunc(99)
|
| 248 | ^
|
| 249 | %3 MYROOT/spec/testdata/debug-frame-lib.ysh:28
|
| 250 | return (identity(myfunc2(42, x+1)))
|
| 251 | ^
|
| 252 | %4 MYROOT/spec/testdata/debug-frame-lib.ysh:23
|
| 253 | print-stack
|
| 254 | ^~~~~~~~~~~
|
| 255 | 142
|
| 256 | ## END
|
| 257 |
|
| 258 | #### DebugFrame.toString() with 'use' builtin
|
| 259 |
|
| 260 | # Work around spec test builtin limitation: line starting with # is treated as
|
| 261 | # a comment
|
| 262 |
|
| 263 | #echo $[ENV.REPO_ROOT]
|
| 264 |
|
| 265 | $[ENV.SH] -c 'use $[ENV.REPO_ROOT]/spec/testdata/debug-frame-use.ysh' |
|
| 266 | sed -e "s;$[ENV.REPO_ROOT];MYROOT;g" -e 's;#;%;g'
|
| 267 |
|
| 268 | #write -- $[ENV.REPO_ROOT] | sed "s;$[ENV.REPO_ROOT];REPO_ROOT;g"
|
| 269 |
|
| 270 | ## STDOUT:
|
| 271 | %1 [ -c flag ]:1
|
| 272 | use $[ENV.REPO_ROOT]/spec/testdata/debug-frame-use.ysh
|
| 273 | ^~~
|
| 274 | %2 MYROOT/spec/testdata/debug-frame-use.ysh:5
|
| 275 | debug-frame-lib my-proc
|
| 276 | ^~~~~~~
|
| 277 | %3 MYROOT/spec/testdata/debug-frame-lib.ysh:15
|
| 278 | print-stack
|
| 279 | ^~~~~~~~~~~
|
| 280 | ## END
|
| 281 |
|
| 282 | #### FUNCNAME BASH_LINENO BASH_SOURCE not available with YSH functions
|
| 283 |
|
| 284 | func g(x) {
|
| 285 | echo ${FUNCNAME[@]}
|
| 286 | echo ${BASH_LINENO[@]}
|
| 287 | echo ${BASH_SOURCE[@]}
|
| 288 | }
|
| 289 |
|
| 290 | func f(x) {
|
| 291 | return (g(x))
|
| 292 | }
|
| 293 |
|
| 294 | # We can allow it in procs -- there's no cost to doing so?
|
| 295 |
|
| 296 | proc p {
|
| 297 | call f(42)
|
| 298 | }
|
| 299 |
|
| 300 | p
|
| 301 |
|
| 302 | ## STDOUT:
|
| 303 | p
|
| 304 | 16
|
| 305 | [ stdin ]
|
| 306 | ## END
|
| 307 |
|
| 308 | #### trap ERR - external failure
|
| 309 |
|
| 310 | source $[ENV.REPO_ROOT]/spec/testdata/debug-frame-lib.ysh
|
| 311 |
|
| 312 | trap 'print-stack (prefix=false)' ERR
|
| 313 | set -o errtrace # enable always
|
| 314 |
|
| 315 | proc f {
|
| 316 | g
|
| 317 | }
|
| 318 |
|
| 319 | proc g {
|
| 320 | false
|
| 321 | }
|
| 322 |
|
| 323 | f
|
| 324 |
|
| 325 | ## status: 1
|
| 326 | ## STDOUT:
|
| 327 | [ stdin ]:14
|
| 328 | f
|
| 329 | ^
|
| 330 | [ stdin ]:7
|
| 331 | g
|
| 332 | ^
|
| 333 | ## END
|
| 334 |
|
| 335 | #### trap ERR - proc subshell failure
|
| 336 |
|
| 337 | source $[ENV.REPO_ROOT]/spec/testdata/debug-frame-lib.ysh
|
| 338 |
|
| 339 | trap 'print-stack (prefix=false)' ERR
|
| 340 | set -o errtrace # enable always
|
| 341 |
|
| 342 | proc f {
|
| 343 | g
|
| 344 | }
|
| 345 |
|
| 346 | proc g {
|
| 347 | ( exit 42 )
|
| 348 | #return 42
|
| 349 | }
|
| 350 |
|
| 351 | f
|
| 352 |
|
| 353 | ## status: 42
|
| 354 | ## STDOUT:
|
| 355 | [ stdin ]:14
|
| 356 | f
|
| 357 | ^
|
| 358 | [ stdin ]:7
|
| 359 | g
|
| 360 | ^
|
| 361 | ## END
|
| 362 |
|
| 363 | #### trap ERR - proc non-zero return status
|
| 364 |
|
| 365 | source $[ENV.REPO_ROOT]/spec/testdata/debug-frame-lib.ysh
|
| 366 |
|
| 367 | trap 'print-stack (prefix=false)' ERR
|
| 368 | set -o errtrace # enable always
|
| 369 |
|
| 370 | proc f {
|
| 371 | g
|
| 372 | }
|
| 373 |
|
| 374 | proc g {
|
| 375 | return 42
|
| 376 | }
|
| 377 |
|
| 378 | f
|
| 379 |
|
| 380 | ## status: 42
|
| 381 |
|
| 382 | # Hm we do not get the "g" call here? Because we get an exception raised
|
| 383 |
|
| 384 | ## STDOUT:
|
| 385 | [ stdin ]:14
|
| 386 | f
|
| 387 | ^
|
| 388 | ## END
|