test-framework-golden-1.1: Golden tests support for test-framework

Safe HaskellSafe-Inferred




The main function



:: Show e 
=> TestName

test name

-> ValueGetter e a

get the golden correct value

-> ValueGetter e a

get the tested value

-> (a -> a -> IO (Maybe e))

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

-> Test 

A very general testing function.

ValueGetter monad

newtype ValueGetter e a Source

An action that yields a value (either golden or tested). Either is for possible errors (file not found, parse error etc.), and CPS allows closing the file handle when using lazy IO to read data.

This is essentially EitherT over Codensity over IO, but that leads to too many dependencies.




runValueGetter :: forall r. (Either e a -> IO r) -> IO r

vgLiftIO :: IO a -> ValueGetter e aSource

Lift an IO action to ValueGetter

vgError :: e -> ValueGetter e aSource

Throw an error in the ValueGetter monad

vgReadFile :: (IOException -> e) -> FilePath -> ValueGetter e ByteStringSource

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

Other useful utilities

newtype Lit Source

A newtype around String whose Show instance produces the string itself.


Lit String 


showLit :: Show a => a -> LitSource

showLit = Lit . show