1 module UnitTests
.Distribution
.Simple
.Command
5 import Distribution
.Simple
.Command
6 import qualified Distribution
.Simple
.Flag
as Flag
7 import Distribution
.Simple
.Setup
(optionVerbosity
)
8 import qualified Distribution
.Verbosity
as Verbosity
10 import Test
.Tasty
.HUnit
12 argumentTests
:: [TestTree
]
14 [ testCase
"parses verbosity successfully" $ do
15 let p
= commandParseArgs cmdUI isGlobal
["-v2"]
16 assertEqual
"expected verbose" (Right verbose
) $ evalParse p
17 , testCase
"handles argument parse error gracefully" $ do
18 let p
= commandParseArgs cmdUI isGlobal
["-v=2"]
19 assertEqual
"expected error" (Left
"errors") $ evalParse p
22 -- evaluate command parse result, to force possible exceptions in 'f'
23 evalParse p
= case p
of
24 CommandErrors _
-> Left
"errors"
25 CommandHelp _
-> Left
"help"
26 CommandList _
-> Left
"list"
27 CommandReadyToGo
(f
, _
) -> Right
$ f Flag
.NoFlag
28 verbose
= Flag
.Flag Verbosity
.verbose
32 , commandSynopsis
= "the command"
33 , commandUsage
= \name
-> name
++ " cmd -v[N]"
34 , commandDescription
= Nothing
35 , commandNotes
= Nothing
36 , commandDefaultFlags
= Flag
.NoFlag
37 , commandOptions
= const [ optField
]
39 optField
= optionVerbosity
id const
43 [ testGroup
"option argument tests" argumentTests