Skip to content

Commit 82eef91

Browse files
committed
Add a test framework and some really simple tests
1 parent ec10e0f commit 82eef91

File tree

9 files changed

+145
-0
lines changed

9 files changed

+145
-0
lines changed

tests/Child.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Child where
2+
3+
import Parent
4+
5+
child :: String
6+
child = "child of " ++ parent

tests/Parent.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Parent where
2+
3+
parent :: String
4+
parent = "parent"

tests/SampleError.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- Sample Module used for testing
2+
3+
-- This module should cause a compilation error:
4+
--
5+
-- Sample2.hs:9:1: parse error (possibly incorrect indentation)
6+
7+
module SampleError where
8+
9+
a = foo

tests/Simple.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- Sample Module used for testing
2+
3+
-- This module contains no errors or warnings
4+
module Sample1 where
5+
6+
increment :: Int -> Int
7+
increment x = x + 1

tests/test_module_file.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
SOCK=`mktemp -u`
6+
7+
$HDEVTOOLS check --socket=$SOCK Child.hs
8+
9+
PARENT=`$HDEVTOOLS modulefile --socket=$SOCK Parent`
10+
11+
[ "$PARENT" = "./Parent.hs" ]
12+
13+
$HDEVTOOLS --socket=$SOCK --stop-server

tests/test_runner.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
ALL_TESTS="\
6+
test_start_stop.sh \
7+
test_simple_check.sh \
8+
test_sample_error.sh \
9+
test_module_file.sh \
10+
"
11+
12+
if [ ! $HDEVTOOLS ]
13+
then
14+
echo 'You must set the HDEVTOOLS environment variable to the path of the hdevtools binary'
15+
exit 1
16+
fi
17+
18+
case "$HDEVTOOLS" in
19+
*/*)
20+
# Convert relative path to absolute:
21+
export HDEVTOOLS=`pwd`/$HDEVTOOLS
22+
esac
23+
24+
echo $HDEVTOOLS
25+
26+
if [ $# -ne 0 ]
27+
then
28+
TESTS=$*
29+
else
30+
TESTS=$ALL_TESTS
31+
echo 'Running All Tests'
32+
fi
33+
34+
echo '------------------------------------------------------------------------'
35+
36+
cd `dirname $0`
37+
38+
ERRORS=0
39+
for i in $TESTS
40+
do
41+
echo $i
42+
echo
43+
if sh $i
44+
then
45+
echo 'Test OK'
46+
else
47+
echo 'Test FAILED'
48+
ERRORS=`expr $ERRORS + 1`
49+
fi
50+
echo '------------------------------------------------------------------------'
51+
done
52+
53+
if [ $ERRORS = 0 ]
54+
then
55+
echo 'All Tests OK'
56+
else
57+
echo $ERRORS 'FAILED Tests'
58+
fi
59+
exit $ERRORS

tests/test_sample_error.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
SOCK=`mktemp -u`
6+
7+
EXPECTED_ERRORS='SampleError.hs:9:5: Not in scope: `foo'\'''
8+
9+
if ERRORS=`$HDEVTOOLS check --socket=$SOCK SampleError.hs`
10+
then
11+
false
12+
elsh
13+
[ "$ERRORS" = "$EXPECTED_ERRORS" ]
14+
fi
15+
16+
$HDEVTOOLS --socket=$SOCK --stop-server

tests/test_simple_check.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
SOCK=`mktemp -u`
6+
7+
ERRORS=`$HDEVTOOLS check --socket=$SOCK Simple.hs`
8+
9+
[ -z "$ERRORS" ]
10+
11+
$HDEVTOOLS --socket=$SOCK --stop-server

tests/test_start_stop.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
SOCK=`mktemp -u`
6+
7+
echo '> Starting the server'
8+
$HDEVTOOLS --socket=$SOCK --start-server
9+
10+
echo '> Checking status'
11+
$HDEVTOOLS --socket=$SOCK --status
12+
13+
echo '> Checking that the socket file exists'
14+
if [ ! -S $SOCK ]; then false; fi
15+
16+
echo '> Stopping the server'
17+
$HDEVTOOLS --socket=$SOCK --stop-server
18+
19+
echo '> Checking that the socket file no longer exists'
20+
if [ -e $SOCK ]; then false; fi

0 commit comments

Comments
 (0)