Skip to content

Commit 458dd95

Browse files
committed
Pretty print test results
1 parent 33fabb8 commit 458dd95

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

bot-plutus-interface.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ test-suite bot-plutus-interface-test
215215
, plutus-pab
216216
, plutus-tx
217217
, plutus-tx-plugin
218+
, pretty-diff
218219
, prettyprinter
219220
, QuickCheck
220221
, quickcheck-instances

test/Spec/BotPlutusInterface/Contract.hs

Lines changed: 15 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,
@@ -898,7 +903,16 @@ assertCommandHistory state =
898903
assertCommandEqual :: String -> Text -> Text -> Assertion
899904
assertCommandEqual err expected actual
900905
| commandEqual expected actual = return ()
901-
| otherwise = assertFailure $ err ++ "\nExpected:\n" ++ show expected ++ "\nGot:\n" ++ show actual
906+
| otherwise =
907+
assertFailure $
908+
err ++ "\n" ++ prettyPrintDiff expected actual
909+
910+
prettyPrintDiff :: Text -> Text -> String
911+
prettyPrintDiff expected actual =
912+
"\nExpected:\n"
913+
++ Text.unpack (Diff.above (Wrap 80) FullContext (Text.replace "\n" " " expected) actual)
914+
++ "\nGot:\n"
915+
++ Text.unpack (Diff.below (Wrap 80) FullContext (Text.replace "\n" " " expected) actual)
902916

903917
{- | Checks if a command matches an expected command pattern
904918
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)