2020-06-09 15:21:29 +02:00
|
|
|
{-# LANGUAGE NamedFieldPuns #-}
|
|
|
|
module Utils (
|
|
|
|
assertAll
|
|
|
|
, assertEqual
|
|
|
|
, simpleTest
|
|
|
|
, tag
|
2020-10-23 15:39:49 +02:00
|
|
|
, testDataPath
|
2020-06-09 15:21:29 +02:00
|
|
|
) where
|
|
|
|
|
|
|
|
import Distribution.TestSuite
|
2020-10-23 15:39:49 +02:00
|
|
|
import System.FilePath ((</>))
|
2020-06-09 15:21:29 +02:00
|
|
|
import Text.Printf (printf)
|
|
|
|
|
|
|
|
tagInstance :: String -> TestInstance -> TestInstance
|
|
|
|
tagInstance tagName testInstance = testInstance {
|
|
|
|
tags = tagName : (tags testInstance)
|
|
|
|
}
|
|
|
|
|
|
|
|
tag :: String -> Test -> Test
|
|
|
|
tag tagName (Test testInstance) = Test (tagInstance tagName testInstance)
|
|
|
|
tag tagName group = group {groupTests = tag tagName <$> groupTests group}
|
|
|
|
|
|
|
|
simpleTest :: (String, IO Progress) -> Test
|
|
|
|
simpleTest (name, run) = Test testInstance
|
|
|
|
where
|
|
|
|
testInstance = TestInstance {
|
|
|
|
run
|
|
|
|
, name
|
|
|
|
, tags = []
|
|
|
|
, options = []
|
|
|
|
, setOption = \_ _ -> Right testInstance
|
|
|
|
}
|
|
|
|
|
|
|
|
wrong :: Show a => String -> a -> a -> IO Progress
|
|
|
|
wrong message expected actual = return . Finished . Fail $
|
|
|
|
printf "%s: %s vs. %s" message (show expected) (show actual)
|
|
|
|
|
|
|
|
assertAll :: [(Bool, IO Progress, String)] -> IO Progress
|
|
|
|
assertAll = foldr assert (return $ Finished Pass)
|
|
|
|
where
|
|
|
|
assert (bool, badIssue, checkMessage) next =
|
|
|
|
if bool then return $ Progress checkMessage next else badIssue
|
|
|
|
|
|
|
|
assertEqual :: (Show a, Eq a) => String -> a -> a -> (Bool, IO Progress, String)
|
|
|
|
assertEqual what a b =
|
|
|
|
(a == b, wrong (what ++ " do not match !") a b, what ++ " ok")
|
|
|
|
|
2020-10-23 15:39:49 +02:00
|
|
|
testDataPath :: FilePath -> FilePath
|
|
|
|
testDataPath = ("test" </>)
|