-- Tests to check Curry modules with ReadWrite instances generated by the tool. import Test.Prop import System.Process ( system ) testGenTypeIO :: PropIO testGenTypeIO = testEx "TypeIO.Defs" "TypeIO/DefsRW.curry" "DefsRW.curry" `returns` True testGenHandle :: PropIO testGenHandle = testEx "Handle.MyData" "Handle/MyDataRW.curry" "MyDataRW.curry" `returns` True testGenPeano :: PropIO testGenPeano = testEx "Peano.Peano" "Peano/PeanoRW.curry" "PeanoRW.curry" `returns` True testGenFlatCurry :: PropIO testGenFlatCurry = testEx "MyFlatCurry.Types" "MyFlatCurry/TypesRW.curry" "TypesRW.curry" `returns` True testGenNewType :: PropIO testGenNewType = testEx "Various.Newtypes" "Various/NewtypesRW.curry" "NewtypesRW.curry" `returns` True testGenManyCons :: PropIO testGenManyCons = testEx "Various.ManyCons" "Various/ManyConsRW.curry" "ManyConsRW.curry" `returns` True testGenFunctions :: PropIO testGenFunctions = testEx "Various.Functions" "Various/FunctionsRW.curry" "FunctionsRW.curry" `returns` True -- Generate RW instances for a given module, compares it to an existing one (second arg.), -- and remove the generated file (third arg.) after the comparison. testEx :: String -> String -> String -> IO Bool testEx mname f1 f2 = do system $ "curry-rw-data -d . " ++ mname c1 <- readFile f1 c2 <- readFile f2 let cmp = c1 == c2 cmp `seq` (system ("rm -f " ++ f2) >> return cmp)