summaryrefslogtreecommitdiff
path: root/Biz/Cli.hs
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2021-01-15 21:11:30 -0500
committerBen Sima <ben@bsima.me>2021-01-15 21:13:33 -0500
commite77cdc025b0e80049344f258d9ca170d0953d0d7 (patch)
tree71b1a438a8f715992627b644dcba7468ef036a09 /Biz/Cli.hs
parent7bb2775667386659402ebb7559c7bc4af46ec268 (diff)
Implement Biz.Test with tasty
Also changes the --test option to a 'test' command. This is because running the tests for a namespace/exe should never be combined with anything else: you either want to run the tests, or not.
Diffstat (limited to 'Biz/Cli.hs')
-rw-r--r--Biz/Cli.hs18
1 files changed, 15 insertions, 3 deletions
diff --git a/Biz/Cli.hs b/Biz/Cli.hs
index f2d7fad..cdd2f80 100644
--- a/Biz/Cli.hs
+++ b/Biz/Cli.hs
@@ -14,13 +14,16 @@ module Biz.Cli
where
import Alpha
+import qualified Data.Text as Text
import qualified System.Console.Docopt as Docopt
import qualified System.Environment as Environment
+import qualified Test.Tasty as Tasty
+import qualified Test.Tasty.Runners as Tasty
data Plan = Plan
{ help :: Docopt.Docopt,
move :: Docopt.Arguments -> IO (),
- test :: Docopt.Arguments -> IO ()
+ test :: Tasty.TestTree
}
main :: Plan -> IO ()
@@ -28,9 +31,18 @@ main Plan {..} =
Environment.getArgs
>>= Docopt.parseArgsOrExit help
>>= \args ->
- if args `has` Docopt.longOption "test"
- then test args
+ if args `has` Docopt.command "test"
+ then runTests test
else move args
+runTests :: Tasty.TestTree -> IO ()
+runTests tree = do
+ Tasty.installSignalHandlers
+ case Tasty.tryIngredients Tasty.defaultIngredients mempty tree of
+ Nothing -> do
+ hPutStrLn stderr <| Text.pack "no ingredients agreed to run"
+ exitFailure
+ Just act -> act >>= \ok -> if ok then exitSuccess else exitFailure
+
has :: Docopt.Arguments -> Docopt.Option -> Bool
has = Docopt.isPresent