    {-# LANGUAGE CPP #-}
    module Info (
      versionInfo
    , info
    , version
    #ifdef TEST
    , formatInfo
    #endif
    ) where

    import           Imports

    import           Data.List
    import           System.Process
    import           System.IO.Unsafe

    #if __GLASGOW_HASKELL__ < 900
    import           Config as GHC
    #else
    import           GHC.Settings.Config as GHC
    #endif

    import           Interpreter (ghc)

    #ifdef TEST

    version :: String
    version = "0.0.0"

    #else

    import           Data.Version (showVersion)
    import qualified Paths_doctest

    version :: String
    version :: String
    version = Version -> String
    showVersion Version
    Paths_doctest.version

    #endif

    ghcVersion :: String
    ghcVersion :: String
    ghcVersion = String
    GHC.cProjectVersion

    versionInfo :: String
    versionInfo :: String
    versionInfo = [String] -> String
    unlines [
        String
    "doctest version " String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ String
    version
      , String
    "using version " String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ String
    ghcVersion String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ String
    " of the GHC API"
      , String
    "using " String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ String
    ghc
      ]

    info :: String
    info :: String
    info = Info -> String
    formatInfo (Info -> String) -> Info -> String
    forall a b. (a -> b) -> a -> b
    $
        (String
    "version", String
    version)
      (String, String) -> Info -> Info
    forall a. a -> [a] -> [a]
    : (String
    "ghc_version", String
    ghcVersion)
      (String, String) -> Info -> Info
    forall a. a -> [a] -> [a]
    : (String
    "ghc", String
    ghc)
      (String, String) -> Info -> Info
    forall a. a -> [a] -> [a]
    : Info
    ghcInfo

    type Info = [(String, String)]

    ghcInfo :: Info
    ghcInfo :: Info
    ghcInfo = String -> Info
    forall a. Read a => String -> a
    read (String -> Info) -> String -> Info
    forall a b. (a -> b) -> a -> b
    $ IO String -> String
    forall a. IO a -> a
    unsafePerformIO (String -> [String] -> String -> IO String
    readProcess String
    ghc [String
    "--info"] String
    "")

    formatInfo :: Info -> String
    formatInfo :: Info -> String
    formatInfo Info
    xs = String
    " [" String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ (String -> [String] -> String
    forall a. [a] -> [[a]] -> [a]
    intercalate String
    "\n ," ([String] -> String) -> [String] -> String
    forall a b. (a -> b) -> a -> b
    $ ((String, String) -> String) -> Info -> [String]
    forall a b. (a -> b) -> [a] -> [b]
    map (String, String) -> String
    forall a. Show a => a -> String
    show Info
    xs) String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ String
    "\n ]\n"