Commit f211508d authored by kristenk's avatar kristenk
Browse files

Add flag to disable Cabal package tests that use shared libraries

The flag --skip-shared-library-tests allows the tests to run when
shared libraries are unavailable, such as during the AppVeyor build.
parent 0dae8bd8
{-# LANGUAGE DeriveDataTypeable #-}
-- 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.
......@@ -25,9 +27,12 @@ import Distribution.Verbosity (normal, flagToVerbosity)
import Distribution.ReadE (readEOrFail)
import Control.Exception
import Data.Typeable (Proxy(..), Typeable)
import Distribution.Compat.Environment ( lookupEnv )
import System.Directory
import Test.Tasty
import Test.Tasty.Options
import Test.Tasty.Ingredients
import Data.Maybe
#if MIN_VERSION_base(4,6,0)
......@@ -173,7 +178,18 @@ main = do
putStrLn $ "Building shared ./Setup executable"
rawCompileSetup verbosity suite [] "tests"
defaultMain $ testGroup "Package Tests" (tests suite)
defaultMainWithIngredients options (tests suite)
-- | The tests are divided into two top-level trees, depending on whether they
-- require shared libraries. The option --skip-shared-library-tests can be used
-- when shared libraries are unavailable.
tests :: SuiteConfig -> TestTree
tests suite = askOption $ \(OptionSkipSharedLibraryTests skip) ->
testGroup "Package Tests" $
noSharedLibs : [sharedLibs | not skip]
where
sharedLibs = testGroup "SharedLibs" $ sharedLibTests suite
noSharedLibs = testGroup "NoSharedLibs" $ nonSharedLibTests suite
-- Reverse of 'interpretPackageDbFlags'.
-- prop_idem stk b
......@@ -255,3 +271,17 @@ getPersistBuildConfig_ filename = do
show err
Left err -> return (throw err)
Right lbi -> return lbi
newtype OptionSkipSharedLibraryTests = OptionSkipSharedLibraryTests Bool
deriving Typeable
instance IsOption OptionSkipSharedLibraryTests where
defaultValue = OptionSkipSharedLibraryTests False
parseValue = fmap OptionSkipSharedLibraryTests . safeRead
optionName = return "skip-shared-library-tests"
optionHelp = return "Skip the tests that require shared libraries"
optionCLParser = flagCLParser Nothing (OptionSkipSharedLibraryTests True)
options :: [Ingredient]
options = includingOptions [Option (Proxy :: Proxy OptionSkipSharedLibraryTests)] :
defaultIngredients
module PackageTests.TestSuiteTests.ExeV10.Check (tests) where
module PackageTests.TestSuiteTests.ExeV10.Check (
sharedLibTests
, nonSharedLibTests
) where
import qualified Control.Exception as E (IOException, catch)
import Control.Monad (when)
......@@ -21,15 +24,18 @@ import Distribution.Version (Version(..), orLaterVersion)
import PackageTests.PackageTester
tests :: SuiteConfig -> [TestTree]
tests config =
sharedLibTests :: SuiteConfig -> [TestTree]
sharedLibTests config = [testGroup "WithHpc" $ hpcTestMatrix True config]
nonSharedLibTests :: SuiteConfig -> [TestTree]
nonSharedLibTests config =
-- TODO: hierarchy and subnaming is a little unfortunate
[ tc "Test" "Default" $ do
cabal_build ["--enable-tests"]
-- This one runs both tests, including the very LONG Foo
-- test which prints a lot of output
cabal "test" ["--show-details=direct"]
, testGroup "WithHpc" $ hpcTestMatrix config
, testGroup "WithHpc" $ hpcTestMatrix False config
, testGroup "WithoutHpc"
-- Ensures that even if -fhpc is manually provided no .tix file is output.
[ tc "NoTix" "NoHpcNoTix" $ do
......@@ -64,8 +70,8 @@ tests config =
= testCase name
(runTestM config "TestSuiteTests/ExeV10" (Just subname) m)
hpcTestMatrix :: SuiteConfig -> [TestTree]
hpcTestMatrix config = do
hpcTestMatrix :: Bool -> SuiteConfig -> [TestTree]
hpcTestMatrix useSharedLibs config = do
libProf <- [True, False]
exeProf <- [True, False]
exeDyn <- [True, False]
......@@ -89,9 +95,13 @@ hpcTestMatrix config = do
enable cond flag
| cond = Just $ "--enable-" ++ flag
| otherwise = Nothing
-- Ensure that both .tix file and markup are generated if coverage
-- is enabled.
return $ tc name ("WithHpc-" ++ name) $ do
-- In order to avoid duplicate tests, each combination should be used for
-- exactly one value of 'useSharedLibs'.
if (exeDyn || shared) /= useSharedLibs
then []
-- Ensure that both .tix file and markup are generated if coverage
-- is enabled.
else return $ tc name ("WithHpc-" ++ name) $ do
isCorrectVersion <- liftIO $ correctHpcVersion
when isCorrectVersion $ do
dist_dir <- distDir
......
module PackageTests.Tests(tests) where
module PackageTests.Tests(sharedLibTests, nonSharedLibTests) where
import PackageTests.PackageTester
......@@ -11,12 +11,14 @@ import Control.Monad
import Data.Version
import Test.Tasty (TestTree, testGroup, mkTimeout, localOption)
import Test.Tasty.HUnit (testCase)
import qualified Test.Tasty.HUnit as HUnit
-- | Tests that do not require shared libraries.
-- TODO: turn this into a "test-defining writer monad".
-- This will let us handle scoping gracefully.
tests :: SuiteConfig -> [TestTree]
tests config =
nonSharedLibTests :: SuiteConfig -> [TestTree]
nonSharedLibTests config =
tail [ undefined
---------------------------------------------------------------------
......@@ -38,15 +40,15 @@ tests config =
-- Test exitcode-stdio-1.0 test suites (and HPC)
[ testGroup "ExeV10"
(PackageTests.TestSuiteTests.ExeV10.Check.tests config)
(PackageTests.TestSuiteTests.ExeV10.Check.nonSharedLibTests config)
-- Test detailed-0.9 test suites
, testGroup "LibV09" $
let
tcs :: FilePath -> TestM a -> TestTree
tcs name m
= testCase name (runTestM config ("TestSuiteTests/LibV09")
(Just name) m)
= HUnit.testCase name (runTestM config ("TestSuiteTests/LibV09")
(Just name) m)
in -- Test if detailed-0.9 builds correctly
[ tcs "Build" $ cabal_build ["--enable-tests"]
......@@ -155,10 +157,6 @@ tests config =
-- (Cabal has to build the non-profiled version first)
, tc "TemplateHaskell/profiling" $ cabal_build ["--enable-library-profiling", "--enable-profiling"]
-- Test building a dynamic library/executable which uses Template
-- Haskell
, tc "TemplateHaskell/dynamic" $ cabal_build ["--enable-shared", "--enable-executable-dynamic"]
-- Test building an executable whose main() function is defined in a C
-- file
, tc "CMain" $ cabal_build []
......@@ -244,5 +242,28 @@ tests config =
(concat $ lines (resultOutput r))
tc :: FilePath -> TestM a -> TestTree
tc name m
= testCase name (runTestM config name Nothing m)
tc = testCase config
-- | Tests that require shared libraries.
sharedLibTests :: SuiteConfig -> [TestTree]
sharedLibTests config =
tail [ undefined
, testGroup "TestSuiteTests"
-- Test exitcode-stdio-1.0 test suites (and HPC) using
-- --enable-executable-dynamic and --enable-shared
[ testGroup "ExeV10"
(PackageTests.TestSuiteTests.ExeV10.Check.sharedLibTests config)
]
-- Test building a dynamic library/executable which uses Template
-- Haskell
, testCase config "TemplateHaskell/dynamic" $
cabal_build ["--enable-shared", "--enable-executable-dynamic"]
]
testCase :: SuiteConfig -> FilePath -> TestM a -> TestTree
testCase config name m
= HUnit.testCase name (runTestM config name Nothing m)
......@@ -14,6 +14,7 @@ build_script:
- Setup configure --user --ghc-option=-Werror --enable-tests
- Setup build
- Setup test unit-tests --show-details=streaming
# - Setup test package-tests --show-details=streaming --test-options=--skip-shared-library-tests
- Setup install
- cd ..\cabal-install
- ghc --make -threaded -i -i. Setup.hs -Wall -Werror
......
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