OILS / asdl / TEST.sh View on Github | oils.pub

134 lines, 76 significant
1#!/usr/bin/env bash
2#
3# Tests for ASDL.
4#
5# Usage:
6# asdl/TEST.sh <function name>
7
8set -o nounset
9set -o pipefail
10set -o errexit
11
12REPO_ROOT=$(cd "$(dirname $0)/.."; pwd)
13
14source devtools/common.sh # banner
15source test/common.sh # run-one-test
16
17cpp-unit() {
18 ### Run unit tests
19
20 for variant in asan asan+gcalways ubsan; do
21 run-one-test 'asdl/gen_cpp_test' '' $variant
22 run-one-test 'asdl/gc_test' '' $variant
23 done
24}
25
26py-unit() {
27 find asdl -name '*_test.py' | while read test_path; do
28 test/unit.sh run-unit-test ':vendor/' $test_path
29 done
30}
31
32#
33# Python codegen
34#
35
36readonly PY_PATH='.:vendor/' # note: could consolidate with other scripts
37
38asdl-check() {
39 # Unlike Python code, we use --strict mode
40 python3 -m mypy --py2 --strict --follow-imports=silent "$@"
41}
42
43# NOTE: We're testing ASDL code generation with --strict because we might want
44# Oils to pass under --strict someday.
45typed-demo-asdl() {
46 # We want to exclude ONLY pylib.collections_, but somehow --exclude
47 # '.*collections_\.py' does not do it. So --follow-imports=silent. Tried
48 # --verbose too
49 asdl-check \
50 _devbuild/gen/typed_demo_asdl.py asdl/examples/typed_demo.py
51
52 PYTHONPATH=$PY_PATH asdl/examples/typed_demo.py "$@"
53}
54
55check-arith() {
56 # NOTE: There are still some Any types here! We don't want them for
57 # translation.
58
59 asdl-check \
60 asdl/examples/typed_arith_parse.py \
61 asdl/examples/typed_arith_parse_test.py \
62 asdl/examples/tdop.py
63}
64
65typed-arith-asdl() {
66 check-arith
67
68 PYTHONPATH=$PY_PATH asdl/examples/typed_arith_parse_test.py
69
70 banner 'parse'
71 PYTHONPATH=$PY_PATH asdl/examples/typed_arith_parse.py parse '40+2'
72 echo
73
74 banner 'eval'
75 PYTHONPATH=$PY_PATH asdl/examples/typed_arith_parse.py eval '40+2+5'
76 echo
77}
78
79check-py-output() {
80 build/py.sh py-asdl-examples
81
82 asdl-check _devbuild/gen/shared_variant_asdl.py
83
84 banner 'typed-arith-asdl'
85 typed-arith-asdl
86
87 banner 'typed-demo-asdl'
88 typed-demo-asdl
89
90 asdl-check asdl/target_lang_test.py
91}
92
93pretty-demo() {
94 local cpp=${1:-}
95
96 OSH=bin/osh
97 YSH=bin/ysh
98
99 if test -n "$cpp"; then
100 ninja _bin/cxx-asan/{osh,ysh}
101 export OSH=_bin/cxx-asan/osh
102 export YSH=_bin/cxx-asan/ysh
103 fi
104
105 # osh -n
106 test/parse-errors.sh test-syntax-abbrev
107 echo
108
109 #return
110
111 # Show Dict[BigInt, str]
112 for i in 12 50 80; do
113 $OSH -c 'declare -a a=(a b); a[$1]=zzz; pp asdl_ (a)' dummy $i
114 echo
115 done
116
117 # Tabular
118 for i in 12 50 100; do
119 $YSH -c 'var i = $1; var x = []; for i in (1 ..= i) { call x->append(i) }; pp (x)' \
120 dummy $i
121 echo
122 done
123
124
125 # Show Dict[str, value_t]
126 $YSH -c 'var d = {x:42}; setvar d.k = d; pp asdl_ (d)'
127 echo
128
129 # hnode::External
130 $YSH -c 'pp asdl_ (len)'
131 echo
132}
133
134"$@"