Last active
December 31, 2015 22:59
-
-
Save margnus1/8057084 to your computer and use it in GitHub Desktop.
GHC port of QuickCheck script
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
-- | |
-- 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