From 14a386c4e194b1836158f7bbdf20275b9df46097 Mon Sep 17 00:00:00 2001 From: John Ky Date: Fri, 12 Sep 2025 08:27:27 +1000 Subject: [PATCH 1/2] chore(test): upgrade tasty-discover dependency Migrates test suite to use the newer tasty-discover API which supports Flavored test monads for platform-specific test filtering. This allows tests to be conditionally executed based on platform constraints. - Add tasty-discover dependency to cardano-cli.cabal - Update Test.Golden.Help to use Flavored API - Rename test_golden_HelpCmds to tasty_golden_HelpCmds - Replace manual Windows platform check with flavored platform filter - Import Test.Tasty.Discover for Flavored type and utilities The platform "!windows" filter preserves the existing behavior of skipping help text tests on Windows due to platform-specific output differences (e.g., cardano-cli.exe vs cardano-cli). --- cardano-cli/cardano-cli.cabal | 1 + .../cardano-cli-golden/Test/Golden/Help.hs | 81 +++++++++---------- 2 files changed, 41 insertions(+), 41 deletions(-) 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 [] = From e07e7ea7e37dc0a5e2d5af555823f5cc7814ed4a Mon Sep 17 00:00:00 2001 From: John Ky Date: Wed, 15 Oct 2025 22:37:52 +1100 Subject: [PATCH 2/2] refactor(test): rename hash_trip_fun to hashTripFun for camelCase consistency --- .../test/cardano-cli-test/Test/Cli/Run/Hash.hs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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"