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

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

import System.Directory (doesFileExist, getCurrentDirectory,
                         setCurrentDirectory)
import System.FilePath ((</>))
51
import System.IO (BufferMode(NoBuffering), hSetBuffering, stdout)
52
53
54
55
56
import Test.Framework (Test, TestName, defaultMain, testGroup)
import Test.Framework.Providers.HUnit (hUnitTestToTests)
import qualified Test.HUnit as HUnit


57
58
59
hunit :: TestName -> HUnit.Test -> Test
hunit name test = testGroup name $ hUnitTestToTests test

Mikhail Glushenkov's avatar
Mikhail Glushenkov committed
60
tests :: Version -> PackageSpec -> FilePath -> FilePath -> [Test]
61
tests version inplaceSpec ghcPath ghcPkgPath =
62
    [ hunit "BuildDeps/SameDepsAllRound"
tibbe's avatar
tibbe committed
63
      (PackageTests.BuildDeps.SameDepsAllRound.Check.suite ghcPath)
tibbe's avatar
tibbe committed
64
65
66
      -- 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
67
      --   (PackageTests.BuildDeps.GlobalBuildDepsNotAdditive1.Check.suite ghcPath)
tibbe's avatar
tibbe committed
68
      -- , hunit "BuildDeps/GlobalBuildDepsNotAdditive2/"
tibbe's avatar
tibbe committed
69
      --   (PackageTests.BuildDeps.GlobalBuildDepsNotAdditive2.Check.suite ghcPath)
70
    , hunit "BuildDeps/InternalLibrary0"
tibbe's avatar
tibbe committed
71
72
73
      (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
74
75
      -- ^ The Test stanza test will eventually be required
      -- only for higher versions.
tibbe's avatar
tibbe committed
76
    , hunit "TestSuiteExeV10/Test" (PackageTests.TestSuiteExeV10.Check.checkTest ghcPath)
tibbe's avatar
tibbe committed
77
    , hunit "TestSuiteExeV10/TestWithHpc"
tibbe's avatar
tibbe committed
78
79
80
      (PackageTests.TestSuiteExeV10.Check.checkTestWithHpc ghcPath)
    , hunit "TestOptions" (PackageTests.TestOptions.Check.suite ghcPath)
    , hunit "BenchmarkStanza" (PackageTests.BenchmarkStanza.Check.suite ghcPath)
tibbe's avatar
tibbe committed
81
82
83
      -- ^ The benchmark stanza test will eventually be required
      -- only for higher versions.
    , hunit "BenchmarkExeV10/Test"
tibbe's avatar
tibbe committed
84
85
      (PackageTests.BenchmarkExeV10.Check.checkBenchmark ghcPath)
    , hunit "BenchmarkOptions" (PackageTests.BenchmarkOptions.Check.suite ghcPath)
86
    , hunit "TemplateHaskell/vanilla"
tibbe's avatar
tibbe committed
87
      (PackageTests.TemplateHaskell.Check.vanilla ghcPath)
88
89
    , hunit "TemplateHaskell/profiling"
      (PackageTests.TemplateHaskell.Check.profiling ghcPath)
tibbe's avatar
tibbe committed
90
    , hunit "PathsModule/Executable"
tibbe's avatar
tibbe committed
91
92
      (PackageTests.PathsModule.Executable.Check.suite ghcPath)
    , hunit "PathsModule/Library" (PackageTests.PathsModule.Library.Check.suite ghcPath)
93
94
    , hunit "DeterministicAr"
        (PackageTests.DeterministicAr.Check.suite ghcPath ghcPkgPath)
refold's avatar
refold committed
95
    , hunit "EmptyLib/emptyLib"
tibbe's avatar
tibbe committed
96
      (PackageTests.EmptyLib.Check.emptyLib ghcPath)
97
    , hunit "Haddock" (PackageTests.Haddock.Check.suite ghcPath)
ttuegel's avatar
ttuegel committed
98
    , hunit "BuildTestSuiteDetailedV09"
tibbe's avatar
tibbe committed
99
      (PackageTests.BuildTestSuiteDetailedV09.Check.suite inplaceSpec ghcPath)
100
    , hunit "OrderFlags"
tibbe's avatar
tibbe committed
101
      (PackageTests.OrderFlags.Check.suite ghcPath)
102
103
    , hunit "TemplateHaskell/dynamic"
      (PackageTests.TemplateHaskell.Check.dynamic ghcPath)
104
105
    ] ++
    -- These tests are only required to pass on cabal version >= 1.7
106
107
    (if version >= Version [1, 7] []
     then [ hunit "BuildDeps/TargetSpecificDeps1"
tibbe's avatar
tibbe committed
108
            (PackageTests.BuildDeps.TargetSpecificDeps1.Check.suite ghcPath)
109
          , hunit "BuildDeps/TargetSpecificDeps2"
tibbe's avatar
tibbe committed
110
            (PackageTests.BuildDeps.TargetSpecificDeps2.Check.suite ghcPath)
111
          , hunit "BuildDeps/TargetSpecificDeps3"
tibbe's avatar
tibbe committed
112
            (PackageTests.BuildDeps.TargetSpecificDeps3.Check.suite ghcPath)
113
          , hunit "BuildDeps/InternalLibrary1"
tibbe's avatar
tibbe committed
114
            (PackageTests.BuildDeps.InternalLibrary1.Check.suite ghcPath)
115
          , hunit "BuildDeps/InternalLibrary2"
tibbe's avatar
tibbe committed
116
            (PackageTests.BuildDeps.InternalLibrary2.Check.suite ghcPath ghcPkgPath)
117
          , hunit "BuildDeps/InternalLibrary3"
tibbe's avatar
tibbe committed
118
            (PackageTests.BuildDeps.InternalLibrary3.Check.suite ghcPath ghcPkgPath)
119
          , hunit "BuildDeps/InternalLibrary4"
tibbe's avatar
tibbe committed
120
            (PackageTests.BuildDeps.InternalLibrary4.Check.suite ghcPath ghcPkgPath)
121
          , hunit "PackageTests/CMain"
tibbe's avatar
tibbe committed
122
            (PackageTests.CMain.Check.checkBuild ghcPath)
tibbe's avatar
tibbe committed
123
124
          ]
     else [])
125

126
main :: IO ()
127
main = do
128
129
130
131
    -- WORKAROUND: disable buffering on stdout to get streaming test logs
    -- test providers _should_ do this themselves
    hSetBuffering stdout NoBuffering

132
133
134
135
136
137
138
139
    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
140
141
    putStrLn $ "Cabal test suite - testing cabal version " ++
        display cabalVersion
tibbe's avatar
tibbe committed
142
143
144
    lbi <- getPersistBuildConfig_ ("dist" </> "setup-config")
    (ghc, _) <- requireProgram normal ghcProgram (withPrograms lbi)
    (ghcPkg, _) <- requireProgram normal ghcPkgProgram (withPrograms lbi)
145
    (haddock, _) <- requireProgram normal haddockProgram (withPrograms lbi)
tibbe's avatar
tibbe committed
146
147
    let ghcPath = programPath ghc
        ghcPkgPath = programPath ghcPkg
148
        haddockPath = programPath haddock
tibbe's avatar
tibbe committed
149
150
    putStrLn $ "Using ghc: " ++ ghcPath
    putStrLn $ "Using ghc-pkg: " ++ ghcPkgPath
151
    putStrLn $ "Using haddock: " ++ haddockPath
152
    setCurrentDirectory "tests"
153
    -- Create a shared Setup executable to speed up Simple tests
tibbe's avatar
tibbe committed
154
    compileSetup "." ghcPath
155
    defaultMain (tests cabalVersion inplaceSpec ghcPath ghcPkgPath)
tibbe's avatar
tibbe committed
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174

-- 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
  exists <- doesFileExist filename
  if not exists
    then die missing
    else withFileContents filename $ \str ->
      case lines str of
        [_header, rest] -> case reads rest of
          [(bi,_)] -> return bi
          _        -> die cantParse
        _            -> die cantParse
  where
    missing   = "Run the 'configure' command first."
    cantParse = "Saved package config file seems to be corrupt. "
             ++ "Try re-running the 'configure' command."