From 82eef9113bb98043efab5785fd64bf523a9f663b Mon Sep 17 00:00:00 2001 From: Bit Connor Date: Sat, 29 Dec 2012 02:31:34 +0200 Subject: [PATCH] Add a test framework and some really simple tests --- tests/Child.hs | 6 ++++ tests/Parent.hs | 4 +++ tests/SampleError.hs | 9 ++++++ tests/Simple.hs | 7 +++++ tests/test_module_file.sh | 13 +++++++++ tests/test_runner.sh | 59 ++++++++++++++++++++++++++++++++++++++ tests/test_sample_error.sh | 16 +++++++++++ tests/test_simple_check.sh | 11 +++++++ tests/test_start_stop.sh | 20 +++++++++++++ 9 files changed, 145 insertions(+) create mode 100644 tests/Child.hs create mode 100644 tests/Parent.hs create mode 100644 tests/SampleError.hs create mode 100644 tests/Simple.hs create mode 100644 tests/test_module_file.sh create mode 100755 tests/test_runner.sh create mode 100644 tests/test_sample_error.sh create mode 100644 tests/test_simple_check.sh create mode 100644 tests/test_start_stop.sh diff --git a/tests/Child.hs b/tests/Child.hs new file mode 100644 index 0000000..f47bff0 --- /dev/null +++ b/tests/Child.hs @@ -0,0 +1,6 @@ +module Child where + +import Parent + +child :: String +child = "child of " ++ parent diff --git a/tests/Parent.hs b/tests/Parent.hs new file mode 100644 index 0000000..0665d15 --- /dev/null +++ b/tests/Parent.hs @@ -0,0 +1,4 @@ +module Parent where + +parent :: String +parent = "parent" diff --git a/tests/SampleError.hs b/tests/SampleError.hs new file mode 100644 index 0000000..21f84dd --- /dev/null +++ b/tests/SampleError.hs @@ -0,0 +1,9 @@ +-- Sample Module used for testing + +-- This module should cause a compilation error: +-- +-- Sample2.hs:9:1: parse error (possibly incorrect indentation) + +module SampleError where + +a = foo diff --git a/tests/Simple.hs b/tests/Simple.hs new file mode 100644 index 0000000..8359a72 --- /dev/null +++ b/tests/Simple.hs @@ -0,0 +1,7 @@ +-- Sample Module used for testing + +-- This module contains no errors or warnings +module Sample1 where + +increment :: Int -> Int +increment x = x + 1 diff --git a/tests/test_module_file.sh b/tests/test_module_file.sh new file mode 100644 index 0000000..f6421db --- /dev/null +++ b/tests/test_module_file.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +set -e + +SOCK=`mktemp -u` + +$HDEVTOOLS check --socket=$SOCK Child.hs + +PARENT=`$HDEVTOOLS modulefile --socket=$SOCK Parent` + +[ "$PARENT" = "./Parent.hs" ] + +$HDEVTOOLS --socket=$SOCK --stop-server diff --git a/tests/test_runner.sh b/tests/test_runner.sh new file mode 100755 index 0000000..3eb1bf5 --- /dev/null +++ b/tests/test_runner.sh @@ -0,0 +1,59 @@ +#!/bin/sh + +set -e + +ALL_TESTS="\ + test_start_stop.sh \ + test_simple_check.sh \ + test_sample_error.sh \ + test_module_file.sh \ + " + +if [ ! $HDEVTOOLS ] +then + echo 'You must set the HDEVTOOLS environment variable to the path of the hdevtools binary' + exit 1 +fi + +case "$HDEVTOOLS" in + */*) + # Convert relative path to absolute: + export HDEVTOOLS=`pwd`/$HDEVTOOLS +esac + +echo $HDEVTOOLS + +if [ $# -ne 0 ] +then + TESTS=$* +else + TESTS=$ALL_TESTS + echo 'Running All Tests' +fi + +echo '------------------------------------------------------------------------' + +cd `dirname $0` + +ERRORS=0 +for i in $TESTS +do + echo $i + echo + if sh $i + then + echo 'Test OK' + else + echo 'Test FAILED' + ERRORS=`expr $ERRORS + 1` + fi + echo '------------------------------------------------------------------------' +done + +if [ $ERRORS = 0 ] +then + echo 'All Tests OK' +else + echo $ERRORS 'FAILED Tests' +fi +exit $ERRORS diff --git a/tests/test_sample_error.sh b/tests/test_sample_error.sh new file mode 100644 index 0000000..476c7af --- /dev/null +++ b/tests/test_sample_error.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +set -e + +SOCK=`mktemp -u` + +EXPECTED_ERRORS='SampleError.hs:9:5: Not in scope: `foo'\''' + +if ERRORS=`$HDEVTOOLS check --socket=$SOCK SampleError.hs` +then + false +elsh + [ "$ERRORS" = "$EXPECTED_ERRORS" ] +fi + +$HDEVTOOLS --socket=$SOCK --stop-server diff --git a/tests/test_simple_check.sh b/tests/test_simple_check.sh new file mode 100644 index 0000000..edb767f --- /dev/null +++ b/tests/test_simple_check.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +set -e + +SOCK=`mktemp -u` + +ERRORS=`$HDEVTOOLS check --socket=$SOCK Simple.hs` + +[ -z "$ERRORS" ] + +$HDEVTOOLS --socket=$SOCK --stop-server diff --git a/tests/test_start_stop.sh b/tests/test_start_stop.sh new file mode 100644 index 0000000..19d8787 --- /dev/null +++ b/tests/test_start_stop.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +set -e + +SOCK=`mktemp -u` + +echo '> Starting the server' +$HDEVTOOLS --socket=$SOCK --start-server + +echo '> Checking status' +$HDEVTOOLS --socket=$SOCK --status + +echo '> Checking that the socket file exists' +if [ ! -S $SOCK ]; then false; fi + +echo '> Stopping the server' +$HDEVTOOLS --socket=$SOCK --stop-server + +echo '> Checking that the socket file no longer exists' +if [ -e $SOCK ]; then false; fi