OILS / test / spec-py.sh View on Github | oilshell.org

175 lines, 72 significant
1#!/usr/bin/env bash
2#
3# Compare Python implementation with other shells.
4#
5# Contrast with test/spec-cpp.sh, which compares the Python and C++ version.
6#
7# Usage:
8# test/spec-py.sh <function name>
9
10set -o nounset
11set -o pipefail
12set -o errexit
13
14REPO_ROOT=$(cd "$(dirname $0)/.."; pwd)
15
16source test/spec-common.sh
17source devtools/run-task.sh
18
19run-file() {
20 local spec_name=$1
21 shift
22
23 sh-spec spec/$spec_name.test.sh \
24 --compare-shells \
25 --oils-bin-dir $PWD/bin "$@"
26}
27
28osh-all() {
29 test/spec.sh check-survey-shells
30
31 # $suite $compare_mode $spec_subdir
32 test/spec-runner.sh all-parallel osh compare-py osh-py "$@"
33
34 # By default, it runs sh_spec.py with --compare-shells
35 # Can also add:
36 # --ovm-bin-dir
37 # --oils-cpp-bin-dir
38 # to compare with more
39}
40
41ysh-all() {
42 # $suite $compare_mode $spec_subdir
43 test/spec-runner.sh all-parallel ysh compare-py ysh-py "$@"
44}
45
46ysh-ovm-tarball() {
47 ### Regression test run by CI
48
49 local version
50 version=$(head -n 1 oil-version.txt)
51
52 local tar_root=$REPO_ROOT/_tmp/oil-tar-test/oil-$version
53
54 pushd $tar_root
55 $REPO_ROOT/devtools/bin.sh make-ovm-links
56 popd
57
58 # Run the file that depends on stdlib/
59
60 #test/spec.sh ysh-stdlib --ovm-bin-dir $tar_root/_bin
61
62 set +o errexit
63 ysh-all-serial --ovm-bin-dir $tar_root/_bin
64 local status=$?
65 set +o errexit
66
67 echo
68 echo status=$status
69}
70
71ysh-stdlib-regress() {
72 test/spec.sh ysh-stdlib --ovm-bin-dir $REPO_ROOT/_bin "$@"
73}
74
75tea-all() {
76 # $suite $compare_mode $spec_subdir
77 test/spec-runner.sh all-parallel tea compare-py tea
78}
79
80osh-minimal() {
81 ### Some tests that work on the minimal build. Run by Soil.
82
83 # depends on link-busybox-ash, then source dev-shell.sh at the top of this
84 # file
85 test/spec.sh check-survey-shells
86
87 # suite compare_mode spec_subdir
88 test/spec-runner.sh all-parallel osh-minimal compare-py osh-minimal "$@"
89}
90
91
92osh-all-serial() { MAX_PROCS=1 $0 osh-all "$@"; }
93ysh-all-serial() { MAX_PROCS=1 $0 ysh-all "$@"; }
94tea-all-serial() { MAX_PROCS=1 $0 tea-all "$@"; }
95osh-minimal-serial() { MAX_PROCS=1 $0 osh-minimal "$@"; }
96
97interactive-osh() {
98 ### Run spec files tagged 'interactive' in soil/interactive, which uses a terminal
99 # This repeats what 'compare-py' does.
100
101 # Doesn't seem to trigger "Stopped" bug, but it hangs in the CI unless serial
102
103 # pass '1' to make it serial. default is N-1 CPUS in test/spec-common.sh
104 local max_procs=${1:-1}
105
106 # Note: without MAX_PROCS=1, I observed at least 2 instances of hanging (for
107 # 30 minutes)
108 #
109 # TODO:
110 # - better diagnostics from those hanging instances
111 # - note: worked OK (failed to hang) one time in soil/host-shim.sh local-test-uke
112 # - I suspect job control, we need to test it more throoughly, by simulating
113 # the kernel in Python unit tests
114
115 # $suite $compare_mode $spec_subdir
116 MAX_PROCS=$max_procs test/spec-runner.sh all-parallel \
117 interactive osh-only interactive-osh "$@"
118}
119
120debug-2023-06() {
121 # 2023-06-30:
122 # HANGING BUG after removing test/spec_param.py, and using run-file
123 # All of the sudden test/spec-py.sh interactive-osh hangs in Docker, and then
124 # this does too
125 # It reproduces LOCALLY as well
126 # But doesn't reproduce outside the container on my machine
127 #
128 # I get an ORPHANED bash -i command running at 100%, outside the container
129 # Remember that runs with docker -t
130
131 # NARROWED DOWN: the bug was that bash ALWAYS fails inside the container
132 #
133 # We don't run with bash and a terminal in the CI
134
135 test/spec.sh run-file-with-osh builtin-history
136}
137
138interactive-bash() {
139 # Triggers the "Stopped" bug with bash alone, unless max_procs=1
140
141 # pass '1' to make it serial. default is N-1 CPUS in test/spec-common.sh
142 local max_procs=${1:-}
143
144 # $suite $compare_mode $spec_subdir
145 MAX_PROCS=$max_procs test/spec-runner.sh all-parallel \
146 interactive bash-only interactive-bash "$@"
147}
148
149interactive-osh-bash() {
150 # Triggers the "Stopped" bug with osh and bash!
151
152 # Note: there's no longer a way to run with 2 shells? We could do
153 # test/sh_spec.py --shells-from-argv foo.test.sh osh bash
154 echo TODO
155}
156
157all-and-smoosh() {
158 ### Published with each release
159
160 # Args are flags to sh_spec.py
161 # --oils-bin-dir
162 # --ovm-bin-dir
163 local -a more_flags=( "$@" )
164
165 # Note: MAX_PROCS=1 prevents [#oil-dev > Random Spec Test Stoppages]
166 # Still need to fix that bug
167 MAX_PROCS=1 osh-all "${more_flags[@]}"
168 ysh-all "${more_flags[@]}"
169
170 # These aren't all green/yellow yet, and are slow.
171 test/spec.sh smoosh-html "${more_flags[@]}"
172 test/spec.sh smoosh-hang-html "${more_flags[@]}"
173}
174
175run-task "$@"