Skip to content

Commit 072c7c2

Browse files
committed
Implement diffVsGoldenFileExcludeTrace
1 parent b208304 commit 072c7c2

File tree

7 files changed

+20
-41
lines changed

7 files changed

+20
-41
lines changed

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

cardano-cli/test/cardano-cli-golden/files/golden/governance/committee/governance_committee_checks_wrong_hash_fails.out

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,3 @@ Error: Command failed: governance committee create-cold-key-resignation-certific
33
Error: Hashes do not match!
44
Expected: "ee38a4f5b8b9d8372386cc923bad19d1a0662298cf355bbe947e5eedf127fa9c"
55
Actual: "de38a4f5b8b9d8372386cc923bad19d1a0662298cf355bbe947e5eedf127fa9c"
6-
CallStack (from HasCallStack):
7-
fromExceptTCli, called at src/Cardano/CLI/EraBased/Governance/Committee/Run.hs:179:10 in cardano-cli-10.8.0.0-inplace:Cardano.CLI.EraBased.Governance.Committee.Run
8-
runGovernanceCommitteeColdKeyResignationCertificate, called at src/Cardano/CLI/EraBased/Governance/Committee/Run.hs:47:5 in cardano-cli-10.8.0.0-inplace:Cardano.CLI.EraBased.Governance.Committee.Run
9-
runGovernanceCommitteeCmds, called at src/Cardano/CLI/EraBased/Governance/Run.hs:51:5 in cardano-cli-10.8.0.0-inplace:Cardano.CLI.EraBased.Governance.Run
10-
runGovernanceCmds, called at src/Cardano/CLI/EraBased/Run.hs:54:20 in cardano-cli-10.8.0.0-inplace:Cardano.CLI.EraBased.Run
11-
12-
HasCallStack backtrace:
13-
collectBacktraces, called at libraries/ghc-internal/src/GHC/Internal/Exception.hs:92:13 in ghc-internal:GHC.Internal.Exception
14-
toExceptionWithBacktrace, called at libraries/ghc-internal/src/GHC/Internal/IO.hs:260:11 in ghc-internal:GHC.Internal.IO
15-
throwIO, called at src/UnliftIO/Exception.hs:441:20 in unliftio-0.2.25.1-72aefeaee6ad674227745dd80100c28616aed606398ce50b030ba8dc9e02a8b9:UnliftIO.Exception
16-
17-

cardano-cli/test/cardano-cli-golden/files/golden/governance/drep/drep_metadata_hash_url_wrong_hash_fails.out

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,3 @@ Error: Command failed: governance drep metadata-hash
33
Error: Hashes do not match!
44
Expected: "ee38a4f5b8b9d8372386cc923bad19d1a0662298cf355bbe947e5eedf127fa9c"
55
Actual: "de38a4f5b8b9d8372386cc923bad19d1a0662298cf355bbe947e5eedf127fa9c"
6-
CallStack (from HasCallStack):
7-
throwCliError, called at src/Cardano/CLI/EraBased/Governance/DRep/Run.hs:207:13 in cardano-cli-10.8.0.0-inplace:Cardano.CLI.EraBased.Governance.DRep.Run
8-
runGovernanceDRepMetadataHashCmd, called at src/Cardano/CLI/EraBased/Governance/DRep/Run.hs:58:5 in cardano-cli-10.8.0.0-inplace:Cardano.CLI.EraBased.Governance.DRep.Run
9-
runGovernanceDRepCmds, called at src/Cardano/CLI/EraBased/Governance/Run.hs:55:5 in cardano-cli-10.8.0.0-inplace:Cardano.CLI.EraBased.Governance.Run
10-
runGovernanceCmds, called at src/Cardano/CLI/EraBased/Run.hs:54:20 in cardano-cli-10.8.0.0-inplace:Cardano.CLI.EraBased.Run
11-
12-
HasCallStack backtrace:
13-
collectBacktraces, called at libraries/ghc-internal/src/GHC/Internal/Exception.hs:92:13 in ghc-internal:GHC.Internal.Exception
14-
toExceptionWithBacktrace, called at libraries/ghc-internal/src/GHC/Internal/IO.hs:260:11 in ghc-internal:GHC.Internal.IO
15-
throwIO, called at src/UnliftIO/Exception.hs:441:20 in unliftio-0.2.25.1-72aefeaee6ad674227745dd80100c28616aed606398ce50b030ba8dc9e02a8b9:UnliftIO.Exception
16-
17-

cardano-cli/test/cardano-cli-golden/files/golden/governance/vote/governance_vote_create_hash_fails.out

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,3 @@ Error: Command failed: governance vote create
33
Error: Hashes do not match!
44
Expected: "ee38a4f5b8b9d8372386cc923bad19d1a0662298cf355bbe947e5eedf127fa9c"
55
Actual: "de38a4f5b8b9d8372386cc923bad19d1a0662298cf355bbe947e5eedf127fa9c"
6-
CallStack (from HasCallStack):
7-
fromExceptTCli, called at src/Cardano/CLI/EraBased/Governance/Vote/Run.hs:68:8 in cardano-cli-10.8.0.0-inplace:Cardano.CLI.EraBased.Governance.Vote.Run
8-
runGovernanceVoteCreateCmd, called at src/Cardano/CLI/EraBased/Governance/Vote/Run.hs:41:5 in cardano-cli-10.8.0.0-inplace:Cardano.CLI.EraBased.Governance.Vote.Run
9-
runGovernanceVoteCmds, called at src/Cardano/CLI/EraBased/Governance/Run.hs:59:5 in cardano-cli-10.8.0.0-inplace:Cardano.CLI.EraBased.Governance.Run
10-
runGovernanceCmds, called at src/Cardano/CLI/EraBased/Run.hs:54:20 in cardano-cli-10.8.0.0-inplace:Cardano.CLI.EraBased.Run
11-
12-
HasCallStack backtrace:
13-
collectBacktraces, called at libraries/ghc-internal/src/GHC/Internal/Exception.hs:92:13 in ghc-internal:GHC.Internal.Exception
14-
toExceptionWithBacktrace, called at libraries/ghc-internal/src/GHC/Internal/IO.hs:260:11 in ghc-internal:GHC.Internal.IO
15-
throwIO, called at src/UnliftIO/Exception.hs:441:20 in unliftio-0.2.25.1-72aefeaee6ad674227745dd80100c28616aed606398ce50b030ba8dc9e02a8b9:UnliftIO.Exception
16-
17-

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)