Skip to content
Browse files

Add a simple framework for running automatic tests.

  • Loading branch information...
1 parent d149261 commit 54b52fd97ff39d0f5135eb913e76509b160654e6 @valderman committed Mar 20, 2012
Showing with 76 additions and 0 deletions.
  1. +16 −0 TestDriver.hs
  2. +20 −0 Tests/Sumlist.hs
  3. +40 −0 runtests.sh
View
16 TestDriver.hs
@@ -0,0 +1,16 @@
+{-# LANGUAGE CPP #-}
+module Main where
+#ifdef HASTE
+import Haste
+#endif
+import Tests.TEST_MODULE (runTest)
+
+#ifdef HASTE
+main = do
+ res <- runTest
+ alert $ show res
+#else
+main = do
+ res <- runTest
+ putStrLn $ show res
+#endif
View
20 Tests/Sumlist.hs
@@ -0,0 +1,20 @@
+{-# LANGUAGE CPP #-}
+module Tests.Sumlist where
+#ifdef HASTE
+import Haste
+str :: Showable a => a -> String
+str = show_
+#else
+str :: Show a => a -> String
+str = show
+#endif
+
+mySum :: Num a => [a] -> a
+mySum (x:xs) = x+mySum xs
+mySum _ = 0
+
+runTest :: IO [String]
+runTest = return [str $ mySum [1::Int .. 10],
+ show $ mySum [1::Integer .. 10],
+ str $ mySum [1::Float .. 10],
+ str $ mySum [1::Double .. 10]]
View
40 runtests.sh
@@ -0,0 +1,40 @@
+#!/bin/bash
+
+let failed=0
+let tests=0
+
+for file in Tests/*.hs; do
+ let tests=$tests+1
+
+ module=`echo $file | sed -e s/Tests\\\/// | sed -e s/\.hs//`
+
+ echo "Running test $module..."
+
+ ghc_output=`runghc -DTEST_MODULE=$module TestDriver.hs`
+
+ hastec --start=asap -DHASTE -DTEST_MODULE=$module TestDriver.hs > /dev/null
+ haste_output=`js TestDriver.js`
+
+ hastec -O2 --start=asap -DHASTE -DTEST_MODULE=$module TestDriver.hs > /dev/null
+ haste_opt_output=`js TestDriver.js`
+
+ if [[ "$ghc_output" != "$haste_output" ]] ; then
+ thistest="failed"
+ echo " GHC disagrees with hastec output!"
+ echo " GHC says '$ghc_output', but hastec says '$haste_output'"
+ fi
+
+ if [[ "$ghc_output" != "$haste_opt_output" ]] ; then
+ thistest="failed"
+ echo " GHC disagrees with hastec -O2 output!"
+ echo " GHC says '$ghc_output', but hastec says '$haste_out_output'"
+ fi
+
+ if [[ $thistest == "failed" ]] ; then
+ let failed=$failed+1
+ fi
+done
+
+echo
+let success=$tests-$failed
+echo "$success/$tests succeeded"

0 comments on commit 54b52fd

Please sign in to comment.
Something went wrong with that request. Please try again.