{-# LANGUAGE RankNTypes #-}

module Plutarch.Test.QuickCheck.Helpers (loudEval) where

import Plutarch (ClosedTerm, Config (..), TracingMode (DoTracing))
import Plutarch.Evaluate (evalTerm)

loudEval :: ClosedTerm p -> ClosedTerm p
loudEval :: forall (p :: PType). ClosedTerm p -> ClosedTerm p
loudEval ClosedTerm p
x =
  case forall (a :: PType).
Config
-> ClosedTerm a
-> Either Text (Either EvalError (ClosedTerm a), ExBudget, [Text])
evalTerm (Config {$sel:tracingMode:Config :: TracingMode
tracingMode = TracingMode
DoTracing}) ClosedTerm p
x of
    Right (Right ClosedTerm p
t, ExBudget
_, [Text]
_) -> ClosedTerm p
t
    Right (Left EvalError
err, ExBudget
_, [Text]
trace) -> forall a. HasCallStack => [Char] -> a
error forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> [Char]
show EvalError
err forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> [Char]
show [Text]
trace -- TODO pretty this output
    Left Text
err -> forall a. HasCallStack => [Char] -> a
error forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> [Char]
show Text
err