tasty-0.11.2.1: Modern and extensible testing framework

Safe Haskell | Safe
Language | Haskell2010

Test.Tasty.Options

Contents

- IsOption class
- Option sets and operations
- Utilities

Description

Extensible options. They are used for provider-specific settings, ingredient-specific settings and core settings (such as the test name pattern).

Synopsis

- class Typeable v => IsOption v where
- data OptionSet
- setOption :: IsOption v => v -> OptionSet -> OptionSet
- changeOption :: forall v. IsOption v => (v -> v) -> OptionSet -> OptionSet
- lookupOption :: forall v. IsOption v => OptionSet -> v
- singleOption :: IsOption v => v -> OptionSet
- data OptionDescription where
  - Option :: IsOption v => Proxy v -> OptionDescription
- flagCLParser :: forall v. IsOption v => Maybe Char -> v -> Parser v
- mkFlagCLParser :: forall v. IsOption v => Mod FlagFields v -> v -> Parser v
- mkOptionCLParser :: forall v. IsOption v => Mod OptionFields v -> Parser v
- safeRead :: Read a => String -> Maybe a

# IsOption class

class Typeable v => IsOption v where #

An option is a data type that inhabits the `IsOption` type class.

Minimal complete definition

defaultValue, parseValue, optionName, optionHelp

Methods

defaultValue :: v #

The value to use if the option was not supplied explicitly

parseValue :: String -> Maybe v #

Try to parse an option value from a string

optionName :: Tagged v String #

The option name. It is used to form the command line option name, for instance. Therefore, it had better not contain spaces or other fancy characters. It is recommended to use dashes instead of spaces.

optionHelp :: Tagged v String #

The option description or help string. This can be an arbitrary string.

optionCLParser :: Parser v #

A command-line option parser.

It has a default implementation in terms of the other methods. You may want to override it in some cases (e.g. add a short flag) and `flagCLParser`, `mkFlagCLParser` and `mkOptionCLParser` might come in handy.

Even if you override this, you still should implement all the methods above, to allow alternative interfaces.

Do not supply a default value here for this parser! This is because if no value was provided on the command line we may lookup the option e.g. in the environment. But if the parser always succeeds, we have no way to tell whether the user really provided the option on the command line.

Instances

IsOption TestPattern # |
Methods defaultValue :: TestPattern # parseValue :: String -> Maybe TestPattern # optionName :: Tagged * TestPattern String # optionHelp :: Tagged * TestPattern String # optionCLParser :: Parser TestPattern #
IsOption Timeout # |
Methods defaultValue :: Timeout # parseValue :: String -> Maybe Timeout # optionName :: Tagged * Timeout String # optionHelp :: Tagged * Timeout String # optionCLParser :: Parser Timeout #
IsOption NumThreads # |
Methods defaultValue :: NumThreads # parseValue :: String -> Maybe NumThreads # optionName :: Tagged * NumThreads String # optionHelp :: Tagged * NumThreads String # optionCLParser :: Parser NumThreads #
IsOption ListTests # |
Methods defaultValue :: ListTests # parseValue :: String -> Maybe ListTests # optionName :: Tagged * ListTests String # optionHelp :: Tagged * ListTests String # optionCLParser :: Parser ListTests #
IsOption HideSuccesses # |
Methods defaultValue :: HideSuccesses # parseValue :: String -> Maybe HideSuccesses # optionName :: Tagged * HideSuccesses String # optionHelp :: Tagged * HideSuccesses String # optionCLParser :: Parser HideSuccesses #
IsOption Quiet # |
Methods defaultValue :: Quiet # parseValue :: String -> Maybe Quiet # optionName :: Tagged * Quiet String # optionHelp :: Tagged * Quiet String # optionCLParser :: Parser Quiet #

# Option sets and operations

data OptionSet #

A set of options. Only one option of each type can be kept.

If some option has not been explicitly set, the default value is used.

Instances

Monoid OptionSet # | Later options override earlier ones
Methods mempty :: OptionSet # mappend :: OptionSet -> OptionSet -> OptionSet # mconcat :: [OptionSet] -> OptionSet #

setOption :: IsOption v => v -> OptionSet -> OptionSet #

Set the option value

changeOption :: forall v. IsOption v => (v -> v) -> OptionSet -> OptionSet #

Change the option value

lookupOption :: forall v. IsOption v => OptionSet -> v #

Query the option value

singleOption :: IsOption v => v -> OptionSet #

Create a singleton `OptionSet`

data OptionDescription where #

The purpose of this data type is to capture the dictionary corresponding to a particular option.

Constructors

Option :: IsOption v => Proxy v -> OptionDescription |

# Utilities

flagCLParser #

Arguments

:: IsOption v |
=> Maybe Char | optional short flag
-> v | non-default value (when the flag is supplied)
-> Parser v |

Command-line parser to use with flags

mkFlagCLParser #

Arguments

:: IsOption v |
=> Mod FlagFields v | option modifier
-> v | non-default value (when the flag is supplied)
-> Parser v |

Command-line flag parser that takes additional option modifiers.

mkOptionCLParser :: forall v. IsOption v => Mod OptionFields v -> Parser v #

Command-line option parser that takes additional option modifiers.

safeRead :: Read a => String -> Maybe a #

Safe read function. Defined here for convenience to use for `parseValue`.