Skip to content

Commit

Permalink
Added a haddock-project test
Browse files Browse the repository at this point in the history
  • Loading branch information
coot committed May 21, 2023
1 parent f915596 commit ce698df
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cabal-install/src/Distribution/Client/ProjectBuilding.hs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ import Distribution.Types.BuildType
import Distribution.Types.PackageDescription.Lens (componentModules)
import Distribution.Simple.Program
import qualified Distribution.Simple.Setup as Cabal
import Distribution.Simple.Command (CommandUI)
import Distribution.Simple.Command (CommandUI, commandName)
import qualified Distribution.Simple.Register as Cabal
import Distribution.Simple.LocalBuildInfo
( ComponentName(..), LibraryName(..) )
Expand Down
1 change: 1 addition & 0 deletions cabal-install/src/Distribution/Client/SetupWrapper.hs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ data SetupMethod = InternalMethod
-- child process
| ExternalMethod FilePath
-- ^ run Cabal commands through a custom \"Setup\" executable
deriving Show

-- TODO: The 'setupWrapper' and 'SetupScriptOptions' should be split into two
-- parts: one that has no policy and just does as it's told with all the
Expand Down
60 changes: 51 additions & 9 deletions cabal-install/tests/IntegrationTests2.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,26 @@ import Distribution.Solver.Types.ConstraintSource
import Distribution.Solver.Types.PackageConstraint
( PackageProperty(PackagePropertySource) )

import qualified Distribution.Client.CmdBuild as CmdBuild
import qualified Distribution.Client.CmdRepl as CmdRepl
import qualified Distribution.Client.CmdRun as CmdRun
import qualified Distribution.Client.CmdTest as CmdTest
import qualified Distribution.Client.CmdBench as CmdBench
import qualified Distribution.Client.CmdHaddock as CmdHaddock
import qualified Distribution.Client.CmdListBin as CmdListBin
import qualified Distribution.Client.CmdBuild as CmdBuild
import qualified Distribution.Client.CmdRepl as CmdRepl
import qualified Distribution.Client.CmdRun as CmdRun
import qualified Distribution.Client.CmdTest as CmdTest
import qualified Distribution.Client.CmdBench as CmdBench
import qualified Distribution.Client.CmdHaddock as CmdHaddock
import qualified Distribution.Client.CmdHaddockProject as CmdHaddockProject
import qualified Distribution.Client.CmdListBin as CmdListBin

import Distribution.Package
import Distribution.PackageDescription
import Distribution.InstalledPackageInfo (InstalledPackageInfo)
import Distribution.Simple.Setup (toFlag, HaddockFlags(..), defaultHaddockFlags)
import Distribution.Client.Setup (globalCommand)
import Distribution.Simple.Setup
( toFlag, HaddockFlags(..), HaddockProjectFlags (..)
, defaultHaddockFlags, defaultHaddockProjectFlags )
import Distribution.Client.Setup (globalCommand, globalStoreDir)
import Distribution.Client.Config (loadConfig, SavedConfig(savedGlobalFlags))
import Distribution.Simple.Compiler
import Distribution.Simple.Command
import Distribution.Client.GlobalFlags (defaultGlobalFlags)
import qualified Distribution.Simple.Flag as Flag
import Distribution.System
import Distribution.Version
Expand Down Expand Up @@ -149,6 +153,13 @@ tests config =
testCase "Test Nix Flag" testNixFlags,
testCase "Test Ignore Project Flag" testIgnoreProjectFlag
]
-- `haddock-project` is only supported by `haddock-2.26.1` and above which is
-- shipped with `ghc-9.4`
#if __GLASGOW_HASKELL__ >= 904
, testGroup "haddock-project"
[ testCase "dependencies" testHaddockProjectDependencies
]
#endif
]

testTargetSelectors :: (String -> IO ()) -> Assertion
Expand Down Expand Up @@ -1968,3 +1979,34 @@ testIgnoreProjectFlag = do
emptyConfig = mempty
ignoreSetConfig :: ProjectConfig
ignoreSetConfig = mempty { projectConfigShared = mempty { projectConfigIgnoreProject = Flag True } }


cleanHaddockProject :: FilePath -> IO ()
cleanHaddockProject testdir = do
cleanProject testdir
let haddocksdir = basedir </> testdir </> "haddocks"
alreadyExists <- doesDirectoryExist haddocksdir
when alreadyExists $ removePathForcibly haddocksdir
let storedir = basedir </> testdir </> "store"
alreadyExists' <- doesDirectoryExist storedir
when alreadyExists' $ removePathForcibly storedir


#if __GLASGOW_HASKELL__ >= 904
testHaddockProjectDependencies :: Assertion
testHaddockProjectDependencies = do
let dir = basedir </> testdir
cleanHaddockProject testdir
withCurrentDirectory dir $ do
CmdHaddockProject.haddockProjectAction
defaultHaddockProjectFlags { haddockProjectVerbosity = Flag verbosity }
["all"]
defaultGlobalFlags { globalStoreDir = Flag "store" }

let haddock = "haddocks" </> "async" </> "async.haddock"
hasHaddock <- doesFileExist haddock
unless hasHaddock $ assertFailure ("File `" ++ haddock ++ "` does not exist.")
cleanHaddockProject testdir
where
testdir = "haddock-project/dependencies"
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: a
version: 0.1.0.0
build-type: Simple
cabal-version: >= 1.10

library
exposed-modules: MyLib
build-depends: base, async
hs-source-dirs: src
default-language: Haskell2010
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
packages: .
-- `jobs` is necessary to use `InternalMethod :: SetupMethod`.
jobs: 1

documentation: True

package async
documentation: True
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module MyLib (someFunc) where

import Control.Concurrent.Async

someFunc :: IO (Async ())
someFunc = async (return ())

0 comments on commit ce698df

Please sign in to comment.