Skip to content

Instantly share code, notes, and snippets.

@thsutton
Created May 26, 2015 01:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thsutton/844401f11d742265dd3e to your computer and use it in GitHub Desktop.
Save thsutton/844401f11d742265dd3e to your computer and use it in GitHub Desktop.
Invoke GHC to check that files compile in a cabal test suite
module Main where
import System.Exit
import System.Process
main :: IO ()
main = do
(c1, o1, e1) <- readProcessWithExitCode "ghc" ["-ilib", "-o", "/tmp/failure", "test/fail.hs"] ""
(c2, o2, e2) <- readProcessWithExitCode "ghc" ["-ilib", "-o", "/tmp/passure", "test/pass.hs"] ""
case (c1, c2) of
(ExitFailure _, ExitSuccess ) -> exitSuccess
(ExitSuccess , ExitSuccess ) -> putStrLn "Fail did not fail" >> exitFailure
(ExitSuccess , ExitFailure _) -> putStrLn "Pass did not pass" >> putStrLn "Fail did not fail" >> exitFailure
(ExitFailure _, ExitFailure _) -> putStrLn "Pass did not pass" >> exitFailure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment