diff --git a/cabal.project b/cabal.project index 7518365c..bf68ce28 100644 --- a/cabal.project +++ b/cabal.project @@ -12,3 +12,5 @@ allow-newer: constraints: aeson >= 2 , hedgehog >= 1.1 + +test-show-details: direct diff --git a/src/Test/Plutip/Contract.hs b/src/Test/Plutip/Contract.hs index 43819d87..847fd252 100644 --- a/src/Test/Plutip/Contract.hs +++ b/src/Test/Plutip/Contract.hs @@ -132,7 +132,7 @@ module Test.Plutip.Contract ( import BotPlutusInterface.Types ( LogContext, LogLevel, - LogLine (LogLine, logLineContext, logLineLevel, logLineMsg), + LogLine (LogLine, logLineContext, logLineLevel), LogsList (getLogsList), sufficientLogLevel, ) @@ -387,7 +387,7 @@ instance render . vcat . zipWith indexedMsg [0 ..] - . map logLineMsg + . map pretty . filterOrDont . getLogsList diff --git a/src/Test/Plutip/Contract/Types.hs b/src/Test/Plutip/Contract/Types.hs index d69f5dbc..1fd20741 100644 --- a/src/Test/Plutip/Contract/Types.hs +++ b/src/Test/Plutip/Contract/Types.hs @@ -55,7 +55,11 @@ instance result <- runResult pure $ bool - (testFailed $ debugInfo predicate result) + ( testFailed $ + debugInfo predicate result + <> "\n\n" + <> "Use assertExecutionWith to show contract logs or budgets." + ) (testPassed "") (pCheck predicate result) diff --git a/src/Test/Plutip/Predicate.hs b/src/Test/Plutip/Predicate.hs index d286394d..fda8924a 100644 --- a/src/Test/Plutip/Predicate.hs +++ b/src/Test/Plutip/Predicate.hs @@ -29,8 +29,10 @@ import Data.Map (Map) import Data.Map qualified as Map import Ledger (ExBudget (ExBudget), ExCPU (ExCPU), ExMemory (ExMemory), TxId, Value) import PlutusCore.Evaluation.Machine.ExMemory (CostingInteger) +import Prettyprinter (Doc, align, defaultLayoutOptions, indent, layoutPretty, viaShow, vsep, (<+>)) +import Prettyprinter.Render.String (renderString) import Test.Plutip.Internal.Types ( - ExecutionResult (contractState, outcome), + ExecutionResult (ExecutionResult, contractState, outcome), FailureReason (CaughtException, ContractExecutionError), budgets, isSuccessful, @@ -83,9 +85,23 @@ shouldSucceed = Predicate "Contract should succeed" "Contract should fail" - (mappend "But it didn't.\nResult: " . show) + (mappend "But it didn't.\nResult: " . renderString . layoutPretty defaultLayoutOptions . prettyExecutionResult) isSuccessful +-- | Pretty print ExecutionResult hiding budget stats and logs. +prettyExecutionResult :: (Show e, Show w, Show a) => ExecutionResult e w a -> Doc ann +prettyExecutionResult ExecutionResult {outcome, contractState} = + vsep + [ "Execution result {" + , indent 4 $ + align $ + vsep + [ "outcome:" <+> viaShow outcome + , "final state: " <+> viaShow contractState + ] + , "}" + ] + -- | Check that Contract didn't succeed. -- -- @since 0.2 diff --git a/test/Spec/Integration.hs b/test/Spec/Integration.hs index 60adb11c..eff83aef 100644 --- a/test/Spec/Integration.hs +++ b/test/Spec/Integration.hs @@ -91,7 +91,11 @@ test = [ShowTraceButOnlyContext ContractLog $ Error [AnyLog]] "Contract 3" (initAda [100]) - (withContract $ const $ Contract.logInfo @Text "Some contract log with Info level." >> getUtxosThrowsEx) + ( withContract $ + const $ do + Contract.logInfo @Text "Some contract log with Info level." + Contract.logDebug @Text "Another contract log with debug level." >> getUtxosThrowsEx + ) [ shouldFail , Predicate.not shouldSucceed ]