OILS / yaks / TEST.sh View on Github | oilshell.org

122 lines, 52 significant
1#!/usr/bin/env bash
2#
3# Usage:
4# yaks/TEST.sh <function name>
5
6set -o nounset
7set -o pipefail
8set -o errexit
9
10REPO_ROOT=$(cd "$(dirname $0)/.."; pwd)
11
12source build/dev-shell.sh # python3 in PATH
13source devtools/run-task.sh
14source test/common.sh # run-test-funcs
15
16unit() {
17 run-one-test 'yaks/yaks_runtime_test' '' asan
18 run-one-test 'frontend/arg_types_test' '' ubsan
19}
20
21build() {
22 build/py.sh gen-asdl-py 'yaks/yaks.asdl'
23}
24
25check() {
26 build
27
28 # pyext/fastfunc is a dependency of ASDL
29 # Source is Python 2
30
31 # These flags are in devtools/types.sh
32 #local mypy_flags='--strict --no-strict-optional'
33
34 # 514 errors! Not sure why we need the extra flag.
35 #local mypy_flags='--strict'
36 local mypy_flags='--strict --follow-imports=silent'
37
38 MYPYPATH='.:pyext' python3 -m \
39 mypy $mypy_flags --py2 yaks/yaks_main.py
40}
41
42yaks() {
43 PYTHONPATH='.:vendor' yaks/yaks_main.py "$@"
44}
45
46BAD=(
47 # should be a module
48 '(print "hi")'
49 '+'
50
51 # Unexpected EOF
52 '(print'
53
54 # Unexpected trailing input
55 '(print)oops'
56
57 # This one works
58 #'(module foo)'
59)
60
61
62# the transformer raises AssertionError
63
64test-syntax-errors() {
65 for b in "${BAD[@]}"; do
66 local src=_tmp/bad.yaks
67
68 echo "$b" >$src
69
70 echo "$b"
71 yaks cpp $src || true
72 echo
73
74 done
75}
76
77test-hello() {
78 yaks cpp yaks/examples/hello.yaks
79
80 # TODO: fibonacci program, etc. building up to yaks in yaks itself.
81
82 # type check only
83 # yaks/yaks.py check testdata/hello.yaks
84}
85
86test-hello-cpp() {
87 # Translate and compile the yaks translator
88 #local bin=_bin/cxx-asan/yaks/yaks_main.mycpp
89 #ninja $bin
90
91 # Generate C++ from an example
92 #$bin cpp yaks/examples/hello.yaks
93
94 # Translate and compile the yaks translator
95 # Then use it to generate C++ from an example
96 # Then wrap and compile that
97 local hello=_bin/cxx-asan/yaks/examples/hello.yaks
98 ninja $hello
99
100 set -o xtrace
101 set +o errexit
102 $hello
103 local status=$?
104 set -o errexit
105
106 echo status=$status
107}
108
109soil-run() {
110 ### Used by soil/worker.sh. Prints to stdout.
111
112 # Hm I guess we need the Python 2 wedge here. Right now deps/Dockerfile.pea
113 # has a Python 3 wedge and MyPy, which we still need.
114 #echo 'Disabled until container image has python2-dev to build pyext/fastfunc'
115 #return
116
117 run-test-funcs
118
119 check
120}
121
122run-task "$@"