1 module Golden.Utils where
3 import Control.Monad (Monad(..))
4 import Data.Either (Either(..))
5 import Data.Function (($))
6 import Data.String (String)
7 import System.IO (IO, FilePath)
8 import qualified Data.ByteString.Lazy as BSL
9 import qualified Data.IORef as IORef
11 import qualified Data.Text.Lazy as TL
12 import qualified Data.Text.Lazy.Encoding as TL
13 import qualified Language.Haskell.TH.Syntax as TH
15 goldenDiff :: FilePath -> FilePath -> [String]
16 goldenDiff ref new = ["diff", "-u", "-w", "-B", ref, new]
18 -- | Resetting 'TH.counter' makes 'makeLetName' deterministic,
19 -- except when GHC or executable flags change, like profiling
20 -- or even --accept unfortunately,
21 -- in those case the 'goldensMachine' tests may fail
22 -- due to a different numbering of the 'def' and 'ref' combinators.
23 -- Hence 'ShowLetName' is used with 'False'.
24 resetTHNameCounter :: IO ()
25 resetTHNameCounter = IORef.writeIORef TH.counter 0
27 unLeft :: Either String BSL.ByteString -> IO BSL.ByteString
28 unLeft lr = case lr of
29 Left err -> return $ TL.encodeUtf8 $ TL.pack err