Skip to content

Commit

Permalink
Improve clarity of counterexample output within golden tests.
Browse files Browse the repository at this point in the history
In particular, we indicate more clearly which value was expected, and
which value was returned.

For example:

```
Failures:

  lib/shelley/test/unit/Cardano/Wallet/Shelley/MinimumUTxOSpec.hs:490:9:
  1) computeMinimumCoinForUTxO, Golden Tests, goldenTests_computeMinimumCoinForUTxO Babbage, golden test #3
       Falsified (after 1 test):
         resultExpected:                                                                                                                                                                           Coin 1323170
             Coin 1323170

         resultReturned:
             Coin 1357650

         Condition violated: resultReturned == resultExpected
```
  • Loading branch information
jonathanknowles committed Jul 13, 2022
1 parent fc2344e commit 964faa4
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions lib/shelley/test/unit/Cardano/Wallet/Shelley/MinimumUTxOSpec.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}

Expand Down Expand Up @@ -64,10 +63,6 @@ import Data.Default
( Default (..) )
import Data.Function
( (&) )
import Data.Generics.Internal.VL.Lens
( view )
import GHC.Generics
( Generic )
import Test.Hspec
( Spec, describe, it )
import Test.QuickCheck
Expand All @@ -87,8 +82,6 @@ import Test.QuickCheck.Extra
( report, verify )
import Test.Utils.Laws
( testLawsMany )
import Test.Utils.Pretty
( (====) )

import qualified Cardano.Api.Shelley as Cardano
import qualified Cardano.Ledger.Alonzo.PParams as Alonzo
Expand Down Expand Up @@ -310,7 +303,7 @@ goldenTests_computeMinimumCoinForUTxO
:: (TokenMap, Coin) -> GoldenTestData (MinimumUTxO, TokenMap) Coin
mkTest (tokenMap, coinExpected) = GoldenTestData
{ params = (minimumUTxO, tokenMap)
, result = coinExpected
, resultExpected = coinExpected
}
title = unwords
["goldenTests_computeMinimumCoinForUTxO", eraName]
Expand Down Expand Up @@ -479,9 +472,9 @@ mkAssetId pid name = AssetId

data GoldenTestData params result = GoldenTestData
{ params :: params
, result :: result
, resultExpected :: result
}
deriving (Eq, Generic, Show)
deriving (Eq, Show)

goldenTests
:: (Eq result, Show result)
Expand All @@ -491,13 +484,17 @@ goldenTests
-> Spec
goldenTests title f goldenTestData =
describe title $
forM_ (zip testNumbers goldenTestData) $
\(testNumber :: Int, test) -> do
let subtitle = "golden test #" <> show testNumber
it subtitle $
let resultExpected = view #result test in
let resultActual = f (view #params test) in
property $ resultExpected ==== resultActual
forM_ (zip testNumbers goldenTestData) $ \(testNumber, testData) -> do
let subtitle = "golden test #" <> show testNumber
it subtitle $ do
let GoldenTestData {params, resultExpected} = testData
let resultReturned = f params
property True
& verify
(resultReturned == resultExpected)
"resultReturned == resultExpected"
& report resultReturned "resultReturned"
& report resultExpected "resultExpected"
where
testNumbers :: [Int]
testNumbers = [0 ..]
Expand Down

0 comments on commit 964faa4

Please sign in to comment.