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.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
- goldenVsToYaml :: forall a. ToJSON a => TestName -> FilePath -> IO a -> TestTree
- data GoldenVsToYAML = forall a.ToJSON a => GoldenVsToYAML FilePath (IO a)
Documentation
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) |