module Test.Tasty.Config (
Config (..)
, GlobPattern
, parseConfig
, defaultConfig
) where
import Data.Maybe (isJust)
import System.Console.GetOpt (ArgDescr (NoArg, ReqArg),
ArgOrder (Permute), OptDescr (Option),
getOpt')
type Ingredient = String
type GlobPattern = String
data Config = Config
{ modules :: Maybe GlobPattern
, moduleSuffix :: Maybe String
, generatedModuleName :: Maybe String
, ignores :: Maybe GlobPattern
, ignoredModules :: [FilePath]
, tastyIngredients :: [Ingredient]
, tastyOptions :: [String]
, noModuleSuffix :: Bool
, debug :: Bool
, treeDisplay :: Bool
} deriving (Show)
defaultConfig :: Config
defaultConfig = Config Nothing Nothing Nothing Nothing [] [] [] False False False
moduleSuffixDeprecationMessage :: String
moduleSuffixDeprecationMessage =
error $ concat
[ "\n\n"
, "----------------------------------------------------------\n"
, "DEPRECATION NOTICE: `--[no-]module-suffix` is deprecated.\n"
, "The default behaviour now discovers all test module suffixes.\n"
, "Please use the `--modules='<glob-pattern>'` option to specify.\n"
, "----------------------------------------------------------\n"
]
ignoreModuleDeprecationMessage :: String
ignoreModuleDeprecationMessage =
error $ concat
[ "\n\n"
, "----------------------------------------------------------\n"
, "DEPRECATION NOTICE: `--ignore-module` is deprecated.\n"
, "Please use the `--ignores='<glob-pattern>'` option instead.\n"
, "----------------------------------------------------------\n"
]
parseConfig :: String -> [String] -> Either String Config
parseConfig prog args = case getOpt' Permute options args of
(opts, rest, rest', []) ->
let config = foldl (flip id) defaultConfig { tastyOptions = rest ++ rest' } opts in
if noModuleSuffix config || isJust (moduleSuffix config) then
error moduleSuffixDeprecationMessage
else
if not $ null (ignoredModules config) then
error ignoreModuleDeprecationMessage
else
Right config
(_, _, _, err:_) -> formatError err
where
formatError err = Left (prog ++ ": " ++ err)
options :: [OptDescr (Config -> Config)]
options = [
Option [] ["modules"]
(ReqArg (\s c -> c {modules = Just s}) "GLOB-PATTERN")
"Specify desired modules with a glob pattern (white-list)"
, Option [] ["module-suffix"]
(ReqArg (\s c -> c {moduleSuffix = Just s}) "SUFFIX")
"<<<DEPRECATED>>>: Specify desired test module suffix"
, Option [] ["generated-module"]
(ReqArg (\s c -> c {generatedModuleName = Just s}) "MODULE")
"Qualified generated module name"
, Option [] ["ignores"]
(ReqArg (\s c -> c {ignores = Just s}) "GLOB-PATTERN")
"Specify desired modules to ignore with a glob pattern (black-list)"
, Option [] ["ignore-module"]
(ReqArg (\s c -> c {ignoredModules = s : ignoredModules c}) "FILE")
"<<<DEPRECATED>>>: Ignore a test module"
, Option [] ["ingredient"]
(ReqArg (\s c -> c {tastyIngredients = s : tastyIngredients c}) "INGREDIENT")
"Qualified tasty ingredient name"
, Option [] ["no-module-suffix"]
(NoArg $ \c -> c {noModuleSuffix = True})
"<<<DEPRECATED>>>: Ignore test module suffix and import them all"
, Option [] ["debug"]
(NoArg $ \c -> c {debug = True})
"Debug output of generated test module"
, Option [] ["tree-display"]
(NoArg $ \c -> c {treeDisplay = True})
"Display test output hierarchically"
]