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 |
|
86 | "$@"
|