Skip to content

Commit

Permalink
More cleanup of test structure.
Browse files Browse the repository at this point in the history
- Move test/smoke.sh to test/osh-usage.sh
- Use a common function in test/common.sh to run and publish all test
  results.

Still need to fix things up in scripts/release.sh.
  • Loading branch information
Andy Chu committed Aug 20, 2018
1 parent 10077ba commit fd1ffce
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 24 deletions.
4 changes: 4 additions & 0 deletions scripts/release.sh
Expand Up @@ -86,6 +86,8 @@ auto-machine1() {
# osh2oil.txt
# gold.txt
# parse-errors.txt
# runtime-errors.txt
# oshc-deps.txt
# tarball/ # log of building and running the tarball?
# asan/ # spec tests or other?
# # or it can be put under test/{spec,wild}
Expand Down Expand Up @@ -169,6 +171,8 @@ _test-release-build() {
test/osh2oil.sh run-for-release
test/gold.sh run-for-release
test/parse-errors.sh run-for-release
test/runtime-errors.sh run-for-release
test/oshc-deps.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
25 changes: 21 additions & 4 deletions test/common.sh
Expand Up @@ -3,10 +3,6 @@
# Usage:
# ./common.sh <function name>

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

# TODO: Remove/rename this. The release process might use the release binary
# instead of this dev binary. test/spec.sh already has its own scheme.
# This is analogous to $OSH_OVM in benchmarks/common.sh.
Expand Down Expand Up @@ -74,6 +70,27 @@ run-all() {
echo "All $0 tests passed."
}

# A quick and dirty function to show logs
run-other-suite-for-release() {
local suite_name=$1
local func_name=$2

local out=_tmp/other/${suite_name}.txt
mkdir -p $(dirname $out)

echo
echo "*** Running test suite '$suite_name' ***"
echo

if $func_name 2>&1 | tee $out; then
echo
log "Test suite '$suite_name' ran without errors. Wrote $out"
else
echo
die "Test suite '$suite_name' failed (running $func_name)"
fi
}

if test "$(basename $0)" = 'common.sh'; then
"$@"
fi
7 changes: 1 addition & 6 deletions test/gold.sh
Expand Up @@ -159,12 +159,7 @@ all-passing() {
}

run-for-release() {
local out_dir=_tmp/gold
mkdir -p $out_dir

all-passing | tee $out_dir/log.txt

echo "Wrote $out_dir/log.txt"
run-other-suite-for-release gold all-passing
}

"$@"
21 changes: 15 additions & 6 deletions test/smoke.sh → test/osh-usage.sh
@@ -1,26 +1,31 @@
#!/usr/bin/env bash
#
# Sanity checks for the shell.
# Test osh usage "from the outside".
#
# Usage:
# ./smoke.sh <function name>
# ./osh-usage.sh <function name>

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

source test/common.sh

# Doesn't work in release automation!
manual-oheap-test() {
# Not dumping to terminal
if bin/osh -n --ast-format oheap -c 'echo hi'; then
die "Should have failed"
fi
echo OK
}

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'
bin/osh -n --ast-format html -c 'echo hi'

# Not dumping to terminal
if bin/osh -n --ast-format oheap -c 'echo hi'; then
die "Should have failed"
fi
local ast_bin=_tmp/smoke-ast.bin
bin/osh -n --ast-format oheap -c 'echo hi' > $ast_bin
ls -l $ast_bin
Expand Down Expand Up @@ -138,4 +143,8 @@ all-passing() {
run-all "${PASSING[@]}"
}

run-for-release() {
run-other-suite-for-release osh-usage all-passing
}

"$@"
6 changes: 5 additions & 1 deletion test/oshc-deps.sh
Expand Up @@ -89,11 +89,15 @@ DEPS

readonly -a PASSING=(
usage
deps
#deps
)

all-passing() {
run-all "${PASSING[@]}"
}

run-for-release() {
run-other-suite-for-release oshc-deps all-passing
}

"$@"
10 changes: 3 additions & 7 deletions test/parse-errors.sh
Expand Up @@ -7,6 +7,8 @@ set -o nounset
set -o pipefail
set -o errexit

source test/common.sh

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

Expand Down Expand Up @@ -55,14 +57,8 @@ all() {
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"
run-other-suite-for-release parse-errors all
}

"$@"
10 changes: 10 additions & 0 deletions test/runtime-errors.sh
Expand Up @@ -5,6 +5,8 @@
#
# Run with bash/dash/mksh/zsh.

source test/common.sh

#
# PARSE ERRORS
#
Expand Down Expand Up @@ -302,4 +304,12 @@ all() {
done
}

run-all-with-osh() {
bin/osh $0 all
}

run-for-release() {
run-other-suite-for-release runtime-errors run-all-with-osh
}

"$@"

0 comments on commit fd1ffce

Please sign in to comment.