PackageTests.hs 8.17 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

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

53
import Control.Exception (try, throw)
ttuegel's avatar
ttuegel committed
54
import Distribution.Compat.Environment ( setEnv )
55
import System.Directory
ttuegel's avatar
ttuegel committed
56
    ( canonicalizePath, setCurrentDirectory )
57
import System.FilePath ((</>))
58
59
import Test.Tasty
import Test.Tasty.HUnit
60
61


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

134
main :: IO ()
135
main = do
ttuegel's avatar
ttuegel committed
136
137
138
139
140
    -- 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
141
142
    (ghc, _) <- requireProgram normal ghcProgram (withPrograms lbi)
    (ghcPkg, _) <- requireProgram normal ghcPkgProgram (withPrograms lbi)
143
    (haddock, _) <- requireProgram normal haddockProgram (withPrograms lbi)
ttuegel's avatar
ttuegel committed
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
    let haddockPath = programPath haddock
        dbFile = distPref_ </> "package.conf.inplace"
        config = SuiteConfig
                 { cabalDistPref = distPref_
                 , ghcPath = programPath ghc
                 , ghcPkgPath = programPath ghcPkg
                 , inplaceSpec = PackageSpec
                   { directory = []
                   , configOpts =
                     [ "--package-db=" ++ dbFile
                     , "--constraint=Cabal == " ++ display cabalVersion
                     ]
                   , distPref = Nothing
                   }
                 }
    putStrLn $ "Cabal test suite - testing cabal version " ++ display cabalVersion
    putStrLn $ "Using ghc: " ++ ghcPath config
    putStrLn $ "Using ghc-pkg: " ++ ghcPkgPath config
162
    putStrLn $ "Using haddock: " ++ haddockPath
163
    setCurrentDirectory "tests"
164
    -- Create a shared Setup executable to speed up Simple tests
ttuegel's avatar
ttuegel committed
165
    compileSetup config "."
166
    defaultMain $ testGroup "Package Tests"
ttuegel's avatar
ttuegel committed
167
      (tests config cabalVersion)
tibbe's avatar
tibbe committed
168
169
170
171
172
173

-- 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
174
175
176
177
178
179
    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