Skip to content

Instantly share code, notes, and snippets.

@margnus1
Last active December 31, 2015 22:59
Show Gist options
  • Save margnus1/8057084 to your computer and use it in GitHub Desktop.
Save margnus1/8057084 to your computer and use it in GitHub Desktop.
GHC port of QuickCheck script
--
-- This file defines a command
-- quickCheck <options> <files>
-- which invokes quickCheck on all properties defined in the files given as
-- arguments, by generating an input script for ghci and then piping it in.
--
import Data.List
import System.Environment (getArgs)
import System.Process
import System.IO
main :: IO ()
main = do as<-getArgs
sequence_ (map (process (filter isOption as))
(filter (not.isOption) as))
process opts file =
do xs<-readFile file
let names = nub$ filter ("prop_" `isPrefixOf`)
(map (fst.head.lex) (lines xs))
if null names then
putStr (file++": no properties to check\n")
else do (Just hStdIn, _, _, pHandle) <-
createProcess (proc "ghci " ("-v0":opts)){std_in = CreatePipe }
hPutStr hStdIn$
unlines ((":l "++file):
["putStr \""++p++": \" >> quickCheck "++p | p<-names])
hPutChar hStdIn '\n'
hClose hStdIn
waitForProcess pHandle
return ()
isOption xs = head xs `elem` "-+"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment