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