@@ -2,6 +2,7 @@ module Main ( main ) where
2
2
3
3
import Checktestdata
4
4
import Checktestdata.Script
5
+ import Checktestdata.Options
5
6
6
7
import Control.Monad
7
8
import Control.Exception
@@ -19,61 +20,72 @@ main = do
19
20
-- Read the tests directory
20
21
allfiles <- listDirectory testsdir
21
22
22
- -- Go over all regular test programs
23
- let isProg f = " testprog" `isPrefixOf` f && " .in" `isSuffixOf` f
24
- r1 <- forM (filter isProg allfiles) $ \ prog -> do
25
- -- Get the test num
26
- let testnum = takeWhile (/= ' .' ) $ drop (length " testprog" ) prog
23
+ -- Generic function we can run for both whitespace and non-whitespace
24
+ let tests opts progf datf = do
25
+ -- Go over all regular test programs
26
+ let isProg f = progf `isPrefixOf` f && " .in" `isSuffixOf` f
27
+ r1 <- forM (filter isProg allfiles) $ \ prog -> do
28
+ -- Get the test num
29
+ let testnum = takeWhile (/= ' .' ) $ drop (length progf) prog
27
30
28
- -- Go over the correct testdata files
29
- let isCorrect f = (" testdata " ++ testnum ++ " .in" ) `isPrefixOf` f
30
- r2 <- forM (filter isCorrect allfiles) $ \ dataf -> checkSuccess prog dataf
31
+ -- Go over the correct testdata files
32
+ let isCorrect f = (datf ++ testnum ++ " .in" ) `isPrefixOf` f
33
+ r2 <- forM (filter isCorrect allfiles) $ \ dataf -> checkSuccess opts prog dataf
31
34
32
- -- Go over the failure testdata files
33
- let isFailure f = (" testdata " ++ testnum ++ " .err" ) `isPrefixOf` f
34
- r3 <- forM (filter isFailure allfiles) $ \ dataf -> checkFailure prog dataf
35
+ -- Go over the failure testdata files
36
+ let isFailure f = (datf ++ testnum ++ " .err" ) `isPrefixOf` f
37
+ r3 <- forM (filter isFailure allfiles) $ \ dataf -> checkFailure opts prog dataf
35
38
36
- return $ r2 ++ r3
39
+ return $ r2 ++ r3
37
40
38
- -- Go over all test programs that should fail
39
- let isErrProg f = " testprog " `isPrefixOf` f && " .err" `isSuffixOf` f
40
- r4 <- forM (filter isErrProg allfiles) $ \ prog -> do
41
- -- Get the test num
42
- let testnum = takeWhile (/= ' .' ) $ drop (length " testprog" ) prog
41
+ -- Go over all test programs that should fail
42
+ let isErrProg f = progf `isPrefixOf` f && " .err" `isSuffixOf` f
43
+ r4 <- forM (filter isErrProg allfiles) $ \ prog -> do
44
+ -- Get the test num
45
+ let testnum = takeWhile (/= ' .' ) $ drop (length " testprog" ) prog
43
46
44
- -- Go over the correct testdata files
45
- let isCorrect f = (" testdata" ++ testnum ++ " .in" ) `isPrefixOf` f
46
- forM (filter isCorrect allfiles) $ \ dataf -> checkFailure prog dataf
47
+ -- Go over the correct testdata files
48
+ let isCorrect f = (datf ++ testnum ++ " .in" ) `isPrefixOf` f
49
+ forM (filter isCorrect allfiles) $ \ dataf -> checkFailure opts prog dataf
50
+
51
+ -- Return all results
52
+ return $ concat $ r1 ++ r4
53
+
54
+ -- Run tests for normal progs
55
+ r1 <- tests defaultOptions " testprog" " testdata"
56
+
57
+ -- Run tests with -w options
58
+ r2 <- tests (defaultOptions { whitespace_ok = True }) " testwsprog" " testwsdata"
47
59
48
60
-- Check that all tests succeeded
49
- when (not $ and $ concat $ r1 ++ r4 ) $ exitFailure
61
+ when (not $ and $ r1 ++ r2 ) $ exitFailure
50
62
51
63
-- | Run the prog on the given data file and ensure that it succeeded.
52
- checkSuccess :: FilePath -> FilePath -> IO Bool
53
- checkSuccess prog dataf = do
54
- res <- checkRun prog dataf
64
+ checkSuccess :: Options -> FilePath -> FilePath -> IO Bool
65
+ checkSuccess opts prog dataf = do
66
+ res <- checkRun opts prog dataf
55
67
case res of
56
68
Right () -> return True
57
69
Left _ -> do
58
70
putStrLn $ " Running " ++ prog ++ " on " ++ dataf ++ " did not succeed"
59
71
return False
60
72
61
73
-- | Run the prog on the given data file and ensure that it failed
62
- checkFailure :: FilePath -> FilePath -> IO Bool
63
- checkFailure prog dataf = do
64
- res <- checkRun prog dataf
74
+ checkFailure :: Options -> FilePath -> FilePath -> IO Bool
75
+ checkFailure opts prog dataf = do
76
+ res <- checkRun opts prog dataf
65
77
case res of
66
78
Left _ -> return True
67
79
Right () -> do
68
80
putStrLn $ " Running " ++ prog ++ " on " ++ dataf ++ " did not fail"
69
81
return False
70
82
71
83
-- | Run the prog on the given data file and return it's success or failure
72
- checkRun :: FilePath -> FilePath -> IO (Either String () )
73
- checkRun prog dataf = do
84
+ checkRun :: Options -> FilePath -> FilePath -> IO (Either String () )
85
+ checkRun opts prog dataf = do
74
86
res <- try $ do
75
87
ctd <- parseScript $ testsdir ++ prog
76
- runCTDFile (interpret ctd) $ testsdir ++ dataf
88
+ runCTDFile opts (interpret ctd) $ testsdir ++ dataf
77
89
case res of
78
90
Left e -> return $ Left $ show (e :: SomeException )
79
91
Right (Left e) -> return $ Left e
0 commit comments