Skip to content

Add flag to disable Cabal package tests that use shared libraries #3146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion Cabal/tests/PackageTests.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# 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.
Expand Down Expand Up @@ -25,9 +27,12 @@ import Distribution.Verbosity (normal, flagToVerbosity)
import Distribution.ReadE (readEOrFail)

import Control.Exception
import Data.Typeable (Proxy(..), Typeable)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, this broke the build on GHC <= 7.6. I changed this line to import Data.Proxy instead and added a dependency on tagged.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I was just looking into that.

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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
28 changes: 19 additions & 9 deletions Cabal/tests/PackageTests/TestSuiteTests/ExeV10/Check.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
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)
Expand All @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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
Expand Down
47 changes: 34 additions & 13 deletions Cabal/tests/PackageTests/Tests.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module PackageTests.Tests(tests) where
module PackageTests.Tests(sharedLibTests, nonSharedLibTests) where

import PackageTests.PackageTester

Expand All @@ -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

---------------------------------------------------------------------
Expand All @@ -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"]

Expand Down Expand Up @@ -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 []
Expand Down Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of undefined here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I see, it's to make rearranging test cases easier (you don't need to delete commas).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied the pattern from the top of the file. I meant to ask if I understood it correctly but forgot.


, 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)
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentional?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it because I thought we could run the package tests soon. The only failure is #3147.

- Setup install
- cd ..\cabal-install
- ghc --make -threaded -i -i. Setup.hs -Wall -Werror
Expand Down