PackageTests.hs 8.3 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.BuildTestSuiteDetailedV09.Check
24
import PackageTests.PackageTester (PackageSpec(..), compileSetup)
tibbe's avatar
tibbe committed
25
26
import PackageTests.PathsModule.Executable.Check
import PackageTests.PathsModule.Library.Check
tibbe's avatar
tibbe committed
27
import PackageTests.PreProcess.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
35
import PackageTests.TestSuiteExeV10.Check
36
import PackageTests.OrderFlags.Check
37
import PackageTests.ReexportedModules.Check
38

39
40
import Distribution.Simple.Configure
    ( ConfigStateFileError(..), getConfigStateFile )
41
42
import Distribution.Simple.LocalBuildInfo (LocalBuildInfo(..))
import Distribution.Simple.Program.Types (programPath)
43
44
import Distribution.Simple.Program.Builtin
    ( ghcProgram, ghcPkgProgram, haddockProgram )
45
import Distribution.Simple.Program.Db (requireProgram)
46
import Distribution.Simple.Utils (cabalVersion)
47
48
49
50
import Distribution.Text (display)
import Distribution.Verbosity (normal)
import Distribution.Version (Version(Version))

51
52
53
import Control.Exception (try, throw)
import System.Directory
    ( getCurrentDirectory, setCurrentDirectory )
54
import System.FilePath ((</>))
55
import System.IO (BufferMode(NoBuffering), hSetBuffering, stdout)
56
57
58
59
60
import Test.Framework (Test, TestName, defaultMain, testGroup)
import Test.Framework.Providers.HUnit (hUnitTestToTests)
import qualified Test.HUnit as HUnit


61
62
63
hunit :: TestName -> HUnit.Test -> Test
hunit name test = testGroup name $ hUnitTestToTests test

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

136
main :: IO ()
137
main = do
138
139
140
141
    -- WORKAROUND: disable buffering on stdout to get streaming test logs
    -- test providers _should_ do this themselves
    hSetBuffering stdout NoBuffering

142
143
144
145
146
147
148
149
    wd <- getCurrentDirectory
    let dbFile = wd </> "dist/package.conf.inplace"
        inplaceSpec = PackageSpec
            { directory = []
            , configOpts = [ "--package-db=" ++ dbFile
                           , "--constraint=Cabal == " ++ display cabalVersion
                           ]
            }
tibbe's avatar
tibbe committed
150
151
    putStrLn $ "Cabal test suite - testing cabal version " ++
        display cabalVersion
tibbe's avatar
tibbe committed
152
153
154
    lbi <- getPersistBuildConfig_ ("dist" </> "setup-config")
    (ghc, _) <- requireProgram normal ghcProgram (withPrograms lbi)
    (ghcPkg, _) <- requireProgram normal ghcPkgProgram (withPrograms lbi)
155
    (haddock, _) <- requireProgram normal haddockProgram (withPrograms lbi)
tibbe's avatar
tibbe committed
156
157
    let ghcPath = programPath ghc
        ghcPkgPath = programPath ghcPkg
158
        haddockPath = programPath haddock
tibbe's avatar
tibbe committed
159
160
    putStrLn $ "Using ghc: " ++ ghcPath
    putStrLn $ "Using ghc-pkg: " ++ ghcPkgPath
161
    putStrLn $ "Using haddock: " ++ haddockPath
162
    setCurrentDirectory "tests"
163
    -- Create a shared Setup executable to speed up Simple tests
tibbe's avatar
tibbe committed
164
    compileSetup "." ghcPath
165
    defaultMain (tests cabalVersion inplaceSpec ghcPath ghcPkgPath)
tibbe's avatar
tibbe committed
166
167
168
169
170
171

-- 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
172
173
174
175
176
177
    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