summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCsaba Hruska <csaba.hruska@gmail.com>2016-01-19 16:10:26 +0100
committerCsaba Hruska <csaba.hruska@gmail.com>2016-01-19 16:10:49 +0100
commit03c8e879558f8e16e49b21d493a82ba9657f7d13 (patch)
tree5debb486051a4c975e0f48e3dac2c500009064bf
parentcb69693769ebfcdac605c90f38a20c788b08eaf3 (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.hs57
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
30instance NFData SourcePos where 30instance NFData SourcePos where
31 rnf _ = () 31 rnf _ = ()
32 32
33acceptPath = "./testdata/accept" 33testDataPath = "./testdata"
34rejectPath = "./testdata/reject"
35timeout = 15 {- in seconds -}
36 34
37data Res = Accepted | New | Rejected | Failed | ErrorCatched 35data Res = Accepted | New | Rejected | Failed | ErrorCatched
38 deriving (Eq, Ord, Show) 36 deriving (Eq, Ord, Show)
@@ -42,34 +40,46 @@ erroneous = (>= Rejected)
42instance NFData Res where 40instance NFData Res where
43 rnf a = a `seq` () 41 rnf a = a `seq` ()
44 42
45optionArgs = ["-v", "-r"] 43optionArgs = ["-v", "-r","-notimeout"]
44
45getDirectoryContentsRecursive 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
47main :: IO () 53main :: IO ()
48main = do 54main = 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
92acceptTests reject = testFrame reject [acceptPath, rejectPath] $ \case 102acceptTests 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
104rejectTests reject = testFrame reject [rejectPath, acceptPath] $ \case 114rejectTests 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
108runMM' = fmap (either (error "impossible") id . fst) . runMM (ioFetch []) 118runMM' = fmap (either (error "impossible") id . fst) . runMM (ioFetch [])
109 119
110testFrame :: Bool -> [FilePath] -> (Either String (FilePath, Either String Exp, Infos) -> Either String (String, String)) -> [String] -> MMT IO [(Res, String)] 120testFrame :: Int -> Bool -> [FilePath] -> (Either String (FilePath, Either String Exp, Infos) -> Either String (String, String)) -> [String] -> MMT IO [(Res, String)]
111testFrame reject dirs f tests 121testFrame 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
123timeOut :: Int -> a -> MM a -> MM a 134timeOut :: 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
131testFrame_ compareResult path action tests = fmap concat $ forM (zip [1..] (tests :: [String])) $ \(i, n) -> do 142testFrame_ 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)]