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

123 lines, 52 significant
1#!/usr/bin/env bash
2#
3# Usage:
4# yaks/TEST.sh <function name>
5
6: ${LIB_OSH=stdlib/osh}
7source $LIB_OSH/bash-strict.sh
8source $LIB_OSH/task-five.sh
9source $LIB_OSH/no-quotes.sh
10
11REPO_ROOT=$(cd "$(dirname $0)/.."; pwd)
12
13source build/dev-shell.sh # python3 in PATH
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 local status
101
102 set -o xtrace
103 nq-run status \
104 $hello
105 set -o errexit
106
107 nq-assert 42 = "$status"
108}
109
110soil-run() {
111 ### Used by soil/worker.sh. Prints to stdout.
112
113 # Hm I guess we need the Python 2 wedge here. Right now deps/Dockerfile.pea
114 # has a Python 3 wedge and MyPy, which we still need.
115 #echo 'Disabled until container image has python2-dev to build pyext/fastfunc'
116 #return
117
118 devtools/byo.sh test $0
119
120 check
121}
122
123task-five "$@"