tasty-1.5.3: Modern and extensible testing framework

Safe Haskell | Safe-Inferred
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).

Since: 0.1

Synopsis

- class Typeable v => IsOption v where
  - defaultValue :: v
  - parseValue :: String -> Maybe v
  - optionName :: Tagged v String
  - optionHelp :: Tagged v String
  - showDefaultValue :: v -> Maybe String
  - optionCLParser :: Parser v
- data OptionSet
- setOption :: IsOption v => v -> OptionSet -> OptionSet
- changeOption :: IsOption v => (v -> v) -> OptionSet -> OptionSet
- lookupOption :: IsOption v => OptionSet -> v
- singleOption :: IsOption v => v -> OptionSet
- data OptionDescription where
  - Option :: forall v. IsOption v => Proxy v -> OptionDescription
- uniqueOptionDescriptions :: [OptionDescription] -> [OptionDescription]
- flagCLParser :: IsOption v => Maybe Char -> v -> Parser v
- mkFlagCLParser :: IsOption v => Mod FlagFields v -> v -> Parser v
- mkOptionCLParser :: IsOption v => Mod OptionFields v -> Parser v
- safeRead :: Read a => String -> Maybe a
- safeReadBool :: String -> Maybe Bool

# IsOption class

class Typeable v => IsOption v where Source #

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

Since: 0.1

Minimal complete definition

defaultValue, parseValue, optionName, optionHelp

Methods

defaultValue :: v Source #

The value to use if the option was not supplied explicitly

parseValue :: String -> Maybe v Source #

Try to parse an option value from a string. Consider using `safeReadBool` for boolean options and `safeRead` for numeric options.

optionName :: Tagged v String Source #

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 Source #

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

showDefaultValue :: v -> Maybe String Source #

How a `defaultValue` should be displayed in the help string. `Nothing` (the default implementation) will result in nothing being displayed, while ``Just` def` will result in `def` being advertised as the default in the help string.

Since: 1.3

optionCLParser :: Parser v Source #

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 (e.g., with the `value` function) 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.

Similarly, do not use `showDefaultWith` here, as it will be ignored. Use the `showDefaultValue` method of `IsOption` instead.

#### Instances

Instances details

IsOption AnsiTricks Source # |
Instance details Defined in Test.Tasty.Ingredients.ConsoleReporter Methods defaultValue :: AnsiTricks Source # parseValue :: String -> Maybe AnsiTricks Source # optionName :: Tagged AnsiTricks String Source # optionHelp :: Tagged AnsiTricks String Source # showDefaultValue :: AnsiTricks -> Maybe String Source # optionCLParser :: Parser AnsiTricks Source #
IsOption HideSuccesses Source # |
Instance details Defined in Test.Tasty.Ingredients.ConsoleReporter Methods defaultValue :: HideSuccesses Source # parseValue :: String -> Maybe HideSuccesses Source # optionName :: Tagged HideSuccesses String Source # optionHelp :: Tagged HideSuccesses String Source # showDefaultValue :: HideSuccesses -> Maybe String Source # optionCLParser :: Parser HideSuccesses Source #
IsOption MinDurationToReport Source # |

Instance details

Defined in Test.Tasty.Ingredients.ConsoleReporter

Methods

defaultValue :: MinDurationToReport Source #

parseValue :: String -> Maybe MinDurationToReport Source #

optionName :: Tagged MinDurationToReport String Source #

optionHelp :: Tagged MinDurationToReport String Source #

showDefaultValue :: MinDurationToReport -> Maybe String Source #

optionCLParser :: Parser MinDurationToReport Source #

IsOption Quiet Source # |
Instance details Defined in Test.Tasty.Ingredients.ConsoleReporter Methods defaultValue :: Quiet Source # parseValue :: String -> Maybe Quiet Source # optionName :: Tagged Quiet String Source # optionHelp :: Tagged Quiet String Source # showDefaultValue :: Quiet -> Maybe String Source # optionCLParser :: Parser Quiet Source #
IsOption UseColor Source # | Control color output
Instance details Defined in Test.Tasty.Ingredients.ConsoleReporter Methods defaultValue :: UseColor Source # parseValue :: String -> Maybe UseColor Source # optionName :: Tagged UseColor String Source # optionHelp :: Tagged UseColor String Source # showDefaultValue :: UseColor -> Maybe String Source # optionCLParser :: Parser UseColor Source #
IsOption ListTests Source # |
Instance details Defined in Test.Tasty.Ingredients.ListTests Methods defaultValue :: ListTests Source # parseValue :: String -> Maybe ListTests Source # optionName :: Tagged ListTests String Source # optionHelp :: Tagged ListTests String Source # showDefaultValue :: ListTests -> Maybe String Source # optionCLParser :: Parser ListTests Source #
IsOption NumThreads Source # |
Instance details Defined in Test.Tasty.Options.Core Methods defaultValue :: NumThreads Source # parseValue :: String -> Maybe NumThreads Source # optionName :: Tagged NumThreads String Source # optionHelp :: Tagged NumThreads String Source # showDefaultValue :: NumThreads -> Maybe String Source # optionCLParser :: Parser NumThreads Source #
IsOption Timeout Source # |
Instance details Defined in Test.Tasty.Options.Core Methods defaultValue :: Timeout Source # parseValue :: String -> Maybe Timeout Source # optionName :: Tagged Timeout String Source # optionHelp :: Tagged Timeout String Source # showDefaultValue :: Timeout -> Maybe String Source # optionCLParser :: Parser Timeout Source #
IsOption TestPattern Source # | Since tasty-1.5, this option can be specified multiple times on the command line. Only the tests matching all given patterns will be selected.
Instance details Defined in Test.Tasty.Patterns Methods defaultValue :: TestPattern Source # parseValue :: String -> Maybe TestPattern Source # optionName :: Tagged TestPattern String Source # optionHelp :: Tagged TestPattern String Source # showDefaultValue :: TestPattern -> Maybe String Source # optionCLParser :: Parser TestPattern Source #

# Option sets and operations

data OptionSet Source #

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.

Since: 0.1

#### Instances

Instances details

Monoid OptionSet Source # |
Instance details Defined in Test.Tasty.Options Methods mempty :: OptionSet Source # mappend :: OptionSet -> OptionSet -> OptionSet Source # mconcat :: [OptionSet] -> OptionSet Source #
Semigroup OptionSet Source # | Later options override earlier ones. Since: 0.12.0.1
Instance details Defined in Test.Tasty.Options Methods (<>) :: OptionSet -> OptionSet -> OptionSet Source # sconcat :: NonEmpty OptionSet -> OptionSet Source # stimes :: Integral b => b -> OptionSet -> OptionSet Source #

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

Set the option value.

Since: 0.1

changeOption :: IsOption v => (v -> v) -> OptionSet -> OptionSet Source #

Change the option value.

Since: 0.1

lookupOption :: IsOption v => OptionSet -> v Source #

Query the option value.

Since: 0.1

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

Create a singleton `OptionSet`.

Since: 0.8

data OptionDescription where Source #

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

Since: 0.1

Constructors

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

uniqueOptionDescriptions :: [OptionDescription] -> [OptionDescription] Source #

Remove duplicated `OptionDescription`, preserving existing order otherwise.

Since: 1.4.1

# Utilities

flagCLParser Source #

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.

Since: 0.8

mkFlagCLParser Source #

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.

Since: 0.11.1

mkOptionCLParser :: IsOption v => Mod OptionFields v -> Parser v Source #

Command-line option parser that takes additional option modifiers.

Since: 0.11.1

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

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

Since: 0.1

safeReadBool :: String -> Maybe Bool Source #

Parse a `Bool` case-insensitively.

Since: 1.0.1