Skip to content

Commit

Permalink
Add a test framework and some really simple tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bitc committed Dec 29, 2012
1 parent ec10e0f commit 82eef91
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/Child.hs
@@ -0,0 +1,6 @@
module Child where

import Parent

child :: String
child = "child of " ++ parent
4 changes: 4 additions & 0 deletions tests/Parent.hs
@@ -0,0 +1,4 @@
module Parent where

parent :: String
parent = "parent"
9 changes: 9 additions & 0 deletions 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
7 changes: 7 additions & 0 deletions 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
13 changes: 13 additions & 0 deletions 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
59 changes: 59 additions & 0 deletions 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
16 changes: 16 additions & 0 deletions 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
11 changes: 11 additions & 0 deletions 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
20 changes: 20 additions & 0 deletions 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

0 comments on commit 82eef91

Please sign in to comment.