Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions Cabal/tests/PackageTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ module Main where
import Data.Version (Version(Version))
import Distribution.Simple.Utils (cabalVersion)
import Distribution.Text (display)
import System.Directory (setCurrentDirectory)
import System.Directory (getCurrentDirectory, setCurrentDirectory)
import System.FilePath ((</>))
import Test.Framework (Test, TestName, defaultMain, testGroup)
import Test.Framework.Providers.HUnit (hUnitTestToTests)
import qualified Test.HUnit as HUnit
Expand All @@ -29,7 +30,7 @@ import PackageTests.BuildDeps.TargetSpecificDeps1.Check
import PackageTests.BuildDeps.TargetSpecificDeps2.Check
import PackageTests.BuildDeps.TargetSpecificDeps3.Check
import PackageTests.BuildTestSuiteDetailedV09.Check
import PackageTests.PackageTester (compileSetup)
import PackageTests.PackageTester (PackageSpec(..), compileSetup)
import PackageTests.PathsModule.Executable.Check
import PackageTests.PathsModule.Library.Check
import PackageTests.PreProcess.Check
Expand All @@ -43,8 +44,8 @@ import PackageTests.TestSuiteExeV10.Check
hunit :: TestName -> HUnit.Test -> Test
hunit name test = testGroup name $ hUnitTestToTests test

tests :: Version -> [Test]
tests version =
tests :: Version -> PackageSpec -> [Test]
tests version inplaceSpec =
[ hunit "BuildDeps/SameDepsAllRound"
PackageTests.BuildDeps.SameDepsAllRound.Check.suite
-- The two following tests were disabled by Johan Tibell as
Expand Down Expand Up @@ -79,7 +80,7 @@ tests version =
, hunit "EmptyLib/emptyLib"
PackageTests.EmptyLib.Check.emptyLib
, hunit "BuildTestSuiteDetailedV09"
PackageTests.BuildTestSuiteDetailedV09.Check.suite
$ PackageTests.BuildTestSuiteDetailedV09.Check.suite inplaceSpec
] ++
-- These tests are only required to pass on cabal version >= 1.7
(if version >= Version [1, 7] []
Expand All @@ -104,9 +105,17 @@ tests version =

main :: IO ()
main = do
wd <- getCurrentDirectory
let dbFile = wd </> "dist/package.conf.inplace"
inplaceSpec = PackageSpec
{ directory = []
, configOpts = [ "--package-db=" ++ dbFile
, "--constraint=Cabal == " ++ display cabalVersion
]
}
putStrLn $ "Cabal test suite - testing cabal version " ++
display cabalVersion
setCurrentDirectory "tests"
-- Create a shared Setup executable to speed up Simple tests
compileSetup "."
defaultMain (tests cabalVersion)
defaultMain (tests cabalVersion inplaceSpec)
9 changes: 6 additions & 3 deletions Cabal/tests/PackageTests/BuildTestSuiteDetailedV09/Check.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import System.FilePath ((</>))

import PackageTests.PackageTester

suite :: Test
suite = TestCase $ do
suite :: PackageSpec -> Test
suite inplaceSpec = TestCase $ do
let dir = "PackageTests" </> "BuildTestSuiteDetailedV09"
spec = PackageSpec dir ["--enable-tests"]
spec = inplaceSpec
{ directory = dir
, configOpts = "--enable-tests" : configOpts inplaceSpec
}
confResult <- cabal_configure spec
assertEqual "configure failed!" (successful confResult) True
buildResult <- cabal_build spec
Expand Down
22 changes: 22 additions & 0 deletions Cabal/tests/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Writing Package Tests
=====================

The tests under the `PackageTests` directory define and build packages which
exercise various components of Cabal. Each test case is an `HUnit` test. The
entry point for the test suite, where all the test cases are listed, is
`PackageTests.hs`. There are utilites for calling the stages of Cabal's build
process in `PackageTests/PackageTester.hs`; have a look at an existing test case
to see how they're used.

It is very important that package tests use the in-place version of Cabal,
rather than the system version. Several long-standing bugs in the test suite
were caused by testing the system (rather than the newly-compiled) version of
Cabal. There are two places where the system Cabal can accidentally be invoked:
1. Compiling `Setup.hs`. `runghc` needs to be told about the in-place package
database. This issue should be solved for all future package tests; see
`compileSetup` in `PackageTests/PackageTester.hs`.
2. Compiling a package which depends on Cabal. In particular, packages with
`detailed` type test suites depend on the Cabal library directly, so it is
important that they are configured to use the in-place package database. The
test suite already creates a stub `PackageSpec` for this case; see
`PackageTests/BuildTestSuiteDetailedV09/Check.hs` to see how it is used.