Skip to content

Commit 87caeed

Browse files
authored
Merge pull request #1103 from IntersectMBO/parallelise-helpcmd-golden
Parallelise HelpCmd golden tests
2 parents cc115e9 + 8b3bedb commit 87caeed

File tree

1 file changed

+35
-20
lines changed
  • cardano-cli/test/cardano-cli-golden/Test/Golden

1 file changed

+35
-20
lines changed

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

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@
44

55
module Test.Golden.Help
66
( hprop_golden_HelpAll
7-
, hprop_golden_HelpCmds
7+
, test_golden_HelpCmds
88
)
99
where
1010

1111
import Prelude hiding (lines)
1212

13-
import Control.Monad (forM_, unless, (<=<))
13+
import Control.Monad (unless, (<=<))
1414
import Data.Char qualified as Char
15+
import Data.List (nub)
1516
import Data.List qualified as List
1617
import Data.Maybe (maybeToList)
1718
import Data.Text (Text)
1819
import Data.Text qualified as Text
1920
import System.FilePath ((</>))
21+
import System.Process.Extra (readProcess)
2022
import Text.Regex (Regex, mkRegex, subRegex)
2123

2224
import Test.Cardano.CLI.Util (execCardanoCLI, propertyOnce)
@@ -26,6 +28,8 @@ import Hedgehog (Property)
2628
import Hedgehog.Extras.Stock.OS (isWin32)
2729
import Hedgehog.Extras.Test.Base qualified as H
2830
import Hedgehog.Extras.Test.Golden qualified as H
31+
import Test.Tasty (TestTree, testGroup)
32+
import Test.Tasty.Hedgehog (testProperty)
2933

3034
ansiRegex :: Regex
3135
ansiRegex = mkRegex "\\[[0-9]+m"
@@ -88,30 +92,41 @@ deselectSuffix suffix text =
8892
selectCmd :: Text -> Maybe Text
8993
selectCmd = selectAndDropPrefix "Usage: cardano-cli " <=< deselectSuffix " COMMAND"
9094

91-
hprop_golden_HelpCmds :: Property
92-
hprop_golden_HelpCmds =
93-
propertyOnce . H.moduleWorkspace "help-commands" $ \_ -> do
94-
-- These tests are not run on Windows because the cardano-cli usage
95-
-- output is slightly different on Windows. For example it uses
96-
-- "cardano-cli.exe" instead of "cardano-cli".
97-
unless isWin32 $ do
95+
test_golden_HelpCmds :: IO TestTree
96+
test_golden_HelpCmds =
97+
-- These tests are not run on Windows because the cardano-cli usage
98+
-- output is slightly different on Windows. For example it uses
99+
-- "cardano-cli.exe" instead of "cardano-cli".
100+
if isWin32
101+
then return $ testGroup "help-commands" []
102+
else do
98103
help <-
99104
filterAnsi
100-
<$> execCardanoCLI
105+
<$> readProcess
106+
"cardano-cli"
101107
[ "help"
102108
]
109+
""
103110

104111
let lines = Text.lines (Text.pack help)
105-
let usages = [] : List.filter (not . null) (fmap extractCmd $ maybeToList . selectCmd =<< lines)
106-
107-
forM_ usages $ \usage -> do
108-
H.noteShow_ usage
109-
let expectedCmdHelpFp =
110-
"test/cardano-cli-golden/files/golden" </> subPath usage
111-
112-
cmdHelp <- filterAnsi . third <$> H.execDetailCardanoCLI (fmap Text.unpack usage)
113-
114-
H.diffVsGoldenFile cmdHelp expectedCmdHelpFp
112+
usages = [] : nub (List.filter (not . null) (fmap extractCmd $ maybeToList . selectCmd =<< lines))
113+
114+
return $
115+
testGroup
116+
"help-commands"
117+
[ testProperty
118+
(subPath usage)
119+
( propertyOnce . H.moduleWorkspace "help-commands" $ \_ -> do
120+
H.noteShow_ usage
121+
let expectedCmdHelpFp =
122+
"test/cardano-cli-golden/files/golden" </> subPath usage
123+
124+
cmdHelp <- filterAnsi . third <$> H.execDetailCardanoCLI (fmap Text.unpack usage)
125+
126+
H.diffVsGoldenFile cmdHelp expectedCmdHelpFp
127+
)
128+
| usage <- usages
129+
]
115130
where
116131
subPath :: [Text] -> FilePath
117132
subPath [] =

0 commit comments

Comments
 (0)