| 1 | #!/usr/bin/env bash
 | 
| 2 | #
 | 
| 3 | # Test opyc from the 'outside'.
 | 
| 4 | #
 | 
| 5 | # Usage:
 | 
| 6 | #   test/opyc.sh <function name>
 | 
| 7 | 
 | 
| 8 | set -o nounset
 | 
| 9 | set -o pipefail
 | 
| 10 | set -o errexit
 | 
| 11 | 
 | 
| 12 | source test/common.sh
 | 
| 13 | 
 | 
| 14 | readonly FILE=osh/word_compile_test.py  # choose a small one
 | 
| 15 | 
 | 
| 16 | # NOTE: We don't really use the 'lex' action.
 | 
| 17 | test-lex() {
 | 
| 18 |   bin/opyc lex $FILE
 | 
| 19 | }
 | 
| 20 | 
 | 
| 21 | test-ast() {
 | 
| 22 |   bin/opyc ast $FILE
 | 
| 23 | }
 | 
| 24 | 
 | 
| 25 | test-symbols() {
 | 
| 26 |   bin/opyc symbols $FILE
 | 
| 27 | }
 | 
| 28 | 
 | 
| 29 | test-cfg() {
 | 
| 30 |   bin/opyc cfg $FILE
 | 
| 31 | }
 | 
| 32 | 
 | 
| 33 | # This should be tested by opy/TEST.sh gold
 | 
| 34 | test-run() {
 | 
| 35 |   bin/opyc run opy/gold/fib_recursive.py
 | 
| 36 | } 
 | 
| 37 | 
 | 
| 38 | test-dis() {
 | 
| 39 |   bin/opyc dis $FILE
 | 
| 40 | }
 | 
| 41 | 
 | 
| 42 | test-parse() {
 | 
| 43 |   bin/opyc parse $FILE
 | 
| 44 | }
 | 
| 45 | 
 | 
| 46 | test-compile() {
 | 
| 47 |   bin/opyc compile $FILE _tmp/opyc-compile-1
 | 
| 48 |   bin/opyc compile --emit-docstring=0 $FILE _tmp/opyc-compile-2
 | 
| 49 |   ls -l _tmp/opyc-compile-*
 | 
| 50 | }
 | 
| 51 | 
 | 
| 52 | test-parse-with() {
 | 
| 53 |   local -a exprs
 | 
| 54 | 
 | 
| 55 |   readonly TESTDATA=pgen2/testdata
 | 
| 56 | 
 | 
| 57 |   exprs=(
 | 
| 58 |     # second alternative
 | 
| 59 |     'a'
 | 
| 60 |     'a = 3'
 | 
| 61 |     'unsigned int a'
 | 
| 62 |     'unsigned unsigned int a'
 | 
| 63 |     'unsigned unsigned b c'
 | 
| 64 |     # It correctly detects these as parse errors
 | 
| 65 |     #'unsigned unsigned b'
 | 
| 66 |     #'a = b'
 | 
| 67 |   )
 | 
| 68 | 
 | 
| 69 |   for e in "${exprs[@]}"; do
 | 
| 70 |     echo
 | 
| 71 |     echo "$e"
 | 
| 72 |     bin/opyc parse-with $TESTDATA/ll-star.grammar paper_input "$e"
 | 
| 73 |   done
 | 
| 74 | 
 | 
| 75 |   exprs=(
 | 
| 76 |     # second alternative
 | 
| 77 |     'unsigned foo(arg);'
 | 
| 78 |     'unsigned foo(arg) { body }'
 | 
| 79 |     # It correctly detects these as parse errors
 | 
| 80 |     #'unsigned foo(arg)'
 | 
| 81 |   )
 | 
| 82 |   for e in "${exprs[@]}"; do
 | 
| 83 |     echo
 | 
| 84 |     echo "$e"
 | 
| 85 |     bin/opyc parse-with $TESTDATA/ll-star.grammar method_input "$e"
 | 
| 86 |   done
 | 
| 87 | 
 | 
| 88 |   exprs=(
 | 
| 89 |     '1 + 2'
 | 
| 90 |     'a - 42'
 | 
| 91 |     'if a - 42'
 | 
| 92 |   )
 | 
| 93 |   for e in "${exprs[@]}"; do
 | 
| 94 |     echo
 | 
| 95 |     echo "$e"
 | 
| 96 |     bin/opyc parse-with $TESTDATA/minimal.grammar eval_input "$e"
 | 
| 97 |   done
 | 
| 98 | 
 | 
| 99 |   echo
 | 
| 100 |   echo 'DONE'
 | 
| 101 | }
 | 
| 102 | 
 | 
| 103 | FAIL-test-help() {
 | 
| 104 |   # Doesn't work yet.
 | 
| 105 |   bin/opyc --help
 | 
| 106 | }
 | 
| 107 | 
 | 
| 108 | run-for-release() {
 | 
| 109 |   run-other-suite-for-release opyc run-test-funcs
 | 
| 110 | }
 | 
| 111 | 
 | 
| 112 | soil-run() {
 | 
| 113 |   make _build/opy/py27.grammar.marshal
 | 
| 114 | 
 | 
| 115 |   run-test-funcs
 | 
| 116 | }
 | 
| 117 | 
 | 
| 118 | "$@"
 |