| 1 |
{-# LANGUAGE RankNTypes #-} |
| 2 |
module Test.Tasty.Golden.Advanced |
| 3 |
( -- * The main functions |
| 4 |
goldenTest, |
| 5 |
goldenTest2 |
| 6 |
) |
| 7 |
where |
| 8 |
|
| 9 |
import Test.Tasty.Providers |
| 10 |
import Test.Tasty.Golden.Internal |
| 11 |
|
| 12 |
-- | A very general testing function. |
| 13 |
goldenTest |
| 14 |
:: TestName -- ^ test name |
| 15 |
-> (IO a) |
| 16 |
-- ^ get the golden correct value |
| 17 |
-- |
| 18 |
-- Note that this action may be followed by the update function call. |
| 19 |
-- |
| 20 |
-- Therefore, this action *should avoid* reading the file lazily; |
| 21 |
-- otherwise, the file may remain half-open and the update action will |
| 22 |
-- fail. |
| 23 |
-> (IO a) -- ^ get the tested value |
| 24 |
-> (a -> a -> IO (Maybe String)) |
| 25 |
-- ^ comparison function. |
| 26 |
-- |
| 27 |
-- If two values are the same, it should return 'Nothing'. If they are |
| 28 |
-- different, it should return an error that will be printed to the user. |
| 29 |
-- First argument is the golden value. |
| 30 |
-- |
| 31 |
-- The function may use 'IO', for example, to launch an external @diff@ |
| 32 |
-- command. |
| 33 |
-> (a -> IO ()) |
| 34 |
-- ^ update the golden file |
| 35 |
-> TestTree |
| 36 |
goldenTest t golden test cmp upd = singleTest t $ Golden golden test cmp upd (return ()) |
| 37 |
|
| 38 |
-- | A variant of 'goldenTest' that also provides for deleting the output |
| 39 |
-- file. The 'Internal.DeleteOuputFile' option controls the circumstances in which |
| 40 |
-- the output file is to be deleted. |
| 41 |
-- |
| 42 |
-- @since 2.3.4 |
| 43 |
goldenTest2 |
| 44 |
:: TestName -- ^ Test name |
| 45 |
-> IO a |
| 46 |
-- ^ Get the golden correct value |
| 47 |
-- |
| 48 |
-- Note that this action may be followed by the update function call. |
| 49 |
-- |
| 50 |
-- Therefore, this action *should avoid* reading the file lazily; |
| 51 |
-- otherwise, the file may remain half-open and the update action will |
| 52 |
-- fail. |
| 53 |
-> IO a |
| 54 |
-- ^ Get the tested value (in this case from the output file) |
| 55 |
-> (a -> a -> IO (Maybe String)) |
| 56 |
-- ^ Comparison function. |
| 57 |
-- |
| 58 |
-- If two values are the same, it should return 'Nothing'. If they are |
| 59 |
-- different, it should return an error that will be printed to the user. |
| 60 |
-- First argument is the golden value. |
| 61 |
-- |
| 62 |
-- The function may use 'IO', for example, to launch an external @diff@ |
| 63 |
-- command. |
| 64 |
-> (a -> IO ()) |
| 65 |
-- ^ Update the golden file |
| 66 |
-> IO () |
| 67 |
-- ^ Action to delete the output file |
| 68 |
-> TestTree |
| 69 |
goldenTest2 t golden test cmp upd del = singleTest t $ Golden golden test cmp upd del |