]> Git — Sourcephile - haskell/symantic-parser.git/blob - test/Golden/Utils.hs
bug: a ref outside its def must be supported
[haskell/symantic-parser.git] / test / Golden / Utils.hs
1 module Golden.Utils where
2
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
10
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
14
15 goldenDiff :: FilePath -> FilePath -> [String]
16 goldenDiff ref new = ["diff", "-u", "-w", "-B", ref, new]
17
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
26
27 unLeft :: Either String BSL.ByteString -> IO BSL.ByteString
28 unLeft lr = case lr of
29 Left err -> return $ TL.encodeUtf8 $ TL.pack err
30 Right a -> return a