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

88 lines, 47 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 build/dev-shell.sh # python3 in $PATH
15source devtools/common.sh # banner
16source test/common.sh # run-one-test
17
18unit() {
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
31readonly PY_PATH='.:vendor/' # note: could consolidate with other scripts
32
33asdl-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.
40typed-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
50check-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
60typed-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
74check-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"$@"