Skip to content

Commit 14a386c

Browse files
committed
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).
1 parent 1d0bfe9 commit 14a386c

File tree

2 files changed

+41
-41
lines changed

2 files changed

+41
-41
lines changed

cardano-cli/cardano-cli.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ test-suite cardano-cli-golden
452452
regex-tdfa,
453453
rio,
454454
tasty,
455+
tasty-discover,
455456
tasty-hedgehog,
456457
text,
457458

cardano-cli/test/cardano-cli-golden/Test/Golden/Help.hs

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
module Test.Golden.Help
55
( hprop_golden_HelpAll
6-
, test_golden_HelpCmds
6+
, tasty_golden_HelpCmds
77
)
88
where
99

@@ -30,6 +30,7 @@ import Hedgehog qualified as H
3030
import Hedgehog.Extras.Stock.OS (isWin32)
3131
import Hedgehog.Extras.Test qualified as H
3232
import Test.Tasty (TestTree, testGroup)
33+
import Test.Tasty.Discover (Flavored, flavored, platform)
3334
import Test.Tasty.Hedgehog (testProperty)
3435

3536
ansiRegex :: Regex
@@ -100,50 +101,48 @@ stripMetavar =
100101
selectCmd :: Text -> Maybe Text
101102
selectCmd = fmap stripMetavar . selectAndDropPrefix "Usage: cardano-cli "
102103

103-
test_golden_HelpCmds :: IO TestTree
104-
test_golden_HelpCmds =
104+
tasty_golden_HelpCmds :: Flavored (IO TestTree)
105+
tasty_golden_HelpCmds =
105106
-- These tests are not run on Windows because the cardano-cli usage
106107
-- output is slightly different on Windows. For example it uses
107108
-- "cardano-cli.exe" instead of "cardano-cli".
108-
if isWin32
109-
then return $ testGroup "help-commands" []
110-
else do
111-
helpText <-
112-
filterAnsi
113-
<$> readProcess
114-
"cardano-cli"
115-
[ "help"
116-
]
117-
""
118-
119-
let lines = Text.lines (Text.pack helpText)
120-
usages = [] : nub (List.filter (not . null) (fmap extractCmd $ maybeToList . selectCmd =<< lines))
121-
122-
return $
123-
testGroup
124-
"help-commands"
125-
[ testProperty
126-
(subPath usage)
127-
( watchdogProp . propertyOnce $ do
128-
H.noteShow_ usage
129-
let expectedCmdHelpFp =
130-
"test/cardano-cli-golden/files/golden" </> subPath usage
131-
132-
(exitCode, stdout, stderr) <- H.execDetailCardanoCLI (Text.unpack <$> usage <> ["--help"])
133-
let cmdHelp = filterAnsi stdout
134-
135-
case exitCode of
136-
ExitSuccess ->
137-
H.diffVsGoldenFile cmdHelp expectedCmdHelpFp
138-
ExitFailure _ -> do
139-
H.note_ "Failed to generate correct help text"
140-
H.noteShow_ exitCode
141-
H.note_ $ filterAnsi stderr
142-
H.note_ cmdHelp -- stdout
143-
H.failure
144-
)
145-
| usage <- usages
109+
flavored (platform "!windows") $ do
110+
helpText <-
111+
filterAnsi
112+
<$> readProcess
113+
"cardano-cli"
114+
[ "help"
146115
]
116+
""
117+
118+
let lines = Text.lines (Text.pack helpText)
119+
usages = [] : nub (List.filter (not . null) (fmap extractCmd $ maybeToList . selectCmd =<< lines))
120+
121+
return $
122+
testGroup
123+
"help-command"
124+
[ testProperty
125+
(subPath usage)
126+
( watchdogProp . propertyOnce $ do
127+
H.noteShow_ usage
128+
let expectedCmdHelpFp =
129+
"test/cardano-cli-golden/files/golden" </> subPath usage
130+
131+
(exitCode, stdout, stderr) <- H.execDetailCardanoCLI (Text.unpack <$> usage <> ["--help"])
132+
let cmdHelp = filterAnsi stdout
133+
134+
case exitCode of
135+
ExitSuccess ->
136+
H.diffVsGoldenFile cmdHelp expectedCmdHelpFp
137+
ExitFailure _ -> do
138+
H.note_ "Failed to generate correct help text"
139+
H.noteShow_ exitCode
140+
H.note_ $ filterAnsi stderr
141+
H.note_ cmdHelp -- stdout
142+
H.failure
143+
)
144+
| usage <- usages
145+
]
147146
where
148147
subPath :: [Text] -> FilePath
149148
subPath [] =

0 commit comments

Comments
 (0)