|
1 |
| -module Main ( main ) where |
2 |
| - |
3 |
| -import Checktestdata |
4 |
| -import Checktestdata.Script |
5 |
| - |
6 |
| -import Control.Monad |
7 |
| -import Control.Exception |
8 |
| - |
9 |
| -import System.Directory ( listDirectory ) |
10 |
| -import Data.List ( isPrefixOf, isSuffixOf ) |
11 |
| - |
12 |
| -import System.Exit ( exitFailure ) |
13 |
| - |
14 |
| -testsdir :: String |
15 |
| -testsdir = "../tests/" |
16 |
| - |
17 |
| -main :: IO () |
18 |
| -main = do |
19 |
| - -- Read the tests directory |
20 |
| - allfiles <- listDirectory testsdir |
21 |
| - |
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 |
27 |
| - |
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 |
| - |
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 |
| - |
36 |
| - return $ r2 ++ r3 |
37 |
| - |
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 |
43 |
| - |
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 |
| - |
48 |
| - -- Check that all tests succeeded |
49 |
| - when (not $ and $ concat $ r1 ++ r4) $ exitFailure |
50 |
| - |
51 |
| --- | 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 |
55 |
| - case res of |
56 |
| - Right () -> return True |
57 |
| - Left _ -> do |
58 |
| - putStrLn $ "Running " ++ prog ++ " on " ++ dataf ++ " did not succeed" |
59 |
| - return False |
60 |
| - |
61 |
| --- | 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 |
65 |
| - case res of |
66 |
| - Left _ -> return True |
67 |
| - Right () -> do |
68 |
| - putStrLn $ "Running " ++ prog ++ " on " ++ dataf ++ " did not fail" |
69 |
| - return False |
70 |
| - |
71 |
| --- | 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 |
74 |
| - res <- try $ do |
75 |
| - ctd <- parseScript $ testsdir ++ prog |
76 |
| - runCTDFile (interpret ctd) $ testsdir ++ dataf |
77 |
| - case res of |
78 |
| - Left e -> return $ Left $ show (e :: SomeException) |
79 |
| - Right (Left e) -> return $ Left e |
80 |
| - Right (Right _) -> return $ Right () |
| 1 | +module Main ( main ) where |
| 2 | + |
| 3 | +import Checktestdata |
| 4 | +import Checktestdata.Script |
| 5 | + |
| 6 | +import Control.Monad |
| 7 | +import Control.Exception |
| 8 | + |
| 9 | +import System.Directory ( listDirectory ) |
| 10 | +import Data.List ( isPrefixOf, isSuffixOf ) |
| 11 | + |
| 12 | +import System.Exit ( exitFailure ) |
| 13 | + |
| 14 | +testsdir :: String |
| 15 | +testsdir = "../tests/" |
| 16 | + |
| 17 | +main :: IO () |
| 18 | +main = do |
| 19 | + -- Read the tests directory |
| 20 | + allfiles <- listDirectory testsdir |
| 21 | + |
| 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 |
| 27 | + |
| 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 | + |
| 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 | + |
| 36 | + return $ r2 ++ r3 |
| 37 | + |
| 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 |
| 43 | + |
| 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 | + |
| 48 | + -- Check that all tests succeeded |
| 49 | + when (not $ and $ concat $ r1 ++ r4) $ exitFailure |
| 50 | + |
| 51 | +-- | 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 |
| 55 | + case res of |
| 56 | + Right () -> return True |
| 57 | + Left _ -> do |
| 58 | + putStrLn $ "Running " ++ prog ++ " on " ++ dataf ++ " did not succeed" |
| 59 | + return False |
| 60 | + |
| 61 | +-- | 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 |
| 65 | + case res of |
| 66 | + Left _ -> return True |
| 67 | + Right () -> do |
| 68 | + putStrLn $ "Running " ++ prog ++ " on " ++ dataf ++ " did not fail" |
| 69 | + return False |
| 70 | + |
| 71 | +-- | 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 |
| 74 | + res <- try $ do |
| 75 | + ctd <- parseScript $ testsdir ++ prog |
| 76 | + runCTDFile (interpret ctd) $ testsdir ++ dataf |
| 77 | + case res of |
| 78 | + Left e -> return $ Left $ show (e :: SomeException) |
| 79 | + Right (Left e) -> return $ Left e |
| 80 | + Right (Right _) -> return $ Right () |
0 commit comments