From 954fd015e0aacc5b30bf02db7ecf929e6f4fc1c6 Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Tue, 5 Jul 2016 11:40:42 -0700 Subject: [PATCH] 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. --- tests/parser/README.rst | 9 +++++++++ tests/parser/run.sh | 40 ++++++++++++++++++++++++++++++++++++++ tests/parser/tiny.cton | 5 +++++ tests/parser/tiny.cton.ref | 4 ++++ 4 files changed, 58 insertions(+) create mode 100644 tests/parser/README.rst create mode 100755 tests/parser/run.sh create mode 100644 tests/parser/tiny.cton create mode 100644 tests/parser/tiny.cton.ref diff --git a/tests/parser/README.rst b/tests/parser/README.rst new file mode 100644 index 0000000000..9ac4658d13 --- /dev/null +++ b/tests/parser/README.rst @@ -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. diff --git a/tests/parser/run.sh b/tests/parser/run.sh new file mode 100755 index 0000000000..e5795df1da --- /dev/null +++ b/tests/parser/run.sh @@ -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 diff --git a/tests/parser/tiny.cton b/tests/parser/tiny.cton new file mode 100644 index 0000000000..acc8ea7384 --- /dev/null +++ b/tests/parser/tiny.cton @@ -0,0 +1,5 @@ +; The smallest possible function. +function minimal() { +ebb0: + trap +} diff --git a/tests/parser/tiny.cton.ref b/tests/parser/tiny.cton.ref new file mode 100644 index 0000000000..474c30527e --- /dev/null +++ b/tests/parser/tiny.cton.ref @@ -0,0 +1,4 @@ +function minimal() { +ebb0: + trap +}