| 1 | #!/usr/bin/env bash
 | 
| 2 | #
 | 
| 3 | # Usage:
 | 
| 4 | #   test/spec.sh <function name>
 | 
| 5 | 
 | 
| 6 | : ${LIB_OSH=stdlib/osh}
 | 
| 7 | source $LIB_OSH/bash-strict.sh
 | 
| 8 | source $LIB_OSH/task-five.sh
 | 
| 9 | 
 | 
| 10 | REPO_ROOT=$(cd "$(dirname $0)/.."; pwd)
 | 
| 11 | 
 | 
| 12 | source test/common.sh
 | 
| 13 | source test/spec-common.sh
 | 
| 14 | 
 | 
| 15 | if test -z "${IN_NIX_SHELL:-}"; then
 | 
| 16 |   source build/dev-shell.sh  # to run 'dash', etc.
 | 
| 17 | fi
 | 
| 18 | 
 | 
| 19 | # TODO: Just use 'dash bash' and $PATH
 | 
| 20 | readonly DASH=dash
 | 
| 21 | readonly BASH=bash
 | 
| 22 | readonly MKSH=mksh
 | 
| 23 | readonly ZSH=zsh
 | 
| 24 | readonly BUSYBOX_ASH=ash
 | 
| 25 | 
 | 
| 26 | # ash and dash are similar, so not including ash by default.  zsh is not quite
 | 
| 27 | # POSIX.
 | 
| 28 | readonly REF_SHELLS=($DASH $BASH $MKSH)
 | 
| 29 | 
 | 
| 30 | check-survey-shells() {
 | 
| 31 |   ### Make sure bash, zsh, OSH, etc. exist
 | 
| 32 | 
 | 
| 33 |   # Note: yash isn't here, but it is used in a couple tests
 | 
| 34 | 
 | 
| 35 |   test/spec-runner.sh shell-sanity-check "${REF_SHELLS[@]}" $ZSH $BUSYBOX_ASH $OSH_LIST
 | 
| 36 | }
 | 
| 37 | 
 | 
| 38 | # TODO: remove this stub after we hollow out this file
 | 
| 39 | 
 | 
| 40 | run-file() { test/spec-py.sh run-file "$@"; }
 | 
| 41 | 
 | 
| 42 | #
 | 
| 43 | # Misc
 | 
| 44 | #
 | 
| 45 | 
 | 
| 46 | # Really what I want is enter(func) and exit(func), and filter by regex?
 | 
| 47 | trace-var-sub() {
 | 
| 48 |   local out=_tmp/coverage
 | 
| 49 |   mkdir -p $out
 | 
| 50 | 
 | 
| 51 |   # This creates *.cover files, with line counts.
 | 
| 52 |   #python -m trace --count -C $out \
 | 
| 53 | 
 | 
| 54 |   # This prints trace with line numbers to stdout.
 | 
| 55 |   #python -m trace --trace -C $out \
 | 
| 56 |   PYTHONPATH=. python -m trace --trackcalls -C $out \
 | 
| 57 |     test/sh_spec.py spec/var-sub.test.sh $DASH $BASH "$@"
 | 
| 58 | 
 | 
| 59 |   ls -l $out
 | 
| 60 |   head $out/*.cover
 | 
| 61 | }
 | 
| 62 | 
 | 
| 63 | #
 | 
| 64 | # Individual tests.
 | 
| 65 | #
 | 
| 66 | # We configure the shells they run on and the number of allowed failures (to
 | 
| 67 | # prevent regressions.)
 | 
| 68 | #
 | 
| 69 | 
 | 
| 70 | interactive-parse() {
 | 
| 71 |   run-file interactive-parse "$@"
 | 
| 72 | }
 | 
| 73 | 
 | 
| 74 | smoke() {
 | 
| 75 |   run-file smoke "$@"
 | 
| 76 | }
 | 
| 77 | 
 | 
| 78 | interactive() {
 | 
| 79 |   run-file interactive "$@"
 | 
| 80 | }
 | 
| 81 | 
 | 
| 82 | prompt() {
 | 
| 83 |   run-file prompt "$@"
 | 
| 84 | }
 | 
| 85 | 
 | 
| 86 | bugs() {
 | 
| 87 |   run-file bugs "$@"
 | 
| 88 | }
 | 
| 89 | 
 | 
| 90 | TODO-deprecate() {
 | 
| 91 |   run-file TODO-deprecate "$@"
 | 
| 92 | }
 | 
| 93 | 
 | 
| 94 | blog1() {
 | 
| 95 |   sh-spec spec/blog1.test.sh \
 | 
| 96 |     ${REF_SHELLS[@]} $ZSH $OSH_LIST "$@"
 | 
| 97 | }
 | 
| 98 | 
 | 
| 99 | blog2() {
 | 
| 100 |   run-file blog2 "$@"
 | 
| 101 | }
 | 
| 102 | 
 | 
| 103 | blog-other1() {
 | 
| 104 |   sh-spec spec/blog-other1.test.sh \
 | 
| 105 |     ${REF_SHELLS[@]} $ZSH $OSH_LIST "$@"
 | 
| 106 | }
 | 
| 107 | 
 | 
| 108 | alias() {
 | 
| 109 |   run-file alias "$@"
 | 
| 110 | }
 | 
| 111 | 
 | 
| 112 | comments() {
 | 
| 113 |   sh-spec spec/comments.test.sh ${REF_SHELLS[@]} $OSH_LIST "$@"
 | 
| 114 | }
 | 
| 115 | 
 | 
| 116 | word-split() {
 | 
| 117 |   run-file word-split "$@"
 | 
| 118 | }
 | 
| 119 | 
 | 
| 120 | word-eval() {
 | 
| 121 |   sh-spec spec/word-eval.test.sh \
 | 
| 122 |     ${REF_SHELLS[@]} $OSH_LIST "$@"
 | 
| 123 | }
 | 
| 124 | 
 | 
| 125 | # These cases apply to many shells.
 | 
| 126 | assign() {
 | 
| 127 |   run-file assign "$@"
 | 
| 128 | }
 | 
| 129 | 
 | 
| 130 | # These cases apply to a few shells.
 | 
| 131 | assign-extended() {
 | 
| 132 |   run-file assign-extended "$@"
 | 
| 133 | }
 | 
| 134 | 
 | 
| 135 | # Corner cases that OSH doesn't handle
 | 
| 136 | assign-deferred() {
 | 
| 137 |   sh-spec spec/assign-deferred.test.sh \
 | 
| 138 |     $BASH $MKSH "$@" 
 | 
| 139 | }
 | 
| 140 | 
 | 
| 141 | # These test associative arrays
 | 
| 142 | assign-dialects() {
 | 
| 143 |   run-file assign-dialects "$@"
 | 
| 144 | }
 | 
| 145 | 
 | 
| 146 | background() {
 | 
| 147 |   run-file background "$@"
 | 
| 148 | }
 | 
| 149 | 
 | 
| 150 | subshell() {
 | 
| 151 |   sh-spec spec/subshell.test.sh \
 | 
| 152 |     ${REF_SHELLS[@]} $OSH_LIST "$@" 
 | 
| 153 | }
 | 
| 154 | 
 | 
| 155 | quote() {
 | 
| 156 |   sh-spec spec/quote.test.sh \
 | 
| 157 |     ${REF_SHELLS[@]} $BUSYBOX_ASH $OSH_LIST "$@"
 | 
| 158 | }
 | 
| 159 | 
 | 
| 160 | unicode() {
 | 
| 161 |   run-file unicode "$@"
 | 
| 162 | }
 | 
| 163 | 
 | 
| 164 | loop() {
 | 
| 165 |   run-file loop "$@"
 | 
| 166 | }
 | 
| 167 | 
 | 
| 168 | case_() {
 | 
| 169 |   run-file case_ "$@"
 | 
| 170 | }
 | 
| 171 | 
 | 
| 172 | if_() {
 | 
| 173 |   sh-spec spec/if_.test.sh \
 | 
| 174 |     ${REF_SHELLS[@]} $ZSH $OSH_LIST "$@"
 | 
| 175 | }
 | 
| 176 | 
 | 
| 177 | builtin-misc() {
 | 
| 178 |   run-file builtin-misc "$@"
 | 
| 179 | }
 | 
| 180 | 
 | 
| 181 | builtin-process() {
 | 
| 182 |   run-file builtin-process "$@"
 | 
| 183 | }
 | 
| 184 | 
 | 
| 185 | builtin-cd() {
 | 
| 186 |   run-file builtin-cd "$@"
 | 
| 187 | }
 | 
| 188 | 
 | 
| 189 | builtin-eval-source() {
 | 
| 190 |   run-file builtin-eval-source "$@"
 | 
| 191 | }
 | 
| 192 | 
 | 
| 193 | builtin-echo() {
 | 
| 194 |   run-file builtin-echo "$@"
 | 
| 195 | }
 | 
| 196 | 
 | 
| 197 | builtin-read() {
 | 
| 198 |   run-file builtin-read "$@"
 | 
| 199 | }
 | 
| 200 | 
 | 
| 201 | nul-bytes() {
 | 
| 202 |   run-file nul-bytes "$@"
 | 
| 203 | }
 | 
| 204 | 
 | 
| 205 | whitespace() {
 | 
| 206 |   run-file whitespace "$@"
 | 
| 207 | }
 | 
| 208 | 
 | 
| 209 | # Special bash printf things like -v and %q.  Portable stuff goes in builtin-io.
 | 
| 210 | builtin-printf() {
 | 
| 211 |   run-file builtin-printf "$@"
 | 
| 212 | }
 | 
| 213 | 
 | 
| 214 | builtin-meta() {
 | 
| 215 |   run-file builtin-meta  "$@"
 | 
| 216 | }
 | 
| 217 | 
 | 
| 218 | builtin-history() {
 | 
| 219 |   run-file builtin-history "$@"
 | 
| 220 | }
 | 
| 221 | 
 | 
| 222 | # dash and mksh don't implement 'dirs'
 | 
| 223 | builtin-dirs() {
 | 
| 224 |   sh-spec spec/builtin-dirs.test.sh \
 | 
| 225 |     $BASH $ZSH $OSH_LIST "$@"
 | 
| 226 | }
 | 
| 227 | 
 | 
| 228 | builtin-vars() {
 | 
| 229 |   run-file builtin-vars "$@"
 | 
| 230 | }
 | 
| 231 | 
 | 
| 232 | builtin-getopts() {
 | 
| 233 |   run-file builtin-getopts "$@"
 | 
| 234 | }
 | 
| 235 | 
 | 
| 236 | builtin-bracket() {
 | 
| 237 |   run-file builtin-bracket "$@"
 | 
| 238 | }
 | 
| 239 | 
 | 
| 240 | builtin-trap() {
 | 
| 241 |   run-file builtin-trap "$@"
 | 
| 242 | }
 | 
| 243 | 
 | 
| 244 | builtin-trap-err() {
 | 
| 245 |   run-file builtin-trap-err "$@"
 | 
| 246 | }
 | 
| 247 | 
 | 
| 248 | builtin-trap-bash() {
 | 
| 249 |   run-file builtin-trap-bash "$@"
 | 
| 250 | }
 | 
| 251 | 
 | 
| 252 | # Bash implements type -t, but no other shell does.  For Nix.
 | 
| 253 | # zsh/mksh/dash don't have the 'help' builtin.
 | 
| 254 | builtin-bash() {
 | 
| 255 |   run-file builtin-bash "$@"
 | 
| 256 | }
 | 
| 257 | 
 | 
| 258 | builtin-type() {
 | 
| 259 |   run-file builtin-type "$@"
 | 
| 260 | }
 | 
| 261 | 
 | 
| 262 | builtin-type-bash() {
 | 
| 263 |   run-file builtin-type-bash "$@"
 | 
| 264 | }
 | 
| 265 | 
 | 
| 266 | vars-bash() {
 | 
| 267 |   run-file vars-bash "$@"
 | 
| 268 | }
 | 
| 269 | 
 | 
| 270 | vars-special() {
 | 
| 271 |   run-file vars-special "$@"
 | 
| 272 | }
 | 
| 273 | 
 | 
| 274 | builtin-completion() {
 | 
| 275 |   run-file builtin-completion "$@"
 | 
| 276 | }
 | 
| 277 | 
 | 
| 278 | builtin-special() {
 | 
| 279 |   run-file builtin-special "$@"
 | 
| 280 | }
 | 
| 281 | 
 | 
| 282 | builtin-times() {
 | 
| 283 |   sh-spec spec/builtin-times.test.sh $BASH $ZSH $OSH_LIST "$@"
 | 
| 284 | }
 | 
| 285 | 
 | 
| 286 | command-parsing() {
 | 
| 287 |   sh-spec spec/command-parsing.test.sh ${REF_SHELLS[@]} $OSH_LIST "$@"
 | 
| 288 | }
 | 
| 289 | 
 | 
| 290 | func-parsing() {
 | 
| 291 |   sh-spec spec/func-parsing.test.sh ${REF_SHELLS[@]} $OSH_LIST "$@"
 | 
| 292 | }
 | 
| 293 | 
 | 
| 294 | sh-func() {
 | 
| 295 |   run-file sh-func "$@"
 | 
| 296 | }
 | 
| 297 | 
 | 
| 298 | glob() {
 | 
| 299 |   run-file glob "$@"
 | 
| 300 | }
 | 
| 301 | 
 | 
| 302 | globignore() {
 | 
| 303 |   run-file globignore "$@"
 | 
| 304 | }
 | 
| 305 | 
 | 
| 306 | arith() {
 | 
| 307 |   run-file arith "$@"
 | 
| 308 | }
 | 
| 309 | 
 | 
| 310 | command-sub() {
 | 
| 311 |   sh-spec spec/command-sub.test.sh \
 | 
| 312 |     ${REF_SHELLS[@]} $OSH_LIST "$@"
 | 
| 313 | }
 | 
| 314 | 
 | 
| 315 | command_() {
 | 
| 316 |   sh-spec spec/command_.test.sh \
 | 
| 317 |     ${REF_SHELLS[@]} $ZSH $OSH_LIST "$@"
 | 
| 318 | }
 | 
| 319 | 
 | 
| 320 | pipeline() {
 | 
| 321 |   sh-spec spec/pipeline.test.sh \
 | 
| 322 |     ${REF_SHELLS[@]} $ZSH $OSH_LIST "$@"
 | 
| 323 | }
 | 
| 324 | 
 | 
| 325 | explore-parsing() {
 | 
| 326 |   sh-spec spec/explore-parsing.test.sh \
 | 
| 327 |     ${REF_SHELLS[@]} $OSH_LIST "$@"
 | 
| 328 | }
 | 
| 329 | 
 | 
| 330 | parse-errors() {
 | 
| 331 |   run-file parse-errors "$@"
 | 
| 332 | }
 | 
| 333 | 
 | 
| 334 | here-doc() {
 | 
| 335 |   # NOTE: The last two tests, 31 and 32, have different behavior on my Ubuntu
 | 
| 336 |   # and Debian machines.
 | 
| 337 |   # - On Ubuntu, read_from_fd.py fails with Errno 9 -- bad file descriptor.
 | 
| 338 |   # - On Debian, the whole process hangs.
 | 
| 339 |   # Is this due to Python 3.2 vs 3.4?  Either way osh doesn't implement the
 | 
| 340 |   # functionality, so it's probably best to just implement it.
 | 
| 341 |   sh-spec spec/here-doc.test.sh --range 0-31 \
 | 
| 342 |     ${REF_SHELLS[@]} $OSH_LIST "$@"
 | 
| 343 | }
 | 
| 344 | 
 | 
| 345 | redirect() {
 | 
| 346 |   run-file redirect "$@"
 | 
| 347 | }
 | 
| 348 | 
 | 
| 349 | redirect-command() {
 | 
| 350 |   run-file redirect-command "$@"
 | 
| 351 | }
 | 
| 352 | 
 | 
| 353 | redirect-multi() {
 | 
| 354 |   run-file redirect-multi "$@"
 | 
| 355 | }
 | 
| 356 | 
 | 
| 357 | posix() {
 | 
| 358 |   sh-spec spec/posix.test.sh \
 | 
| 359 |     ${REF_SHELLS[@]} $OSH_LIST "$@"
 | 
| 360 | }
 | 
| 361 | 
 | 
| 362 | introspect() {
 | 
| 363 |   run-file introspect "$@"
 | 
| 364 | }
 | 
| 365 | 
 | 
| 366 | tilde() {
 | 
| 367 |   run-file tilde "$@"
 | 
| 368 | }
 | 
| 369 | 
 | 
| 370 | var-op-test() {
 | 
| 371 |   run-file var-op-test "$@"
 | 
| 372 | }
 | 
| 373 | 
 | 
| 374 | var-op-len() {
 | 
| 375 |   sh-spec spec/var-op-len.test.sh \
 | 
| 376 |     ${REF_SHELLS[@]} $ZSH $OSH_LIST "$@"
 | 
| 377 | }
 | 
| 378 | 
 | 
| 379 | var-op-patsub() {
 | 
| 380 |   # 1 unicode failure, and [^]] which is a parsing divergence
 | 
| 381 |   run-file var-op-patsub "$@"
 | 
| 382 | }
 | 
| 383 | 
 | 
| 384 | var-op-slice() {
 | 
| 385 |   run-file var-op-slice "$@"
 | 
| 386 | }
 | 
| 387 | 
 | 
| 388 | var-op-bash() {
 | 
| 389 |   run-file var-op-bash "$@"
 | 
| 390 | }
 | 
| 391 | 
 | 
| 392 | var-op-strip() {
 | 
| 393 |   sh-spec spec/var-op-strip.test.sh \
 | 
| 394 |     ${REF_SHELLS[@]} $ZSH $BUSYBOX_ASH $OSH_LIST "$@"
 | 
| 395 | }
 | 
| 396 | 
 | 
| 397 | var-sub() {
 | 
| 398 |   # NOTE: ZSH has interesting behavior, like echo hi > "$@" can write to TWO
 | 
| 399 |   # FILES!  But ultimately we don't really care, so I disabled it.
 | 
| 400 |   sh-spec spec/var-sub.test.sh \
 | 
| 401 |     ${REF_SHELLS[@]} $OSH_LIST "$@"
 | 
| 402 | }
 | 
| 403 | 
 | 
| 404 | var-num() {
 | 
| 405 |   run-file var-num "$@"
 | 
| 406 | }
 | 
| 407 | 
 | 
| 408 | var-sub-quote() {
 | 
| 409 |   sh-spec spec/var-sub-quote.test.sh \
 | 
| 410 |     ${REF_SHELLS[@]} $OSH_LIST "$@"
 | 
| 411 | }
 | 
| 412 | 
 | 
| 413 | sh-usage() {
 | 
| 414 |   run-file sh-usage "$@"
 | 
| 415 | }
 | 
| 416 | 
 | 
| 417 | sh-options() {
 | 
| 418 |   run-file sh-options "$@"
 | 
| 419 | }
 | 
| 420 | 
 | 
| 421 | xtrace() {
 | 
| 422 |   run-file xtrace "$@"
 | 
| 423 | }
 | 
| 424 | 
 | 
| 425 | strict-options() {
 | 
| 426 |   run-file strict-options "$@"
 | 
| 427 | }
 | 
| 428 | 
 | 
| 429 | exit-status() {
 | 
| 430 |   run-file exit-status "$@"
 | 
| 431 | }
 | 
| 432 | 
 | 
| 433 | errexit() {
 | 
| 434 |   run-file errexit "$@"
 | 
| 435 | }
 | 
| 436 | 
 | 
| 437 | errexit-osh() {
 | 
| 438 |   run-file errexit-osh "$@"
 | 
| 439 | }
 | 
| 440 | 
 | 
| 441 | fatal-errors() {
 | 
| 442 |   sh-spec spec/fatal-errors.test.sh \
 | 
| 443 |     ${REF_SHELLS[@]} $ZSH $OSH_LIST "$@"
 | 
| 444 | }
 | 
| 445 | 
 | 
| 446 | # 
 | 
| 447 | # Non-POSIX extensions: arrays, brace expansion, [[, ((, etc.
 | 
| 448 | #
 | 
| 449 | 
 | 
| 450 | # There as many non-POSIX arithmetic contexts.
 | 
| 451 | arith-context() {
 | 
| 452 |   run-file arith-context "$@"
 | 
| 453 | }
 | 
| 454 | 
 | 
| 455 | array() {
 | 
| 456 |   run-file array "$@"
 | 
| 457 | }
 | 
| 458 | 
 | 
| 459 | array-basic() {
 | 
| 460 |   run-file array-basic "$@"
 | 
| 461 | }
 | 
| 462 | 
 | 
| 463 | array-compat() {
 | 
| 464 |   run-file array-compat "$@"
 | 
| 465 | }
 | 
| 466 | 
 | 
| 467 | type-compat() {
 | 
| 468 |   run-file type-compat "$@"
 | 
| 469 | }
 | 
| 470 | 
 | 
| 471 | # += is not POSIX and not in dash.
 | 
| 472 | append() {
 | 
| 473 |   run-file append "$@"
 | 
| 474 | }
 | 
| 475 | 
 | 
| 476 | # associative array -- mksh and zsh implement different associative arrays.
 | 
| 477 | assoc() {
 | 
| 478 |   run-file assoc "$@"
 | 
| 479 | }
 | 
| 480 | 
 | 
| 481 | # ZSH also has associative arrays
 | 
| 482 | assoc-zsh() {
 | 
| 483 |   sh-spec spec/assoc-zsh.test.sh $ZSH "$@"
 | 
| 484 | }
 | 
| 485 | 
 | 
| 486 | dbracket() {
 | 
| 487 |   run-file dbracket "$@"
 | 
| 488 | }
 | 
| 489 | 
 | 
| 490 | dparen() {
 | 
| 491 |   run-file dparen "$@"
 | 
| 492 | }
 | 
| 493 | 
 | 
| 494 | brace-expansion() {
 | 
| 495 |   run-file brace-expansion "$@"
 | 
| 496 | }
 | 
| 497 | 
 | 
| 498 | regex() {
 | 
| 499 |   run-file regex "$@"
 | 
| 500 | }
 | 
| 501 | 
 | 
| 502 | process-sub() {
 | 
| 503 |   run-file process-sub "$@"
 | 
| 504 | }
 | 
| 505 | 
 | 
| 506 | # This does file system globbing
 | 
| 507 | extglob-files() {
 | 
| 508 |   run-file extglob-files "$@"
 | 
| 509 | }
 | 
| 510 | 
 | 
| 511 | # This does string matching.
 | 
| 512 | extglob-match() {
 | 
| 513 |   sh-spec spec/extglob-match.test.sh \
 | 
| 514 |     $BASH $MKSH $OSH_LIST "$@"
 | 
| 515 | }
 | 
| 516 | 
 | 
| 517 | nocasematch-match() {
 | 
| 518 |   run-file nocasematch-match "$@"
 | 
| 519 | }
 | 
| 520 | 
 | 
| 521 | # ${!var} syntax -- oil should replace this with associative arrays.
 | 
| 522 | # mksh has completely different behavior for this syntax.  Not worth testing.
 | 
| 523 | var-ref() {
 | 
| 524 |   run-file var-ref "$@"
 | 
| 525 | }
 | 
| 526 | 
 | 
| 527 | nameref() {
 | 
| 528 |   ### declare -n / local -n
 | 
| 529 |   run-file nameref "$@"
 | 
| 530 | }
 | 
| 531 | 
 | 
| 532 | let() {
 | 
| 533 |   sh-spec spec/let.test.sh $BASH $MKSH $ZSH "$@"
 | 
| 534 | }
 | 
| 535 | 
 | 
| 536 | for-expr() {
 | 
| 537 |   run-file for-expr "$@"
 | 
| 538 | }
 | 
| 539 | 
 | 
| 540 | empty-bodies() {
 | 
| 541 |   sh-spec spec/empty-bodies.test.sh "${REF_SHELLS[@]}" $ZSH $OSH_LIST "$@"
 | 
| 542 | }
 | 
| 543 | 
 | 
| 544 | # TODO: This is for the ANTLR grammars, in the oil-sketch repo.
 | 
| 545 | # osh has infinite loop?
 | 
| 546 | shell-grammar() {
 | 
| 547 |   sh-spec spec/shell-grammar.test.sh $BASH $MKSH $ZSH "$@"
 | 
| 548 | }
 | 
| 549 | 
 | 
| 550 | serialize() {
 | 
| 551 |   run-file serialize "$@"
 | 
| 552 | }
 | 
| 553 | 
 | 
| 554 | #
 | 
| 555 | # Smoosh
 | 
| 556 | #
 | 
| 557 | 
 | 
| 558 | readonly SMOOSH_REPO=~/git/languages/smoosh
 | 
| 559 | 
 | 
| 560 | sh-spec-smoosh-env() {
 | 
| 561 |   local test_file=$1
 | 
| 562 |   shift
 | 
| 563 | 
 | 
| 564 |   # - smoosh tests use $TEST_SHELL instead of $SH
 | 
| 565 |   # - cd $TMP to avoid littering repo
 | 
| 566 |   # - pass -o posix
 | 
| 567 |   # - timeout of 1 second
 | 
| 568 |   # - Some tests in smoosh use $HOME and $LOGNAME
 | 
| 569 | 
 | 
| 570 |   sh-spec $test_file \
 | 
| 571 |     --sh-env-var-name TEST_SHELL \
 | 
| 572 |     --posix \
 | 
| 573 |     --env-pair "TEST_UTIL=$SMOOSH_REPO/tests/util" \
 | 
| 574 |     --env-pair "LOGNAME=$LOGNAME" \
 | 
| 575 |     --env-pair "HOME=$HOME" \
 | 
| 576 |     --timeout 1 \
 | 
| 577 |     --oils-bin-dir $REPO_ROOT/bin \
 | 
| 578 |     --compare-shells \
 | 
| 579 |     "$@"
 | 
| 580 | }
 | 
| 581 | 
 | 
| 582 | # For speed, only run with one copy of OSH.
 | 
| 583 | readonly smoosh_osh_list=$OSH_CPYTHON
 | 
| 584 | 
 | 
| 585 | smoosh() {
 | 
| 586 |   ### Run case smoosh from the console
 | 
| 587 | 
 | 
| 588 |   # TODO: Use --oils-bin-dir
 | 
| 589 |   # our_shells, etc.
 | 
| 590 | 
 | 
| 591 |   sh-spec-smoosh-env _tmp/smoosh.test.sh \
 | 
| 592 |     ${REF_SHELLS[@]} $smoosh_osh_list \
 | 
| 593 |     "$@"
 | 
| 594 | }
 | 
| 595 | 
 | 
| 596 | smoosh-hang() {
 | 
| 597 |   ### Run case smoosh-hang from the console
 | 
| 598 | 
 | 
| 599 |   # Need the smoosh timeout tool to run correctly.
 | 
| 600 |   sh-spec-smoosh-env _tmp/smoosh-hang.test.sh \
 | 
| 601 |     --timeout-bin "$SMOOSH_REPO/tests/util/timeout" \
 | 
| 602 |     --timeout 1 \
 | 
| 603 |     "$@"
 | 
| 604 | }
 | 
| 605 | 
 | 
| 606 | _one-html() {
 | 
| 607 |   local spec_name=$1
 | 
| 608 |   shift
 | 
| 609 | 
 | 
| 610 |   local out_dir=_tmp/spec/smoosh
 | 
| 611 |   local tmp_dir=_tmp/src-smoosh
 | 
| 612 |   mkdir -p $out_dir $out_dir
 | 
| 613 | 
 | 
| 614 |   doctools/src_tree.py smoosh-file \
 | 
| 615 |     _tmp/$spec_name.test.sh \
 | 
| 616 |     $out_dir/$spec_name.test.html
 | 
| 617 | 
 | 
| 618 |   local out=$out_dir/${spec_name}.html
 | 
| 619 |   set +o errexit
 | 
| 620 |   # Shell function is smoosh or smoosh-hang
 | 
| 621 |   time $spec_name --format html "$@" > $out
 | 
| 622 |   set -o errexit
 | 
| 623 | 
 | 
| 624 |   echo
 | 
| 625 |   echo "Wrote $out"
 | 
| 626 | 
 | 
| 627 |   # NOTE: This IGNORES the exit status.
 | 
| 628 | }
 | 
| 629 | 
 | 
| 630 | # TODO:
 | 
| 631 | # - Put these tests in the CI
 | 
| 632 | # - Import smoosh spec tests into the repo, with 'test/smoosh.sh'
 | 
| 633 | 
 | 
| 634 | smoosh-html() {
 | 
| 635 |   ### Run by devtools/release.sh
 | 
| 636 |   _one-html smoosh "$@"
 | 
| 637 | }
 | 
| 638 | 
 | 
| 639 | smoosh-hang-html() {
 | 
| 640 |   ### Run by devtools/release.sh
 | 
| 641 |   _one-html smoosh-hang "$@"
 | 
| 642 | }
 | 
| 643 | 
 | 
| 644 | html-demo() {
 | 
| 645 |   ### Test for --format html
 | 
| 646 | 
 | 
| 647 |   local out=_tmp/spec/demo.html
 | 
| 648 |   builtin-special --format html "$@" > $out
 | 
| 649 | 
 | 
| 650 |   echo
 | 
| 651 |   echo "Wrote $out"
 | 
| 652 | }
 | 
| 653 | 
 | 
| 654 | #
 | 
| 655 | # Hay is part of the YSH suite
 | 
| 656 | #
 | 
| 657 | 
 | 
| 658 | hay() {
 | 
| 659 |   run-file hay "$@"
 | 
| 660 | }
 | 
| 661 | 
 | 
| 662 | hay-isolation() {
 | 
| 663 |   run-file hay-isolation "$@"
 | 
| 664 | }
 | 
| 665 | 
 | 
| 666 | hay-meta() {
 | 
| 667 |   run-file hay-meta "$@"
 | 
| 668 | }
 | 
| 669 | 
 | 
| 670 | #
 | 
| 671 | # YSH
 | 
| 672 | #
 | 
| 673 | 
 | 
| 674 | ysh-convert() {
 | 
| 675 |   run-file ysh-convert "$@"
 | 
| 676 | }
 | 
| 677 | 
 | 
| 678 | ysh-completion() {
 | 
| 679 |   run-file ysh-completion "$@"
 | 
| 680 | }
 | 
| 681 | 
 | 
| 682 | ysh-stdlib() {
 | 
| 683 |   run-file ysh-stdlib "$@"
 | 
| 684 | }
 | 
| 685 | 
 | 
| 686 | ysh-stdlib-2() {
 | 
| 687 |   run-file ysh-stdlib-2 "$@"
 | 
| 688 | }
 | 
| 689 | 
 | 
| 690 | ysh-stdlib-args() {
 | 
| 691 |   run-file ysh-stdlib-args "$@"
 | 
| 692 | }
 | 
| 693 | 
 | 
| 694 | ysh-stdlib-testing() {
 | 
| 695 |   run-file ysh-stdlib-testing "$@"
 | 
| 696 | }
 | 
| 697 | 
 | 
| 698 | ysh-stdlib-synch() {
 | 
| 699 |   run-file ysh-stdlib-synch "$@"
 | 
| 700 | }
 | 
| 701 | 
 | 
| 702 | ysh-source() {
 | 
| 703 |   run-file ysh-source "$@"
 | 
| 704 | }
 | 
| 705 | 
 | 
| 706 | ysh-usage() {
 | 
| 707 |   run-file ysh-usage "$@"
 | 
| 708 | }
 | 
| 709 | 
 | 
| 710 | ysh-unicode() {
 | 
| 711 |   run-file ysh-unicode "$@"
 | 
| 712 | }
 | 
| 713 | 
 | 
| 714 | ysh-bin() {
 | 
| 715 |   run-file ysh-bin "$@"
 | 
| 716 | }
 | 
| 717 | 
 | 
| 718 | ysh-dict() {
 | 
| 719 |   run-file ysh-dict "$@"
 | 
| 720 | }
 | 
| 721 | 
 | 
| 722 | ysh-list() {
 | 
| 723 |   run-file ysh-list "$@"
 | 
| 724 | }
 | 
| 725 | 
 | 
| 726 | ysh-place() {
 | 
| 727 |   run-file ysh-place "$@"
 | 
| 728 | }
 | 
| 729 | 
 | 
| 730 | ysh-prompt() {
 | 
| 731 |   run-file ysh-prompt "$@"
 | 
| 732 | }
 | 
| 733 | 
 | 
| 734 | ysh-assign() {
 | 
| 735 |   run-file ysh-assign "$@"
 | 
| 736 | }
 | 
| 737 | 
 | 
| 738 | ysh-augmented() {
 | 
| 739 |   run-file ysh-augmented "$@"
 | 
| 740 | }
 | 
| 741 | 
 | 
| 742 | ysh-blocks() {
 | 
| 743 |   run-file ysh-blocks "$@"
 | 
| 744 | }
 | 
| 745 | 
 | 
| 746 | ysh-bugs() {
 | 
| 747 |   run-file ysh-bugs "$@"
 | 
| 748 | }
 | 
| 749 | 
 | 
| 750 | ysh-builtins() {
 | 
| 751 |   run-file ysh-builtins "$@"
 | 
| 752 | }
 | 
| 753 | 
 | 
| 754 | ysh-builtin-module() {
 | 
| 755 |   run-file ysh-builtin-module "$@"
 | 
| 756 | }
 | 
| 757 | 
 | 
| 758 | ysh-builtin-eval() {
 | 
| 759 |   run-file ysh-builtin-eval "$@"
 | 
| 760 | }
 | 
| 761 | 
 | 
| 762 | # Related to errexit-oil
 | 
| 763 | ysh-builtin-error() {
 | 
| 764 |   run-file ysh-builtin-error "$@"
 | 
| 765 | }
 | 
| 766 | 
 | 
| 767 | ysh-builtin-meta() {
 | 
| 768 |   run-file ysh-builtin-meta "$@"
 | 
| 769 | }
 | 
| 770 | 
 | 
| 771 | ysh-builtin-process() {
 | 
| 772 |   run-file ysh-builtin-process "$@"
 | 
| 773 | }
 | 
| 774 | 
 | 
| 775 | ysh-builtin-shopt() {
 | 
| 776 |   run-file ysh-builtin-shopt "$@"
 | 
| 777 | }
 | 
| 778 | 
 | 
| 779 | ysh-case() {
 | 
| 780 |   run-file ysh-case "$@"
 | 
| 781 | }
 | 
| 782 | 
 | 
| 783 | ysh-command-sub() {
 | 
| 784 |   run-file ysh-command-sub "$@"
 | 
| 785 | }
 | 
| 786 | 
 | 
| 787 | ysh-demo() {
 | 
| 788 |   run-file ysh-demo "$@"
 | 
| 789 | }
 | 
| 790 | 
 | 
| 791 | ysh-expr() {
 | 
| 792 |   run-file ysh-expr "$@"
 | 
| 793 | }
 | 
| 794 | 
 | 
| 795 | ysh-int-float() {
 | 
| 796 |   run-file ysh-int-float "$@"
 | 
| 797 | }
 | 
| 798 | 
 | 
| 799 | ysh-expr-bool() {
 | 
| 800 |   run-file ysh-expr-bool "$@"
 | 
| 801 | }
 | 
| 802 | 
 | 
| 803 | ysh-expr-arith() {
 | 
| 804 |   run-file ysh-expr-arith "$@"
 | 
| 805 | }
 | 
| 806 | 
 | 
| 807 | ysh-expr-compare() {
 | 
| 808 |   run-file ysh-expr-compare "$@"
 | 
| 809 | }
 | 
| 810 | 
 | 
| 811 | ysh-expr-sub() {
 | 
| 812 |   run-file ysh-expr-sub "$@"
 | 
| 813 | }
 | 
| 814 | 
 | 
| 815 | ysh-cmd-lang() {
 | 
| 816 |   run-file ysh-cmd-lang "$@"
 | 
| 817 | }
 | 
| 818 | 
 | 
| 819 | ysh-for() {
 | 
| 820 |   run-file ysh-for "$@"
 | 
| 821 | }
 | 
| 822 | 
 | 
| 823 | ysh-methods() {
 | 
| 824 |   run-file ysh-methods "$@"
 | 
| 825 | }
 | 
| 826 | 
 | 
| 827 | ysh-func() {
 | 
| 828 |   run-file ysh-func "$@"
 | 
| 829 | }
 | 
| 830 | 
 | 
| 831 | ysh-func-builtin() {
 | 
| 832 |   run-file ysh-func-builtin "$@"
 | 
| 833 | }
 | 
| 834 | 
 | 
| 835 | ysh-funcs-external() {
 | 
| 836 |   run-file ysh-funcs-external "$@"
 | 
| 837 | }
 | 
| 838 | 
 | 
| 839 | ysh-interactive() {
 | 
| 840 |   run-file ysh-interactive "$@"
 | 
| 841 | }
 | 
| 842 | 
 | 
| 843 | ysh-json() {
 | 
| 844 |   run-file ysh-json "$@"
 | 
| 845 | }
 | 
| 846 | 
 | 
| 847 | ysh-keywords() {
 | 
| 848 |   run-file ysh-keywords "$@"
 | 
| 849 | }
 | 
| 850 | 
 | 
| 851 | ysh-multiline() {
 | 
| 852 |   run-file ysh-multiline "$@"
 | 
| 853 | }
 | 
| 854 | 
 | 
| 855 | ysh-options() {
 | 
| 856 |   run-file ysh-options "$@"
 | 
| 857 | }
 | 
| 858 | 
 | 
| 859 | ysh-options-assign() {
 | 
| 860 |   run-file ysh-options-assign "$@"
 | 
| 861 | }
 | 
| 862 | 
 | 
| 863 | ysh-proc() {
 | 
| 864 |   run-file ysh-proc "$@"
 | 
| 865 | }
 | 
| 866 | 
 | 
| 867 | ysh-regex() {
 | 
| 868 |   run-file ysh-regex "$@"
 | 
| 869 | }
 | 
| 870 | 
 | 
| 871 | ysh-regex-api() {
 | 
| 872 |   run-file ysh-regex-api "$@"
 | 
| 873 | }
 | 
| 874 | 
 | 
| 875 | ysh-reserved() {
 | 
| 876 |   run-file ysh-reserved "$@"
 | 
| 877 | }
 | 
| 878 | 
 | 
| 879 | ysh-scope() {
 | 
| 880 |   run-file ysh-scope "$@"
 | 
| 881 | }
 | 
| 882 | 
 | 
| 883 | ysh-slice-range() {
 | 
| 884 |   run-file ysh-slice-range "$@"
 | 
| 885 | }
 | 
| 886 | 
 | 
| 887 | ysh-string() {
 | 
| 888 |   run-file ysh-string "$@"
 | 
| 889 | }
 | 
| 890 | 
 | 
| 891 | ysh-special-vars() {
 | 
| 892 |   run-file ysh-special-vars "$@"
 | 
| 893 | }
 | 
| 894 | 
 | 
| 895 | ysh-tuple() {
 | 
| 896 |   run-file ysh-tuple "$@"
 | 
| 897 | }
 | 
| 898 | 
 | 
| 899 | ysh-var-sub() {
 | 
| 900 |   run-file ysh-var-sub "$@"
 | 
| 901 | }
 | 
| 902 | 
 | 
| 903 | ysh-with-sh() {
 | 
| 904 |   run-file ysh-with-sh "$@"
 | 
| 905 | }
 | 
| 906 | 
 | 
| 907 | ysh-word-eval() {
 | 
| 908 |   run-file ysh-word-eval "$@"
 | 
| 909 | }
 | 
| 910 | 
 | 
| 911 | ysh-xtrace() {
 | 
| 912 |   run-file ysh-xtrace "$@"
 | 
| 913 | }
 | 
| 914 | 
 | 
| 915 | ysh-user-feedback() {
 | 
| 916 |   run-file ysh-user-feedback "$@"
 | 
| 917 | }
 | 
| 918 | 
 | 
| 919 | ysh-builtin-ctx() {
 | 
| 920 |   run-file ysh-builtin-ctx "$@"
 | 
| 921 | }
 | 
| 922 | 
 | 
| 923 | ysh-builtin-error() {
 | 
| 924 |   run-file ysh-builtin-error "$@"
 | 
| 925 | }
 | 
| 926 | 
 | 
| 927 | ysh-builtin-help() {
 | 
| 928 |   run-file ysh-builtin-help "$@"
 | 
| 929 | }
 | 
| 930 | 
 | 
| 931 | ysh-dev() {
 | 
| 932 |   run-file ysh-dev "$@"
 | 
| 933 | }
 | 
| 934 | 
 | 
| 935 | ysh-printing() {
 | 
| 936 |   run-file ysh-printing "$@"
 | 
| 937 | }
 | 
| 938 | 
 | 
| 939 | 
 | 
| 940 | #
 | 
| 941 | # More OSH
 | 
| 942 | #
 | 
| 943 | 
 | 
| 944 | nix-idioms() {
 | 
| 945 |   run-file nix-idioms "$@"
 | 
| 946 | }
 | 
| 947 | 
 | 
| 948 | zsh-idioms() {
 | 
| 949 |   run-file zsh-idioms "$@"
 | 
| 950 | }
 | 
| 951 | 
 | 
| 952 | ble-idioms() {
 | 
| 953 |   sh-spec spec/ble-idioms.test.sh \
 | 
| 954 |     $BASH $ZSH $MKSH $BUSYBOX_ASH $OSH_LIST "$@"
 | 
| 955 | }
 | 
| 956 | 
 | 
| 957 | ble-features() {
 | 
| 958 |   run-file ble-features "$@"
 | 
| 959 | }
 | 
| 960 | 
 | 
| 961 | toysh() {
 | 
| 962 |   run-file toysh "$@"
 | 
| 963 | }
 | 
| 964 | 
 | 
| 965 | toysh-posix() {
 | 
| 966 |   run-file toysh-posix "$@"
 | 
| 967 | }
 | 
| 968 | 
 | 
| 969 | task-five "$@"
 |