diff options
author | Csaba Hruska <csaba.hruska@gmail.com> | 2016-01-19 16:10:26 +0100 |
---|---|---|
committer | Csaba Hruska <csaba.hruska@gmail.com> | 2016-01-19 16:10:49 +0100 |
commit | 03c8e879558f8e16e49b21d493a82ba9657f7d13 (patch) | |
tree | 5debb486051a4c975e0f48e3dac2c500009064bf | |
parent | cb69693769ebfcdac605c90f38a20c788b08eaf3 (diff) |
improve test framework: add -notimeout flag, collect test in nested directories, skips NAME.ignore dirs, reject tests has .reject.lc extension
-rw-r--r-- | test/runTests.hs | 57 |
1 files changed, 34 insertions, 23 deletions
diff --git a/test/runTests.hs b/test/runTests.hs index d09bec7b..2ca95608 100644 --- a/test/runTests.hs +++ b/test/runTests.hs | |||
@@ -30,9 +30,7 @@ import Text.Parsec.Pos | |||
30 | instance NFData SourcePos where | 30 | instance NFData SourcePos where |
31 | rnf _ = () | 31 | rnf _ = () |
32 | 32 | ||
33 | acceptPath = "./testdata/accept" | 33 | testDataPath = "./testdata" |
34 | rejectPath = "./testdata/reject" | ||
35 | timeout = 15 {- in seconds -} | ||
36 | 34 | ||
37 | data Res = Accepted | New | Rejected | Failed | ErrorCatched | 35 | data Res = Accepted | New | Rejected | Failed | ErrorCatched |
38 | deriving (Eq, Ord, Show) | 36 | deriving (Eq, Ord, Show) |
@@ -42,34 +40,46 @@ erroneous = (>= Rejected) | |||
42 | instance NFData Res where | 40 | instance NFData Res where |
43 | rnf a = a `seq` () | 41 | rnf a = a `seq` () |
44 | 42 | ||
45 | optionArgs = ["-v", "-r"] | 43 | optionArgs = ["-v", "-r","-notimeout"] |
44 | |||
45 | getDirectoryContentsRecursive path = do | ||
46 | l <- map (path </>) . filter (\n -> notElem n [".",".."]) <$> getDirectoryContents path | ||
47 | -- ignore sub directories that name include .ignore | ||
48 | dirs <- filter (not . isInfixOf ".ignore") <$> filterM doesDirectoryExist l | ||
49 | files <- filterM doesFileExist l | ||
50 | innerContent <- mapM getDirectoryContentsRecursive dirs | ||
51 | return $ concat $ (filter ((".lc" ==) . takeExtension) files) : innerContent | ||
46 | 52 | ||
47 | main :: IO () | 53 | main :: IO () |
48 | main = do | 54 | main = do |
49 | hSetBuffering stdout NoBuffering | 55 | hSetBuffering stdout NoBuffering |
50 | hSetBuffering stdin NoBuffering | 56 | hSetBuffering stdin NoBuffering |
51 | args <- getArgs | 57 | args <- getArgs |
52 | |||
53 | let samplesToAccept = filter (not . flip elem optionArgs) args | 58 | let samplesToAccept = filter (not . flip elem optionArgs) args |
54 | verbose = elem "-v" args | 59 | verbose = elem "-v" args |
55 | reject = elem "-r" args | 60 | reject = elem "-r" args |
56 | (testToAccept,testToReject) <- case samplesToAccept of | 61 | timeout = if elem "-notimeout" args then 15 * 60 else 15 {- in seconds -} |
57 | [] -> do | 62 | testData <- getDirectoryContentsRecursive testDataPath |
58 | toAccept <- map dropExtension . filter (\n -> ".lc" == takeExtension n) <$> getDirectoryContents acceptPath | 63 | let (testToAccept,testToReject) = case samplesToAccept of |
59 | toReject <- map dropExtension . filter (\n -> ".lc" == takeExtension n) <$> getDirectoryContents rejectPath | 64 | [] -> |
60 | return (toAccept, toReject) | 65 | let toAccept = map dropExtension . filter (\n -> ".lc" == takeExtensions n) $ testData |
61 | _ -> do | 66 | toReject = map dropExtension . filter (\n -> ".reject.lc" == takeExtensions n) $ testData |
62 | let intersect = Set.toList . Set.intersection (Set.fromList samplesToAccept) . Set.fromList | 67 | in (toAccept, toReject) |
63 | toAccept <- intersect . map dropExtension . filter (\n -> ".lc" == takeExtension n) <$> getDirectoryContents acceptPath | 68 | _ -> |
64 | toReject <- intersect . map dropExtension . filter (\n -> ".lc" == takeExtension n) <$> getDirectoryContents rejectPath | 69 | let samples = Set.toList . Set.fromList $ concat [filter (isInfixOf s) testData | s <- samplesToAccept] |
65 | return (toAccept, toReject) | 70 | toAccept = map dropExtension . filter (\n -> ".lc" == takeExtensions n) $ samples |
71 | toReject = map dropExtension . filter (\n -> ".reject.lc" == takeExtensions n) $ samples | ||
72 | in (toAccept, toReject) | ||
73 | when (null $ testToAccept ++ testToReject) $ do | ||
74 | liftIO $ putStrLn $ "test files not found: " ++ show samplesToAccept | ||
75 | exitFailure | ||
66 | 76 | ||
67 | n <- runMM' $ do | 77 | n <- runMM' $ do |
68 | liftIO $ putStrLn $ "------------------------------------ Checking valid pipelines" | 78 | liftIO $ putStrLn $ "------------------------------------ Checking valid pipelines" |
69 | n1 <- acceptTests reject testToAccept | 79 | n1 <- acceptTests timeout reject testToAccept |
70 | 80 | ||
71 | liftIO $ putStrLn $ "------------------------------------ Catching errors (must get an error)" | 81 | liftIO $ putStrLn $ "------------------------------------ Catching errors (must get an error)" |
72 | n2 <- rejectTests reject testToReject | 82 | n2 <- rejectTests timeout reject testToReject |
73 | 83 | ||
74 | return $ n1 ++ n2 | 84 | return $ n1 ++ n2 |
75 | 85 | ||
@@ -89,7 +99,7 @@ main = do | |||
89 | ++ sh "accepted result" Accepted | 99 | ++ sh "accepted result" Accepted |
90 | when (any erroneous results) exitFailure | 100 | when (any erroneous results) exitFailure |
91 | 101 | ||
92 | acceptTests reject = testFrame reject [acceptPath, rejectPath] $ \case | 102 | acceptTests timeout reject = testFrame timeout reject [".",testDataPath] $ \case |
93 | Left e -> Left e | 103 | Left e -> Left e |
94 | Right (fname, Left e, i) -> Right ("typechecked", unlines $ e: "tooltips:": [showRange (b, e) ++ " " ++ m | (b, e, m) <- nub{-temporal; TODO: fail in case of duplicate items-} i, sourceName b == fname]) | 104 | Right (fname, Left e, i) -> Right ("typechecked", unlines $ e: "tooltips:": [showRange (b, e) ++ " " ++ m | (b, e, m) <- nub{-temporal; TODO: fail in case of duplicate items-} i, sourceName b == fname]) |
95 | Right (fname, Right e, i) | 105 | Right (fname, Right e, i) |
@@ -101,23 +111,24 @@ acceptTests reject = testFrame reject [acceptPath, rejectPath] $ \case | |||
101 | | otherwise -> Right ("reduced main " ++ ppShow (tyOf e), ppShow e) | 111 | | otherwise -> Right ("reduced main " ++ ppShow (tyOf e), ppShow e) |
102 | -- | otherwise -> Right ("System-F main ", ppShow . toCore mempty $ e) | 112 | -- | otherwise -> Right ("System-F main ", ppShow . toCore mempty $ e) |
103 | 113 | ||
104 | rejectTests reject = testFrame reject [rejectPath, acceptPath] $ \case | 114 | rejectTests timeout reject = testFrame timeout reject [".",testDataPath] $ \case |
105 | Left e -> Right ("error message", e) | 115 | Left e -> Right ("error message", e) |
106 | Right _ -> Left "failed to catch error" | 116 | Right _ -> Left "failed to catch error" |
107 | 117 | ||
108 | runMM' = fmap (either (error "impossible") id . fst) . runMM (ioFetch []) | 118 | runMM' = fmap (either (error "impossible") id . fst) . runMM (ioFetch []) |
109 | 119 | ||
110 | testFrame :: Bool -> [FilePath] -> (Either String (FilePath, Either String Exp, Infos) -> Either String (String, String)) -> [String] -> MMT IO [(Res, String)] | 120 | testFrame :: Int -> Bool -> [FilePath] -> (Either String (FilePath, Either String Exp, Infos) -> Either String (String, String)) -> [String] -> MMT IO [(Res, String)] |
111 | testFrame reject dirs f tests | 121 | testFrame timeout reject dirs f tests |
112 | = local (const $ ioFetch dirs') | 122 | = local (const $ ioFetch dirs') |
113 | $ testFrame_ | 123 | $ testFrame_ |
124 | timeout | ||
114 | (if reject then alwaysReject else compareResult) | 125 | (if reject then alwaysReject else compareResult) |
115 | (head dirs') | 126 | (head dirs') |
116 | (\n -> f <$> (Right <$> getDef n "main" Nothing) `catchMM` (return . Left . show)) | 127 | (\n -> f <$> (Right <$> getDef n "main" Nothing) `catchMM` (return . Left . show)) |
117 | tests | 128 | tests |
118 | where | 129 | where |
119 | dirs_ = [takeDirectory f | f <- tests, takeFileName f /= f] | 130 | dirs_ = [takeDirectory f | f <- tests, takeFileName f /= f] |
120 | dirs' = if null dirs_ then dirs else dirs_ | 131 | dirs' = dirs ++ dirs_ -- if null dirs_ then dirs else dirs_ |
121 | 132 | ||
122 | 133 | ||
123 | timeOut :: Int -> a -> MM a -> MM a | 134 | timeOut :: Int -> a -> MM a -> MM a |
@@ -128,7 +139,7 @@ timeOut n d = mapMMT $ \m -> | |||
128 | where | 139 | where |
129 | race' a b = either id id <$> race a b | 140 | race' a b = either id id <$> race a b |
130 | 141 | ||
131 | testFrame_ compareResult path action tests = fmap concat $ forM (zip [1..] (tests :: [String])) $ \(i, n) -> do | 142 | testFrame_ timeout compareResult path action tests = fmap concat $ forM (zip [1..] (tests :: [String])) $ \(i, n) -> do |
132 | let er e = do | 143 | let er e = do |
133 | liftIO $ putStrLn $ "\n!Crashed " ++ n ++ "\n" ++ tab e | 144 | liftIO $ putStrLn $ "\n!Crashed " ++ n ++ "\n" ++ tab e |
134 | return [(ErrorCatched, n)] | 145 | return [(ErrorCatched, n)] |