quox/tests/Options.idr

44 lines
1,003 B
Idris

module Options
import Data.String
import System
import System.Console.GetOpt
public export
record Options where
constructor Opts
tapVersion : String
defaultOpts = Opts {tapVersion = "13"}
OptMod = Options -> Options
opts : List (OptDescr OptMod)
opts = [
MkOpt ['V'] ["version"]
(ReqArg (\v => the OptMod {tapVersion := v}) "VERSION")
"TAP version to output (13 or 14, default 13)"
]
-- [todo] get rid of "the OptMod" when type inference is better, maybe
makeOpts : List OptMod -> Options
makeOpts = foldl (flip ($)) defaultOpts
getArgs1 : IO (List String)
getArgs1 =
case !getArgs of
_ :: args => pure args
[] => do
putStrLn "expecting getArgs to start with exe name"
exitFailure
export
getTestOpts : IO Options
getTestOpts =
case getOpt Permute opts !getArgs1 of
MkResult opts [] [] [] => pure $ makeOpts opts
res => do
traverse_ putStrLn $ res.errors ++ [usageInfo "quox test suite" opts]
exitFailure