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.GoldenVsToYAML

Description

These helpers are useful for creating golden tests for ToJSON instances, that you want to convert to YAML using the Data.Yaml package.

Synopsis

Documentation

goldenVsToYaml 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-to-YAML golden tests. Use when you want to test ToJSON instances against a golden example of YAML on disk.

Example use:

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

 test_ToYAML :: TestTree
 test_ToYAML = do
   let inputFile = goldenFilesPath </> "Person.yaml"
   goldenVsToYAML
     "Test YAML serialization for Person"
     (goldenFilesPath </> "Person.golden.yaml")
     (Aeson.decodeFileStrict' @Person inputFile)

data GoldenVsToYAML Source #

Tasty-discoverable type for creating golden tests for ToJSON instances, that you want to convert to YAML using the Data.Yaml package.

Example use:

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

 tasty_FromJSON_ToYAML :: GoldenVsToYAML
 tasty_FromJSON_ToYAML =
   GoldenVsToYAML (goldenFilesPath </> "Person.golden.yaml") $
     Aeson.eitherDecodeFileStrict @Person (goldenFilesPath </> "Person.json")

Constructors

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

Instances

Instances details
Tasty GoldenVsToYAML Source # 
Instance details

Defined in Test.Tasty.Golden.Extra.GoldenVsToYAML