{-# LANGUAGE CPP #-}
module Test.Hspec.Core.Config.Definition (
Config(..)
, ColorMode(..)
, filterOr
, defaultConfig
, commandLineOnlyOptions
, formatterOptions
, smallCheckOptions
, quickCheckOptions
, runnerOptions
#ifdef TEST
, formatOrList
#endif
) where
import Prelude ()
import Test.Hspec.Core.Compat
import Test.Hspec.Core.Example (Params(..), defaultParams)
import Test.Hspec.Core.Format (Format, FormatConfig)
import qualified Test.Hspec.Core.Formatters.V1 as V1
import qualified Test.Hspec.Core.Formatters.V2 as V2
import Test.Hspec.Core.Util
import GetOpt.Declarative
data ColorMode = ColorAuto | ColorNever | ColorAlways
deriving (ColorMode -> ColorMode -> Bool
(ColorMode -> ColorMode -> Bool)
-> (ColorMode -> ColorMode -> Bool) -> Eq ColorMode
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ColorMode -> ColorMode -> Bool
$c/= :: ColorMode -> ColorMode -> Bool
== :: ColorMode -> ColorMode -> Bool
$c== :: ColorMode -> ColorMode -> Bool
Eq, Int -> ColorMode -> ShowS
[ColorMode] -> ShowS
ColorMode -> String
(Int -> ColorMode -> ShowS)
-> (ColorMode -> String)
-> ([ColorMode] -> ShowS)
-> Show ColorMode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ColorMode] -> ShowS
$cshowList :: [ColorMode] -> ShowS
show :: ColorMode -> String
$cshow :: ColorMode -> String
showsPrec :: Int -> ColorMode -> ShowS
$cshowsPrec :: Int -> ColorMode -> ShowS
Show)
data Config = Config {
Config -> Bool
configIgnoreConfigFile :: Bool
, Config -> Bool
configDryRun :: Bool
, Config -> Bool
configFocusedOnly :: Bool
, Config -> Bool
configFailOnFocused :: Bool
, Config -> Maybe Int
configPrintSlowItems :: Maybe Int
, Config -> Bool
configPrintCpuTime :: Bool
, Config -> Bool
configFastFail :: Bool
, Config -> Bool
configRandomize :: Bool
, Config -> Maybe String
configFailureReport :: Maybe FilePath
, Config -> Bool
configRerun :: Bool
, Config -> Bool
configRerunAllOnSuccess :: Bool
, Config -> Maybe (Path -> Bool)
configFilterPredicate :: Maybe (Path -> Bool)
, Config -> Maybe (Path -> Bool)
configSkipPredicate :: Maybe (Path -> Bool)
, Config -> Maybe Integer
configQuickCheckSeed :: Maybe Integer
, Config -> Maybe Int
configQuickCheckMaxSuccess :: Maybe Int
, Config -> Maybe Int
configQuickCheckMaxDiscardRatio :: Maybe Int
, Config -> Maybe Int
configQuickCheckMaxSize :: Maybe Int
, Config -> Maybe Int
configQuickCheckMaxShrinks :: Maybe Int
, Config -> Int
configSmallCheckDepth :: Int
, Config -> ColorMode
configColorMode :: ColorMode
, Config -> Bool
configDiff :: Bool
, Config -> Bool
configTimes :: Bool
, Config -> Maybe (FormatConfig -> IO Format)
configFormat :: Maybe (FormatConfig -> IO Format)
, Config -> Maybe Formatter
configFormatter :: Maybe V1.Formatter
, Config -> Bool
configHtmlOutput :: Bool
, Config -> Maybe Int
configConcurrentJobs :: Maybe Int
}
defaultConfig :: Config
defaultConfig :: Config
defaultConfig = Config :: Bool
-> Bool
-> Bool
-> Bool
-> Maybe Int
-> Bool
-> Bool
-> Bool
-> Maybe String
-> Bool
-> Bool
-> Maybe (Path -> Bool)
-> Maybe (Path -> Bool)
-> Maybe Integer
-> Maybe Int
-> Maybe Int
-> Maybe Int
-> Maybe Int
-> Int
-> ColorMode
-> Bool
-> Bool
-> Maybe (FormatConfig -> IO Format)
-> Maybe Formatter
-> Bool
-> Maybe Int
-> Config
Config {
configIgnoreConfigFile :: Bool
configIgnoreConfigFile = Bool
False
, configDryRun :: Bool
configDryRun = Bool
False
, configFocusedOnly :: Bool
configFocusedOnly = Bool
False
, configFailOnFocused :: Bool
configFailOnFocused = Bool
False
, configPrintSlowItems :: Maybe Int
configPrintSlowItems = Maybe Int
forall a. Maybe a
Nothing
, configPrintCpuTime :: Bool
configPrintCpuTime = Bool
False
, configFastFail :: Bool
configFastFail = Bool
False
, configRandomize :: Bool
configRandomize = Bool
False
, configFailureReport :: Maybe String
configFailureReport = Maybe String
forall a. Maybe a
Nothing
, configRerun :: Bool
configRerun = Bool
False
, configRerunAllOnSuccess :: Bool
configRerunAllOnSuccess = Bool
False
, configFilterPredicate :: Maybe (Path -> Bool)
configFilterPredicate = Maybe (Path -> Bool)
forall a. Maybe a
Nothing
, configSkipPredicate :: Maybe (Path -> Bool)
configSkipPredicate = Maybe (Path -> Bool)
forall a. Maybe a
Nothing
, configQuickCheckSeed :: Maybe Integer
configQuickCheckSeed = Maybe Integer
forall a. Maybe a
Nothing
, configQuickCheckMaxSuccess :: Maybe Int
configQuickCheckMaxSuccess = Maybe Int
forall a. Maybe a
Nothing
, configQuickCheckMaxDiscardRatio :: Maybe Int
configQuickCheckMaxDiscardRatio = Maybe Int
forall a. Maybe a
Nothing
, configQuickCheckMaxSize :: Maybe Int
configQuickCheckMaxSize = Maybe Int
forall a. Maybe a
Nothing
, configQuickCheckMaxShrinks :: Maybe Int
configQuickCheckMaxShrinks = Maybe Int
forall a. Maybe a
Nothing
, configSmallCheckDepth :: Int
configSmallCheckDepth = Params -> Int
paramsSmallCheckDepth Params
defaultParams
, configColorMode :: ColorMode
configColorMode = ColorMode
ColorAuto
, configDiff :: Bool
configDiff = Bool
True
, configTimes :: Bool
configTimes = Bool
False
, configFormat :: Maybe (FormatConfig -> IO Format)
configFormat = Maybe (FormatConfig -> IO Format)
forall a. Maybe a
Nothing
, configFormatter :: Maybe Formatter
configFormatter = Maybe Formatter
forall a. Maybe a
Nothing
, configHtmlOutput :: Bool
configHtmlOutput = Bool
False
, configConcurrentJobs :: Maybe Int
configConcurrentJobs = Maybe Int
forall a. Maybe a
Nothing
}
option :: String -> OptionSetter config -> String -> Option config
option :: String -> OptionSetter config -> String -> Option config
option name :: String
name arg :: OptionSetter config
arg help :: String
help = String
-> Maybe Char
-> OptionSetter config
-> String
-> Bool
-> Option config
forall config.
String
-> Maybe Char
-> OptionSetter config
-> String
-> Bool
-> Option config
Option String
name Maybe Char
forall a. Maybe a
Nothing OptionSetter config
arg String
help Bool
True
mkFlag :: String -> (Bool -> Config -> Config) -> String -> Option Config
mkFlag :: String -> (Bool -> Config -> Config) -> String -> Option Config
mkFlag name :: String
name setter :: Bool -> Config -> Config
setter = String -> OptionSetter Config -> String -> Option Config
forall config.
String -> OptionSetter config -> String -> Option config
option String
name ((Bool -> Config -> Config) -> OptionSetter Config
forall config. (Bool -> config -> config) -> OptionSetter config
Flag Bool -> Config -> Config
setter)
mkOptionNoArg :: String -> Maybe Char -> (Config -> Config) -> String -> Option Config
mkOptionNoArg :: String
-> Maybe Char -> (Config -> Config) -> String -> Option Config
mkOptionNoArg name :: String
name shortcut :: Maybe Char
shortcut setter :: Config -> Config
setter help :: String
help = String
-> Maybe Char
-> OptionSetter Config
-> String
-> Bool
-> Option Config
forall config.
String
-> Maybe Char
-> OptionSetter config
-> String
-> Bool
-> Option config
Option String
name Maybe Char
shortcut ((Config -> Config) -> OptionSetter Config
forall config. (config -> config) -> OptionSetter config
NoArg Config -> Config
setter) String
help Bool
True
mkOption :: String -> Maybe Char -> OptionSetter Config -> String -> Option Config
mkOption :: String
-> Maybe Char -> OptionSetter Config -> String -> Option Config
mkOption name :: String
name shortcut :: Maybe Char
shortcut arg :: OptionSetter Config
arg help :: String
help = String
-> Maybe Char
-> OptionSetter Config
-> String
-> Bool
-> Option Config
forall config.
String
-> Maybe Char
-> OptionSetter config
-> String
-> Bool
-> Option config
Option String
name Maybe Char
shortcut OptionSetter Config
arg String
help Bool
True
undocumented :: Option config -> Option config
undocumented :: Option config -> Option config
undocumented opt :: Option config
opt = Option config
opt {optionDocumented :: Bool
optionDocumented = Bool
False}
argument :: String -> (String -> Maybe a) -> (a -> Config -> Config) -> OptionSetter Config
argument :: String
-> (String -> Maybe a)
-> (a -> Config -> Config)
-> OptionSetter Config
argument name :: String
name parser :: String -> Maybe a
parser setter :: a -> Config -> Config
setter = String -> (String -> Config -> Maybe Config) -> OptionSetter Config
forall config.
String -> (String -> config -> Maybe config) -> OptionSetter config
Arg String
name ((String -> Config -> Maybe Config) -> OptionSetter Config)
-> (String -> Config -> Maybe Config) -> OptionSetter Config
forall a b. (a -> b) -> a -> b
$ \ input :: String
input c :: Config
c -> (a -> Config -> Config) -> Config -> a -> Config
forall a b c. (a -> b -> c) -> b -> a -> c
flip a -> Config -> Config
setter Config
c (a -> Config) -> Maybe a -> Maybe Config
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> Maybe a
parser String
input
formatterOptions :: [Option Config]
formatterOptions :: [Option Config]
formatterOptions = [
String
-> Maybe Char -> OptionSetter Config -> String -> Option Config
mkOption "format" (Char -> Maybe Char
forall a. a -> Maybe a
Just 'f') (String
-> (String -> Maybe (FormatConfig -> IO Format))
-> ((FormatConfig -> IO Format) -> Config -> Config)
-> OptionSetter Config
forall a.
String
-> (String -> Maybe a)
-> (a -> Config -> Config)
-> OptionSetter Config
argument "FORMATTER" String -> Maybe (FormatConfig -> IO Format)
readFormatter (FormatConfig -> IO Format) -> Config -> Config
setFormatter) String
helpForFormat
, String -> (Bool -> Config -> Config) -> String -> Option Config
mkFlag "color" Bool -> Config -> Config
setColor "colorize the output"
, String -> (Bool -> Config -> Config) -> String -> Option Config
mkFlag "diff" Bool -> Config -> Config
setDiff "show colorized diffs"
, String -> (Bool -> Config -> Config) -> String -> Option Config
mkFlag "times" Bool -> Config -> Config
setTimes "report times for individual spec items"
, String
-> Maybe Char -> (Config -> Config) -> String -> Option Config
mkOptionNoArg "print-cpu-time" Maybe Char
forall a. Maybe a
Nothing Config -> Config
setPrintCpuTime "include used CPU time in summary"
, Option Config
printSlowItemsOption
, Option Config -> Option Config
forall config. Option config -> Option config
undocumented (Option Config -> Option Config) -> Option Config -> Option Config
forall a b. (a -> b) -> a -> b
$ String
-> Maybe Char -> (Config -> Config) -> String -> Option Config
mkOptionNoArg "html" Maybe Char
forall a. Maybe a
Nothing Config -> Config
setHtml "produce HTML output"
]
where
setHtml :: Config -> Config
setHtml config :: Config
config = Config
config {configHtmlOutput :: Bool
configHtmlOutput = Bool
True}
formatters :: [(String, FormatConfig -> IO Format)]
formatters :: [(String, FormatConfig -> IO Format)]
formatters = ((String, Formatter) -> (String, FormatConfig -> IO Format))
-> [(String, Formatter)] -> [(String, FormatConfig -> IO Format)]
forall a b. (a -> b) -> [a] -> [b]
map ((Formatter -> FormatConfig -> IO Format)
-> (String, Formatter) -> (String, FormatConfig -> IO Format)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Formatter -> FormatConfig -> IO Format
V2.formatterToFormat) [
("checks", Formatter
V2.checks)
, ("specdoc", Formatter
V2.specdoc)
, ("progress", Formatter
V2.progress)
, ("failed-examples", Formatter
V2.failed_examples)
, ("silent", Formatter
V2.silent)
]
helpForFormat :: String
helpForFormat :: String
helpForFormat = "use a custom formatter; this can be one of " String -> ShowS
forall a. [a] -> [a] -> [a]
++ ([String] -> String
formatOrList ([String] -> String) -> [String] -> String
forall a b. (a -> b) -> a -> b
$ ((String, FormatConfig -> IO Format) -> String)
-> [(String, FormatConfig -> IO Format)] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (String, FormatConfig -> IO Format) -> String
forall a b. (a, b) -> a
fst [(String, FormatConfig -> IO Format)]
formatters)
readFormatter :: String -> Maybe (FormatConfig -> IO Format)
readFormatter :: String -> Maybe (FormatConfig -> IO Format)
readFormatter = (String
-> [(String, FormatConfig -> IO Format)]
-> Maybe (FormatConfig -> IO Format)
forall a b. Eq a => a -> [(a, b)] -> Maybe b
`lookup` [(String, FormatConfig -> IO Format)]
formatters)
setFormatter :: (FormatConfig -> IO Format) -> Config -> Config
setFormatter :: (FormatConfig -> IO Format) -> Config -> Config
setFormatter f :: FormatConfig -> IO Format
f c :: Config
c = Config
c {configFormat :: Maybe (FormatConfig -> IO Format)
configFormat = (FormatConfig -> IO Format) -> Maybe (FormatConfig -> IO Format)
forall a. a -> Maybe a
Just FormatConfig -> IO Format
f}
setColor :: Bool -> Config -> Config
setColor :: Bool -> Config -> Config
setColor v :: Bool
v config :: Config
config = Config
config {configColorMode :: ColorMode
configColorMode = if Bool
v then ColorMode
ColorAlways else ColorMode
ColorNever}
setDiff :: Bool -> Config -> Config
setDiff :: Bool -> Config -> Config
setDiff v :: Bool
v config :: Config
config = Config
config {configDiff :: Bool
configDiff = Bool
v}
setTimes :: Bool -> Config -> Config
setTimes :: Bool -> Config -> Config
setTimes v :: Bool
v config :: Config
config = Config
config {configTimes :: Bool
configTimes = Bool
v}
setPrintCpuTime :: Config -> Config
setPrintCpuTime config :: Config
config = Config
config {configPrintCpuTime :: Bool
configPrintCpuTime = Bool
True}
printSlowItemsOption :: Option Config
printSlowItemsOption :: Option Config
printSlowItemsOption = String
-> Maybe Char
-> OptionSetter Config
-> String
-> Bool
-> Option Config
forall config.
String
-> Maybe Char
-> OptionSetter config
-> String
-> Bool
-> Option config
Option String
name (Char -> Maybe Char
forall a. a -> Maybe a
Just 'p') (String
-> (Maybe String -> Config -> Maybe Config) -> OptionSetter Config
forall config.
String
-> (Maybe String -> config -> Maybe config) -> OptionSetter config
OptArg "N" Maybe String -> Config -> Maybe Config
arg) "print the N slowest spec items (default: 10)" Bool
True
where
name :: String
name = "print-slow-items"
setter :: Maybe Int -> Config -> Config
setter :: Maybe Int -> Config -> Config
setter v :: Maybe Int
v c :: Config
c = Config
c {configPrintSlowItems :: Maybe Int
configPrintSlowItems = Maybe Int
v}
arg :: Maybe String -> Config -> Maybe Config
arg :: Maybe String -> Config -> Maybe Config
arg = (Config -> Maybe Config)
-> (String -> Config -> Maybe Config)
-> Maybe String
-> Config
-> Maybe Config
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Config -> Maybe Config
forall a. a -> Maybe a
Just (Config -> Maybe Config)
-> (Config -> Config) -> Config -> Maybe Config
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe Int -> Config -> Config
setter (Maybe Int -> Config -> Config) -> Maybe Int -> Config -> Config
forall a b. (a -> b) -> a -> b
$ Int -> Maybe Int
forall a. a -> Maybe a
Just 10)) String -> Config -> Maybe Config
parseArg
parseArg :: String -> Config -> Maybe Config
parseArg :: String -> Config -> Maybe Config
parseArg input :: String
input c :: Config
c = case String -> Maybe Int
forall a. Read a => String -> Maybe a
readMaybe String
input of
Just 0 -> Config -> Maybe Config
forall a. a -> Maybe a
Just (Maybe Int -> Config -> Config
setter Maybe Int
forall a. Maybe a
Nothing Config
c)
Just n :: Int
n -> Config -> Maybe Config
forall a. a -> Maybe a
Just (Maybe Int -> Config -> Config
setter (Int -> Maybe Int
forall a. a -> Maybe a
Just Int
n) Config
c)
Nothing -> Maybe Config
forall a. Maybe a
Nothing
smallCheckOptions :: [Option Config]
smallCheckOptions :: [Option Config]
smallCheckOptions = [
String -> OptionSetter Config -> String -> Option Config
forall config.
String -> OptionSetter config -> String -> Option config
option "depth" (String
-> (String -> Maybe Int)
-> (Int -> Config -> Config)
-> OptionSetter Config
forall a.
String
-> (String -> Maybe a)
-> (a -> Config -> Config)
-> OptionSetter Config
argument "N" String -> Maybe Int
forall a. Read a => String -> Maybe a
readMaybe Int -> Config -> Config
setDepth) "maximum depth of generated test values for SmallCheck properties"
]
setDepth :: Int -> Config -> Config
setDepth :: Int -> Config -> Config
setDepth n :: Int
n c :: Config
c = Config
c {configSmallCheckDepth :: Int
configSmallCheckDepth = Int
n}
quickCheckOptions :: [Option Config]
quickCheckOptions :: [Option Config]
quickCheckOptions = [
String
-> Maybe Char
-> OptionSetter Config
-> String
-> Bool
-> Option Config
forall config.
String
-> Maybe Char
-> OptionSetter config
-> String
-> Bool
-> Option config
Option "qc-max-success" (Char -> Maybe Char
forall a. a -> Maybe a
Just 'a') (String
-> (String -> Maybe Int)
-> (Int -> Config -> Config)
-> OptionSetter Config
forall a.
String
-> (String -> Maybe a)
-> (a -> Config -> Config)
-> OptionSetter Config
argument "N" String -> Maybe Int
forall a. Read a => String -> Maybe a
readMaybe Int -> Config -> Config
setMaxSuccess) "maximum number of successful tests before a QuickCheck property succeeds" Bool
True
, String -> OptionSetter Config -> String -> Option Config
forall config.
String -> OptionSetter config -> String -> Option config
option "qc-max-discard" (String
-> (String -> Maybe Int)
-> (Int -> Config -> Config)
-> OptionSetter Config
forall a.
String
-> (String -> Maybe a)
-> (a -> Config -> Config)
-> OptionSetter Config
argument "N" String -> Maybe Int
forall a. Read a => String -> Maybe a
readMaybe Int -> Config -> Config
setMaxDiscardRatio) "maximum number of discarded tests per successful test before giving up"
, String -> OptionSetter Config -> String -> Option Config
forall config.
String -> OptionSetter config -> String -> Option config
option "qc-max-size" (String
-> (String -> Maybe Int)
-> (Int -> Config -> Config)
-> OptionSetter Config
forall a.
String
-> (String -> Maybe a)
-> (a -> Config -> Config)
-> OptionSetter Config
argument "N" String -> Maybe Int
forall a. Read a => String -> Maybe a
readMaybe Int -> Config -> Config
setMaxSize) "size to use for the biggest test cases"
, String -> OptionSetter Config -> String -> Option Config
forall config.
String -> OptionSetter config -> String -> Option config
option "qc-max-shrinks" (String
-> (String -> Maybe Int)
-> (Int -> Config -> Config)
-> OptionSetter Config
forall a.
String
-> (String -> Maybe a)
-> (a -> Config -> Config)
-> OptionSetter Config
argument "N" String -> Maybe Int
forall a. Read a => String -> Maybe a
readMaybe Int -> Config -> Config
setMaxShrinks) "maximum number of shrinks to perform before giving up (a value of 0 turns shrinking off)"
, String -> OptionSetter Config -> String -> Option Config
forall config.
String -> OptionSetter config -> String -> Option config
option "seed" (String
-> (String -> Maybe Integer)
-> (Integer -> Config -> Config)
-> OptionSetter Config
forall a.
String
-> (String -> Maybe a)
-> (a -> Config -> Config)
-> OptionSetter Config
argument "N" String -> Maybe Integer
forall a. Read a => String -> Maybe a
readMaybe Integer -> Config -> Config
setSeed) "used seed for QuickCheck properties"
, Option Config -> Option Config
forall config. Option config -> Option config
undocumented (Option Config -> Option Config) -> Option Config -> Option Config
forall a b. (a -> b) -> a -> b
$ String -> OptionSetter Config -> String -> Option Config
forall config.
String -> OptionSetter config -> String -> Option config
option "maximum-generated-tests" (String
-> (String -> Maybe Int)
-> (Int -> Config -> Config)
-> OptionSetter Config
forall a.
String
-> (String -> Maybe a)
-> (a -> Config -> Config)
-> OptionSetter Config
argument "NUMBER" String -> Maybe Int
forall a. Read a => String -> Maybe a
readMaybe Int -> Config -> Config
setMaxSuccess) "how many automated tests something like QuickCheck should try, by default"
]
setMaxSuccess :: Int -> Config -> Config
setMaxSuccess :: Int -> Config -> Config
setMaxSuccess n :: Int
n c :: Config
c = Config
c {configQuickCheckMaxSuccess :: Maybe Int
configQuickCheckMaxSuccess = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
n}
setMaxDiscardRatio :: Int -> Config -> Config
setMaxDiscardRatio :: Int -> Config -> Config
setMaxDiscardRatio n :: Int
n c :: Config
c = Config
c {configQuickCheckMaxDiscardRatio :: Maybe Int
configQuickCheckMaxDiscardRatio = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
n}
setMaxSize :: Int -> Config -> Config
setMaxSize :: Int -> Config -> Config
setMaxSize n :: Int
n c :: Config
c = Config
c {configQuickCheckMaxSize :: Maybe Int
configQuickCheckMaxSize = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
n}
setMaxShrinks :: Int -> Config -> Config
setMaxShrinks :: Int -> Config -> Config
setMaxShrinks n :: Int
n c :: Config
c = Config
c {configQuickCheckMaxShrinks :: Maybe Int
configQuickCheckMaxShrinks = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
n}
setSeed :: Integer -> Config -> Config
setSeed :: Integer -> Config -> Config
setSeed n :: Integer
n c :: Config
c = Config
c {configQuickCheckSeed :: Maybe Integer
configQuickCheckSeed = Integer -> Maybe Integer
forall a. a -> Maybe a
Just Integer
n}
runnerOptions :: [Option Config]
runnerOptions :: [Option Config]
runnerOptions = [
String -> (Bool -> Config -> Config) -> String -> Option Config
mkFlag "dry-run" Bool -> Config -> Config
setDryRun "pretend that everything passed; don't verify anything"
, String -> (Bool -> Config -> Config) -> String -> Option Config
mkFlag "focused-only" Bool -> Config -> Config
setFocusedOnly "do not run anything, unless there are focused spec items"
, String -> (Bool -> Config -> Config) -> String -> Option Config
mkFlag "fail-on-focused" Bool -> Config -> Config
setFailOnFocused "fail on focused spec items"
, String -> (Bool -> Config -> Config) -> String -> Option Config
mkFlag "fail-fast" Bool -> Config -> Config
setFastFail "abort on first failure"
, String -> (Bool -> Config -> Config) -> String -> Option Config
mkFlag "randomize" Bool -> Config -> Config
setRandomize "randomize execution order"
, String
-> Maybe Char -> (Config -> Config) -> String -> Option Config
mkOptionNoArg "rerun" (Char -> Maybe Char
forall a. a -> Maybe a
Just 'r') Config -> Config
setRerun "rerun all examples that failed in the previous test run (only works in combination with --failure-report or in GHCi)"
, String -> OptionSetter Config -> String -> Option Config
forall config.
String -> OptionSetter config -> String -> Option config
option "failure-report" (String
-> (String -> Maybe String)
-> (String -> Config -> Config)
-> OptionSetter Config
forall a.
String
-> (String -> Maybe a)
-> (a -> Config -> Config)
-> OptionSetter Config
argument "FILE" String -> Maybe String
forall (m :: * -> *) a. Monad m => a -> m a
return String -> Config -> Config
setFailureReport) "read/write a failure report for use with --rerun"
, String
-> Maybe Char -> (Config -> Config) -> String -> Option Config
mkOptionNoArg "rerun-all-on-success" Maybe Char
forall a. Maybe a
Nothing Config -> Config
setRerunAllOnSuccess "run the whole test suite after a previously failing rerun succeeds for the first time (only works in combination with --rerun)"
, String
-> Maybe Char -> OptionSetter Config -> String -> Option Config
mkOption "jobs" (Char -> Maybe Char
forall a. a -> Maybe a
Just 'j') (String
-> (String -> Maybe Int)
-> (Int -> Config -> Config)
-> OptionSetter Config
forall a.
String
-> (String -> Maybe a)
-> (a -> Config -> Config)
-> OptionSetter Config
argument "N" String -> Maybe Int
readMaxJobs Int -> Config -> Config
setMaxJobs) "run at most N parallelizable tests simultaneously (default: number of available processors)"
]
where
readMaxJobs :: String -> Maybe Int
readMaxJobs :: String -> Maybe Int
readMaxJobs s :: String
s = do
Int
n <- String -> Maybe Int
forall a. Read a => String -> Maybe a
readMaybe String
s
Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Maybe ()) -> Bool -> Maybe ()
forall a b. (a -> b) -> a -> b
$ Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 0
Int -> Maybe Int
forall (m :: * -> *) a. Monad m => a -> m a
return Int
n
setFailureReport :: String -> Config -> Config
setFailureReport :: String -> Config -> Config
setFailureReport file :: String
file c :: Config
c = Config
c {configFailureReport :: Maybe String
configFailureReport = String -> Maybe String
forall a. a -> Maybe a
Just String
file}
setMaxJobs :: Int -> Config -> Config
setMaxJobs :: Int -> Config -> Config
setMaxJobs n :: Int
n c :: Config
c = Config
c {configConcurrentJobs :: Maybe Int
configConcurrentJobs = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
n}
setDryRun :: Bool -> Config -> Config
setDryRun :: Bool -> Config -> Config
setDryRun value :: Bool
value config :: Config
config = Config
config {configDryRun :: Bool
configDryRun = Bool
value}
setFocusedOnly :: Bool -> Config -> Config
setFocusedOnly :: Bool -> Config -> Config
setFocusedOnly value :: Bool
value config :: Config
config = Config
config {configFocusedOnly :: Bool
configFocusedOnly = Bool
value}
setFailOnFocused :: Bool -> Config -> Config
setFailOnFocused :: Bool -> Config -> Config
setFailOnFocused value :: Bool
value config :: Config
config = Config
config {configFailOnFocused :: Bool
configFailOnFocused = Bool
value}
setFastFail :: Bool -> Config -> Config
setFastFail :: Bool -> Config -> Config
setFastFail value :: Bool
value config :: Config
config = Config
config {configFastFail :: Bool
configFastFail = Bool
value}
setRandomize :: Bool -> Config -> Config
setRandomize :: Bool -> Config -> Config
setRandomize value :: Bool
value config :: Config
config = Config
config {configRandomize :: Bool
configRandomize = Bool
value}
setRerun :: Config -> Config
setRerun config :: Config
config = Config
config {configRerun :: Bool
configRerun = Bool
True}
setRerunAllOnSuccess :: Config -> Config
setRerunAllOnSuccess config :: Config
config = Config
config {configRerunAllOnSuccess :: Bool
configRerunAllOnSuccess = Bool
True}
commandLineOnlyOptions :: [Option Config]
commandLineOnlyOptions :: [Option Config]
commandLineOnlyOptions = [
String
-> Maybe Char -> (Config -> Config) -> String -> Option Config
mkOptionNoArg "ignore-dot-hspec" Maybe Char
forall a. Maybe a
Nothing Config -> Config
setIgnoreConfigFile "do not read options from ~/.hspec and .hspec"
, String
-> Maybe Char -> OptionSetter Config -> String -> Option Config
mkOption "match" (Char -> Maybe Char
forall a. a -> Maybe a
Just 'm') (String
-> (String -> Maybe String)
-> (String -> Config -> Config)
-> OptionSetter Config
forall a.
String
-> (String -> Maybe a)
-> (a -> Config -> Config)
-> OptionSetter Config
argument "PATTERN" String -> Maybe String
forall (m :: * -> *) a. Monad m => a -> m a
return String -> Config -> Config
addMatch) "only run examples that match given PATTERN"
, String -> OptionSetter Config -> String -> Option Config
forall config.
String -> OptionSetter config -> String -> Option config
option "skip" (String
-> (String -> Maybe String)
-> (String -> Config -> Config)
-> OptionSetter Config
forall a.
String
-> (String -> Maybe a)
-> (a -> Config -> Config)
-> OptionSetter Config
argument "PATTERN" String -> Maybe String
forall (m :: * -> *) a. Monad m => a -> m a
return String -> Config -> Config
addSkip) "skip examples that match given PATTERN"
]
where
setIgnoreConfigFile :: Config -> Config
setIgnoreConfigFile config :: Config
config = Config
config {configIgnoreConfigFile :: Bool
configIgnoreConfigFile = Bool
True}
addMatch :: String -> Config -> Config
addMatch :: String -> Config -> Config
addMatch s :: String
s c :: Config
c = Config
c {configFilterPredicate :: Maybe (Path -> Bool)
configFilterPredicate = (Path -> Bool) -> Maybe (Path -> Bool)
forall a. a -> Maybe a
Just (String -> Path -> Bool
filterPredicate String
s) Maybe (Path -> Bool)
-> Maybe (Path -> Bool) -> Maybe (Path -> Bool)
`filterOr` Config -> Maybe (Path -> Bool)
configFilterPredicate Config
c}
addSkip :: String -> Config -> Config
addSkip :: String -> Config -> Config
addSkip s :: String
s c :: Config
c = Config
c {configSkipPredicate :: Maybe (Path -> Bool)
configSkipPredicate = (Path -> Bool) -> Maybe (Path -> Bool)
forall a. a -> Maybe a
Just (String -> Path -> Bool
filterPredicate String
s) Maybe (Path -> Bool)
-> Maybe (Path -> Bool) -> Maybe (Path -> Bool)
`filterOr` Config -> Maybe (Path -> Bool)
configSkipPredicate Config
c}
filterOr :: Maybe (Path -> Bool) -> Maybe (Path -> Bool) -> Maybe (Path -> Bool)
filterOr :: Maybe (Path -> Bool)
-> Maybe (Path -> Bool) -> Maybe (Path -> Bool)
filterOr p1_ :: Maybe (Path -> Bool)
p1_ p2_ :: Maybe (Path -> Bool)
p2_ = case (Maybe (Path -> Bool)
p1_, Maybe (Path -> Bool)
p2_) of
(Just p1 :: Path -> Bool
p1, Just p2 :: Path -> Bool
p2) -> (Path -> Bool) -> Maybe (Path -> Bool)
forall a. a -> Maybe a
Just ((Path -> Bool) -> Maybe (Path -> Bool))
-> (Path -> Bool) -> Maybe (Path -> Bool)
forall a b. (a -> b) -> a -> b
$ \path :: Path
path -> Path -> Bool
p1 Path
path Bool -> Bool -> Bool
|| Path -> Bool
p2 Path
path
_ -> Maybe (Path -> Bool)
p1_ Maybe (Path -> Bool)
-> Maybe (Path -> Bool) -> Maybe (Path -> Bool)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe (Path -> Bool)
p2_
formatOrList :: [String] -> String
formatOrList :: [String] -> String
formatOrList xs :: [String]
xs = case [String]
xs of
[] -> ""
x :: String
x : ys :: [String]
ys -> (case [String]
ys of
[] -> String
x
_ : [] -> String
x String -> ShowS
forall a. [a] -> [a] -> [a]
++ " or "
_ : _ : _ -> String
x String -> ShowS
forall a. [a] -> [a] -> [a]
++ ", ") String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
formatOrList [String]
ys