1 | #!/usr/bin/env bash
|
2 | #
|
3 | # Run ble.sh tests.
|
4 | #
|
5 | # Usage:
|
6 | # test/ble.sh <function name>
|
7 |
|
8 | set -o nounset
|
9 | set -o pipefail
|
10 | set -o errexit
|
11 |
|
12 | source build/dev-shell.sh # python2
|
13 | source test/common.sh
|
14 |
|
15 | readonly BASE_DIR=_clone/ble.sh
|
16 |
|
17 | clone() {
|
18 | local out=$BASE_DIR
|
19 | mkdir -p $out
|
20 | git clone --recursive --depth=50 --branch=osh \
|
21 | https://github.com/akinomyoga/ble.sh $out
|
22 | git clone --depth=50 \
|
23 | https://github.com/akinomyoga/contra.git $out/ext/contra.src
|
24 | }
|
25 |
|
26 | build() {
|
27 | # make ble.sh
|
28 | cd $BASE_DIR
|
29 | make
|
30 |
|
31 | # make contra for test
|
32 | cd ext/contra.src
|
33 | make
|
34 | cp src/contra ..
|
35 | }
|
36 |
|
37 | # https://superuser.com/questions/380772/removing-ansi-color-codes-from-text-stream
|
38 | filter-ansi() {
|
39 | sed 's/\x1b\[[0-9;]*m//g'
|
40 | }
|
41 |
|
42 | run-tests-osh-bash() {
|
43 | # Hm the tests detect ble.osh or ble.sh, this doesn't work
|
44 | run-tests-osh bash
|
45 | }
|
46 |
|
47 | run-tests-osh-py() {
|
48 | run-tests-osh ../../bin/osh
|
49 | }
|
50 |
|
51 | run-tests-osh-cpp() {
|
52 | # Find osh binary created by devtools/release-native.sh test-tar
|
53 | # test/wild-runner.sh uses it. We can't extract it over the repo.
|
54 | export-osh-cpp _tmp/native-tar-test opt
|
55 |
|
56 | run-tests-osh $OSH
|
57 | }
|
58 |
|
59 | run-tests-osh() {
|
60 | ### Source the 35K line file, but only run selected tests
|
61 |
|
62 | local osh=$1
|
63 |
|
64 | pushd $BASE_DIR
|
65 |
|
66 | # Fork of oshrc.test-util, to make it take less time
|
67 | local myscript=myscript
|
68 |
|
69 | cat >$myscript <<'EOF'
|
70 | #shopt -s eval_unsafe_arith
|
71 | HISTFILE=$HOME/.osh_history
|
72 |
|
73 | # Disabled for now, takes quite awhile
|
74 | # lib/test-canvas.sh \
|
75 |
|
76 | for script in \
|
77 | "out/ble.osh --lib" \
|
78 | lib/test-main.sh \
|
79 | lib/test-util.sh \
|
80 | lib/test-decode.sh
|
81 | do
|
82 | echo
|
83 | echo "Running $script"
|
84 | echo
|
85 |
|
86 | time . $script
|
87 |
|
88 | echo
|
89 | echo "DONE Running $script"
|
90 | echo
|
91 | done
|
92 |
|
93 | exit
|
94 | EOF
|
95 |
|
96 | #wc -l oshrc.test-util
|
97 | #wc -l out/ble.osh
|
98 | #wc -l lib/test-util.sh
|
99 |
|
100 | # Shorter tests
|
101 | $osh --rcfile $myscript -i | filter-ansi
|
102 |
|
103 | #../../bin/osh -i --rcfile oshrc.test-util | filter-ansi
|
104 |
|
105 | # Longer tests
|
106 | # TODO: Run these with osh-cpp
|
107 | # ../../bin/osh out/ble.osh --test | filter-ansi
|
108 |
|
109 | popd
|
110 |
|
111 | echo DONE
|
112 | }
|
113 |
|
114 | # Seems to take about 12 seconds
|
115 | bash-suite() {
|
116 | ### Run the 35K line file with --test
|
117 |
|
118 | cd $BASE_DIR
|
119 |
|
120 | set +o errexit
|
121 | bash out/ble.sh --test | filter-ansi
|
122 | echo 'Failure suppressed'
|
123 |
|
124 | # Some failures, possibly due to old version of bash
|
125 |
|
126 | # 98.1% [section] ble/util: 1205/1228 (23 fail, 0 crash, 6 skip)
|
127 | # 100.0% [section] ble/canvas/trace (relative:confine:measure-bbox): 17/17 (0 fail, 0 crash, 0 skip)
|
128 | # 100.0% [section] ble/canvas/trace (cfuncs): 18/18 (0 fail, 0 crash, 0 skip)
|
129 | # 100.0% [section] ble/canvas/trace (justify): 30/30 (0 fail, 0 crash, 0 skip)
|
130 | # 100.0% [section] ble/canvas/trace-text: 11/11 (0 fail, 0 crash, 0 skip)
|
131 | # 100.0% [section] ble/textmap#update: 5/5 (0 fail, 0 crash, 0 skip)
|
132 | # 100.0% [section] ble/unicode/GraphemeCluster/c2break: 77/77 (0 fail, 0 crash, 0 skip)
|
133 | # 100.0% [section] ble/unicode/GraphemeCluster/c2break (GraphemeBreakTest.txt): 3251/3251 (0 fail, 0 crash, 0 skip)
|
134 | # 100.0% [section] ble/decode: 33/33 (0 fail, 0 crash, 0 skip)
|
135 | # 100.0% [section] ble/edit: 2/2 (0 fail, 0 crash, 0 skip)
|
136 | # 100.0% [section] ble/syntax: 22/22 (0 fail, 0 crash, 0 skip)
|
137 | # 100.0% [section] ble/complete: 7/7 (0 fail, 0 crash, 0 skip)
|
138 | }
|
139 |
|
140 | find-lhs-array-one() {
|
141 | local path=$1
|
142 |
|
143 | #echo "finding $path"
|
144 | bin/osh --tool find-lhs-array $path
|
145 | }
|
146 |
|
147 | find-lhs-array() {
|
148 | local root=../ble.sh
|
149 | #find $root/src $root/lib -name '*.sh' | xargs wc -l
|
150 |
|
151 | find $root/src $root/lib -name '*.sh' | xargs -n 1 --verbose -- $0 find-lhs-array-one
|
152 | }
|
153 |
|
154 | "$@"
|