@@ -9,6 +9,7 @@ import Control.Exception
9
9
import System.Directory ( listDirectory )
10
10
import Data.List ( isPrefixOf , isSuffixOf )
11
11
12
+ import System.Exit ( exitFailure )
12
13
13
14
testsdir :: String
14
15
testsdir = " ../tests/"
@@ -20,44 +21,52 @@ main = do
20
21
21
22
-- Go over all regular test programs
22
23
let isProg f = " testprog" `isPrefixOf` f && " .in" `isSuffixOf` f
23
- forM_ (filter isProg allfiles) $ \ prog -> do
24
+ r1 <- forM (filter isProg allfiles) $ \ prog -> do
24
25
-- Get the test num
25
26
let testnum = takeWhile (/= ' .' ) $ drop (length " testprog" ) prog
26
27
27
28
-- Go over the correct testdata files
28
29
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
30
31
31
32
-- Go over the failure testdata files
32
33
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
34
37
35
38
-- Go over all test programs that should fail
36
39
let isErrProg f = " testprog" `isPrefixOf` f && " .err" `isSuffixOf` f
37
- forM_ (filter isErrProg allfiles) $ \ prog -> do
40
+ r4 <- forM (filter isErrProg allfiles) $ \ prog -> do
38
41
-- Get the test num
39
42
let testnum = takeWhile (/= ' .' ) $ drop (length " testprog" ) prog
40
43
41
44
-- Go over the correct testdata files
42
45
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
44
47
48
+ -- Check that all tests succeeded
49
+ when (not $ and $ concat $ r1 ++ r4) $ exitFailure
45
50
46
51
-- | Run the prog on the given data file and ensure that it succeeded.
47
- checkSuccess :: FilePath -> FilePath -> IO ()
52
+ checkSuccess :: FilePath -> FilePath -> IO Bool
48
53
checkSuccess prog dataf = do
49
54
res <- checkRun prog dataf
50
55
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
53
60
54
61
-- | Run the prog on the given data file and ensure that it failed
55
- checkFailure :: FilePath -> FilePath -> IO ()
62
+ checkFailure :: FilePath -> FilePath -> IO Bool
56
63
checkFailure prog dataf = do
57
64
res <- checkRun prog dataf
58
65
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
61
70
62
71
-- | Run the prog on the given data file and return it's success or failure
63
72
checkRun :: FilePath -> FilePath -> IO (Either String () )
0 commit comments