Commit 5bcb6f76 authored by Iain Nicol's avatar Iain Nicol
Browse files

Add some tests of our Haddock support

parent e417655d
......@@ -80,6 +80,10 @@ extra-source-files:
tests/PackageTests/DeterministicAr/Lib.hs
tests/PackageTests/DeterministicAr/my.cabal
tests/PackageTests/EmptyLib/empty/empty.cabal
tests/PackageTests/Haddock/CPP.hs
tests/PackageTests/Haddock/Literate.lhs
tests/PackageTests/Haddock/my.cabal
tests/PackageTests/Haddock/Simple.hs
tests/PackageTests/OrderFlags/Foo.hs
tests/PackageTests/OrderFlags/my.cabal
tests/PackageTests/PathsModule/Executable/Main.hs
......@@ -261,6 +265,7 @@ test-suite package-tests
PackageTests.CMain.Check
PackageTests.DeterministicAr.Check
PackageTests.EmptyLib.Check
PackageTests.Haddock.Check
PackageTests.OrderFlags.Check
PackageTests.PackageTester
PackageTests.PathsModule.Executable.Check
......
......@@ -29,6 +29,7 @@ import PackageTests.TemplateHaskell.Check
import PackageTests.CMain.Check
import PackageTests.DeterministicAr.Check
import PackageTests.EmptyLib.Check
import PackageTests.Haddock.Check
import PackageTests.TestOptions.Check
import PackageTests.TestStanza.Check
import PackageTests.TestSuiteExeV10.Check
......@@ -37,7 +38,8 @@ import PackageTests.OrderFlags.Check
import Distribution.Compat.Exception (catchIO)
import Distribution.Simple.LocalBuildInfo (LocalBuildInfo(..))
import Distribution.Simple.Program.Types (programPath)
import Distribution.Simple.Program.Builtin (ghcProgram, ghcPkgProgram)
import Distribution.Simple.Program.Builtin (ghcProgram, ghcPkgProgram,
haddockProgram)
import Distribution.Simple.Program.Db (requireProgram)
import Distribution.Simple.Utils (cabalVersion, die, withFileContents)
import Distribution.Text (display)
......@@ -95,6 +97,7 @@ tests version inplaceSpec ghcPath ghcPkgPath =
(PackageTests.DeterministicAr.Check.suite ghcPath ghcPkgPath)
, hunit "EmptyLib/emptyLib"
(PackageTests.EmptyLib.Check.emptyLib ghcPath)
, hunit "Haddock" (PackageTests.Haddock.Check.suite ghcPath)
, hunit "BuildTestSuiteDetailedV09"
(PackageTests.BuildTestSuiteDetailedV09.Check.suite inplaceSpec ghcPath)
, hunit "OrderFlags"
......@@ -142,10 +145,13 @@ main = do
lbi <- getPersistBuildConfig_ ("dist" </> "setup-config")
(ghc, _) <- requireProgram normal ghcProgram (withPrograms lbi)
(ghcPkg, _) <- requireProgram normal ghcPkgProgram (withPrograms lbi)
(haddock, _) <- requireProgram normal haddockProgram (withPrograms lbi)
let ghcPath = programPath ghc
ghcPkgPath = programPath ghcPkg
haddockPath = programPath haddock
putStrLn $ "Using ghc: " ++ ghcPath
putStrLn $ "Using ghc-pkg: " ++ ghcPkgPath
putStrLn $ "Using haddock: " ++ haddockPath
setCurrentDirectory "tests"
-- Create a shared Setup executable to speed up Simple tests
compileSetup "." ghcPath
......
{-# LANGUAGE CPP #-}
module CPP where
#define HIDING hiding
#define NEEDLES needles
-- | For HIDING NEEDLES.
data Haystack = Haystack
module PackageTests.Haddock.Check (suite) where
import Control.Monad (unless, when)
import Data.List (isInfixOf)
import System.FilePath ((</>))
import System.Directory (doesDirectoryExist, removeDirectoryRecursive)
import Test.HUnit (Assertion, Test (TestCase), assertFailure)
import Distribution.Simple.Utils (withFileContents)
import PackageTests.PackageTester
(PackageSpec(..), assertHaddockSucceeded, cabal_haddock)
this :: String
this = "Haddock"
suite :: FilePath -> Test
suite ghcPath = TestCase $ do
let dir = "PackageTests" </> this
haddocksDir = dir </> "dist" </> "doc" </> "html" </> "Haddock"
spec = PackageSpec dir []
haddocksDirExists <- doesDirectoryExist haddocksDir
when haddocksDirExists (removeDirectoryRecursive haddocksDir)
hResult <- cabal_haddock spec [] ghcPath
assertHaddockSucceeded hResult
let docFiles = map (haddocksDir </>)
["CPP.html", "Literate.html", "Simple.html"]
mapM_ (assertFindInFile "For hiding needles.") docFiles
assertFindInFile :: String -> FilePath -> Assertion
assertFindInFile needle path =
withFileContents path
(\contents ->
unless (needle `isInfixOf` contents)
(assertFailure ("expected: " ++ needle ++ "\n" ++
" in file: " ++ path)))
> module Literate where
> -- | For hiding needles.
> data Haystack = Haystack
module Simple where
-- | For hiding needles.
data Haystack = Haystack
name: Haddock
version: 0.1
license: BSD3
author: Iain Nicol
stability: stable
category: PackageTests
build-type: Simple
Cabal-version: >= 1.2
description:
Check that Cabal successfully invokes Haddock.
Library
exposed-modules: CPP, Literate, Simple
other-extensions: CPP
build-depends: base
......@@ -10,6 +10,7 @@ module PackageTests.PackageTester
-- * Running cabal commands
, cabal_configure
, cabal_build
, cabal_haddock
, cabal_test
, cabal_bench
, cabal_install
......@@ -20,6 +21,7 @@ module PackageTests.PackageTester
-- * Test helpers
, assertBuildSucceeded
, assertBuildFailed
, assertHaddockSucceeded
, assertTestSucceeded
, assertInstallSucceeded
, assertOutputContains
......@@ -54,6 +56,7 @@ data PackageSpec = PackageSpec
data Success = Failure
| ConfigureSuccess
| BuildSuccess
| HaddockSuccess
| InstallSuccess
| TestSuccess
| BenchSuccess
......@@ -112,6 +115,22 @@ cabal_build spec ghcPath = do
record spec res
return res
cabal_haddock :: PackageSpec -> [String] -> FilePath -> IO Result
cabal_haddock spec extraArgs ghcPath = do
res <- doCabalHaddock spec extraArgs ghcPath
record spec res
return res
doCabalHaddock :: PackageSpec -> [String] -> FilePath -> IO Result
doCabalHaddock spec extraArgs ghcPath = do
configResult <- doCabalConfigure spec ghcPath
if successful configResult
then do
res <- cabal spec ("haddock" : extraArgs) ghcPath
return $ recordRun res HaddockSuccess configResult
else
return configResult
unregister :: String -> FilePath -> IO ()
unregister libraryName ghcPkgPath = do
res@(_, _, output) <- run Nothing ghcPkgPath ["unregister", "--user", libraryName]
......@@ -233,6 +252,12 @@ assertBuildFailed result = when (successful result) $
"expected: \'setup build\' should fail\n" ++
" output: " ++ outputText result
assertHaddockSucceeded :: Result -> Assertion
assertHaddockSucceeded result = unless (successful result) $
assertFailure $
"expected: \'setup haddock\' should succeed\n" ++
" output: " ++ outputText result
assertTestSucceeded :: Result -> Assertion
assertTestSucceeded result = unless (successful result) $
assertFailure $
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment