42 lines
1.2 KiB
Haskell
42 lines
1.2 KiB
Haskell
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)
|
|
]
|