Skip to content

Commit 9f81c62

Browse files
committed
Add pretty annotating functions
1 parent 2a7d307 commit 9f81c62

File tree

1 file changed

+106
-6
lines changed

1 file changed

+106
-6
lines changed

src/Hedgehog/Extras/Test/Base.hs

+106-6
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,30 @@ module Hedgehog.Extras.Test.Base
1616
, noteIO_
1717

1818
, noteShow
19-
, noteShow_
20-
, noteShowM
21-
, noteShowM_
19+
, noteShowPretty
2220
, noteShowIO
21+
, noteShowPrettyIO
2322
, noteShowIO_
23+
, noteShowPrettyIO_
24+
, noteShowM
25+
, noteShowPrettyM
26+
, noteShowM_
27+
, noteShowPrettyM_
28+
, noteShow_
29+
, noteShowPretty_
2430

2531
, noteEach
26-
, noteEach_
27-
, noteEachM
28-
, noteEachM_
32+
, noteEachPretty
2933
, noteEachIO
34+
, noteEachPrettyIO
3035
, noteEachIO_
36+
, noteEachPrettyIO_
37+
, noteEachM
38+
, noteEachPrettyM
39+
, noteEachM_
40+
, noteEachPrettyM_
41+
, noteEach_
42+
, noteEachPretty_
3143

3244
, noteTempFile
3345

@@ -119,6 +131,7 @@ import qualified Hedgehog as H
119131
import qualified Hedgehog.Extras.Internal.Test.Integration as H
120132
import qualified Hedgehog.Extras.Test.MonadAssertion as H
121133
import qualified Hedgehog.Internal.Property as H
134+
import qualified Hedgehog.Internal.Show as H
122135
import qualified System.Directory as IO
123136
import qualified System.Environment as IO
124137
import qualified System.Info as IO
@@ -224,74 +237,161 @@ noteShow a = GHC.withFrozenCallStack $ do
224237
noteWithCallstack GHC.callStack (show b)
225238
return b
226239

240+
-- | Annotate the given value, pretty printing it with indentation. Note that large data structures will take
241+
-- a significant amount of vertical screen space.
242+
noteShowPretty :: (MonadTest m, HasCallStack, Show a) => a -> m a
243+
noteShowPretty a = GHC.withFrozenCallStack $ do
244+
!b <- H.eval a
245+
noteWithCallstack GHC.callStack (H.showPretty b)
246+
return b
247+
227248
-- | Annotate the given value returning unit.
228249
noteShow_ :: (MonadTest m, HasCallStack, Show a) => a -> m ()
229250
noteShow_ a = GHC.withFrozenCallStack $ noteWithCallstack GHC.callStack (show a)
230251

252+
-- | Annotate the given value returning unit, pretty printing it with indentation. Note that large data structures will take
253+
-- a significant amount of vertical screen space.
254+
noteShowPretty_ :: (MonadTest m, HasCallStack, Show a) => a -> m ()
255+
noteShowPretty_ a = GHC.withFrozenCallStack $ noteWithCallstack GHC.callStack (H.showPretty a)
256+
231257
-- | Annotate the given value in a monadic context.
232258
noteShowM :: (MonadTest m, MonadCatch m, HasCallStack, Show a) => m a -> m a
233259
noteShowM a = GHC.withFrozenCallStack $ do
234260
!b <- H.evalM a
235261
noteWithCallstack GHC.callStack (show b)
236262
return b
237263

264+
-- | Annotate the given value in a monadic context, pretty printing it with indentation. Note that large data structures will take
265+
-- a significant amount of vertical screen space.
266+
noteShowPrettyM :: (MonadTest m, MonadCatch m, HasCallStack, Show a) => m a -> m a
267+
noteShowPrettyM a = GHC.withFrozenCallStack $ do
268+
!b <- H.evalM a
269+
noteWithCallstack GHC.callStack (H.showPretty b)
270+
return b
271+
238272
-- | Annotate the given value in a monadic context returning unit.
239273
noteShowM_ :: (MonadTest m, MonadCatch m, HasCallStack, Show a) => m a -> m ()
240274
noteShowM_ a = GHC.withFrozenCallStack $ do
241275
!b <- H.evalM a
242276
noteWithCallstack GHC.callStack (show b)
243277
return ()
244278

279+
-- | Annotate the given value in a monadic context returning unit, pretty printing it with indentation. Note that large data structures will take
280+
-- a significant amount of vertical screen space.
281+
noteShowPrettyM_ :: (MonadTest m, MonadCatch m, HasCallStack, Show a) => m a -> m ()
282+
noteShowPrettyM_ a = GHC.withFrozenCallStack $ do
283+
!b <- H.evalM a
284+
noteWithCallstack GHC.callStack (H.showPretty b)
285+
return ()
286+
245287
-- | Annotate the given value in IO.
246288
noteShowIO :: (MonadTest m, MonadIO m, HasCallStack, Show a) => IO a -> m a
247289
noteShowIO f = GHC.withFrozenCallStack $ do
248290
!a <- H.evalIO f
249291
noteWithCallstack GHC.callStack (show a)
250292
return a
251293

294+
-- | Annotate the given value in IO, pretty printing it with indentation. Note that large data structures will take
295+
-- a significant amount of vertical screen space.
296+
noteShowPrettyIO :: (MonadTest m, MonadIO m, HasCallStack, Show a) => IO a -> m a
297+
noteShowPrettyIO f = GHC.withFrozenCallStack $ do
298+
!a <- H.evalIO f
299+
noteWithCallstack GHC.callStack (H.showPretty a)
300+
return a
301+
252302
-- | Annotate the given value in IO returning unit.
253303
noteShowIO_ :: (MonadTest m, MonadIO m, HasCallStack, Show a) => IO a -> m ()
254304
noteShowIO_ f = GHC.withFrozenCallStack $ do
255305
!a <- H.evalIO f
256306
noteWithCallstack GHC.callStack (show a)
257307
return ()
258308

309+
-- | Annotate the given value in IO returning unit, pretty printing it with indentation. Note that large data structures will take
310+
-- a significant amount of vertical screen space.
311+
noteShowPrettyIO_ :: (MonadTest m, MonadIO m, HasCallStack, Show a) => IO a -> m ()
312+
noteShowPrettyIO_ f = GHC.withFrozenCallStack $ do
313+
!a <- H.evalIO f
314+
noteWithCallstack GHC.callStack (H.showPretty a)
315+
return ()
316+
259317
-- | Annotate the each value in the given traversable.
260318
noteEach :: (MonadTest m, HasCallStack, Show a, Traversable f) => f a -> m (f a)
261319
noteEach as = GHC.withFrozenCallStack $ do
262320
for_ as $ noteWithCallstack GHC.callStack . show
263321
return as
264322

323+
-- | Annotate the each value in the given traversable, pretty printing it with indentation. Note that large data structures will take
324+
-- a significant amount of vertical screen space.
325+
noteEachPretty :: (MonadTest m, HasCallStack, Show a, Traversable f) => f a -> m (f a)
326+
noteEachPretty as = GHC.withFrozenCallStack $ do
327+
for_ as $ noteWithCallstack GHC.callStack . H.showPretty
328+
return as
329+
265330
-- | Annotate the each value in the given traversable returning unit.
266331
noteEach_ :: (MonadTest m, HasCallStack, Show a, Traversable f) => f a -> m ()
267332
noteEach_ as = GHC.withFrozenCallStack $ for_ as $ noteWithCallstack GHC.callStack . show
268333

334+
-- | Annotate the each value in the given traversable returning unit, pretty printing it with indentation. Note that large data structures will take
335+
-- a significant amount of vertical screen space.
336+
noteEachPretty_ :: (MonadTest m, HasCallStack, Show a, Traversable f) => f a -> m ()
337+
noteEachPretty_ as = GHC.withFrozenCallStack $ for_ as $ noteWithCallstack GHC.callStack . H.showPretty
338+
269339
-- | Annotate the each value in the given traversable in a monadic context.
270340
noteEachM :: (MonadTest m, HasCallStack, Show a, Traversable f) => m (f a) -> m (f a)
271341
noteEachM f = GHC.withFrozenCallStack $ do
272342
!as <- f
273343
for_ as $ noteWithCallstack GHC.callStack . show
274344
return as
275345

346+
-- | Annotate the each value in the given traversable in a monadic context, pretty printing it with indentation. Note that large data structures will take
347+
-- a significant amount of vertical screen space.
348+
noteEachPrettyM :: (MonadTest m, HasCallStack, Show a, Traversable f) => m (f a) -> m (f a)
349+
noteEachPrettyM f = GHC.withFrozenCallStack $ do
350+
!as <- f
351+
for_ as $ noteWithCallstack GHC.callStack . H.showPretty
352+
return as
353+
276354
-- | Annotate the each value in the given traversable in a monadic context returning unit.
277355
noteEachM_ :: (MonadTest m, HasCallStack, Show a, Traversable f) => m (f a) -> m ()
278356
noteEachM_ f = GHC.withFrozenCallStack $ do
279357
!as <- f
280358
for_ as $ noteWithCallstack GHC.callStack . show
281359

360+
-- | Annotate the each value in the given traversable in a monadic context returning unit, pretty printing it with indentation. Note that large data structures will take
361+
-- a significant amount of vertical screen space.
362+
noteEachPrettyM_ :: (MonadTest m, HasCallStack, Show a, Traversable f) => m (f a) -> m ()
363+
noteEachPrettyM_ f = GHC.withFrozenCallStack $ do
364+
!as <- f
365+
for_ as $ noteWithCallstack GHC.callStack . H.showPretty
366+
282367
-- | Annotate the each value in the given traversable in IO.
283368
noteEachIO :: (MonadTest m, MonadIO m, HasCallStack, Show a, Traversable f) => IO (f a) -> m (f a)
284369
noteEachIO f = GHC.withFrozenCallStack $ do
285370
!as <- H.evalIO f
286371
for_ as $ noteWithCallstack GHC.callStack . show
287372
return as
288373

374+
-- | Annotate the each value in the given traversable in IO, pretty printing it with indentation. Note that large data structures will take
375+
-- a significant amount of vertical screen space.
376+
noteEachPrettyIO :: (MonadTest m, MonadIO m, HasCallStack, Show a, Traversable f) => IO (f a) -> m (f a)
377+
noteEachPrettyIO f = GHC.withFrozenCallStack $ do
378+
!as <- H.evalIO f
379+
for_ as $ noteWithCallstack GHC.callStack . H.showPretty
380+
return as
381+
289382
-- | Annotate the each value in the given traversable in IO returning unit.
290383
noteEachIO_ :: (MonadTest m, MonadIO m, HasCallStack, Show a, Traversable f) => IO (f a) -> m ()
291384
noteEachIO_ f = GHC.withFrozenCallStack $ do
292385
!as <- H.evalIO f
293386
for_ as $ noteWithCallstack GHC.callStack . show
294387

388+
-- | Annotate the each value in the given traversable in IO returning unit, pretty printing it with indentation. Note that large data structures will take
389+
-- a significant amount of vertical screen space.
390+
noteEachPrettyIO_ :: (MonadTest m, MonadIO m, HasCallStack, Show a, Traversable f) => IO (f a) -> m ()
391+
noteEachPrettyIO_ f = GHC.withFrozenCallStack $ do
392+
!as <- H.evalIO f
393+
for_ as $ noteWithCallstack GHC.callStack . H.showPretty
394+
295395
-- | Return the test file path after annotating it relative to the project root directory
296396
noteTempFile :: (MonadTest m, HasCallStack) => FilePath -> FilePath -> m FilePath
297397
noteTempFile tempDir filePath = GHC.withFrozenCallStack $ do

0 commit comments

Comments
 (0)