55
66module Test.Golden.Help
77 ( hprop_golden_HelpAll
8- , test_golden_HelpCmds
8+ , tasty_golden_HelpCmds
99 )
1010where
1111
@@ -32,6 +32,7 @@ import Hedgehog qualified as H
3232import Hedgehog.Extras.Stock.OS (isWin32 )
3333import Hedgehog.Extras.Test qualified as H
3434import Test.Tasty (TestTree , testGroup )
35+ import Test.Tasty.Discover (Flavored , flavored , platform )
3536import Test.Tasty.Hedgehog (testProperty )
3637
3738ansiRegex :: Regex
@@ -104,50 +105,48 @@ stripMetavar =
104105selectCmd :: Text -> Maybe Text
105106selectCmd = fmap stripMetavar . selectAndDropPrefix " Usage: cardano-cli "
106107
107- test_golden_HelpCmds :: IO TestTree
108- test_golden_HelpCmds =
108+ tasty_golden_HelpCmds :: Flavored ( IO TestTree )
109+ tasty_golden_HelpCmds =
109110 -- These tests are not run on Windows because the cardano-cli usage
110111 -- output is slightly different on Windows. For example it uses
111112 -- "cardano-cli.exe" instead of "cardano-cli".
112- if isWin32
113- then return $ testGroup " help-commands" []
114- else do
115- helpText <-
116- filterAnsi
117- <$> readProcess
118- " cardano-cli"
119- [ " help"
120- ]
121- " "
122-
123- let lines = Text. lines (Text. pack helpText)
124- usages = [] : nub (List. filter (not . null ) (fmap extractCmd $ maybeToList . selectCmd =<< lines ))
125-
126- return $
127- testGroup
128- " help-commands"
129- [ testProperty
130- (subPath usage)
131- ( watchdogProp . propertyOnce $ do
132- H. noteShow_ usage
133- let expectedCmdHelpFp =
134- " test/cardano-cli-golden/files/golden" </> subPath usage
135-
136- (exitCode, stdout, stderr) <- H. execDetailCardanoCLI (Text. unpack <$> usage <> [" --help" ])
137- let cmdHelp = filterAnsi stdout
138-
139- case exitCode of
140- ExitSuccess ->
141- H. diffVsGoldenFile cmdHelp expectedCmdHelpFp
142- ExitFailure _ -> do
143- H. note_ " Failed to generate correct help text"
144- H. noteShow_ exitCode
145- H. note_ $ filterAnsi stderr
146- H. note_ cmdHelp -- stdout
147- H. failure
148- )
149- | usage <- usages
113+ flavored (platform " !windows" ) $ do
114+ helpText <-
115+ filterAnsi
116+ <$> readProcess
117+ " cardano-cli"
118+ [ " help"
150119 ]
120+ " "
121+
122+ let lines = Text. lines (Text. pack helpText)
123+ usages = [] : nub (List. filter (not . null ) (fmap extractCmd $ maybeToList . selectCmd =<< lines ))
124+
125+ return $
126+ testGroup
127+ " help-command"
128+ [ testProperty
129+ (subPath usage)
130+ ( watchdogProp . propertyOnce $ do
131+ H. noteShow_ usage
132+ let expectedCmdHelpFp =
133+ " test/cardano-cli-golden/files/golden" </> subPath usage
134+
135+ (exitCode, stdout, stderr) <- H. execDetailCardanoCLI (Text. unpack <$> usage <> [" --help" ])
136+ let cmdHelp = filterAnsi stdout
137+
138+ case exitCode of
139+ ExitSuccess ->
140+ H. diffVsGoldenFile cmdHelp expectedCmdHelpFp
141+ ExitFailure _ -> do
142+ H. note_ " Failed to generate correct help text"
143+ H. noteShow_ exitCode
144+ H. note_ $ filterAnsi stderr
145+ H. note_ cmdHelp -- stdout
146+ H. failure
147+ )
148+ | usage <- usages
149+ ]
151150 where
152151 subPath :: [Text ] -> FilePath
153152 subPath [] =
0 commit comments