module Test.Tasty.CmdLine
( optionParser
, suiteOptions
, suiteOptionParser
, defaultMainWithIngredients
) where
import Options.Applicative
import Data.Monoid
import Data.Proxy
import System.Exit
import Test.Tasty.Core
import Test.Tasty.CoreOptions
import Test.Tasty.Ingredients
import Test.Tasty.Options
optionParser :: [OptionDescription] -> Parser OptionSet
optionParser = foldr addOption (pure mempty) where
addOption :: OptionDescription -> Parser OptionSet -> Parser OptionSet
addOption (Option (Proxy :: Proxy v)) p =
setOption <$> (optionCLParser :: Parser v) <*> p
suiteOptions :: [Ingredient] -> TestTree -> [OptionDescription]
suiteOptions ins tree =
coreOptions ++
ingredientsOptions ins ++
treeOptions tree
suiteOptionParser :: [Ingredient] -> TestTree -> Parser OptionSet
suiteOptionParser ins tree = optionParser $ suiteOptions ins tree
defaultMainWithIngredients :: [Ingredient] -> TestTree -> IO ()
defaultMainWithIngredients ins testTree = do
opts <- execParser $
info (helper <*> suiteOptionParser ins testTree)
( fullDesc <>
header "Mmm... tasty test suite"
)
case tryIngredients ins opts testTree of
Nothing ->
putStrLn
"This doesn't taste right. Check your ingredients — did you forget a test reporter?"
Just act -> do
ok <- act
if ok then exitSuccess else exitFailure