SJW/test/Tests.hs

43 lines
1.2 KiB
Haskell
Raw Permalink Normal View History

2020-12-08 12:06:19 +01:00
module Tests (
tests
) where
import Distribution.TestSuite
import SJW (compile, source)
import System.FilePath ((</>))
import Text.Printf (printf)
testData :: FilePath
testData = "test" </> "data"
checkResult :: (String, Bool) -> IO Progress
checkResult (dirName, expected) = do
result <- either failed passed =<< compile (source [testData </> dirName])
return . Finished $ if result == expected then Pass else Fail (explain message)
where
failed s = putStrLn s>> return False
passed _ = return True
explain = uncurry (printf "Compilation %sed when it was expected to %s")
message = if expected then ("fail", "succeed") else ("succeed", "fail")
makeTest :: (String, Bool) -> TestInstance
makeTest (patternName, expected) = testInstance
where
testInstance = TestInstance {
run = checkResult (patternName, expected)
, name = patternName
, tags = []
, options = []
, setOption = \_ _ -> Right testInstance
}
tests :: IO [Test]
tests = return $ (Test . makeTest) <$> [
("cycle", False)
, ("diamond", True)
, ("loop", False)
, ("q", False)
, ("simple", True)
, ("triangle", True)
]