diff --git a/Cabal/Distribution/Simple/Haddock.hs b/Cabal/Distribution/Simple/Haddock.hs index 119455c6385..07d898c6321 100644 --- a/Cabal/Distribution/Simple/Haddock.hs +++ b/Cabal/Distribution/Simple/Haddock.hs @@ -559,7 +559,9 @@ runHaddock verbosity tmpFileOpts comp platform haddockProg args renderArgs verbosity tmpFileOpts haddockVersion comp platform args $ \(flags,result)-> do - runProgram verbosity haddockProg flags + haddockOut <- getProgramOutput verbosity haddockProg flags + unless (verbosity <= silent) $ + putStr haddockOut notice verbosity $ "Documentation created: " ++ result diff --git a/cabal-testsuite/PackageTests/NewHaddock/Fails/cabal.out b/cabal-testsuite/PackageTests/NewHaddock/Fails/cabal.out index cbfc470cbba..860963efde9 100644 --- a/cabal-testsuite/PackageTests/NewHaddock/Fails/cabal.out +++ b/cabal-testsuite/PackageTests/NewHaddock/Fails/cabal.out @@ -12,4 +12,5 @@ In order, the following will be built: - example-1.0 (lib) (first run) Preprocessing library for example-1.0.. Running Haddock on library for example-1.0.. +cabal: '' exited with an error: cabal: Failed to build documentation for example-1.0-inplace. diff --git a/cabal-testsuite/src/Test/Cabal/Monad.hs b/cabal-testsuite/src/Test/Cabal/Monad.hs index 19695aaa37b..77f4f6fa5dc 100644 --- a/cabal-testsuite/src/Test/Cabal/Monad.hs +++ b/cabal-testsuite/src/Test/Cabal/Monad.hs @@ -411,6 +411,10 @@ mkNormalizerEnv = do list_out <- liftIO $ readProcess (programPath ghc_pkg_program) ["list", "--global", "--simple-output"] "" tmpDir <- liftIO $ getTemporaryDirectory + haddock <- let prog = fromJust $ lookupKnownProgram "haddock" (testProgramDb env) + in fmap (fst . fromJust) $ liftIO $ + programFindLocation prog (testVerbosity env) + [ProgramSearchPathDefault] return NormalizerEnv { normalizerRoot = addTrailingPathSeparator (testSourceDir env), @@ -423,8 +427,12 @@ mkNormalizerEnv = do normalizerKnownPackages = mapMaybe simpleParse (words list_out), normalizerPlatform - = testPlatform env + = testPlatform env, + normalizerHaddock + = haddock } + where + requireProgramM :: Program -> TestM ConfiguredProgram requireProgramM program = do diff --git a/cabal-testsuite/src/Test/Cabal/OutputNormalizer.hs b/cabal-testsuite/src/Test/Cabal/OutputNormalizer.hs index fd7457b3324..ce67115bd44 100644 --- a/cabal-testsuite/src/Test/Cabal/OutputNormalizer.hs +++ b/cabal-testsuite/src/Test/Cabal/OutputNormalizer.hs @@ -14,6 +14,7 @@ import Distribution.System import qualified Data.Foldable as F import Text.Regex +import Data.List normalizeOutput :: NormalizerEnv -> String -> String normalizeOutput nenv = @@ -54,11 +55,41 @@ normalizeOutput nenv = else id) -- hackage-security locks occur non-deterministically . resub "(Released|Acquired|Waiting) .*hackage-security-lock\n" "" + -- Substitute the haddock binary with + -- Do this before the substitution + . resub (posixRegexEscape (normalizerHaddock nenv)) "" + . removeErrors where packageIdRegex pid = resub (posixRegexEscape (display pid) ++ "(-[A-Za-z0-9.-]+)?") (prettyShow (packageName pid) ++ "-") +{- Given +cabal: blah exited with an error: +Example.hs:6:11: error: + * Couldn't match expected type `Int' with actual type `Bool' + * In the expression: False + In an equation for `example': example = False +| +6 | example = False +| ^^^^^ +cabal: Failed to build documentation for example-1.0-inplace. + +this will remove the error in between the first line with "exited with an error" +and the closing "cabal:". Pretty nasty, but its needed to ignore errors from +external programs whose output might change. +-} +removeErrors :: String -> String +removeErrors s = unlines (go (lines s) False) + where + go [] _ = [] + go (x:xs) True + | "cabal:" `isPrefixOf` x = x:(go xs False) + | otherwise = go xs True + go (x:xs) False + | "exited with an error" `isInfixOf` x = x:(go xs True) + | otherwise = x:(go xs False) + data NormalizerEnv = NormalizerEnv { normalizerRoot :: FilePath , normalizerTmpDir :: FilePath @@ -66,6 +97,7 @@ data NormalizerEnv = NormalizerEnv , normalizerGhcVersion :: Version , normalizerKnownPackages :: [PackageId] , normalizerPlatform :: Platform + , normalizerHaddock :: FilePath } posixSpecialChars :: [Char]