module SystemTest.Main where
import Control.Monad (zipWithM_)
import Data.Aeson
import Data.Text()
import qualified Data.ByteString.Lazy as B (readFile)
import System.Console.ANSI
import System.Environment (getArgs)
import System.Exit (exitFailure, exitSuccess)
import SystemTest.Test
progMain :: IO ()
progMain = do
args <- getArgs
_ <- mapM testFile args
return ()
testFile :: String -> IO ()
testFile file = do
let contents = B.readFile file
parsed <- (eitherDecode <$> contents) :: IO (Either String [Test])
case parsed of
Left err -> do
putStrLn ("Unable to parse test definition file `" ++ file ++ "`:\n")
putStrLn err
exitFailure
Right tests -> do
results <- mapM runTest tests
zipWithM_ printResults tests results
let total = Prelude.length results
let failures = Prelude.length $ Prelude.filter (\ (x, _) -> not x) results
endProgram failures total
printResults :: Test -> TestResults -> IO ()
printResults test results = do
case results of
(True, _) -> setSGR [SetColor Foreground Dull Green]
(False, _) -> setSGR [SetColor Foreground Dull Red]
putStrLn $ showResults test results
setSGR [Reset]
endProgram :: Int -> Int -> IO ()
endProgram failures total = case failures of
0 -> do
putStrLn "\nAll tests passed"
exitSuccess
_ -> do
putStrLn ("\n" ++ show failures ++ " / " ++ show total ++ " tests failed")
exitFailure