Skip to content

Commit bb822fa

Browse files
committed
Use getDataFileName for golden tests
1 parent 5c5a59b commit bb822fa

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

cuddle.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ tested-with: ghc ==9.6 || ==9.8 || ==9.10 || ==9.12
2525
data-files:
2626
example/cddl-files/*.cddl
2727
example/cddl-files/validator/negative/*.cddl
28+
golden/*.txt
2829

2930
source-repository head
3031
type: git

test/Test/Codec/CBOR/Cuddle/CDDL/Examples/Huddle.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ huddleRangeMap =
9595
]
9696

9797
simpleRule :: Name -> Rule
98-
simpleRule n = withGenerator (S . C.TInt <$> choose (4, 6)) $ n =:= arr [1, 2, 3]
98+
simpleRule n = withGenerator (\_ -> S . C.TInt <$> choose (4, 6)) $ n =:= arr [1, 2, 3]
9999

100100
simpleTermExample :: Huddle
101101
simpleTermExample =

test/Test/Codec/CBOR/Cuddle/CDDL/Validator/Golden.hs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ import Codec.CBOR.Cuddle.Huddle (Huddle, toCDDL)
1515
import Codec.CBOR.Cuddle.IndexMappable (mapCDDLDropExt, mapIndex)
1616
import Codec.CBOR.Term (Term (..), encodeTerm)
1717
import Codec.CBOR.Write qualified as CBOR
18+
import Control.Monad ((<=<))
1819
import Data.Either (fromRight)
1920
import Data.Text qualified as T
21+
import Data.Text.IO qualified as T
22+
import Paths_cuddle (getDataFileName)
2023
import Prettyprinter (defaultLayoutOptions, layoutPretty)
2124
import Prettyprinter.Render.Terminal qualified as Ansi
2225
import System.FilePath ((</>))
@@ -26,7 +29,7 @@ import Test.Codec.CBOR.Cuddle.CDDL.Examples.Huddle (
2629
refTermExample,
2730
)
2831
import Test.Hspec (Spec, describe, it)
29-
import Test.Hspec.Golden (Golden (..), defaultGolden)
32+
import Test.Hspec.Golden (Golden (..))
3033

3134
huddleRangeArrayTermTwoStrings :: Term
3235
huddleRangeArrayTermTwoStrings =
@@ -60,9 +63,14 @@ choiceAlmostSecond =
6063
validatorPrettyGolden :: String -> Huddle -> Name -> Term -> Spec
6164
validatorPrettyGolden testName huddle n term =
6265
it testName $
63-
(defaultGolden testName $ T.unpack str)
66+
Golden
6467
{ goldenFile = "golden" </> testName <> ".txt"
68+
, readFromFile = T.readFile <=< getDataFileName
69+
, writeToFile = \fp txt -> getDataFileName fp >>= (`T.writeFile` txt)
6570
, actualFile = Nothing
71+
, output = str
72+
, encodePretty = T.unpack
73+
, failFirstTime = False
6674
}
6775
where
6876
bs = CBOR.toStrictByteString $ encodeTerm term

0 commit comments

Comments
 (0)