4
4
5
5
module Test.Golden.Help
6
6
( hprop_golden_HelpAll
7
- , hprop_golden_HelpCmds
7
+ , test_golden_HelpCmds
8
8
)
9
9
where
10
10
11
11
import Prelude hiding (lines )
12
12
13
- import Control.Monad (forM_ , unless , (<=<) )
13
+ import Control.Monad (unless , (<=<) )
14
14
import Data.Char qualified as Char
15
+ import Data.List (nub )
15
16
import Data.List qualified as List
16
17
import Data.Maybe (maybeToList )
17
18
import Data.Text (Text )
18
19
import Data.Text qualified as Text
19
20
import System.FilePath ((</>) )
21
+ import System.Process.Extra (readProcess )
20
22
import Text.Regex (Regex , mkRegex , subRegex )
21
23
22
24
import Test.Cardano.CLI.Util (execCardanoCLI , propertyOnce )
@@ -26,6 +28,8 @@ import Hedgehog (Property)
26
28
import Hedgehog.Extras.Stock.OS (isWin32 )
27
29
import Hedgehog.Extras.Test.Base qualified as H
28
30
import Hedgehog.Extras.Test.Golden qualified as H
31
+ import Test.Tasty (TestTree , testGroup )
32
+ import Test.Tasty.Hedgehog (testProperty )
29
33
30
34
ansiRegex :: Regex
31
35
ansiRegex = mkRegex " \\ [[0-9]+m"
@@ -88,30 +92,41 @@ deselectSuffix suffix text =
88
92
selectCmd :: Text -> Maybe Text
89
93
selectCmd = selectAndDropPrefix " Usage: cardano-cli " <=< deselectSuffix " COMMAND"
90
94
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
98
103
help <-
99
104
filterAnsi
100
- <$> execCardanoCLI
105
+ <$> readProcess
106
+ " cardano-cli"
101
107
[ " help"
102
108
]
109
+ " "
103
110
104
111
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
+ ]
115
130
where
116
131
subPath :: [Text ] -> FilePath
117
132
subPath [] =
0 commit comments