diff --git a/cardano-cli/cardano-cli.cabal b/cardano-cli/cardano-cli.cabal index 0fbe6af805..8d1adcfba7 100644 --- a/cardano-cli/cardano-cli.cabal +++ b/cardano-cli/cardano-cli.cabal @@ -452,6 +452,7 @@ test-suite cardano-cli-golden regex-tdfa, rio, tasty, + tasty-discover, tasty-hedgehog, text, diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Help.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Help.hs index 29d64fe832..59f80278d4 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Help.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Help.hs @@ -3,7 +3,7 @@ module Test.Golden.Help ( hprop_golden_HelpAll - , test_golden_HelpCmds + , tasty_golden_HelpCmds ) where @@ -30,6 +30,7 @@ import Hedgehog qualified as H import Hedgehog.Extras.Stock.OS (isWin32) import Hedgehog.Extras.Test qualified as H import Test.Tasty (TestTree, testGroup) +import Test.Tasty.Discover (Flavored, flavored, platform) import Test.Tasty.Hedgehog (testProperty) ansiRegex :: Regex @@ -100,50 +101,48 @@ stripMetavar = selectCmd :: Text -> Maybe Text selectCmd = fmap stripMetavar . selectAndDropPrefix "Usage: cardano-cli " -test_golden_HelpCmds :: IO TestTree -test_golden_HelpCmds = +tasty_golden_HelpCmds :: Flavored (IO TestTree) +tasty_golden_HelpCmds = -- These tests are not run on Windows because the cardano-cli usage -- output is slightly different on Windows. For example it uses -- "cardano-cli.exe" instead of "cardano-cli". - if isWin32 - then return $ testGroup "help-commands" [] - else do - helpText <- - filterAnsi - <$> readProcess - "cardano-cli" - [ "help" - ] - "" - - let lines = Text.lines (Text.pack helpText) - usages = [] : nub (List.filter (not . null) (fmap extractCmd $ maybeToList . selectCmd =<< lines)) - - return $ - testGroup - "help-commands" - [ testProperty - (subPath usage) - ( watchdogProp . propertyOnce $ do - H.noteShow_ usage - let expectedCmdHelpFp = - "test/cardano-cli-golden/files/golden" subPath usage - - (exitCode, stdout, stderr) <- H.execDetailCardanoCLI (Text.unpack <$> usage <> ["--help"]) - let cmdHelp = filterAnsi stdout - - case exitCode of - ExitSuccess -> - H.diffVsGoldenFile cmdHelp expectedCmdHelpFp - ExitFailure _ -> do - H.note_ "Failed to generate correct help text" - H.noteShow_ exitCode - H.note_ $ filterAnsi stderr - H.note_ cmdHelp -- stdout - H.failure - ) - | usage <- usages + flavored (platform "!windows") $ do + helpText <- + filterAnsi + <$> readProcess + "cardano-cli" + [ "help" ] + "" + + let lines = Text.lines (Text.pack helpText) + usages = [] : nub (List.filter (not . null) (fmap extractCmd $ maybeToList . selectCmd =<< lines)) + + return $ + testGroup + "help-command" + [ testProperty + (subPath usage) + ( watchdogProp . propertyOnce $ do + H.noteShow_ usage + let expectedCmdHelpFp = + "test/cardano-cli-golden/files/golden" subPath usage + + (exitCode, stdout, stderr) <- H.execDetailCardanoCLI (Text.unpack <$> usage <> ["--help"]) + let cmdHelp = filterAnsi stdout + + case exitCode of + ExitSuccess -> + H.diffVsGoldenFile cmdHelp expectedCmdHelpFp + ExitFailure _ -> do + H.note_ "Failed to generate correct help text" + H.noteShow_ exitCode + H.note_ $ filterAnsi stderr + H.note_ cmdHelp -- stdout + H.failure + ) + | usage <- usages + ] where subPath :: [Text] -> FilePath subPath [] = diff --git a/cardano-cli/test/cardano-cli-test/Test/Cli/Run/Hash.hs b/cardano-cli/test/cardano-cli-test/Test/Cli/Run/Hash.hs index 61f0db1eb4..11878db6b9 100644 --- a/cardano-cli/test/cardano-cli-test/Test/Cli/Run/Hash.hs +++ b/cardano-cli/test/cardano-cli-test/Test/Cli/Run/Hash.hs @@ -17,15 +17,15 @@ import Hedgehog.Extras qualified as H hprop_hash_trip :: Property hprop_hash_trip = watchdogProp . propertyOnce $ do - hash_trip_fun "foo" - hash_trip_fun "longerText" - hash_trip_fun "nonAscii: 你好" - hash_trip_fun "nonAscii: à la mode de Cæn" + hashTripFun "foo" + hashTripFun "longerText" + hashTripFun "nonAscii: 你好" + hashTripFun "nonAscii: à la mode de Cæn" -- Test that @cardano-cli hash --text > file1@ and -- @cardano-cli --text --out-file file2@ yields -- similar @file1@ and @file2@ files. -hash_trip_fun +hashTripFun :: ( MonadBaseControl IO m , MonadTest m , MonadCatch m @@ -34,7 +34,7 @@ hash_trip_fun , HasCallStack ) => String -> m () -hash_trip_fun input = +hashTripFun input = H.moduleWorkspace "tmp" $ \tempDir -> do hashFile <- noteTempFile tempDir "hash.txt"