[commit: haddock] 2.17.3.1-spanfix, alexbiehl-patch-1, ghc-8.0, ghc-8.0-facebook, ghc-head, ghc-head1, haddock-quick, headdock-library-1.4.5, ie_avails, issue-303, issue-475, master, pr-filter-maps, pr/cabal-desc, travis, v2.17, v2.17.3, v2.18, wip-located-module-as, wip/D2418, wip/T11080-open-data-kinds, wip/T11430, wip/T12105, wip/T12105-2, wip/T12942, wip/T13163, wip/T14529, wip/T3384, wip/embelleshed-rdr, wip/new-tree-one-param, wip/rae, wip/remove-frames, wip/remove-frames1, wip/revert-ttg-2017-11-20, wip/ttg-2017-10-13, wip/ttg-2017-10-31, wip/ttg-2017-11-06, wip/ttg2-2017-11-10, wip/ttg3-2017-11-12, wip/ttg4-constraints-2017-11-13, wip/ttg6-unrevert-2017-11-22: Implement output accepting mechanism in test package. (5568091)

git at git.haskell.org git at git.haskell.org
Tue Nov 28 11:37:30 UTC 2017


Repository : ssh://git@git.haskell.org/haddock

On branches: 2.17.3.1-spanfix,alexbiehl-patch-1,ghc-8.0,ghc-8.0-facebook,ghc-head,ghc-head1,haddock-quick,headdock-library-1.4.5,ie_avails,issue-303,issue-475,master,pr-filter-maps,pr/cabal-desc,travis,v2.17,v2.17.3,v2.18,wip-located-module-as,wip/D2418,wip/T11080-open-data-kinds,wip/T11430,wip/T12105,wip/T12105-2,wip/T12942,wip/T13163,wip/T14529,wip/T3384,wip/embelleshed-rdr,wip/new-tree-one-param,wip/rae,wip/remove-frames,wip/remove-frames1,wip/revert-ttg-2017-11-20,wip/ttg-2017-10-13,wip/ttg-2017-10-31,wip/ttg-2017-11-06,wip/ttg2-2017-11-10,wip/ttg3-2017-11-12,wip/ttg4-constraints-2017-11-13,wip/ttg6-unrevert-2017-11-22
Link       : http://git.haskell.org/haddock.git/commitdiff/5568091a53ee53f742b6fe9f11b3edd1664228b9

>---------------------------------------------------------------

commit 5568091a53ee53f742b6fe9f11b3edd1664228b9
Author: Ɓukasz Hanuszczak <lukasz.hanuszczak at gmail.com>
Date:   Mon Aug 17 12:54:48 2015 +0200

    Implement output accepting mechanism in test package.


>---------------------------------------------------------------

5568091a53ee53f742b6fe9f11b3edd1664228b9
 haddock-test/src/Test/Haddock.hs        | 16 +++++++++++++++-
 haddock-test/src/Test/Haddock/Config.hs |  6 ++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/haddock-test/src/Test/Haddock.hs b/haddock-test/src/Test/Haddock.hs
index 7820484..a2c6609 100644
--- a/haddock-test/src/Test/Haddock.hs
+++ b/haddock-test/src/Test/Haddock.hs
@@ -29,7 +29,11 @@ data CheckResult
 
 
 runAndCheck :: Config c -> IO ()
-runAndCheck cfg = runHaddock cfg >> checkFiles cfg
+runAndCheck cfg = do
+    runHaddock cfg
+    if cfgAccept cfg
+        then acceptFiles cfg
+        else checkFiles cfg
 
 
 checkFiles :: Config c -> IO ()
@@ -55,6 +59,16 @@ checkFiles cfg@(Config { .. }) = do
             exitFailure
 
 
+acceptFiles :: Config c -> IO ()
+acceptFiles (Config { cfgFiles = files, cfgDirConfig = dcfg }) = do
+
+    forM_ files $ \file -> do
+        let mdl = takeBaseName file
+        putStr $ "Accepting " ++ mdl ++ "... "
+        copyFile (outFile dcfg mdl) (refFile dcfg mdl)
+        putStrLn "DONE"
+
+
 maybeDiff :: Config c -> [String] -> IO ()
 maybeDiff (Config { cfgDiffTool = Nothing }) _ = pure ()
 maybeDiff cfg@(Config { cfgDiffTool = (Just diff) }) mdls = do
diff --git a/haddock-test/src/Test/Haddock/Config.hs b/haddock-test/src/Test/Haddock/Config.hs
index 4f6bb81..451cd80 100644
--- a/haddock-test/src/Test/Haddock/Config.hs
+++ b/haddock-test/src/Test/Haddock/Config.hs
@@ -68,6 +68,7 @@ data Config c = Config
     , cfgHaddockStdOut :: FilePath
     , cfgDiffTool :: Maybe FilePath
     , cfgEnv :: Environment
+    , cfgAccept :: Bool
     , cfgCheckConfig :: CheckConfig c
     , cfgDirConfig :: DirConfig
     }
@@ -87,6 +88,7 @@ data Flag
     | FlagHaddockStdOut FilePath
     | FlagDiffTool FilePath
     | FlagNoDiff
+    | FlagAccept
     | FlagHelp
     deriving Eq
 
@@ -118,6 +120,8 @@ options =
         "where to redirect Haddock output"
     , Option [] ["diff-tool"] (ReqArg FlagDiffTool "PATH")
         "diff tool to use when printing failed cases"
+    , Option ['a'] ["accept"] (NoArg FlagAccept)
+        "accept generated output"
     , Option [] ["no-diff"] (NoArg FlagNoDiff)
         "do not print diff for failed cases"
     , Option ['h'] ["help"] (NoArg FlagHelp)
@@ -178,6 +182,8 @@ loadConfig ccfg dcfg flags files = do
         then pure Nothing
         else (<|>) <$> pure (flagsDiffTool flags) <*> defaultDiffTool
 
+    let cfgAccept = FlagAccept `elem` flags
+
     let cfgCheckConfig = ccfg
     let cfgDirConfig = dcfg
 



More information about the ghc-commits mailing list