Skip to content

Commit 91554e7

Browse files
committed
Implement diffVsGoldenFileExcludeTrace
1 parent 0c525cb commit 91554e7

File tree

11 files changed

+43
-11
lines changed

11 files changed

+43
-11
lines changed

cardano-cli/src/Cardano/CLI/EraBased/Genesis/Run.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import Cardano.CLI.EraIndependent.Node.Run
5656
, runNodeKeyGenVrfCmd
5757
)
5858
import Cardano.CLI.IO.Lazy qualified as Lazy
59+
import Cardano.CLI.Read
5960
import Cardano.CLI.Type.Common
6061
import Cardano.CLI.Type.Error.GenesisCmdError
6162
import Cardano.CLI.Type.Error.NodeCmdError

cardano-cli/src/Cardano/CLI/EraBased/Governance/Vote/Run.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
{-# LANGUAGE NamedFieldPuns #-}
66
{-# LANGUAGE RankNTypes #-}
77
{-# LANGUAGE ScopedTypeVariables #-}
8+
{-# LANGUAGE TypeApplications #-}
89
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
910

1011
{-# HLINT ignore "Redundant id" #-}
@@ -119,5 +120,4 @@ runGovernanceVoteViewCmd
119120
)
120121
$ unVotingProcedures voteProcedures
121122

122-
fromExceptTCli $
123-
writeLazyByteStringOutput mOutFile output
123+
fromEitherIOCli @(FileError ()) $ writeLazyByteStringOutput mOutFile output

cardano-cli/src/Cardano/CLI/Legacy/Governance/Run.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ import Cardano.CLI.EraBased.Governance.GenesisKeyDelegationCertificate.Run
2323
import Cardano.CLI.EraBased.Governance.Run
2424
import Cardano.CLI.Legacy.Governance.Command
2525
import Cardano.CLI.Orphan ()
26+
import Cardano.CLI.Read
2627
import Cardano.CLI.Type.Common
2728
import Cardano.CLI.Type.Error.GovernanceCmdError
2829

2930
import Control.Monad
3031
import Data.Aeson (eitherDecode)
3132
import Data.ByteString.Lazy qualified as LB
32-
import Data.Text (Text)
3333

3434
runLegacyGovernanceCmds :: LegacyGovernanceCmds -> CIO e ()
3535
runLegacyGovernanceCmds = \case

cardano-cli/src/Cardano/CLI/Orphan.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import Cardano.Ledger.Conway.Governance qualified as L
2525
import Cardano.Ledger.State qualified as L
2626

2727
import Data.Aeson
28-
import Data.Text qualified as Text
2928

3029
instance ToJSON L.DefaultVote where
3130
toJSON defaultVote =
@@ -69,6 +68,8 @@ instance Convert Era ConwayEraOnwards where
6968
convert = \case
7069
Exp.ConwayEra -> ConwayEraOnwardsConway
7170

71+
-- TODO: Convert readVerificationKeySource to use CIO. We can then
72+
-- remove this instance
7273
instance
7374
Error
7475
( Either
@@ -83,7 +84,7 @@ instance
8384
Right e -> prettyError e
8485

8586
instance Error GovernancePollError where
86-
prettyError = pshow . Text.unpack . renderGovernancePollError
87+
prettyError = pretty . renderGovernancePollError
8788

8889
instance Error String where
89-
prettyError = pshow
90+
prettyError = pretty

cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Committee.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,6 @@ hprop_golden_governance_committee_checks_wrong_hash_fails =
390390

391391
exitCode === ExitFailure 1
392392

393-
H.diffVsGoldenFile
393+
diffVsGoldenFileExcludeTrace
394394
result
395395
"test/cardano-cli-golden/files/golden/governance/committee/governance_committee_checks_wrong_hash_fails.out"

cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/DRep.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import System.Posix.Files (fileMode, getFileStatus)
2020
import GHC.IO.Exception (ExitCode (ExitFailure))
2121
import Test.Cardano.CLI.Hash (exampleAnchorDataHash, exampleAnchorDataIpfsHash,
2222
exampleAnchorDataPathGolden, serveFilesWhile, tamperBase16Hash)
23-
import Test.Cardano.CLI.Util (execCardanoCLI, execDetailCardanoCLI,
23+
import Test.Cardano.CLI.Util (diffVsGoldenFileExcludeTrace, execCardanoCLI, execDetailCardanoCLI,
2424
noteInputFile, noteTempFile, propertyOnce)
2525

2626
import Hedgehog
@@ -502,6 +502,6 @@ hprop_golden_drep_metadata_hash_url_wrong_hash_fails =
502502

503503
exitCode === ExitFailure 1
504504

505-
H.diffVsGoldenFile
505+
diffVsGoldenFileExcludeTrace
506506
result
507507
"test/cardano-cli-golden/files/golden/governance/drep/drep_metadata_hash_url_wrong_hash_fails.out"

cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Vote.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import Test.Cardano.CLI.Hash
1515
, tamperBase16Hash
1616
)
1717
import Test.Cardano.CLI.Util
18-
( execCardanoCLI
18+
( diffVsGoldenFileExcludeTrace
19+
, execCardanoCLI
1920
, execDetailConfigCardanoCLI
2021
, noteInputFile
2122
, propertyOnce
@@ -241,4 +242,4 @@ hprop_golden_governance_vote_create_hash_fails =
241242

242243
exitCode === ExitFailure 1
243244

244-
H.diffVsGoldenFile result voteGold
245+
diffVsGoldenFileExcludeTrace result voteGold
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Command failed: governance committee create-cold-key-resignation-certificate
2+
Error: Command failed: governance committee create-cold-key-resignation-certificate
3+
Error: Hashes do not match!
4+
Expected: "ee38a4f5b8b9d8372386cc923bad19d1a0662298cf355bbe947e5eedf127fa9c"
5+
Actual: "de38a4f5b8b9d8372386cc923bad19d1a0662298cf355bbe947e5eedf127fa9c"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Command failed: governance drep metadata-hash
2+
Error: Command failed: governance drep metadata-hash
3+
Error: Hashes do not match!
4+
Expected: "ee38a4f5b8b9d8372386cc923bad19d1a0662298cf355bbe947e5eedf127fa9c"
5+
Actual: "de38a4f5b8b9d8372386cc923bad19d1a0662298cf355bbe947e5eedf127fa9c"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Command failed: governance vote create
2+
Error: Command failed: governance vote create
3+
Error: Hashes do not match!
4+
Expected: "ee38a4f5b8b9d8372386cc923bad19d1a0662298cf355bbe947e5eedf127fa9c"
5+
Actual: "de38a4f5b8b9d8372386cc923bad19d1a0662298cf355bbe947e5eedf127fa9c"

cardano-cli/test/cardano-cli-test-lib/Test/Cardano/CLI/Util.hs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module Test.Cardano.CLI.Util
99
( assertDirectoryMissing
1010
, checkTxCddlFormat
1111
, checkTextEnvelopeFormat
12+
, diffVsGoldenFileExcludeTrace
1213
, equivalence
1314
, execCardanoCLI
1415
, execCardanoCLIWithEnvVars
@@ -42,6 +43,7 @@ import Data.Function ((&))
4243
import Data.List qualified as List
4344
import Data.Monoid (Last (..))
4445
import Data.Text (Text)
46+
import Data.Text qualified as Text
4547
import GHC.IO.Exception (ExitCode (..))
4648
import GHC.Stack (CallStack, HasCallStack)
4749
import GHC.Stack qualified as GHC
@@ -57,6 +59,7 @@ import Hedgehog qualified as H
5759
import Hedgehog.Extras (ExecConfig)
5860
import Hedgehog.Extras qualified as H
5961
import Hedgehog.Extras.Test (ExecConfig (..))
62+
import Hedgehog.Extras.Test.Golden qualified as H
6063
import Hedgehog.Internal.Property (Diff, MonadTest, Property (..), liftTest, mkTest)
6164
import Hedgehog.Internal.Property qualified as H
6265
import Hedgehog.Internal.Show (ValueDiff (ValueSame), mkValue, showPretty, valueDiff)
@@ -362,3 +365,14 @@ watchdogProp :: HasCallStack => H.Property -> H.Property
362365
watchdogProp prop@Property{propertyTest} = prop{propertyTest = H.runWithWatchdog_ cfg propertyTest}
363366
where
364367
cfg = H.WatchdogConfig{H.watchdogTimeout = 20}
368+
369+
diffVsGoldenFileExcludeTrace :: (MonadIO m, MonadTest m, HasCallStack) => String -> FilePath -> m ()
370+
diffVsGoldenFileExcludeTrace inputString refFile = GHC.withFrozenCallStack $ do
371+
case List.uncons $ Text.splitOn "CallStack" $ Text.pack inputString of
372+
Just (stackTraceRemoved, _) -> H.diffVsGoldenFile (Text.unpack stackTraceRemoved) refFile
373+
Nothing ->
374+
H.failWith Nothing $
375+
List.unlines
376+
[ "Input string was empty"
377+
, "Reference file: " <> refFile
378+
]

0 commit comments

Comments
 (0)