1 | #!/usr/bin/env bash
|
2 | #
|
3 | # Usage:
|
4 | # ysh/run.sh <function name>
|
5 |
|
6 | set -o nounset
|
7 | set -o pipefail
|
8 | set -o errexit
|
9 |
|
10 | source test/common.sh
|
11 |
|
12 | YSH=${YSH:-'bin/ysh'}
|
13 | OSH_CPP=_bin/cxx-asan/osh
|
14 | # Assertion failed
|
15 | #OSH_CPP=_bin/cxx-dbg/osh
|
16 |
|
17 | # This doesn't distinguish if they should parse with osh or ysh though!
|
18 |
|
19 | parse-one() {
|
20 | echo ---
|
21 | # TODO: these tests can be removed once the rest of ysh/ is translated
|
22 | if test "$OSH" = "$OSH_CPP"; then
|
23 | local prog="$1"
|
24 | local skip=''
|
25 | case $prog in
|
26 | (*/assign.osh) skip=T ;;
|
27 | esac
|
28 |
|
29 | if test -n "$skip"; then
|
30 | echo "skipping $prog"
|
31 | return
|
32 | fi
|
33 | fi
|
34 |
|
35 | set +o errexit
|
36 | $OSH -n "$@"
|
37 | if test $? -ne 0; then return 255; fi # make xargs quit
|
38 | }
|
39 |
|
40 | test-parse-osh() {
|
41 | find ysh/testdata -name '*.sh' -o -name '*.osh' \
|
42 | | xargs -n 1 -- $0 parse-one
|
43 | }
|
44 |
|
45 | test-run-osh() {
|
46 | ### Run programs with OSH
|
47 |
|
48 | for prog in ysh/testdata/*.{sh,osh}; do
|
49 | echo $prog
|
50 |
|
51 | local skip=''
|
52 | case $prog in
|
53 | */assign.osh) skip=T ;;
|
54 | */no-dynamic-scope.osh) skip=T ;;
|
55 | */inline-function-calls.sh) skip=T ;;
|
56 | esac
|
57 |
|
58 | if test -n "$skip"; then
|
59 | echo "skipping $prog"
|
60 | continue
|
61 | fi
|
62 |
|
63 | echo ---
|
64 | $OSH $prog
|
65 | done
|
66 | }
|
67 |
|
68 | test-run-ysh() {
|
69 | ### Run programs with YSH
|
70 |
|
71 | for prog in ysh/testdata/*.ysh; do
|
72 | echo ---
|
73 | $YSH $prog all
|
74 | done
|
75 | }
|
76 |
|
77 | demo() {
|
78 | ### Run some of them selectively
|
79 |
|
80 | bin/osh ysh/testdata/array-rewrite-1.sh
|
81 |
|
82 | bin/osh ysh/testdata/array-rewrite-2.sh
|
83 | bin/osh ysh/testdata/array-splice-demo.osh
|
84 |
|
85 | bin/osh ysh/testdata/hello.osh
|
86 |
|
87 | bin/osh ysh/testdata/inline-function-calls.ysh all
|
88 |
|
89 | bin/osh ysh/testdata/sigil-pairs.sh
|
90 |
|
91 | set +o errexit
|
92 | # Fails correctly
|
93 | bin/osh ysh/testdata/no-dynamic-scope.osh
|
94 |
|
95 | bin/osh ysh/testdata/assign.osh
|
96 | }
|
97 |
|
98 | soil-run() {
|
99 | ### Used by soil/worker.sh. Prints to stdout.
|
100 | run-test-funcs
|
101 | }
|
102 |
|
103 | soil-run-cpp() {
|
104 | local osh=$OSH_CPP
|
105 |
|
106 | ninja $osh
|
107 |
|
108 | # TODO: replace with run-test-funcs once the rest of ysh is translated
|
109 | OILS_GC_ON_EXIT=1 OSH=$osh test-parse-osh
|
110 | }
|
111 |
|
112 | run-for-release() {
|
113 | ### Used by devtools/release.sh. Writes a file.
|
114 | run-other-suite-for-release ysh-large run-test-funcs
|
115 | }
|
116 |
|
117 | "$@"
|