Skip to content

Commit 774ff04

Browse files
authored
Merge pull request #9505 from mpickering/wip/refactor-testsuite
2 parents eb0f95b + 2a2d0b3 commit 774ff04

File tree

23 files changed

+119
-98
lines changed

23 files changed

+119
-98
lines changed

Cabal-tests/Cabal-tests.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ source-repository head
2222
library
2323
hs-source-dirs: lib
2424
exposed-modules: Test.Utils.TempTestDir
25-
build-depends: base, directory, Cabal, filepath
25+
build-depends: base, directory, Cabal, filepath, exceptions
2626

2727
-- Small, fast running tests.
2828
test-suite unit-tests

Cabal-tests/lib/Test/Utils/TempTestDir.hs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ import Distribution.Simple.Utils (warn)
1010
import Distribution.Verbosity
1111

1212
import Control.Concurrent (threadDelay)
13-
import Control.Exception (bracket, throwIO, try)
13+
import Control.Exception (throwIO, try)
1414
import Control.Monad (when)
15+
import Control.Monad.Catch ( bracket, MonadMask)
16+
import Control.Monad.IO.Class
1517

1618
import System.Directory
1719
import System.IO.Error
@@ -20,13 +22,13 @@ import qualified System.Info (os)
2022

2123
-- | Much like 'withTemporaryDirectory' but with a number of hacks to make
2224
-- sure on windows that we can clean up the directory at the end.
23-
withTestDir :: Verbosity -> String -> (FilePath -> IO a) -> IO a
25+
withTestDir :: (MonadIO m, MonadMask m) => Verbosity -> String -> (FilePath -> m a) -> m a
2426
withTestDir verbosity template action = do
25-
systmpdir <- getTemporaryDirectory
27+
systmpdir <- liftIO getTemporaryDirectory
2628
bracket
27-
( do { tmpRelDir <- createTempDirectory systmpdir template
29+
( do { tmpRelDir <- liftIO $ createTempDirectory systmpdir template
2830
; return $ systmpdir </> tmpRelDir } )
29-
(removeDirectoryRecursiveHack verbosity)
31+
(liftIO . removeDirectoryRecursiveHack verbosity)
3032
action
3133

3234
-- | On Windows, file locks held by programs we run (in this case VCSs)

Cabal-tests/tests/UnitTests/Distribution/PackageDescription/Check.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
module UnitTests.Distribution.PackageDescription.Check (tests) where
55

6-
import Distribution.Compat.Prelude.Internal
6+
import Distribution.Compat.Prelude
77
import Prelude ()
88

99
import Distribution.PackageDescription.Check
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import Test.Cabal.Prelude
2-
main = withShorterPathForNewBuildStore $ \storeDir ->
3-
cabalTest $ do
2+
main = cabalTest $ withShorterPathForNewBuildStore $ do
43
skipUnlessGhcVersion ">= 8.1"
54
skipIfWindows -- TODO: https://github.com/haskell/cabal/issues/6271
65
withProjectFile "cabal.repo.project" $ do
76
withRepo "repo" $ do
8-
cabalG ["--store-dir=" ++ storeDir] "v2-build" ["exe"]
7+
cabal "v2-build" ["exe"]
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Test.Cabal.Prelude
2-
main = withShorterPathForNewBuildStore $ \storeDir ->
3-
cabalTest $ do
2+
main =
3+
cabalTest $ withShorterPathForNewBuildStore $ do
44
skipUnlessGhcVersion ">= 8.1"
55
skipIfWindows -- TODO: https://github.com/haskell/cabal/issues/6271
66
withRepo "repo" $ do
7-
cabalG ["--store-dir=" ++ storeDir] "v2-build" ["T6385"]
7+
cabal "v2-build" ["T6385"]

cabal-testsuite/PackageTests/BuildTargets/UseLocalPackageForSetup/use-local-package-as-setup-dep.test.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ import Test.Cabal.Prelude
1010
-- qualifier as pkg, even though they are both build targets of the project.
1111
-- The solution must use --independent-goals to give pkg and setup-dep different
1212
-- qualifiers.
13-
main = withShorterPathForNewBuildStore $ \storeDir ->
14-
cabalTest $ do
13+
main =
14+
cabalTest $ withShorterPathForNewBuildStore $ do
1515
skipUnless "no v2-build compatible boot-Cabal" =<< hasNewBuildCompatBootCabal
1616
withRepo "repo" $ do
17-
fails $ cabalG ["--store-dir=" ++ storeDir] "v2-build" ["pkg:my-exe", "--dry-run"]
17+
fails $ cabal "v2-build" ["pkg:my-exe", "--dry-run"]
1818
-- Disabled recording because whether or not we get
1919
-- detailed information for the build of my-exe depends
2020
-- on whether or not the Cabal library version is recent
2121
-- enough
22-
r1 <- recordMode DoNotRecord $ cabalG' ["--store-dir=" ++ storeDir] "v2-build" ["pkg:my-exe", "--independent-goals"]
22+
r1 <- recordMode DoNotRecord $ cabal' "v2-build" ["pkg:my-exe", "--independent-goals"]
2323
assertOutputContains "Setup.hs: setup-dep from project" r1
2424
withPlan $ do
2525
r2 <- runPlanExe' "pkg" "my-exe" []
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import Test.Cabal.Prelude
22

3-
main = withShorterPathForNewBuildStore $ \storeDir -> cabalTest $ withRepo "repo" $ do
3+
main = cabalTest $ withShorterPathForNewBuildStore $ withRepo "repo" $ do
44
skipUnlessGhcVersion ">= 8.8"
5-
cabalG ["--store-dir=" ++ storeDir] "v2-build" ["hie"]
6-
liftIO $ do
7-
installedDependencyLibDir <- findDependencyInStore storeDir "hie-dependency"
8-
shouldExist $ installedDependencyLibDir </> "lib" </> "extra-compilation-artifacts" </> "hie" </> "HieDependency.hie"
5+
cabal "v2-build" ["hie"]
6+
installedDependencyLibDir <- findDependencyInStore "hie-dependency"
7+
shouldExist $ installedDependencyLibDir </> "lib" </> "extra-compilation-artifacts" </> "hie" </> "HieDependency.hie"

cabal-testsuite/PackageTests/HaddockArgs/hoogle.test.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import Test.Cabal.Prelude
22

3-
main = withShorterPathForNewBuildStore $ \storeDir -> cabalTest $ withRepo "repo" $ do
3+
main = cabalTest $ withShorterPathForNewBuildStore $ withRepo "repo" $ do
44
-- Checks if hoogle txt files are generated.
55
-- Logs contain something like "Documentation created: dist/doc/html/indef/indef.txt", so we don't need
66
-- to do extra check
7-
cabalG ["--store-dir=" ++ storeDir] "v2-build"
7+
cabal "v2-build"
88
[ "example"
99
, "--enable-documentation"
1010
, "--haddock-hoogle"

cabal-testsuite/PackageTests/HaddockArgs/quickjump.test.hs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ import Test.Cabal.Prelude
33
import System.Directory
44
import System.FilePath
55

6-
main = withShorterPathForNewBuildStore $ \storeDir -> cabalTest $ withRepo "repo" $ do
7-
cabalG ["--store-dir=" ++ storeDir] "v2-build"
6+
main = cabalTest $ withShorterPathForNewBuildStore $ withRepo "repo" $ do
7+
cabal "v2-build"
88
[ "example"
99
, "--enable-documentation"
1010
, "--haddock-quickjump"
1111
]
12-
liftIO $ do
13-
libDir <- findDependencyInStore storeDir "indef"
14-
assertFileDoesContain (libDir </> "cabal-hash.txt") "haddock-quickjump: True"
15-
docIndexJsonExists <- doesFileExist (libDir </> "share" </> "doc" </> "html" </> "doc-index.json")
16-
assertBool "doc-index.json doesn't exist, --quickjump is probably not passed to haddock" docIndexJsonExists
12+
libDir <- findDependencyInStore "indef"
13+
assertFileDoesContain (libDir </> "cabal-hash.txt") "haddock-quickjump: True"
14+
docIndexJsonExists <- liftIO $ doesFileExist (libDir </> "share" </> "doc" </> "html" </> "doc-index.json")
15+
assertBool "doc-index.json doesn't exist, --quickjump is probably not passed to haddock" docIndexJsonExists

cabal-testsuite/PackageTests/HaddockBuildDepends/cabal.test.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@ main = cabalTest . withRepo "repo" $ do
55
cabal "build" ["--enable-documentation"]
66

77
env <- getTestEnv
8-
let storeDir = testCabalDir env </> "store"
98

109
-- Check properties of executable component
11-
libDir <- liftIO $ findDependencyInStore storeDir "exe"
10+
libDir <- findDependencyInStore "exe"
1211
-- Documentation is enabled..
1312
assertFileDoesContain (libDir </> "cabal-hash.txt") "documentation: True"
1413
-- But not built
1514
shouldDirectoryNotExist ( libDir </> "share" </> "doc" )
1615

1716
-- Check properties of library
18-
libDir <- liftIO $ findDependencyInStore storeDir "lib"
17+
libDir <- findDependencyInStore "lib"
1918
-- Documentation is enabled..
2019
assertFileDoesContain (libDir </> "cabal-hash.txt") "documentation: True"
2120
-- and has been built

0 commit comments

Comments
 (0)