moduleTest.Hspec.Options(Options(..),ColorMode(..),defaultOptions,parseOptions-- exported to silence warnings,Arg(..))whereimportData.ListimportSystem.ExitimportSystem.Console.GetOptimportTest.Hspec.FormattersimportTest.Hspec.Util-- for Monad (Either e) when base < 4.3importControl.Monad.Trans.Error()dataOptions=Options{optionsDryRun::Bool,optionsPrintCpuTime::Bool,optionsRerun::Bool,optionsFastFail::Bool,optionsMatch::[String],optionsMaxSuccess::MaybeInt,optionsDepth::MaybeInt,optionsSeed::MaybeInteger,optionsMaxSize::MaybeInt,optionsMaxDiscardRatio::MaybeInt,optionsColorMode::ColorMode,optionsFormatter::Formatter,optionsHtmlOutput::Bool,optionsOutputFile::MaybeFilePath}addMatch::String->Options->OptionsaddMatchsc=c{optionsMatch=s:optionsMatchc}setDepth::Int->Options->OptionssetDepthnc=c{optionsDepth=Justn}setMaxSuccess::Int->Options->OptionssetMaxSuccessnc=c{optionsMaxSuccess=Justn}setMaxSize::Int->Options->OptionssetMaxSizenc=c{optionsMaxSize=Justn}setMaxDiscardRatio::Int->Options->OptionssetMaxDiscardRationc=c{optionsMaxDiscardRatio=Justn}setSeed::Integer->Options->OptionssetSeednc=c{optionsSeed=Justn}dataColorMode=ColorAuto|ColorNever|ColorAlwaysderiving(Eq,Show)defaultOptions::OptionsdefaultOptions=OptionsFalseFalseFalseFalse[]NothingNothingNothingNothingNothingColorAutospecdocFalseNothingformatters::[(String,Formatter)]formatters=[("specdoc",specdoc),("progress",progress),("failed-examples",failed_examples),("silent",silent)]formatHelp::StringformatHelp=unlines(addLineBreaks"use a custom formatter; this can be one of:"++map((" "++).fst)formatters)typeResult=EitherNoConfigOptionsdataNoConfig=Help|InvalidArgumentStringStringdataArga=Arg{argumentName::String,argumentParser::String->Maybea,argumentSetter::a->Options->Options}mkOption::[Char]->String->Arga->String->OptDescr(Result->Result)mkOptionshortcutname(ArgargNameparsersetter)help=Optionshortcut[name](ReqArgargargName)helpwherearg::String->Result->Resultarginputx=x>>=\c->caseparserinputofJustn->Right(setternc)Nothing->Left(InvalidArgumentnameinput)addLineBreaks::String->[String]addLineBreaks=lineBreaksAt44options::[OptDescr(Result->Result)]options=[Option[]["help"](NoArg(const$LeftHelp))(h"display this help and exit"),mkOption"m""match"(Arg"PATTERN"returnaddMatch)(h"only run examples that match given PATTERN"),Option[]["color"](NoArgsetColor)(h"colorize the output"),Option[]["no-color"](NoArgsetNoColor)(h"do not colorize the output"),mkOption"f""format"(Arg"FORMATTER"readFormattersetFormatter)formatHelp,mkOption"o""out"(Arg"FILE"returnsetOutputFile)(h"write output to a file instead of STDOUT"),mkOption[]"depth"(Arg"N"readMaybesetDepth)(h"maximum depth of generated test values for SmallCheck properties"),mkOption"a""qc-max-success"(Arg"N"readMaybesetMaxSuccess)(h"maximum number of successful tests before a QuickCheck property succeeds"),mkOption"""qc-max-size"(Arg"N"readMaybesetMaxSize)(h"size to use for the biggest test cases"),mkOption"""qc-max-discard"(Arg"N"readMaybesetMaxDiscardRatio)(h"maximum number of discarded tests per successful test before giving up"),mkOption[]"seed"(Arg"N"readMaybesetSeed)(h"used seed for QuickCheck properties"),Option[]["print-cpu-time"](NoArgsetPrintCpuTime)(h"include used CPU time in summary"),Option[]["dry-run"](NoArgsetDryRun)(h"pretend that everything passed; don't verify anything"),Option[]["fail-fast"](NoArgsetFastFail)(h"abort on first failure"),Option"r"["rerun"](NoArgsetRerun)(h"rerun all examples that failed in the previously test run (only works in GHCi)")]whereh=unlines.addLineBreaksreadFormatter::String->MaybeFormatterreadFormatter=(`lookup`formatters)setFormatter::Formatter->Options->OptionssetFormatterfc=c{optionsFormatter=f}setOutputFile::String->Options->OptionssetOutputFilefilec=c{optionsOutputFile=Justfile}setPrintCpuTimex=x>>=\c->returnc{optionsPrintCpuTime=True}setDryRunx=x>>=\c->returnc{optionsDryRun=True}setFastFailx=x>>=\c->returnc{optionsFastFail=True}setRerunx=x>>=\c->returnc{optionsRerun=True}setNoColorx=x>>=\c->returnc{optionsColorMode=ColorNever}setColorx=x>>=\c->returnc{optionsColorMode=ColorAlways}undocumentedOptions::[OptDescr(Result->Result)]undocumentedOptions=[-- for compatibility with test-frameworkmkOption[]"maximum-generated-tests"(Arg"NUMBER"readMaybesetMaxSuccess)"how many automated tests something like QuickCheck should try, by default"-- undocumented for now, as we probably want to change this to produce a-- standalone HTML report in the future,Option[]["html"](NoArgsetHtml)"produce HTML output"-- now a noop,Option"v"["verbose"](NoArgid)"do not suppress output to stdout when evaluating examples"]wheresetHtml::Result->ResultsetHtmlx=x>>=\c->returnc{optionsHtmlOutput=True}parseOptions::Options->String->[String]->Either(ExitCode,String)OptionsparseOptionscprogargs=casegetOptPermute(options++undocumentedOptions)argsof(opts,[],[])->casefoldl'(flipid)(Rightc)optsofLeftHelp->Left(ExitSuccess,usageInfo("Usage: "++prog++" [OPTION]...\n\nOPTIONS")options)Left(InvalidArgumentflagvalue)->tryHelp("invalid argument `"++value++"' for `--"++flag++"'\n")Rightx->Rightx(_,_,err:_)->tryHelperr(_,arg:_,_)->tryHelp("unexpected argument `"++arg++"'\n")wheretryHelpmsg=Left(ExitFailure1,prog++": "++msg++"Try `"++prog++" --help' for more information.\n")