tasty-silver-3.0.0.1: Golden tests support for tasty. Fork of tasty-golden.

Safe HaskellNone
LanguageHaskell2010

Test.Tasty.Silver.Advanced

Contents

Synopsis

The main function

goldenTest1 Source

Arguments

:: TestName

test name

-> (forall r. ValueGetter r (Maybe a))

get the golden correct value

-> (forall r. ValueGetter r a)

get the tested value

-> (a -> a -> GDiff)

comparison function.

If two values are the same, it should return Equal. If they are different, it should return a diff representation. First argument is golden value.

-> (a -> GShow)

Show the golden/actual value.

-> (a -> IO ())

update the golden file

-> TestTree 

A very general testing function.

goldenTestIO Source

Arguments

:: TestName

test name

-> (forall r. ValueGetter r (Maybe a))

get the golden correct value

-> (forall r. ValueGetter r a)

get the tested value

-> (a -> a -> IO GDiff)

comparison function.

If two values are the same, it should return Equal. If they are different, it should return a diff representation. First argument is golden value.

-> (a -> IO GShow)

Show the golden/actual value.

-> (a -> IO ())

update the golden file

-> TestTree 

A very general testing function. The IO version of show/diff are useful when using external diff or show mechanisms. If IO is not required, the goldenTest1 function should be used instead.

goldenTest Source

Arguments

:: TestName

test name

-> (forall r. ValueGetter r a)

get the golden correct value

-> (forall r. ValueGetter r a)

get the tested value

-> (a -> a -> IO (Maybe String))

comparison function.

If two values are the same, it should return Nothing. If they are different, it should return an error that will be printed to the user. First argument is the golden value.

The function may use IO, for example, to launch an external diff command.

-> (a -> IO ())

update the golden file

-> TestTree 

A very general testing function. Use goldenTest1 instead if you can.

data GShow Source

How to show a value to the user.

Constructors

ShowText Text

Show the given text.

data GDiff Source

The comparison/diff result.

Constructors

Equal

Values are equal.

DiffText

The two values are different, show a diff between the two given texts.

Fields

gActual :: Text
 
gExpected :: Text
 
ShowDiffed

The two values are different, just show the given text to the user.

Fields

gDiff :: Text
 

ValueGetter monad

newtype ValueGetter r a Source

An action that yields a value (either golden or tested).

CPS allows closing the file handle when using lazy IO to read data.

Constructors

ValueGetter 

Fields

runValueGetter :: ContT r IO a
 

vgReadFile :: FilePath -> ValueGetter r ByteString Source

Lazily read a file. The file handle will be closed after the ValueGetter action is run.

vgReadFileMaybe :: FilePath -> ValueGetter r (Maybe ByteString) Source

Lazily read a file. The file handle will be closed after the ValueGetter action is run. Will return Nothing if the file does not exist.