From 66d7114dc8d310e1dc1105a0805c1c491312b43c Mon Sep 17 00:00:00 2001 From: Ɓukasz Hanuszczak Date: Thu, 13 Aug 2015 17:28:24 +0200 Subject: Make Haddock test package more generic. --- haddock-test/src/Test/Haddock/Config.hs | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'haddock-test/src/Test/Haddock/Config.hs') diff --git a/haddock-test/src/Test/Haddock/Config.hs b/haddock-test/src/Test/Haddock/Config.hs index b9444c3e..3b6dfdeb 100644 --- a/haddock-test/src/Test/Haddock/Config.hs +++ b/haddock-test/src/Test/Haddock/Config.hs @@ -30,6 +30,13 @@ import Test.Haddock.Process import Test.Haddock.Utils +data CheckConfig c = CheckConfig + { ccfgRead :: String -> String -> Maybe c + , ccfgDump :: c -> String + , ccfgEqual :: c -> c -> Bool + } + + data DirConfig = DirConfig { dcfgSrcDir :: FilePath , dcfgRefDir :: FilePath @@ -49,24 +56,26 @@ defaultDirConfig baseDir = DirConfig rootDir = baseDir ".." -data Config = Config +data Config c = Config { cfgHaddockPath :: FilePath , cfgFiles :: [FilePath] , cfgHaddockArgs :: [String] , cfgHaddockStdOut :: FilePath , cfgDiffTool :: Maybe FilePath , cfgEnv :: Environment + , cfgCheckConfig :: CheckConfig c , cfgDirConfig :: DirConfig } -cfgSrcDir, cfgRefDir, cfgOutDir, cfgResDir :: Config -> FilePath +cfgSrcDir, cfgRefDir, cfgOutDir, cfgResDir :: Config c -> FilePath cfgSrcDir = dcfgSrcDir . cfgDirConfig cfgRefDir = dcfgRefDir . cfgDirConfig cfgOutDir = dcfgOutDir . cfgDirConfig cfgResDir = dcfgResDir . cfgDirConfig + data Flag = FlagHaddockPath FilePath | FlagGhcPath FilePath @@ -133,9 +142,9 @@ checkOpt args = do return (flags, files) -loadConfig :: DirConfig -> [Flag] -> [String] -> IO Config -loadConfig cfgDirConfig@(DirConfig { .. }) flags files = do - cfgEnv <- (:) ("haddock_datadir", dcfgResDir) <$> getEnvironment +loadConfig :: CheckConfig c -> DirConfig -> [Flag] -> [String] -> IO (Config c) +loadConfig ccfg dcfg flags files = do + cfgEnv <- (:) ("haddock_datadir", dcfgResDir dcfg) <$> getEnvironment systemHaddockPath <- List.lookup "HADDOCK_PATH" <$> getEnvironment cfgHaddockPath <- case flagsHaddockPath flags <|> systemHaddockPath of @@ -149,11 +158,11 @@ loadConfig cfgDirConfig@(DirConfig { .. }) flags files = do printVersions cfgEnv cfgHaddockPath - cfgFiles <- processFileArgs cfgDirConfig files + cfgFiles <- processFileArgs dcfg files cfgHaddockArgs <- liftM concat . sequence $ [ pure ["--no-warnings"] - , pure ["--odir=" ++ dcfgOutDir] + , pure ["--odir=" ++ dcfgOutDir dcfg] , pure ["--pretty-html"] , pure ["--html"] , pure ["--optghc=-w"] @@ -167,6 +176,9 @@ loadConfig cfgDirConfig@(DirConfig { .. }) flags files = do then pure Nothing else (<|>) <$> pure (flagsDiffTool flags) <*> defaultDiffTool + let cfgCheckConfig = ccfg + let cfgDirConfig = dcfg + return $ Config { .. } -- cgit v1.2.3