tasty-golden-extra-0.1.0.0: Additional golden test helpers for the tasty-golden package
Copyright(C) 2024 Bellroy Pty Ltd
LicenseBSD-3-Clause
MaintainerBellroy Tech Team <haskell@bellroy.com>
Stabilityexperimental
Safe HaskellSafe-Inferred
LanguageHaskell2010

Test.Tasty.Golden.Extra.GoldenVsToJSON

Description

These helpers are useful for creating golden tests for ToJSON instances.

Synopsis

Documentation

data GoldenVsToJSON Source #

Tasty-discoverable type for creating golden tests for ToJSON instances.

Example use:

 import MySchemasWithToJSONInstances.Person (Person)
 import qualified Data.Aeson as Aeson
 import System.FilePath ((</>))
 import Test.Tasty.Golden.Extra.GoldenVsToJSON (GoldenVsToJSON (..))

 tasty_FromJSON_ToJSON :: GoldenVsToJSON
 tasty_FromJSON_ToJSON =
   GoldenVsToJSON (goldenFilesPath </> "Person.golden.json") $
     Aeson.eitherDecodeFileStrict @Person (goldenFilesPath </> "Person.json")

Constructors

forall a.ToJSON a => GoldenVsToJSON FilePath (IO a) 

Instances

Instances details
Tasty GoldenVsToJSON Source # 
Instance details

Defined in Test.Tasty.Golden.Extra.GoldenVsToJSON

goldenVsToJson Source #

Arguments

:: forall a. ToJSON a 
=> TestName

test name

-> FilePath

path to the «golden» file (the file that contains correct output)

-> IO a

action that returns an instance of the type whose instance is being tested

-> TestTree

the test verifies that the returned string is the same as the golden file contents

Helper function for creating a TestTree for ToJSON golden tests. Use when you want to test ToJSON instances against a golden example on disk.

Example use:

 import MySchemasWithToJSONInstances.Person (Person)
 import qualified Data.Aeson as Aeson
 import System.FilePath ((</>))
 import Test.Tasty.Golden.Extra.GoldenVsToJSON (goldenVsToJSON)

 test_ToJSON :: TestTree
 test_ToJSON = do
   let inputFile = goldenFilesPath </> "Person.json"
   goldenVsToJSON
     "Test ToJSON instance for Person"
     (goldenFilesPath </> "Person.golden.json")
     (Aeson.decodeFileStrict' @Person inputFile)