Commit fa5e37ab authored by Mikhail Glushenkov's avatar Mikhail Glushenkov
Browse files

Migrate the test suite to Tasty.

parent fdae633c
......@@ -261,11 +261,10 @@ test-suite unit-tests
main-is: UnitTests.hs
build-depends:
base,
test-framework,
test-framework-hunit,
test-framework-quickcheck2,
HUnit,
QuickCheck < 2.8,
tasty,
tasty-hunit,
tasty-quickcheck,
QuickCheck < 2.9,
Cabal
ghc-options: -Wall
default-language: Haskell98
......@@ -308,11 +307,10 @@ test-suite package-tests
build-depends:
base,
containers,
test-framework,
test-framework-quickcheck2 >= 0.2.12,
test-framework-hunit,
HUnit,
QuickCheck >= 2.1.0.1 && < 2.8,
tasty,
tasty-quickcheck,
tasty-hunit,
QuickCheck >= 2.1.0.1 && < 2.9,
Cabal,
process,
directory,
......
......@@ -52,87 +52,78 @@ import Control.Exception (try, throw)
import System.Directory
( getCurrentDirectory, setCurrentDirectory )
import System.FilePath ((</>))
import System.IO (BufferMode(NoBuffering), hSetBuffering, stdout)
import Test.Framework (Test, TestName, defaultMain, testGroup)
import Test.Framework.Providers.HUnit (hUnitTestToTests)
import qualified Test.HUnit as HUnit
import Test.Tasty
import Test.Tasty.HUnit
hunit :: TestName -> HUnit.Test -> Test
hunit name test = testGroup name $ hUnitTestToTests test
tests :: Version -> PackageSpec -> FilePath -> FilePath -> [Test]
tests :: Version -> PackageSpec -> FilePath -> FilePath -> [TestTree]
tests version inplaceSpec ghcPath ghcPkgPath =
[ hunit "BuildDeps/SameDepsAllRound"
[ testCase "BuildDeps/SameDepsAllRound"
(PackageTests.BuildDeps.SameDepsAllRound.Check.suite ghcPath)
-- The two following tests were disabled by Johan Tibell as
-- they have been failing for a long time:
-- , hunit "BuildDeps/GlobalBuildDepsNotAdditive1/"
-- , testCase "BuildDeps/GlobalBuildDepsNotAdditive1/"
-- (PackageTests.BuildDeps.GlobalBuildDepsNotAdditive1.Check.suite ghcPath)
-- , hunit "BuildDeps/GlobalBuildDepsNotAdditive2/"
-- , testCase "BuildDeps/GlobalBuildDepsNotAdditive2/"
-- (PackageTests.BuildDeps.GlobalBuildDepsNotAdditive2.Check.suite ghcPath)
, hunit "BuildDeps/InternalLibrary0"
, testCase "BuildDeps/InternalLibrary0"
(PackageTests.BuildDeps.InternalLibrary0.Check.suite version ghcPath)
, hunit "PreProcess" (PackageTests.PreProcess.Check.suite ghcPath)
, hunit "TestStanza" (PackageTests.TestStanza.Check.suite ghcPath)
, testCase "PreProcess" (PackageTests.PreProcess.Check.suite ghcPath)
, testCase "TestStanza" (PackageTests.TestStanza.Check.suite ghcPath)
-- ^ The Test stanza test will eventually be required
-- only for higher versions.
, testGroup "TestSuiteExeV10" (PackageTests.TestSuiteExeV10.Check.checks ghcPath)
, hunit "TestOptions" (PackageTests.TestOptions.Check.suite ghcPath)
, hunit "BenchmarkStanza" (PackageTests.BenchmarkStanza.Check.suite ghcPath)
, testCase "TestOptions" (PackageTests.TestOptions.Check.suite ghcPath)
, testCase "BenchmarkStanza" (PackageTests.BenchmarkStanza.Check.suite ghcPath)
-- ^ The benchmark stanza test will eventually be required
-- only for higher versions.
, hunit "BenchmarkExeV10/Test"
, testCase "BenchmarkExeV10/Test"
(PackageTests.BenchmarkExeV10.Check.checkBenchmark ghcPath)
, hunit "BenchmarkOptions" (PackageTests.BenchmarkOptions.Check.suite ghcPath)
, hunit "TemplateHaskell/vanilla"
, testCase "BenchmarkOptions" (PackageTests.BenchmarkOptions.Check.suite ghcPath)
, testCase "TemplateHaskell/vanilla"
(PackageTests.TemplateHaskell.Check.vanilla ghcPath)
, hunit "TemplateHaskell/profiling"
, testCase "TemplateHaskell/profiling"
(PackageTests.TemplateHaskell.Check.profiling ghcPath)
, hunit "PathsModule/Executable"
, testCase "PathsModule/Executable"
(PackageTests.PathsModule.Executable.Check.suite ghcPath)
, hunit "PathsModule/Library" (PackageTests.PathsModule.Library.Check.suite ghcPath)
, hunit "DeterministicAr"
, testCase "PathsModule/Library" (PackageTests.PathsModule.Library.Check.suite ghcPath)
, testCase "DeterministicAr"
(PackageTests.DeterministicAr.Check.suite ghcPath ghcPkgPath)
, hunit "EmptyLib/emptyLib"
, testCase "EmptyLib/emptyLib"
(PackageTests.EmptyLib.Check.emptyLib ghcPath)
, hunit "Haddock" (PackageTests.Haddock.Check.suite ghcPath)
, hunit "BuildTestSuiteDetailedV09"
, testCase "Haddock" (PackageTests.Haddock.Check.suite ghcPath)
, testCase "BuildTestSuiteDetailedV09"
(PackageTests.BuildTestSuiteDetailedV09.Check.suite inplaceSpec ghcPath)
, hunit "OrderFlags"
, testCase "OrderFlags"
(PackageTests.OrderFlags.Check.suite ghcPath)
, hunit "TemplateHaskell/dynamic"
, testCase "TemplateHaskell/dynamic"
(PackageTests.TemplateHaskell.Check.dynamic ghcPath)
, hunit "ReexportedModules"
, testCase "ReexportedModules"
(PackageTests.ReexportedModules.Check.suite ghcPath)
] ++
-- These tests are only required to pass on cabal version >= 1.7
(if version >= Version [1, 7] []
then [ hunit "BuildDeps/TargetSpecificDeps1"
then [ testCase "BuildDeps/TargetSpecificDeps1"
(PackageTests.BuildDeps.TargetSpecificDeps1.Check.suite ghcPath)
, hunit "BuildDeps/TargetSpecificDeps2"
, testCase "BuildDeps/TargetSpecificDeps2"
(PackageTests.BuildDeps.TargetSpecificDeps2.Check.suite ghcPath)
, hunit "BuildDeps/TargetSpecificDeps3"
, testCase "BuildDeps/TargetSpecificDeps3"
(PackageTests.BuildDeps.TargetSpecificDeps3.Check.suite ghcPath)
, hunit "BuildDeps/InternalLibrary1"
, testCase "BuildDeps/InternalLibrary1"
(PackageTests.BuildDeps.InternalLibrary1.Check.suite ghcPath)
, hunit "BuildDeps/InternalLibrary2"
, testCase "BuildDeps/InternalLibrary2"
(PackageTests.BuildDeps.InternalLibrary2.Check.suite ghcPath ghcPkgPath)
, hunit "BuildDeps/InternalLibrary3"
, testCase "BuildDeps/InternalLibrary3"
(PackageTests.BuildDeps.InternalLibrary3.Check.suite ghcPath ghcPkgPath)
, hunit "BuildDeps/InternalLibrary4"
, testCase "BuildDeps/InternalLibrary4"
(PackageTests.BuildDeps.InternalLibrary4.Check.suite ghcPath ghcPkgPath)
, hunit "PackageTests/CMain"
, testCase "PackageTests/CMain"
(PackageTests.CMain.Check.checkBuild ghcPath)
]
else [])
main :: IO ()
main = do
-- WORKAROUND: disable buffering on stdout to get streaming test logs
-- test providers _should_ do this themselves
hSetBuffering stdout NoBuffering
wd <- getCurrentDirectory
let dbFile = wd </> "dist/package.conf.inplace"
inplaceSpec = PackageSpec
......@@ -157,7 +148,8 @@ main = do
setCurrentDirectory "tests"
-- Create a shared Setup executable to speed up Simple tests
compileSetup "." ghcPath
defaultMain (tests cabalVersion inplaceSpec ghcPath ghcPkgPath)
defaultMain $ testGroup "Package Tests"
(tests cabalVersion inplaceSpec ghcPath ghcPkgPath)
-- Like Distribution.Simple.Configure.getPersistBuildConfig but
-- doesn't check that the Cabal version matches, which it doesn't when
......
......@@ -4,13 +4,13 @@ module PackageTests.BenchmarkExeV10.Check
import PackageTests.PackageTester
import System.FilePath
import Test.HUnit
import Test.Tasty.HUnit
dir :: FilePath
dir = "PackageTests" </> "BenchmarkExeV10"
checkBenchmark :: FilePath -> Test
checkBenchmark ghcPath = TestCase $ do
checkBenchmark :: FilePath -> Assertion
checkBenchmark ghcPath = do
let spec = PackageSpec dir Nothing ["--enable-benchmarks"]
buildResult <- cabal_build spec ghcPath
assertBuildSucceeded buildResult
......@@ -2,10 +2,10 @@ module PackageTests.BenchmarkOptions.Check where
import PackageTests.PackageTester
import System.FilePath
import Test.HUnit
import Test.Tasty.HUnit
suite :: FilePath -> Test
suite ghcPath = TestCase $ do
suite :: FilePath -> Assertion
suite ghcPath = do
let spec = PackageSpec
{ directory = "PackageTests" </> "BenchmarkOptions"
, configOpts = ["--enable-benchmarks"]
......
module PackageTests.BenchmarkStanza.Check where
import Test.HUnit
import Test.Tasty.HUnit
import System.FilePath
import qualified Data.Map as Map
import PackageTests.PackageTester
......@@ -22,8 +22,8 @@ import Distribution.Compiler
( CompilerId(..), CompilerFlavor(..), unknownCompilerInfo, AbiTag(..) )
import Distribution.Text
suite :: FilePath -> Test
suite ghcPath = TestCase $ do
suite :: FilePath -> Assertion
suite ghcPath = do
let dir = "PackageTests" </> "BenchmarkStanza"
pdFile = dir </> "my" <.> "cabal"
spec = PackageSpec { directory = dir, configOpts = [], distPref = Nothing }
......
module PackageTests.BuildDeps.GlobalBuildDepsNotAdditive1.Check where
import Test.HUnit
import Test.Tasty.HUnit
import PackageTests.PackageTester
import System.FilePath
import Data.List
......@@ -8,8 +8,8 @@ import Control.Exception
import Prelude hiding (catch)
suite :: FilePath -> Test
suite ghcPath = TestCase $ do
suite :: FilePath -> Assertion
suite ghcPath = do
let spec = PackageSpec ("PackageTests" </> "BuildDeps" </> "GlobalBuildDepsNotAdditive1") []
result <- cabal_build spec ghcPath
do
......
module PackageTests.BuildDeps.GlobalBuildDepsNotAdditive2.Check where
import Test.HUnit
import Test.Tasty.HUnit
import PackageTests.PackageTester
import System.FilePath
import Data.List
......@@ -8,8 +8,8 @@ import Control.Exception
import Prelude hiding (catch)
suite :: FilePath -> Test
suite ghcPath = TestCase $ do
suite :: FilePath -> Assertion
suite ghcPath = do
let spec = PackageSpec ("PackageTests" </> "BuildDeps" </> "GlobalBuildDepsNotAdditive2") []
result <- cabal_build spec ghcPath
do
......
......@@ -4,11 +4,11 @@ import Control.Monad
import Data.Version
import PackageTests.PackageTester
import System.FilePath
import Test.HUnit
import Test.Tasty.HUnit
suite :: Version -> FilePath -> Test
suite cabalVersion ghcPath = TestCase $ do
suite :: Version -> FilePath -> Assertion
suite cabalVersion ghcPath = do
let spec = PackageSpec
{ directory = "PackageTests" </> "BuildDeps" </> "InternalLibrary0"
, configOpts = []
......
......@@ -2,11 +2,11 @@ module PackageTests.BuildDeps.InternalLibrary1.Check where
import PackageTests.PackageTester
import System.FilePath
import Test.HUnit
import Test.Tasty.HUnit
suite :: FilePath -> Test
suite ghcPath = TestCase $ do
suite :: FilePath -> Assertion
suite ghcPath = do
let spec = PackageSpec
{ directory = "PackageTests" </> "BuildDeps" </> "InternalLibrary1"
, configOpts = []
......
......@@ -3,11 +3,11 @@ module PackageTests.BuildDeps.InternalLibrary2.Check where
import qualified Data.ByteString.Char8 as C
import PackageTests.PackageTester
import System.FilePath
import Test.HUnit
import Test.Tasty.HUnit
suite :: FilePath -> FilePath -> Test
suite ghcPath ghcPkgPath = TestCase $ do
suite :: FilePath -> FilePath -> Assertion
suite ghcPath ghcPkgPath = do
let spec = PackageSpec
{ directory = "PackageTests" </> "BuildDeps" </> "InternalLibrary2"
, configOpts = []
......@@ -29,4 +29,3 @@ suite ghcPath ghcPkgPath = TestCase $ do
(_, _, output) <- run (Just $ directory spec) (directory spec </> "dist" </> "build" </> "lemon" </> "lemon") [] []
C.appendFile (directory spec </> "test-log.txt") (C.pack $ "\ndist/build/lemon/lemon\n"++output)
assertEqual "executable should have linked with the internal library" "myLibFunc internal" (concat $ lines output)
......@@ -3,11 +3,11 @@ module PackageTests.BuildDeps.InternalLibrary3.Check where
import qualified Data.ByteString.Char8 as C
import PackageTests.PackageTester
import System.FilePath
import Test.HUnit
import Test.Tasty.HUnit
suite :: FilePath -> FilePath -> Test
suite ghcPath ghcPkgPath = TestCase $ do
suite :: FilePath -> FilePath -> Assertion
suite ghcPath ghcPkgPath = do
let spec = PackageSpec
{ directory = "PackageTests" </> "BuildDeps" </> "InternalLibrary3"
, configOpts = []
......@@ -29,4 +29,3 @@ suite ghcPath ghcPkgPath = TestCase $ do
(_, _, output) <- run (Just $ directory spec) (directory spec </> "dist" </> "build" </> "lemon" </> "lemon") [] []
C.appendFile (directory spec </> "test-log.txt") (C.pack $ "\ndist/build/lemon/lemon\n"++output)
assertEqual "executable should have linked with the internal library" "myLibFunc internal" (concat $ lines output)
......@@ -3,11 +3,11 @@ module PackageTests.BuildDeps.InternalLibrary4.Check where
import qualified Data.ByteString.Char8 as C
import PackageTests.PackageTester
import System.FilePath
import Test.HUnit
import Test.Tasty.HUnit
suite :: FilePath -> FilePath -> Test
suite ghcPath ghcPkgPath = TestCase $ do
suite :: FilePath -> FilePath -> Assertion
suite ghcPath ghcPkgPath = do
let spec = PackageSpec
{ directory = "PackageTests" </> "BuildDeps" </> "InternalLibrary4"
, configOpts = []
......@@ -29,4 +29,3 @@ suite ghcPath ghcPkgPath = TestCase $ do
(_, _, output) <- run (Just $ directory spec) (directory spec </> "dist" </> "build" </> "lemon" </> "lemon") [] []
C.appendFile (directory spec </> "test-log.txt") (C.pack $ "\ndist/build/lemon/lemon\n"++output)
assertEqual "executable should have linked with the installed library" "myLibFunc installed" (concat $ lines output)
module PackageTests.BuildDeps.SameDepsAllRound.Check where
import Test.HUnit
import Test.Tasty.HUnit
import PackageTests.PackageTester
import System.FilePath
import qualified Control.Exception as E
suite :: FilePath -> Test
suite ghcPath = TestCase $ do
suite :: FilePath -> Assertion
suite ghcPath = do
let spec = PackageSpec
{ directory = "PackageTests" </> "BuildDeps" </> "SameDepsAllRound"
, configOpts = []
......
module PackageTests.BuildDeps.TargetSpecificDeps1.Check where
import Test.HUnit
import Test.Tasty.HUnit
import PackageTests.PackageTester
import System.FilePath
import Data.List
......@@ -8,8 +8,8 @@ import qualified Control.Exception as E
import Text.Regex.Posix
suite :: FilePath -> Test
suite ghcPath = TestCase $ do
suite :: FilePath -> Assertion
suite ghcPath = do
let spec = PackageSpec
{ directory = "PackageTests" </> "BuildDeps" </> "TargetSpecificDeps1"
, configOpts = []
......
module PackageTests.BuildDeps.TargetSpecificDeps2.Check where
import Test.HUnit
import Test.Tasty.HUnit
import PackageTests.PackageTester
import System.FilePath
import qualified Control.Exception as E
suite :: FilePath -> Test
suite ghcPath = TestCase $ do
suite :: FilePath -> Assertion
suite ghcPath = do
let spec = PackageSpec
{ directory = "PackageTests" </> "BuildDeps" </> "TargetSpecificDeps2"
, configOpts = []
......
module PackageTests.BuildDeps.TargetSpecificDeps3.Check where
import Test.HUnit
import Test.Tasty.HUnit
import PackageTests.PackageTester
import System.FilePath
import Data.List
......@@ -8,8 +8,8 @@ import qualified Control.Exception as E
import Text.Regex.Posix
suite :: FilePath -> Test
suite ghcPath = TestCase $ do
suite :: FilePath -> Assertion
suite ghcPath = do
let spec = PackageSpec
{ directory = "PackageTests" </> "BuildDeps" </> "TargetSpecificDeps3"
, configOpts = []
......
module PackageTests.BuildTestSuiteDetailedV09.Check where
import Test.HUnit
import Test.Tasty.HUnit
import System.FilePath ((</>))
import PackageTests.PackageTester
suite :: PackageSpec -> FilePath -> Test
suite inplaceSpec ghcPath = TestCase $ do
suite :: PackageSpec -> FilePath -> Assertion
suite inplaceSpec ghcPath = do
let dir = "PackageTests" </> "BuildTestSuiteDetailedV09"
spec = inplaceSpec
{ directory = dir
......
......@@ -2,15 +2,15 @@ module PackageTests.CMain.Check
( checkBuild
) where
import Test.HUnit
import Test.Tasty.HUnit
import System.FilePath
import PackageTests.PackageTester
dir :: FilePath
dir = "PackageTests" </> "CMain"
checkBuild :: FilePath -> Test
checkBuild ghcPath = TestCase $ do
checkBuild :: FilePath -> Assertion
checkBuild ghcPath = do
let spec = PackageSpec
{ directory = dir
, distPref = Nothing
......
......@@ -15,7 +15,7 @@ import PackageTests.PackageTester
import System.Exit
import System.FilePath
import System.IO
import Test.HUnit (Assertion, Test (TestCase), assertFailure)
import Test.Tasty.HUnit (Assertion, assertFailure)
import Distribution.Compiler (CompilerFlavor(..), CompilerId(..))
import Distribution.Package (packageKeyHash)
......@@ -58,8 +58,8 @@ ghcPkg_field1 libraryName fieldName ghcPkgPath = do
this :: String
this = "DeterministicAr"
suite :: FilePath -> FilePath -> Test
suite ghcPath ghcPkgPath = TestCase $ do
suite :: FilePath -> FilePath -> Assertion
suite ghcPath ghcPkgPath = do
let dir = "PackageTests" </> this
let spec = PackageSpec
{ directory = dir
......
......@@ -2,11 +2,11 @@ module PackageTests.EmptyLib.Check where
import PackageTests.PackageTester
import System.FilePath
import Test.HUnit
import Test.Tasty.HUnit
-- See https://github.com/haskell/cabal/issues/1241
emptyLib :: FilePath -> Test
emptyLib ghcPath = TestCase $ do
emptyLib :: FilePath -> Assertion
emptyLib ghcPath = do
let spec = PackageSpec
{ directory = "PackageTests" </> "EmptyLib" </> "empty"
, configOpts = []
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment