Skip to content

Commit 7114cab

Browse files
committed
Pretty print test results
1 parent 12d594a commit 7114cab

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

bot-plutus-interface.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ test-suite bot-plutus-interface-test
217217
, plutus-script-utils
218218
, plutus-tx
219219
, plutus-tx-plugin
220+
, pretty-diff
220221
, prettyprinter
221222
, QuickCheck
222223
, quickcheck-instances

flake.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/Spec/BotPlutusInterface/Contract.hs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ import Plutus.Contract (
5151
import Plutus.Script.Utils.V1.Scripts qualified as ScriptUtils
5252
import PlutusTx qualified
5353
import PlutusTx.Builtins (fromBuiltin)
54+
import Pretty.Diff (
55+
MultilineContext (FullContext),
56+
Wrapping (Wrap),
57+
)
58+
import Pretty.Diff qualified as Diff
5459
import Spec.MockContract (
5560
MockContractState (..),
5661
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)