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

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