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

Description

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

Synopsis

Documentation

goldenVsShow Source #

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

Instances details
Tasty GoldenVsShow Source # 
Instance details

Defined in Test.Tasty.Golden.Extra.GoldenVsShow