Commit a7ea861a authored by Iustin Pop's avatar Iustin Pop
Browse files

Add test for CLI.parseYesNo



Also fix a tiny typo in the docstring.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent 8b5a517a
......@@ -31,6 +31,7 @@ module Ganeti.HTools.CLI
( Options(..)
, OptType
, parseOpts
, parseYesNo
, parseISpecString
, shTemplate
, defaultLuxiSocket
......@@ -411,14 +412,14 @@ oVerbose = Option "v" ["verbose"]
-- * Functions
-- | Helper for parsing a yes\/no command line flag.
parseYesNo :: Bool -- ^ Default whalue (when we get a @Nothing@)
parseYesNo :: Bool -- ^ Default value (when we get a @Nothing@)
-> Maybe String -- ^ Parameter value
-> Result Bool -- ^ Resulting boolean value
parseYesNo v Nothing = return v
parseYesNo _ (Just "yes") = return True
parseYesNo _ (Just "no") = return False
parseYesNo _ (Just s) = fail $ "Invalid choice '" ++ s ++
"', pass one of 'yes' or 'no'"
parseYesNo _ (Just s) = fail ("Invalid choice '" ++ s ++
"', pass one of 'yes' or 'no'")
-- | Usage info.
usageHelp :: String -> [OptType] -> String
......
......@@ -1478,7 +1478,18 @@ prop_CLI_parseISpecFail descr =
Types.Ok v -> failTest $ "Expected failure, got " ++ show v
_ -> property True
-- | Test parseYesNo.
prop_CLI_parseYesNo def testval val =
forAll (elements [val, "yes", "no"]) $ \actual_val ->
if testval
then CLI.parseYesNo def Nothing ==? Types.Ok def
else let result = CLI.parseYesNo def (Just actual_val)
in if actual_val `elem` ["yes", "no"]
then result ==? Types.Ok (actual_val == "yes")
else property $ Types.isBad result
testSuite "CLI"
[ 'prop_CLI_parseISpec
, 'prop_CLI_parseISpecFail
, 'prop_CLI_parseYesNo
]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment