Skip to content

Commit

Permalink
Test cleanup, including consolidating parse error tests.
Browse files Browse the repository at this point in the history
- Polish of test/smoke.sh
  - Revealed a bug in oheap; now fixed
- Extract test/parse-errors.sh from test/smoke.sh
  - Move data files to test/parse-errors/
- Plan new release directory structure to publish more tests
  • Loading branch information
Andy Chu committed Aug 20, 2018
1 parent 3154117 commit 10077ba
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 31 deletions.
5 changes: 3 additions & 2 deletions asdl/encode.py
Expand Up @@ -174,8 +174,9 @@ def EncodeArray(obj_list, item_desc, enc, out):
else:
# A simple value is either an int, enum, or pointer. (Later: Iter<Str>
# might be possible for locality.)
assert isinstance(item_desc, asdl.Sum) or \
isinstance(item_desc, asdl.Product), item_desc
assert \
isinstance(item_desc, asdl.SumType) or \
isinstance(item_desc, asdl.CompoundType), item_desc

# This is like vector<T*>
# Later:
Expand Down
13 changes: 9 additions & 4 deletions scripts/release.sh
Expand Up @@ -81,9 +81,11 @@ auto-machine1() {
# spec.wwz/
# machine-lisa/
# wild.wwz/
# unit/
# osh2oil/
# gold/
# unit.wwz/
# other.wwz/
# osh2oil.txt
# gold.txt
# parse-errors.txt
# tarball/ # log of building and running the tarball?
# asan/ # spec tests or other?
# # or it can be put under test/{spec,wild}
Expand All @@ -110,7 +112,7 @@ auto-machine1() {

_clean-tmp-dirs() {
rm -r -f \
_tmp/{spec,unit,gold,osh2oil,wild/www} \
_tmp/{spec,unit,gold,parse-errors,osh2oil,wild/www} \
_tmp/metrics \
_tmp/opy-test \
_tmp/{osh-parser,osh-runtime,vm-baseline,ovm-build,oheap} \
Expand Down Expand Up @@ -166,6 +168,7 @@ _test-release-build() {

test/osh2oil.sh run-for-release
test/gold.sh run-for-release
test/parse-errors.sh run-for-release

# Just test the release build (not under CPython or byterun. That comes later.)
OSH_LIST="$OSH_RELEASE_BINARY" test/spec.sh all
Expand Down Expand Up @@ -547,6 +550,8 @@ compress-txt() {
compress() {
local root=$PWD/_release/VERSION/

# TODO: Change this to test/other.wwz/{gold,osh2oil,...}.txt

# There is a single log.txt file in _tmp/{osh2oil,gold}
compress-txt osh2oil
compress-txt gold
Expand Down
68 changes: 68 additions & 0 deletions test/parse-errors.sh
@@ -0,0 +1,68 @@
#!/bin/bash
#
# Usage:
# ./parse-errors.sh <function name>

set -o nounset
set -o pipefail
set -o errexit

# Run with SH=bash too
SH=${SH:-bin/osh}

banner() {
echo
echo ===== CASE: "$@" =====
echo
}

_error-case() {
banner "$@"
echo
$SH -c "$@"
}

cases-in-strings() {
set +o errexit

_error-case 'echo < <<'
_error-case '${foo:}'
_error-case '$(( 1 + ))'
_error-case 'echo $( echo > >> )'
_error-case 'echo ${'
}

# Cases in their own file
cases-in-files() {
set +o errexit # Don't fail

for t in test/parse-errors/*.sh; do
banner $t
$SH $t
done
}

all() {
cases-in-strings

echo
echo ----------------------
echo

cases-in-files

# Always passes
return 0
}

# TODO:
run-for-release() {
local out=_tmp/parse-errors/log.txt
mkdir -p $(dirname $out)

echo '1'
all >$out 2>&1
echo "Wrote $out"
}

"$@"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
33 changes: 8 additions & 25 deletions test/smoke.sh
Expand Up @@ -11,7 +11,7 @@ set -o errexit

source test/common.sh

ast() {
ast-formats() {
bin/osh -n -c 'echo hi'
bin/osh -n --ast-format text -c 'echo hi'
bin/osh -n --ast-format abbrev-html -c 'echo hi'
Expand All @@ -27,14 +27,11 @@ ast() {
hexdump -C $ast_bin
}


# Read from a file.
osh-file() {
echo ===== Hello
cat >_tmp/hi.sh <<EOF
cat >_tmp/smoke-prog.sh <<EOF
echo hi
echo bye
func() {
echo "inside func"
Expand All @@ -47,7 +44,7 @@ func 1 2 3
echo \$(echo ComSub)
EOF
$OSH _tmp/hi.sh
$OSH _tmp/smoke-prog.sh

echo ===== EMPTY
touch _tmp/empty.sh
Expand All @@ -60,7 +57,7 @@ EOF

# Read from stdin.
osh-stdin() {
$OSH < _tmp/hi.sh
$OSH < _tmp/smoke-prog.sh

echo ===== EMPTY
$OSH < _tmp/empty.sh
Expand Down Expand Up @@ -89,13 +86,15 @@ func() {
}
EOF
# TODO: test while loop
}

osh-interactive() {
echo 'echo hi' | $OSH -i

echo 'exit' | $OSH -i

# Parse failure
echo ';' | $OSH -i
}

help() {
Expand All @@ -120,30 +119,14 @@ help() {
assert $? -eq 0
}

_error-case() {
echo
echo "$@"
echo
bin/osh -c "$@"
}

parse-errors() {
set +o errexit
_error-case 'echo < <<'
_error-case '${foo:}'
_error-case '$(( 1 + ))'
_error-case 'echo $( echo > >> )'
#_error-case 'echo ${'
}

exit-builtin-interactive() {
set +o errexit
echo 'echo one; exit 42; echo two' | bin/osh -i
assert $? -eq 42
}

readonly -a PASSING=(
ast
ast-formats
osh-file
osh-stdin
osh-interactive
Expand Down

0 comments on commit 10077ba

Please sign in to comment.