| Copyright | (C) 2024 Bellroy Pty Ltd |
|---|---|
| License | BSD-3-Clause |
| Maintainer | Bellroy Tech Team <haskell@bellroy.com> |
| Stability | experimental |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Test.Tasty.Golden.Extra.GoldenVsToJSON
Description
These helpers are useful for creating golden tests for ToJSON instances.
Synopsis
- data GoldenVsToJSON = forall a.ToJSON a => GoldenVsToJSON FilePath (IO a)
- goldenVsToJson :: forall a. ToJSON a => TestName -> FilePath -> IO a -> TestTree
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
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)