]> Git — Sourcephile - haskell/symantic-parser.git/blob - test/Golden/Utils.hs
change ShowLetName into HideableName
[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.Semigroup (Semigroup(..))
7 import Data.String (String)
8 import System.IO (IO, FilePath)
9 import System.IO.Unsafe (unsafePerformIO)
10 import qualified Data.ByteString.Lazy as BSL
11 import qualified Data.IORef as IORef
12
13 import qualified Data.Text.Lazy as TL
14 import qualified Data.Text.Lazy.Encoding as TL
15 import qualified Language.Haskell.TH.Syntax as TH
16 import Paths_symantic_parser
17
18 getGoldenDir :: FilePath -> FilePath
19 getGoldenDir p = unsafePerformIO $ getDataFileName $ "test/Golden/" <> p
20
21 goldenDiff :: FilePath -> FilePath -> [String]
22 goldenDiff ref new = ["diff", "-u", "-w", "-B", ref, new]
23
24 -- | Resetting 'TH.counter' makes 'makeLetName' deterministic,
25 -- except when GHC or executable flags change, like profiling
26 -- or even --accept unfortunately,
27 -- in those case the golden tests may fail
28 -- due to a different numbering of the 'ref' combinators.
29 -- Hence 'ShowLetName' is used with 'False' there.
30 resetTHNameCounter :: IO ()
31 resetTHNameCounter = IORef.writeIORef TH.counter 0
32
33 unLeft :: Either String BSL.ByteString -> IO BSL.ByteString
34 unLeft lr = case lr of
35 Left err -> return $ TL.encodeUtf8 $ TL.pack err
36 Right a -> return a