summaryrefslogtreecommitdiff
path: root/testsuite/tests/hiefile/should_run/TestUtils.hs
blob: ec5d75e73f6823fe8d4f8b6774d79df4368e9f07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
module TestUtils
  ( readTestHie
  , render
  , text
  , DynFlags
  , module GHC.Iface.Ext.Types
  , module GHC.Iface.Ext.Utils
  ) where

import System.Environment
import Data.Tree
import GHC.Types.Name.Cache
import GHC.Types.SrcLoc
import GHC.Types.Unique.Supply
import GHC.Types.Name
import GHC.Utils.Outputable                 ( Outputable, renderWithContext, ppr, defaultUserStyle, text)
import GHC.Iface.Ext.Binary
import GHC.Iface.Ext.Types
import GHC.Iface.Ext.Utils
 
import GHC.Driver.Session
import GHC.SysTools

makeNc :: IO NameCache
makeNc = initNameCache 'z' []
 
dynFlagsForPrinting :: String -> IO DynFlags
dynFlagsForPrinting libdir = do
  systemSettings <- initSysTools libdir
  return $ defaultDynFlags systemSettings

readTestHie :: FilePath -> IO (DynFlags, HieFile)
readTestHie fp = do
  libdir:_ <- getArgs
  df <- dynFlagsForPrinting libdir
  nc <- makeNc
  hfr <- readHieFile nc fp
  pure (df, hie_file_result hfr)

render :: Outputable a => DynFlags -> a -> String
render df = renderWithContext (initSDocContext df defaultUserStyle) . ppr