0 | module Hedgehog.Internal.Options
3 | import Decidable.Equality
4 | import Hedgehog.Internal.Property
5 | import System.GetOpts
10 | data NumTest = Relaxed TestLimit | Forced TestLimit
14 | constructor MkConfig
16 | numTests : Maybe NumTest
17 | numShrinks : Maybe ShrinkLimit
18 | confidence : Maybe Confidence
22 | init = MkConfig False Nothing Nothing Nothing
24 | parseNat : String -> Either (List String) Nat
26 | maybe (Left [#"Not a natural number: \#{s}"#]) Right $
parsePositive s
28 | toConfidence : Nat -> Either (List String) Confidence
30 | let c := cast {to = Bits64} n
31 | in case decEq (c >= 2) True of
32 | (Yes prf) => Right $
MkConfidence c prf
33 | (No contra) => Left [ #"Not a valid confidence value: \#{show n}"# ]
35 | setTests : String -> Config -> Either (List String) Config
38 | (\n => { numTests := Just $
Relaxed $
MkTagged n} c)
41 | setShrinks : String -> Config -> Either (List String) Config
44 | (\n => { numShrinks := Just $
MkTagged n} c)
47 | setConfidence : String -> Config -> Either (List String) Config
50 | (\n => { confidence := Just n} c)
51 | (parseNat s >>= toConfidence)
53 | setTestsForced : String -> Config -> Either (List String) Config
54 | setTestsForced s c =
56 | (\n => { numTests := Just $
Forced $
MkTagged n} c)
59 | setHelp : Config -> Either (List String) Config
60 | setHelp = Right . { printHelp := True }
62 | descs : List $
OptDescr (Config -> Either (List String) Config)
64 | [ MkOpt ['n'] ["testlimit"] (ReqArg setTests "<tests>")
65 | "number of tests to be passed by each property"
66 | , MkOpt ['N'] ["testlimit!"] (ReqArg setTestsForced "<tests>")
67 | "like -n but includes tests that are only run once"
68 | , MkOpt ['s'] ["shrinklimit"] (ReqArg setShrinks "<shrinks>")
69 | "maximal number of shrinks in case of a failed test"
70 | , MkOpt ['c'] ["confidence"] (ReqArg setConfidence "<confidence>")
71 | "acceptable occurence of false positives"
72 | , MkOpt [] ["--help"] (NoArg setHelp)
73 | "print this help text"
78 | info = usageInfo "Hedgehog command line args:\n" descs
81 | applyArgs : List String -> Either (List String) Config
83 | case getOpt Permute descs args of
84 | MkResult opts _ _ [] => foldl (>>=) (Right init) opts
85 | MkResult _ _ _ e => Left e
88 | applyConfig : Config -> Group -> Group
89 | applyConfig (MkConfig _ nt ns c) =
90 | maybe id adjTests nt . maybe id withShrinks ns . maybe id withConfidence c
93 | adjPropTests : NumTest -> Property -> Property
94 | adjPropTests (Forced x) = withTests x
95 | adjPropTests (Relaxed x) = mapTests $
\n => if n > 1 then x else n
97 | adjTests : NumTest -> Group -> Group
98 | adjTests = mapProperty . adjPropTests