From 626be1675602e95a5880b2b321e912e9030dc0f5 Mon Sep 17 00:00:00 2001 From: Zachary Churchill Date: Thu, 24 Feb 2022 11:48:49 -0500 Subject: [PATCH] move pretty trace code --- .../cardano-ledger-alonzo-test.cabal | 1 - .../src/Test/Cardano/Ledger/Alonzo/Trace.hs | 19 ------------------- .../cardano-ledger-babbage-test.cabal | 1 - .../src/Test/Cardano/Ledger/Babbage/Trace.hs | 19 ------------------- hie.yaml | 3 +++ .../cardano-ledger-pretty.cabal | 9 +++++---- .../src/Cardano/Ledger/Pretty.hs | 12 ++++++++++++ 7 files changed, 20 insertions(+), 44 deletions(-) delete mode 100644 eras/alonzo/test-suite/src/Test/Cardano/Ledger/Alonzo/Trace.hs delete mode 100644 eras/babbage/test-suite/src/Test/Cardano/Ledger/Babbage/Trace.hs diff --git a/eras/alonzo/test-suite/cardano-ledger-alonzo-test.cabal b/eras/alonzo/test-suite/cardano-ledger-alonzo-test.cabal index 4edc3ad7628..65442142b4e 100644 --- a/eras/alonzo/test-suite/cardano-ledger-alonzo-test.cabal +++ b/eras/alonzo/test-suite/cardano-ledger-alonzo-test.cabal @@ -48,7 +48,6 @@ library Test.Cardano.Ledger.Alonzo.Serialisation.Generators Test.Cardano.Ledger.Alonzo.AlonzoEraGen Test.Cardano.Ledger.Alonzo.Scripts - Test.Cardano.Ledger.Alonzo.Trace Test.Cardano.Ledger.Alonzo.PlutusScripts build-depends: bytestring, diff --git a/eras/alonzo/test-suite/src/Test/Cardano/Ledger/Alonzo/Trace.hs b/eras/alonzo/test-suite/src/Test/Cardano/Ledger/Alonzo/Trace.hs deleted file mode 100644 index 9dd59e2d8b3..00000000000 --- a/eras/alonzo/test-suite/src/Test/Cardano/Ledger/Alonzo/Trace.hs +++ /dev/null @@ -1,19 +0,0 @@ -{-# OPTIONS_GHC -fno-warn-orphans #-} - --- | Special tracing code usefull for debugging tests -module Test.Cardano.Ledger.Alonzo.Trace (trace, ptrace, occaisionally) where - -import Cardano.Ledger.Pretty (PrettyA (..), ppMap) -import Data.Hashable (Hashable (..)) -import Data.Map (Map) -import Debug.Trace (trace) - -ptrace :: PrettyA t => [Char] -> t -> a -> a -ptrace x y z = trace ("\n" ++ show (prettyA y) ++ "\n" ++ show x) z - -instance (PrettyA x, PrettyA y) => PrettyA (Map x y) where - prettyA m = ppMap prettyA prettyA m - --- | turn on trace appromimately 1 in 'n' times it is called. -occaisionally :: Hashable a => a -> Int -> String -> String -occaisionally x n s = if mod (hash x) n == 0 then trace s s else s diff --git a/eras/babbage/test-suite/cardano-ledger-babbage-test.cabal b/eras/babbage/test-suite/cardano-ledger-babbage-test.cabal index 728299324f7..45e7832034f 100644 --- a/eras/babbage/test-suite/cardano-ledger-babbage-test.cabal +++ b/eras/babbage/test-suite/cardano-ledger-babbage-test.cabal @@ -39,7 +39,6 @@ library exposed-modules: Test.Cardano.Ledger.Babbage.Serialisation.Generators - Test.Cardano.Ledger.Babbage.Trace build-depends: bytestring, cardano-binary, diff --git a/eras/babbage/test-suite/src/Test/Cardano/Ledger/Babbage/Trace.hs b/eras/babbage/test-suite/src/Test/Cardano/Ledger/Babbage/Trace.hs deleted file mode 100644 index 6dcd60f082e..00000000000 --- a/eras/babbage/test-suite/src/Test/Cardano/Ledger/Babbage/Trace.hs +++ /dev/null @@ -1,19 +0,0 @@ -{-# OPTIONS_GHC -fno-warn-orphans #-} - --- | Special tracing code usefull for debugging tests -module Test.Cardano.Ledger.Babbage.Trace (trace, ptrace, occaisionally) where - -import Cardano.Ledger.Pretty (PrettyA (..), ppMap) -import Data.Hashable (Hashable (..)) -import Data.Map (Map) -import Debug.Trace (trace) - -ptrace :: PrettyA t => [Char] -> t -> a -> a -ptrace x y z = trace ("\n" ++ show (prettyA y) ++ "\n" ++ show x) z - -instance (PrettyA x, PrettyA y) => PrettyA (Map x y) where - prettyA m = ppMap prettyA prettyA m - --- | turn on trace appromimately 1 in 'n' times it is called. -occaisionally :: Hashable a => a -> Int -> String -> String -occaisionally x n s = if mod (hash x) n == 0 then trace s s else s diff --git a/hie.yaml b/hie.yaml index 14bf6501c0e..fcdd75b9878 100644 --- a/hie.yaml +++ b/hie.yaml @@ -104,3 +104,6 @@ cradle: - path: "libs/set-algebra/test" component: "set-algebra:test:tests" + + - path: "libs/cardano-ledger-pretty/src" + component: "lib:cardano-ledger-pretty" diff --git a/libs/cardano-ledger-pretty/cardano-ledger-pretty.cabal b/libs/cardano-ledger-pretty/cardano-ledger-pretty.cabal index 654a95ac930..dea753339eb 100644 --- a/libs/cardano-ledger-pretty/cardano-ledger-pretty.cabal +++ b/libs/cardano-ledger-pretty/cardano-ledger-pretty.cabal @@ -40,21 +40,22 @@ library build-depends: bech32, bytestring, + cardano-crypto-class, cardano-data, cardano-ledger-alonzo, + cardano-ledger-byron, + cardano-ledger-core, cardano-ledger-shelley, cardano-ledger-shelley-ma, - cardano-crypto-class, - cardano-ledger-byron, cardano-protocol-tpraos, cardano-slotting, - containers, compact-map, + containers, + hashable, iproute, mtl, plutus-ledger-api, prettyprinter, small-steps, - cardano-ledger-core, strict-containers, text, diff --git a/libs/cardano-ledger-pretty/src/Cardano/Ledger/Pretty.hs b/libs/cardano-ledger-pretty/src/Cardano/Ledger/Pretty.hs index 44f013065d3..ec049622f04 100644 --- a/libs/cardano-ledger-pretty/src/Cardano/Ledger/Pretty.hs +++ b/libs/cardano-ledger-pretty/src/Cardano/Ledger/Pretty.hs @@ -180,6 +180,7 @@ import qualified Data.ByteString as Long (ByteString) import qualified Data.ByteString.Lazy as Lazy (ByteString, toStrict) import qualified Data.Compact.SplitMap as SplitMap import qualified Data.Compact.VMap as VMap +import qualified Data.Hashable as Hashable import Data.IP (IPv4, IPv6) import qualified Data.Map.Strict as Map (Map, toList) import Data.MemoBytes (MemoBytes (..)) @@ -189,6 +190,7 @@ import Data.Set (Set, toList) import Data.Text (Text) import Data.Typeable (Typeable) import Data.Word (Word16, Word32, Word64, Word8) +import Debug.Trace (trace) import GHC.Natural (Natural) import GHC.Records import Prettyprinter @@ -1661,3 +1663,13 @@ instance PrettyA Bool where instance PrettyA Int where prettyA = ppInt + +ptrace :: PrettyA t => String -> t -> a -> a +ptrace x y z = trace ("\n" ++ show (prettyA y) ++ "\n" ++ show x) z + +instance (PrettyA x, PrettyA y) => PrettyA (Map.Map x y) where + prettyA m = ppMap prettyA prettyA m + +-- | turn on trace appromimately 1 in 'n' times it is called. +occaisionally :: Hashable.Hashable a => a -> Int -> String -> String +occaisionally x n s = if mod (Hashable.hash x) n == 0 then trace s s else s