Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make failing tests possible, improve test output. #123

Merged
merged 1 commit into from
Apr 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions src/tests/encore/basic/Makefile
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
ROOT_PATH=../../../..
ENCOREC=$(ROOT_PATH)/release/encorec

OUTFILES=$(shell ls *.out)

ENCORE_SOURCES=$(shell ls *.enc)
ENCORE_TARGETS=$(ENCORE_SOURCES:.enc=)

test: embed_tl.o
@$(foreach PROG,$(ENCORE_TARGETS), make -Bqk $(PROG) || make -Bk $(PROG) || true;)
@echo
@echo Basic tests:
@./test.sh $(ENCORE_TARGETS)

embed_tl.o: embed_tl.c embed_tl.h
clang -c embed_tl.c

%: %.enc
#ls -l
@rm -f $@
@echo "compiling '$@'"
@$(ENCOREC) $@.enc -clang -c

clean:
rm -rf *.dSYM *_src $(ENCORE_TARGETS)
rm -f embed_tl.o
Expand Down
36 changes: 35 additions & 1 deletion src/tests/encore/basic/test.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,43 @@
#!/bin/bash

function run_test {
# the function looks for either a file called "testname.out" or a
# script called "testname.chk".
#
# In the case of an .out file, the output of the executable has to
# match exactly; in the case of a .chk file, the output of
# compiling and (if successful) running the executable will be
# piped into that script. The test is successful iff the script
# returns normally (exit 0).

program=$1
source=$1.enc
# compile and, if successful, run the program:
output=$(encorec $source && ./$program)
checking_script=./$program.chk
expected=$program.out
./$program | cmp $expected
if [ -x "$checking_script" ] ; then
if [ -e $expected ] ; then
echo "ERROR: both $checking_script and $expected exist, don't know which to use"
false
else
echo "$output" | ./$checking_script ||
(echo "ERROR: test $program's checking script failed.";
false)
fi
else
if [ -e "$expected" ]; then
./$program | cmp $expected ||
(echo "ERROR: test $program failed with output:";
echo "vvvvvvvvvvvvvvvvvvvv"
echo "$output"
echo "^^^^^^^^^^^^^^^^^^^^";
false)
else
echo "ERROR: incomplete test <$1>: neither checking script $checking_script, nor output file $expected is available"
exit 1
fi
fi
}

passed=0
Expand Down
19 changes: 19 additions & 0 deletions src/tests/encore/basic/testutils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
STDIN=$(cat)

function FAIL {
MSG=$1
echo "ERROR: $1"
exit 1
}

# Requires that an error was reported in a specific line
function error_at {
LINE=$1
(echo "$STDIN" | grep -A1 "(line $LINE, column" > /dev/null) || FAIL "expected error on line $LINE"
}

# Requires that an error was reported with a specific message
function error_msg {
MSG=$1
(echo "$STDIN" | grep "$MSG" > /dev/null) || FAIL "expected error with message '$MSG'"
}