Commit 89298c04 authored by Iustin Pop's avatar Iustin Pop
Browse files

Add some very basic options test



Just tests that passing a string argument returns it correctly. We're
not interested in the flags themselves that much just that the
function itself parses some options at least correctly.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent 51c3d88f
...@@ -47,9 +47,11 @@ import Data.List (findIndex, intercalate, nub, isPrefixOf) ...@@ -47,9 +47,11 @@ import Data.List (findIndex, intercalate, nub, isPrefixOf)
import qualified Data.Set as Set import qualified Data.Set as Set
import Data.Maybe import Data.Maybe
import Control.Monad import Control.Monad
import qualified System.Console.GetOpt as GetOpt
import qualified Text.JSON as J import qualified Text.JSON as J
import qualified Data.Map import qualified Data.Map
import qualified Data.IntMap as IntMap import qualified Data.IntMap as IntMap
import qualified Ganeti.OpCodes as OpCodes import qualified Ganeti.OpCodes as OpCodes
import qualified Ganeti.Jobs as Jobs import qualified Ganeti.Jobs as Jobs
import qualified Ganeti.Luxi import qualified Ganeti.Luxi
...@@ -1488,8 +1490,30 @@ prop_CLI_parseYesNo def testval val = ...@@ -1488,8 +1490,30 @@ prop_CLI_parseYesNo def testval val =
then result ==? Types.Ok (actual_val == "yes") then result ==? Types.Ok (actual_val == "yes")
else property $ Types.isBad result else property $ Types.isBad result
-- | Helper to check for correct parsing of string arg.
checkStringArg val (opt, fn) =
let GetOpt.Option _ longs _ _ = opt
in case longs of
[] -> failTest "no long options?"
cmdarg:_ ->
case CLI.parseOptsInner ["--" ++ cmdarg ++ "=" ++ val] "prog" [opt] of
Left e -> failTest $ "Failed to parse option: " ++ show e
Right (options, _) -> fn options ==? Just val
-- | Test a few string arguments.
prop_CLI_StringArg argument =
let args = [ (CLI.oDataFile, CLI.optDataFile)
, (CLI.oDynuFile, CLI.optDynuFile)
, (CLI.oSaveCluster, CLI.optSaveCluster)
, (CLI.oReplay, CLI.optReplay)
, (CLI.oPrintCommands, CLI.optShowCmds)
, (CLI.oLuxiSocket, CLI.optLuxi)
]
in conjoin $ map (checkStringArg argument) args
testSuite "CLI" testSuite "CLI"
[ 'prop_CLI_parseISpec [ 'prop_CLI_parseISpec
, 'prop_CLI_parseISpecFail , 'prop_CLI_parseISpecFail
, 'prop_CLI_parseYesNo , 'prop_CLI_parseYesNo
, 'prop_CLI_StringArg
] ]
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