Skip to content

Commit

Permalink
test fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
sheaf committed Apr 26, 2024
1 parent d13e968 commit ac33796
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
12 changes: 12 additions & 0 deletions cabal-install/src/Distribution/Client/InLibrary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ where
import Distribution.Client.Compat.Prelude
import Prelude ()

import Distribution.Backpack.DescribeUnitId (setupMessage')
import Distribution.Client.ProjectPlanning.Types
import Distribution.Client.RebuildMonad
import qualified Distribution.Client.SetupHooks.CallHooksExe as ExternalHooksExe
Expand Down Expand Up @@ -136,6 +137,17 @@ configure
confHooks = configureHooks $ ExternalHooksExe.buildTypeSetupHooks mbWorkDir distPref bt

-- Configure package
let pkgId :: PD.PackageIdentifier
pkgId = PD.package pkgDesc
case mbComp of
Nothing -> setupMessage verbosity "Configuring" pkgId
Just cname ->
setupMessage'
verbosity
"Configuring"
pkgId
cname
(Just (Cabal.configInstantiateWith cfg))

-- SetupHooks TODO: we should avoid re-doing package-wide things
-- over and over in the per-component world, e.g.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ custom-setup

library
exposed-modules: MyLib
build-depends: base ^>=4.19.1.0
build-depends: base >= 4.12 && < 5.0
hs-source-dirs: src
default-language: Haskell2010
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import Test.Cabal.Prelude

import System.Directory ( doesFileExist )

main = cabalTest $ do
mpkgdb <- testPackageDbPath <$> getTestEnv
case mpkgdb of
env <- getTestEnv
case testPackageDbPath env of
Nothing -> skip "Cabal-hooks library unavailable."
Just pkgdb -> recordMode DoNotRecord $ do
cabal "build" [ "--package-db=" ++ pkgdb ]
liftIO $ appendFile "SetupHooks.hs" "definitely-wrong!"
let setupHooksPath = testCurrentDir env </> "SetupHooks.hs"
setupHooksExists <- liftIO $ doesFileExist setupHooksPath
unless setupHooksExists $
error "Broken test: tried to write to a SetupHooks.hs file that doesn't exist."
liftIO $ appendFile setupHooksPath "this should fail to compile!"
-- If this doesn't fail, it's because we didn't re-build.
fails $ cabal "build" [ "--package-db=" ++ pkgdb ]
5 changes: 3 additions & 2 deletions cabal-testsuite/main/cabal-tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ buildCabalLibsProject projString verb mbGhc dir = do
, "--project-file=" ++ dir </> "cabal.project-test"
, "build"
, "-w", programPath ghc
, "Cabal", "Cabal-syntax", "Cabal-hooks"
, "Cabal", "Cabal-syntax", "Cabal-hooks", "hooks-exe"
] ) { progInvokeCwd = Just dir })
return final_package_db

Expand All @@ -169,7 +169,8 @@ buildCabalLibsSpecific ver verb mbGhc builddir_rel = do
buildCabalLibsIntree :: String -> Verbosity -> Maybe FilePath -> FilePath -> IO FilePath
buildCabalLibsIntree root verb mbGhc builddir_rel = do
dir <- canonicalizePath (builddir_rel </> "intree")
buildCabalLibsProject ("packages: " ++ root </> "Cabal" ++ " " ++ root </> "Cabal-syntax" ++ " " ++ root </> "Cabal-hooks") verb mbGhc dir
let libs = [ "Cabal", "Cabal-syntax", "Cabal-hooks", "hooks-exe", "../process" ]
buildCabalLibsProject ("packages: " ++ unwords ( map ( root </> ) libs ) ) verb mbGhc dir

main :: IO ()
main = do
Expand Down

0 comments on commit ac33796

Please sign in to comment.