update jinja2 per CVE-2024-34064
[cabal.git] / Cabal-tests / tests / UnitTests / Distribution / Simple / Command.hs
blobfd60a79209e904bff726ff447cde68ba77687ef4
1 module UnitTests.Distribution.Simple.Command
2 ( tests
3 ) where
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
9 import Test.Tasty
10 import Test.Tasty.HUnit
12 argumentTests :: [TestTree]
13 argumentTests =
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
21 where
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
29 isGlobal = True
30 cmdUI = CommandUI
31 { commandName = "cmd"
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
41 tests :: [TestTree]
42 tests =
43 [ testGroup "option argument tests" argumentTests