Skip to content

Commit

Permalink
Fixes chshersh#57
Browse files Browse the repository at this point in the history
  • Loading branch information
CThuleHansen committed Oct 1, 2022
1 parent 1bede5f commit 97098fa
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions test/Test/Iris/Cli.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Iris.Settings (defaultCliEnvSettings, cliEnvSettingsVersionSettings)
import Iris.Cli.Version (defaultVersionSettings)
import qualified Options.Applicative as Opt
import qualified Paths_iris as Autogen
import Iris.Cli (VersionSettings(versionSettingsMkDesc))


expectedHelpText :: String
Expand All @@ -20,7 +21,7 @@ expectedHelpText =
\\n\
\Available options:\n\
\ -h,--help Show this help text\n\
\ --no-input Enter the terminal in non-interactive mode"
\ --no-input Enter the terminal in non-interactive mode"

expectedHelpTextWithVersion :: String
expectedHelpTextWithVersion =
Expand All @@ -34,11 +35,14 @@ expectedHelpTextWithVersion =
\ -h,--help Show this help text\n\
\ --version Show application version\n\
\ --numeric-version Show only numeric application version\n\
\ --no-input Enter the terminal in non-interactive mode"
\ --no-input Enter the terminal in non-interactive mode"

expectedNumericVersion :: String
expectedNumericVersion = "0.0.0.0"

cliSpec :: Spec
cliSpec = describe "Cli Options" $ do
let parserPrefs = Opt.defaultPrefs
let parserPrefs = Opt.defaultPrefs
it "help without version environment" $ do
let parserInfo = cmdParserInfo defaultCliEnvSettings
let result = Opt.execParserPure parserPrefs parserInfo ["--help"]
Expand All @@ -48,12 +52,25 @@ cliSpec = describe "Cli Options" $ do
let parserInfo= cmdParserInfo cliEnvSettings
let result = Opt.execParserPure parserPrefs parserInfo ["--help"]
parseResultHandler result expectedHelpTextWithVersion
it "--numeric-version returns correct version" $ do
let cliEnvSettings = defaultCliEnvSettings { cliEnvSettingsVersionSettings = Just (defaultVersionSettings Autogen.version)}
let parserInfo= cmdParserInfo cliEnvSettings
let result = Opt.execParserPure parserPrefs parserInfo ["--numeric-version"]
parseResultHandler result expectedNumericVersion
it "--version returns correct version text" $ do
let expectedVersionMkDescription = ("Version " ++)
let cliEnvSettings = defaultCliEnvSettings { cliEnvSettingsVersionSettings = Just $ (defaultVersionSettings Autogen.version) {versionSettingsMkDesc = expectedVersionMkDescription}}
let parserInfo= cmdParserInfo cliEnvSettings
let expectedVersion = expectedVersionMkDescription expectedNumericVersion
let result = Opt.execParserPure parserPrefs parserInfo ["--version"]
parseResultHandler result expectedVersion
where
parseResultHandler parseResult expected =
case parseResult of
case parseResult of
-- The help functionality is baked into optparse-applicative and presents itself as a ParserFailure.
Opt.Failure (Opt.ParserFailure getFailure) -> do
let (helpText, _exitCode, _int) = getFailure "<iris-test>"
let (helpText, _exitCode, _int) = getFailure "<iris-test>"
show helpText `shouldBe` expected
Opt.Success _ -> expectationFailure "Expected 'Failure' but got Success "
Opt.CompletionInvoked completionResult -> expectationFailure $ "Expected 'Failure' but got: " <> show completionResult
Opt.CompletionInvoked completionResult -> expectationFailure $ "Expected 'Failure' but got: " <> show completionResult

0 comments on commit 97098fa

Please sign in to comment.