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