Created
April 21, 2018 05:10
-
-
Save nskeip/f7e91cb4379d3c15873c65edfc3af637 to your computer and use it in GitHub Desktop.
Green OKs and red FAILs test helper :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
module Main where | |
import Lib | |
import GHC.List (take) | |
import Data.Text as T | |
import System.Console.ANSI | |
import System.Exit (exitFailure) | |
assert :: String -> Bool -> IO Bool | |
assert | |
testTitle | |
test = | |
do | |
let printColorfulResult txt col = do | |
putStr "[" | |
setSGR [SetColor Foreground Vivid col] | |
putStr txt | |
setSGR [Reset] | |
putStr "] " | |
if test | |
then printColorfulResult " OK " Green | |
else printColorfulResult "FAIL" Red | |
putStrLn testTitle | |
return test | |
main :: IO () | |
main = do | |
putStrLn "" | |
putStrLn "------------------------------" | |
putStrLn "Running tests now..." | |
result <- | |
sequence [ | |
(assert "Success example" True), | |
(assert "Fail example" False) | |
] | |
putStrLn "------------------------------" | |
if and $ result | |
then putStrLn "Success!" | |
else exitFailure |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment