Skip to content

Commit 7e363fb

Browse files
committed
[haskell_edsl] Let test suite fail when one or more tests fail
1 parent 7110812 commit 7e363fb

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

haskell_edsl/src-main/Test.hs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Control.Exception
99
import System.Directory ( listDirectory )
1010
import Data.List ( isPrefixOf, isSuffixOf )
1111

12+
import System.Exit ( exitFailure )
1213

1314
testsdir :: String
1415
testsdir = "../tests/"
@@ -20,44 +21,52 @@ main = do
2021

2122
-- Go over all regular test programs
2223
let isProg f = "testprog" `isPrefixOf` f && ".in" `isSuffixOf` f
23-
forM_ (filter isProg allfiles) $ \prog -> do
24+
r1 <- forM (filter isProg allfiles) $ \prog -> do
2425
-- Get the test num
2526
let testnum = takeWhile (/='.') $ drop (length "testprog") prog
2627

2728
-- Go over the correct testdata files
2829
let isCorrect f = ("testdata"++ testnum ++ ".in") `isPrefixOf` f
29-
forM_ (filter isCorrect allfiles) $ \dataf -> checkSuccess prog dataf
30+
r2 <- forM (filter isCorrect allfiles) $ \dataf -> checkSuccess prog dataf
3031

3132
-- Go over the failure testdata files
3233
let isFailure f = ("testdata"++ testnum ++ ".err") `isPrefixOf` f
33-
forM_ (filter isFailure allfiles) $ \dataf -> checkFailure prog dataf
34+
r3 <- forM (filter isFailure allfiles) $ \dataf -> checkFailure prog dataf
35+
36+
return $ r2 ++ r3
3437

3538
-- Go over all test programs that should fail
3639
let isErrProg f = "testprog" `isPrefixOf` f && ".err" `isSuffixOf` f
37-
forM_ (filter isErrProg allfiles) $ \prog -> do
40+
r4 <- forM (filter isErrProg allfiles) $ \prog -> do
3841
-- Get the test num
3942
let testnum = takeWhile (/='.') $ drop (length "testprog") prog
4043

4144
-- Go over the correct testdata files
4245
let isCorrect f = ("testdata"++ testnum ++ ".in") `isPrefixOf` f
43-
forM_ (filter isCorrect allfiles) $ \dataf -> checkFailure prog dataf
46+
forM (filter isCorrect allfiles) $ \dataf -> checkFailure prog dataf
4447

48+
-- Check that all tests succeeded
49+
when (not $ and $ concat $ r1 ++ r4) $ exitFailure
4550

4651
-- | Run the prog on the given data file and ensure that it succeeded.
47-
checkSuccess :: FilePath -> FilePath -> IO ()
52+
checkSuccess :: FilePath -> FilePath -> IO Bool
4853
checkSuccess prog dataf = do
4954
res <- checkRun prog dataf
5055
case res of
51-
Right () -> return ()
52-
Left _ -> putStrLn $ "Running " ++ prog ++ " on " ++ dataf ++ " did not succeed"
56+
Right () -> return True
57+
Left _ -> do
58+
putStrLn $ "Running " ++ prog ++ " on " ++ dataf ++ " did not succeed"
59+
return False
5360

5461
-- | Run the prog on the given data file and ensure that it failed
55-
checkFailure :: FilePath -> FilePath -> IO ()
62+
checkFailure :: FilePath -> FilePath -> IO Bool
5663
checkFailure prog dataf = do
5764
res <- checkRun prog dataf
5865
case res of
59-
Right () -> putStrLn $ "Running " ++ prog ++ " on " ++ dataf ++ " did not fail"
60-
Left _ -> return ()
66+
Left _ -> return True
67+
Right () -> do
68+
putStrLn $ "Running " ++ prog ++ " on " ++ dataf ++ " did not fail"
69+
return False
6170

6271
-- | Run the prog on the given data file and return it's success or failure
6372
checkRun :: FilePath -> FilePath -> IO (Either String ())

0 commit comments

Comments
 (0)