Skip to content

Commit 2983fdb

Browse files
authored
Merge pull request #130 from mlabs-haskell/gergely/pretty-print-test-diff
Pretty print test results
2 parents af1968c + 641e60d commit 2983fdb

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

bot-plutus-interface.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ test-suite bot-plutus-interface-test
219219
, plutus-pab
220220
, plutus-tx
221221
, plutus-tx-plugin
222+
, pretty-diff
222223
, prettyprinter
223224
, QuickCheck
224225
, quickcheck-instances

test/Spec/BotPlutusInterface/Contract.hs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ import Plutus.Contract (
4545
)
4646
import PlutusTx qualified
4747
import PlutusTx.Builtins (fromBuiltin)
48+
import Pretty.Diff (
49+
MultilineContext (FullContext),
50+
Wrapping (Wrap),
51+
)
52+
import Pretty.Diff qualified as Diff
4853
import Spec.MockContract (
4954
MockContractState (..),
5055
addr1,
@@ -903,7 +908,14 @@ assertCommandHistory state =
903908
assertCommandEqual :: String -> Text -> Text -> Assertion
904909
assertCommandEqual err expected actual
905910
| commandEqual expected actual = pure ()
906-
| otherwise = assertFailure $ err ++ "\nExpected:\n" ++ show expected ++ "\nGot:\n" ++ show actual
911+
| otherwise = assertFailure $ err ++ "\n" ++ prettyPrintDiff expected actual
912+
913+
prettyPrintDiff :: Text -> Text -> String
914+
prettyPrintDiff expected actual =
915+
"\nExpected:\n"
916+
++ Text.unpack (Diff.above (Wrap 80) FullContext (Text.replace "\n" " " expected) actual)
917+
++ "\nGot:\n"
918+
++ Text.unpack (Diff.below (Wrap 80) FullContext (Text.replace "\n" " " expected) actual)
907919

908920
{- | Checks if a command matches an expected command pattern
909921
Where a command pattern may use new lines in place of spaces, and use the wildcard `?` to match up to the next space

0 commit comments

Comments
 (0)