Commit b5f546b6 authored by Camil Staps's avatar Camil Staps 🚀

Use @property-test-with on module level; test macros

parent 22e94fd3
Cloogle @ 6987d49d
Subproject commit f7c26a577fe7994912b67e9f38132fe024b7f8e2
Subproject commit 6987d49de50bdef8d5ec4e3df04a90210d88903d
......@@ -40,13 +40,13 @@ Start w
# opts = fromOk opts
| any ((==) "") [opts.Options.name, opts.input, opts.output]
= exit ("Usage: " +++ prog +++ " -n NAME -i FILE -o FILE") w
# (funs,_,_,_,_,_,_,_,(_,mod,_),w) = findModuleContents False (dropExtension opts.input) w
# (funs,macros,_,_,_,_,_,_,(_,mod,_),w) = findModuleContents False (dropExtension opts.input) w
# props = generatePropertyModule
opts.Options.name
opts.print_options
opts.test_options
mod
[f \\ (_,f,_) <- funs]
[f \\ (_,f,_) <- funs ++ macros]
# (ok,w) = writeFile opts.output props w
| isError ok = exit (fromError ok <+ " " +++ opts.output) w
= w
......@@ -92,10 +92,11 @@ generatePropertyModule name print_options test_options me fes = join "\n\n"
: [gp.gp_implementation \\ gp <- props]
]
where
props = concatMap generateProperties fes
props = concatMap (generateProperties pvis) fes
where pvis = fromMaybe [] $ docPropertyTestWith <$> me.me_documentation
bootstrap = case me.me_documentation of
Just d -> fromMaybe "" $ fromMultiLine <$> d.property_bootstrap
Just d -> fromMaybe "" $ docPropertyBootstrap d
Nothing -> ""
start = join "\n\t"
......@@ -111,11 +112,12 @@ where
, gp_implementation :: !String
}
generateProperties :: !FunctionEntry -> [GeneratedProperty]
generateProperties fe=:{fe_documentation=Just doc} =
[gen p config
generateProperties :: ![PropertyVarInstantiation] !FunctionEntry -> [GeneratedProperty]
generateProperties pvis fe=:{fe_documentation=Just doc} =
[gen i p config
\\ p <- doc.properties
, config <- configurations $ groupInstantiations doc.property_test_with]
, config <- configurations $ groupInstantiations $ pvis ++ docPropertyTestWith doc
& i <- [1..]]
where
groupInstantiations :: [PropertyVarInstantiation] -> [[(String,Type)]]
groupInstantiations pvis = groupBy ((==) `on` fst) $ sortBy ((<) `on` fst) [vi \\ PropertyVarInstantiation vi <- pvis]
......@@ -124,8 +126,8 @@ where
configurations [vis:viss] = [[vi`:vis`] \\ vi` <- vis, vis` <- configurations viss]
configurations [] = [[]]
gen :: !Property ![(String,Type)] -> GeneratedProperty
gen (ForAll name ts imp) vis =
gen :: !Int !Property ![(String,Type)] -> GeneratedProperty
gen i (ForAll name ts imp) vis =
{ gp_name = name`
, gp_implementation = join "\n"
[ name` +++ " :: " +++ toString type
......@@ -133,6 +135,6 @@ where
]
}
where
name` = "prop_" +++ name
name` = if (i == 1) name (name +++ "_" +++ toString i)
type = fromJust $ assignAll vis $ Func (map snd ts) (Type "Property" []) []
generateProperties _ = []
generateProperties _ _ = []
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment