@@ -2,6 +2,7 @@ module Main ( main ) where
22
33import Checktestdata
44import Checktestdata.Script
5+ import Checktestdata.Options
56
67import Control.Monad
78import Control.Exception
@@ -19,61 +20,72 @@ main = do
1920 -- Read the tests directory
2021 allfiles <- listDirectory testsdir
2122
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
2730
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
3134
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
3538
36- return $ r2 ++ r3
39+ return $ r2 ++ r3
3740
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
4346
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"
4759
4860 -- Check that all tests succeeded
49- when (not $ and $ concat $ r1 ++ r4 ) $ exitFailure
61+ when (not $ and $ r1 ++ r2 ) $ exitFailure
5062
5163-- | 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
5567 case res of
5668 Right () -> return True
5769 Left _ -> do
5870 putStrLn $ " Running " ++ prog ++ " on " ++ dataf ++ " did not succeed"
5971 return False
6072
6173-- | 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
6577 case res of
6678 Left _ -> return True
6779 Right () -> do
6880 putStrLn $ " Running " ++ prog ++ " on " ++ dataf ++ " did not fail"
6981 return False
7082
7183-- | 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
7486 res <- try $ do
7587 ctd <- parseScript $ testsdir ++ prog
76- runCTDFile (interpret ctd) $ testsdir ++ dataf
88+ runCTDFile opts (interpret ctd) $ testsdir ++ dataf
7789 case res of
7890 Left e -> return $ Left $ show (e :: SomeException )
7991 Right (Left e) -> return $ Left e
0 commit comments