OILS / test / spec-common.sh View on Github | oils.pub

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