Add very basic test framework for parser tests.
Start with a shell script that runs .cton files through 'cton-util cat' and compares the output to a reference. This can get fancy later.
This commit is contained in:
9
tests/parser/README.rst
Normal file
9
tests/parser/README.rst
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
Parser tests
|
||||||
|
============
|
||||||
|
|
||||||
|
This directory contains test cases for the Cretonne IL parser.
|
||||||
|
|
||||||
|
Each test case consists of a `foo.cton` input file and a `foo.ref` reference
|
||||||
|
output file. Each input file is run through the `cton-util cat` command, and the
|
||||||
|
output is compared against the reference file. If the two are identical, the
|
||||||
|
test passes.
|
||||||
40
tests/parser/run.sh
Executable file
40
tests/parser/run.sh
Executable file
@@ -0,0 +1,40 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Go to tests directory.
|
||||||
|
cd $(dirname "$0")/..
|
||||||
|
|
||||||
|
# The path to cton-util should be in $CTONUTIL.
|
||||||
|
if [ -z "$CTONUTIL" ]; then
|
||||||
|
CTONUTIL=../src/tools/target/debug/cton-util
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -x "$CTONUTIL" ]; then
|
||||||
|
echo "Can't fund executable cton-util: $CTONUTIL" 1>&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
declare -a fails
|
||||||
|
|
||||||
|
for testcase in $(find parser -name '*.cton'); do
|
||||||
|
ref="${testcase}.ref"
|
||||||
|
if [ ! -r "$ref" ]; then
|
||||||
|
fails=(${fails[@]} "$testcase")
|
||||||
|
echo MISSING: $ref
|
||||||
|
elif diff -u "$ref" <("$CTONUTIL" cat "$testcase"); then
|
||||||
|
echo OK $testcase
|
||||||
|
else
|
||||||
|
fails=(${fails[@]} "$testcase")
|
||||||
|
echo FAIL $testcase
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ ${#fails[@]} -ne 0 ]; then
|
||||||
|
echo
|
||||||
|
echo Failures:
|
||||||
|
for f in "${fails[@]}"; do
|
||||||
|
echo " $f"
|
||||||
|
done
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "All passed"
|
||||||
|
fi
|
||||||
5
tests/parser/tiny.cton
Normal file
5
tests/parser/tiny.cton
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
; The smallest possible function.
|
||||||
|
function minimal() {
|
||||||
|
ebb0:
|
||||||
|
trap
|
||||||
|
}
|
||||||
4
tests/parser/tiny.cton.ref
Normal file
4
tests/parser/tiny.cton.ref
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
function minimal() {
|
||||||
|
ebb0:
|
||||||
|
trap
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user