| 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.GoldenVsShow
Description
These helpers are useful for creating golden tests for Show instances.
Synopsis
- goldenVsShow :: Show a => TestName -> FilePath -> IO a -> TestTree
- data GoldenVsShow = forall a.Show a => GoldenVsShow FilePath (IO a)
Documentation
Arguments
| :: Show 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 Show golden tests.
Use when you want to test Show instances against a golden example on disk.
Example use:
import MySchemasWithShowAndShowInstances.Person (Person)
import qualified Data.Aeson as Aeson
import System.FilePath ((</>))
import Test.Tasty.Golden.Extra.GoldenVsShow (goldenVsShow)
test_Show :: TestTree
test_Show = do
let inputFile = goldenFilesPath </> "Person.json"
goldenVsShow
"Test Show instance for Person"
(goldenFilesPath </> "Person.golden.txt")
(Aeson.decodeFileStrict' @Person inputFile)
data GoldenVsShow Source #
Tasty-discoverable type for creating golden tests for Show instances.
Example use:
import MySchemasWithShowAndToJSONInstances.Person (Person)
import qualified Data.Aeson as Aeson
import System.FilePath ((</>))
import Test.Tasty.Golden.Extra.GoldenVsShow (GoldenVsShow (..))
tasty_GoldenVsShow :: GoldenVsShow
tasty_GoldenVsShow =
GoldenVsShow (goldenFilesPath </> "Person.golden.txt") $
Aeson.eitherDecodeFileStrict @Person (goldenFilesPath </> "Person.json")
Constructors
| forall a.Show a => GoldenVsShow FilePath (IO a) |
Instances
| Tasty GoldenVsShow Source # | |
Defined in Test.Tasty.Golden.Extra.GoldenVsShow | |