PackageTests.hs 8.76 KB
Newer Older
1
2
3
4
5
6
7
8
-- The intention is that this will be the new unit test framework.
-- Please add any working tests here.  This file should do nothing
-- but import tests from other modules.
--
-- Stephen Blackheath, 2009

module Main where

tibbe's avatar
tibbe committed
9
import PackageTests.BenchmarkExeV10.Check
10
import PackageTests.BenchmarkOptions.Check
tibbe's avatar
tibbe committed
11
import PackageTests.BenchmarkStanza.Check
tibbe's avatar
tibbe committed
12
13
-- import PackageTests.BuildDeps.GlobalBuildDepsNotAdditive1.Check
-- import PackageTests.BuildDeps.GlobalBuildDepsNotAdditive2.Check
14
import PackageTests.BuildDeps.InternalLibrary0.Check
15
16
17
18
import PackageTests.BuildDeps.InternalLibrary1.Check
import PackageTests.BuildDeps.InternalLibrary2.Check
import PackageTests.BuildDeps.InternalLibrary3.Check
import PackageTests.BuildDeps.InternalLibrary4.Check
tibbe's avatar
tibbe committed
19
20
21
22
import PackageTests.BuildDeps.SameDepsAllRound.Check
import PackageTests.BuildDeps.TargetSpecificDeps1.Check
import PackageTests.BuildDeps.TargetSpecificDeps2.Check
import PackageTests.BuildDeps.TargetSpecificDeps3.Check
ttuegel's avatar
ttuegel committed
23
import PackageTests.PackageTester (PackageSpec(..), SuiteConfig(..), compileSetup)
tibbe's avatar
tibbe committed
24
25
import PackageTests.PathsModule.Executable.Check
import PackageTests.PathsModule.Library.Check
tibbe's avatar
tibbe committed
26
import PackageTests.PreProcess.Check
27
import PackageTests.PreProcessExtraSources.Check
tibbe's avatar
tibbe committed
28
import PackageTests.TemplateHaskell.Check
29
import PackageTests.CMain.Check
30
import PackageTests.DeterministicAr.Check
refold's avatar
refold committed
31
import PackageTests.EmptyLib.Check
32
import PackageTests.Haddock.Check
ttuegel's avatar
ttuegel committed
33
import PackageTests.TestOptions.Check
ttuegel's avatar
ttuegel committed
34
import PackageTests.TestStanza.Check
ttuegel's avatar
ttuegel committed
35
import PackageTests.TestSuiteTests.ExeV10.Check
36
import PackageTests.TestSuiteTests.LibV09.Check
37
import PackageTests.OrderFlags.Check
38
import PackageTests.ReexportedModules.Check
39
import PackageTests.UniqueIPID.Check
40

41
import Distribution.Simple.Configure
ttuegel's avatar
ttuegel committed
42
    ( ConfigStateFileError(..), findDistPrefOrDefault, getConfigStateFile )
enolan's avatar
enolan committed
43
import Distribution.Simple.Compiler (PackageDB(..))
44
45
import Distribution.Simple.LocalBuildInfo (LocalBuildInfo(..))
import Distribution.Simple.Program.Types (programPath)
46
47
import Distribution.Simple.Program.Builtin
    ( ghcProgram, ghcPkgProgram, haddockProgram )
48
import Distribution.Simple.Program.Db (requireProgram)
ttuegel's avatar
ttuegel committed
49
import Distribution.Simple.Setup (Flag(..))
50
import Distribution.Simple.Utils (cabalVersion)
51
52
53
54
import Distribution.Text (display)
import Distribution.Verbosity (normal)
import Distribution.Version (Version(Version))

55
import Control.Exception (try, throw)
ttuegel's avatar
ttuegel committed
56
import Distribution.Compat.Environment ( setEnv )
enolan's avatar
enolan committed
57
58
59
#if !MIN_VERSION_base(4,8,0)
import Data.Functor ((<$>))
#endif
60
import System.Directory
ttuegel's avatar
ttuegel committed
61
    ( canonicalizePath, setCurrentDirectory )
62
import System.FilePath ((</>))
63
64
import Test.Tasty
import Test.Tasty.HUnit
65
66


ttuegel's avatar
ttuegel committed
67
68
tests :: SuiteConfig -> Version -> [TestTree]
tests config version =
69
    [ testCase "BuildDeps/SameDepsAllRound"
ttuegel's avatar
ttuegel committed
70
      (PackageTests.BuildDeps.SameDepsAllRound.Check.suite config)
tibbe's avatar
tibbe committed
71
72
      -- The two following tests were disabled by Johan Tibell as
      -- they have been failing for a long time:
73
      -- , testCase "BuildDeps/GlobalBuildDepsNotAdditive1/"
tibbe's avatar
tibbe committed
74
      --   (PackageTests.BuildDeps.GlobalBuildDepsNotAdditive1.Check.suite ghcPath)
75
      -- , testCase "BuildDeps/GlobalBuildDepsNotAdditive2/"
tibbe's avatar
tibbe committed
76
      --   (PackageTests.BuildDeps.GlobalBuildDepsNotAdditive2.Check.suite ghcPath)
77
    , testCase "BuildDeps/InternalLibrary0"
ttuegel's avatar
ttuegel committed
78
79
      (PackageTests.BuildDeps.InternalLibrary0.Check.suite config version)
    , testCase "PreProcess" (PackageTests.PreProcess.Check.suite config)
80
    , testCase "PreProcessExtraSources"
ttuegel's avatar
ttuegel committed
81
82
      (PackageTests.PreProcessExtraSources.Check.suite config)
    , testCase "TestStanza" (PackageTests.TestStanza.Check.suite config)
tibbe's avatar
tibbe committed
83
84
      -- ^ The Test stanza test will eventually be required
      -- only for higher versions.
ttuegel's avatar
ttuegel committed
85
86
    , testGroup "TestSuiteTests"
      [ testGroup "ExeV10"
87
        (PackageTests.TestSuiteTests.ExeV10.Check.checks config)
88
      , testGroup "LibV09"
89
        (PackageTests.TestSuiteTests.LibV09.Check.checks config)
ttuegel's avatar
ttuegel committed
90
      ]
91
92
    , testCase "TestOptions" (PackageTests.TestOptions.Check.suite config)
    , testCase "BenchmarkStanza" (PackageTests.BenchmarkStanza.Check.suite config)
tibbe's avatar
tibbe committed
93
94
      -- ^ The benchmark stanza test will eventually be required
      -- only for higher versions.
95
    , testCase "BenchmarkExeV10/Test"
ttuegel's avatar
ttuegel committed
96
97
      (PackageTests.BenchmarkExeV10.Check.checkBenchmark config)
    , testCase "BenchmarkOptions" (PackageTests.BenchmarkOptions.Check.suite config)
98
    , testCase "TemplateHaskell/vanilla"
ttuegel's avatar
ttuegel committed
99
      (PackageTests.TemplateHaskell.Check.vanilla config)
100
    , testCase "TemplateHaskell/profiling"
ttuegel's avatar
ttuegel committed
101
      (PackageTests.TemplateHaskell.Check.profiling config)
102
    , testCase "PathsModule/Executable"
ttuegel's avatar
ttuegel committed
103
104
105
      (PackageTests.PathsModule.Executable.Check.suite config)
    , testCase "PathsModule/Library"
      (PackageTests.PathsModule.Library.Check.suite config)
106
    , testCase "DeterministicAr"
ttuegel's avatar
ttuegel committed
107
      (PackageTests.DeterministicAr.Check.suite config)
108
    , testCase "EmptyLib/emptyLib"
109
110
      (PackageTests.EmptyLib.Check.emptyLib config)
    , testCase "Haddock" (PackageTests.Haddock.Check.suite config)
111
    , testCase "OrderFlags"
ttuegel's avatar
ttuegel committed
112
      (PackageTests.OrderFlags.Check.suite config)
113
    , testCase "TemplateHaskell/dynamic"
ttuegel's avatar
ttuegel committed
114
      (PackageTests.TemplateHaskell.Check.dynamic config)
115
    , testCase "ReexportedModules"
ttuegel's avatar
ttuegel committed
116
      (PackageTests.ReexportedModules.Check.suite config)
117
118
    , testCase "UniqueIPID"
      (PackageTests.UniqueIPID.Check.suite config)
119
120
    ] ++
    -- These tests are only required to pass on cabal version >= 1.7
121
    (if version >= Version [1, 7] []
122
     then [ testCase "BuildDeps/TargetSpecificDeps1"
ttuegel's avatar
ttuegel committed
123
            (PackageTests.BuildDeps.TargetSpecificDeps1.Check.suite config)
124
          , testCase "BuildDeps/TargetSpecificDeps2"
ttuegel's avatar
ttuegel committed
125
            (PackageTests.BuildDeps.TargetSpecificDeps2.Check.suite config)
126
          , testCase "BuildDeps/TargetSpecificDeps3"
ttuegel's avatar
ttuegel committed
127
            (PackageTests.BuildDeps.TargetSpecificDeps3.Check.suite config)
128
          , testCase "BuildDeps/InternalLibrary1"
ttuegel's avatar
ttuegel committed
129
            (PackageTests.BuildDeps.InternalLibrary1.Check.suite config)
130
          , testCase "BuildDeps/InternalLibrary2"
ttuegel's avatar
ttuegel committed
131
            (PackageTests.BuildDeps.InternalLibrary2.Check.suite config)
132
          , testCase "BuildDeps/InternalLibrary3"
ttuegel's avatar
ttuegel committed
133
            (PackageTests.BuildDeps.InternalLibrary3.Check.suite config)
134
          , testCase "BuildDeps/InternalLibrary4"
ttuegel's avatar
ttuegel committed
135
            (PackageTests.BuildDeps.InternalLibrary4.Check.suite config)
136
          , testCase "PackageTests/CMain"
ttuegel's avatar
ttuegel committed
137
            (PackageTests.CMain.Check.checkBuild config)
tibbe's avatar
tibbe committed
138
139
          ]
     else [])
140

141
main :: IO ()
142
main = do
ttuegel's avatar
ttuegel committed
143
144
145
146
147
    -- Find the builddir used to build Cabal
    distPref_ <- findDistPrefOrDefault NoFlag >>= canonicalizePath
    -- Use the default builddir for all of the subsequent package tests
    setEnv "CABAL_BUILDDIR" "dist"
    lbi <- getPersistBuildConfig_ (distPref_ </> "setup-config")
tibbe's avatar
tibbe committed
148
149
    (ghc, _) <- requireProgram normal ghcProgram (withPrograms lbi)
    (ghcPkg, _) <- requireProgram normal ghcPkgProgram (withPrograms lbi)
150
    (haddock, _) <- requireProgram normal haddockProgram (withPrograms lbi)
enolan's avatar
enolan committed
151
    packageDBStack' <- mapM canonicalizePackageDB $ withPackageDB lbi
ttuegel's avatar
ttuegel committed
152
    let haddockPath = programPath haddock
enolan's avatar
enolan committed
153
        inplaceDBFile = distPref_ </> "package.conf.inplace"
ttuegel's avatar
ttuegel committed
154
155
156
157
158
159
160
        config = SuiteConfig
                 { cabalDistPref = distPref_
                 , ghcPath = programPath ghc
                 , ghcPkgPath = programPath ghcPkg
                 , inplaceSpec = PackageSpec
                   { directory = []
                   , configOpts =
enolan's avatar
enolan committed
161
                     [ "--package-db=" ++ inplaceDBFile
ttuegel's avatar
ttuegel committed
162
163
164
165
                     , "--constraint=Cabal == " ++ display cabalVersion
                     ]
                   , distPref = Nothing
                   }
enolan's avatar
enolan committed
166
                 , packageDBStack = packageDBStack'
ttuegel's avatar
ttuegel committed
167
168
169
170
                 }
    putStrLn $ "Cabal test suite - testing cabal version " ++ display cabalVersion
    putStrLn $ "Using ghc: " ++ ghcPath config
    putStrLn $ "Using ghc-pkg: " ++ ghcPkgPath config
171
    putStrLn $ "Using haddock: " ++ haddockPath
172
    setCurrentDirectory "tests"
173
    -- Create a shared Setup executable to speed up Simple tests
174
    putStrLn $ "Building shared ./Setup executable"
ttuegel's avatar
ttuegel committed
175
    compileSetup config "."
176
    defaultMain $ testGroup "Package Tests"
ttuegel's avatar
ttuegel committed
177
      (tests config cabalVersion)
tibbe's avatar
tibbe committed
178
179
180
181
182
183

-- Like Distribution.Simple.Configure.getPersistBuildConfig but
-- doesn't check that the Cabal version matches, which it doesn't when
-- we run Cabal's own test suite, due to bootstrapping issues.
getPersistBuildConfig_ :: FilePath -> IO LocalBuildInfo
getPersistBuildConfig_ filename = do
184
185
186
187
188
189
    eLBI <- try $ getConfigStateFile filename
    case eLBI of
      Left (ConfigStateFileBadVersion _ _ (Right lbi)) -> return lbi
      Left (ConfigStateFileBadVersion _ _ (Left err)) -> throw err
      Left err -> throw err
      Right lbi -> return lbi
enolan's avatar
enolan committed
190
191
192
193

canonicalizePackageDB :: PackageDB -> IO PackageDB
canonicalizePackageDB (SpecificPackageDB path) = SpecificPackageDB <$> canonicalizePath path
canonicalizePackageDB x = return x