quox/tests/Options.idr
rhiannon morris e3384d4e6e support TAP 13 for /usr/bin/prove's benefit
13 doesn't support test trees so we gotta flatten it >:(
2022-05-02 00:21:35 +02:00

40 lines
927 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
[] => die "expecting getArgs to start with exe name"
export
getTestOpts : IO Options
getTestOpts =
case getOpt Permute opts !getArgs1 of
MkResult opts [] [] [] => pure $ makeOpts opts
res => die $ unlines $ res.errors ++ [usageInfo "quox test suite" opts]