Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ test-suite cardano-cli-golden
regex-tdfa,
rio,
tasty,
tasty-discover,
tasty-hedgehog,
text,

Expand Down
81 changes: 40 additions & 41 deletions cardano-cli/test/cardano-cli-golden/Test/Golden/Help.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

module Test.Golden.Help
( hprop_golden_HelpAll
, test_golden_HelpCmds
, tasty_golden_HelpCmds
)
where

Expand All @@ -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
Expand Down Expand Up @@ -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 [] =
Expand Down
12 changes: 6 additions & 6 deletions cardano-cli/test/cardano-cli-test/Test/Cli/Run/Hash.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"

Expand Down
Loading