| 1 | #!/usr/bin/env bash
|
| 2 | #
|
| 3 | # Library shared between test/{spec,spec-alpine,spec-bin}.sh.
|
| 4 |
|
| 5 | readonly BASH_NAME='bash-4.4' # TODO: 5.1 upgrade
|
| 6 | readonly BUSYBOX_NAME='busybox-1.35.0'
|
| 7 | readonly DASH_NAME='dash-0.5.10.2'
|
| 8 | readonly YASH_NAME='yash-2.49'
|
| 9 |
|
| 10 | # for test/spec-{runner,cpp,any}.sh
|
| 11 | NUM_SPEC_TASKS=${NUM_SPEC_TASKS:-400}
|
| 12 |
|
| 13 | spec-html-head() {
|
| 14 | local prefix=$1
|
| 15 | local title=$2
|
| 16 |
|
| 17 | html-head --title "$title" \
|
| 18 | $prefix/web/ajax.js \
|
| 19 | $prefix/web/table/table-sort.js $prefix/web/table/table-sort.css \
|
| 20 | $prefix/web/base.css \
|
| 21 | $prefix/web/spec-cpp.css
|
| 22 | }
|
| 23 |
|
| 24 | sh-spec() {
|
| 25 | local test_file=$1
|
| 26 | shift
|
| 27 |
|
| 28 | if [[ $test_file != *.test.sh ]]; then
|
| 29 | die "Test file should end with .test.sh"
|
| 30 | fi
|
| 31 |
|
| 32 | local repo_root
|
| 33 | repo_root=$(cd "$(dirname $0)/.."; pwd)
|
| 34 |
|
| 35 | # Create under PID dir
|
| 36 | local tmp_env
|
| 37 | tmp_env=$repo_root/_tmp/spec-tmp/$(basename $test_file)
|
| 38 |
|
| 39 | # In general we leave the tmp dir around so you can inspect it. It's always
|
| 40 | # safe to get rid of the cruft like this:
|
| 41 | #
|
| 42 | # rm -r -f _tmp/spec-tmp
|
| 43 |
|
| 44 | # - Prepend spec/bin on the front of the $PATH. We can't isolate $PATH
|
| 45 | # because we might be running in Nix, etc.
|
| 46 | # - Force LC_ALL=C.UTF-8 for unicode testing
|
| 47 | # - TODO: should test with LC_ALL=C as well
|
| 48 | # - or do we put that in spec tests?
|
| 49 | # - en_US.UTF-8 seems hard to support on Debian, even though it's the default on Debian.
|
| 50 | # - Description: https://stackoverflow.com/questions/55673886/what-is-the-difference-between-c-utf-8-and-en-us-utf-8-locales/55693338
|
| 51 | # - LOCALE_ARCHIVE is allowed to leak for Nix.
|
| 52 | # - OILS_GC_ON_EXIT is to pass ASAN.
|
| 53 | # - REPO_ROOT is to find things in spec/testdata
|
| 54 |
|
| 55 | PYTHONPATH=. test/sh_spec.py \
|
| 56 | --tmp-env "$tmp_env" \
|
| 57 | --path-env "$repo_root/spec/bin:$PATH" \
|
| 58 | --env-pair 'LC_ALL=C.UTF-8' \
|
| 59 | --env-pair "LOCALE_ARCHIVE=${LOCALE_ARCHIVE:-}" \
|
| 60 | --env-pair "OILS_GC_ON_EXIT=${OILS_GC_ON_EXIT:-}" \
|
| 61 | --env-pair "REPO_ROOT=$repo_root" \
|
| 62 | "$test_file" \
|
| 63 | "$@"
|
| 64 |
|
| 65 | # Don't need this now that we have OILS_GC_ON_EXIT
|
| 66 | # --env-pair "ASAN_OPTIONS=${ASAN_OPTIONS:-}" \
|
| 67 | }
|
| 68 |
|
| 69 | # Usage: callers can override OSH_LIST to test on more than one version.
|
| 70 | #
|
| 71 | # Example:
|
| 72 | # OSH_LIST='bin/osh _bin/osh' test/spec-py.sh osh-all
|
| 73 |
|
| 74 | readonly OSH_CPYTHON="$REPO_ROOT/bin/osh"
|
| 75 | readonly OSH_OVM=${OSH_OVM:-$REPO_ROOT/_bin/osh}
|
| 76 |
|
| 77 | OSH_LIST=${OSH_LIST:-} # A space-separated list.
|
| 78 |
|
| 79 | if test -z "$OSH_LIST"; then
|
| 80 | # By default, run with both, unless $OSH_OVM isn't available.
|
| 81 | if test -e $OSH_OVM; then
|
| 82 | # TODO: Does it make sense to copy the binary to an unrelated to directory,
|
| 83 | # like /tmp? /tmp/{oil.ovm,osh}.
|
| 84 | OSH_LIST="$OSH_CPYTHON $OSH_OVM"
|
| 85 | else
|
| 86 | OSH_LIST="$OSH_CPYTHON"
|
| 87 | fi
|
| 88 | fi
|
| 89 |
|
| 90 | readonly YSH_CPYTHON="$REPO_ROOT/bin/ysh"
|
| 91 | readonly YSH_OVM=${YSH_OVM:-$REPO_ROOT/_bin/ysh}
|
| 92 |
|
| 93 | YSH_LIST=${YSH_LIST:-} # A space-separated list.
|
| 94 |
|
| 95 | if test -z "$YSH_LIST"; then
|
| 96 | # By default, run with both, unless $YSH_OVM isn't available.
|
| 97 | if test -e $YSH_OVM; then
|
| 98 | YSH_LIST="$YSH_CPYTHON $YSH_OVM"
|
| 99 | else
|
| 100 | YSH_LIST="$YSH_CPYTHON"
|
| 101 | fi
|
| 102 | fi
|
| 103 |
|