Commit 725af53f authored by kristenk's avatar kristenk
Browse files

Skip Cabal package tests that cannot run in the current environment

The functions 'testWhen' and 'testUnless' filter tests in the 'TestTreeM' monad.
The option '--enable-all-tests' ignores filtering.  This commit also applies
filtering to the existing package tests that cannot run on Windows.
parent 257c0429
......@@ -119,6 +119,7 @@ extra-source-files:
tests/PackageTests/HaddockNewline/A.hs
tests/PackageTests/HaddockNewline/HaddockNewline.cabal
tests/PackageTests/HaddockNewline/Setup.hs
tests/PackageTests/Options.hs
tests/PackageTests/OrderFlags/Foo.hs
tests/PackageTests/OrderFlags/my.cabal
tests/PackageTests/PathsModule/Executable/Main.hs
......
......@@ -6,6 +6,7 @@
module Main where
import PackageTests.Options
import PackageTests.PackageTester
import PackageTests.Tests
......@@ -14,7 +15,7 @@ import Distribution.Simple.Configure
, interpretPackageDbFlags )
import Distribution.Simple.Compiler (PackageDB(..), PackageDBStack)
import Distribution.Simple.LocalBuildInfo (LocalBuildInfo(..))
import Distribution.Simple.Program.Types (programPath, programVersion)
import Distribution.Simple.Program.Types (Program(..), programPath, programVersion)
import Distribution.Simple.Program.Builtin
( ghcProgram, ghcPkgProgram, haddockProgram )
import Distribution.Simple.Program.Db (requireProgram)
......@@ -25,9 +26,12 @@ import Distribution.Verbosity (normal, flagToVerbosity)
import Distribution.ReadE (readEOrFail)
import Control.Exception
import Data.Proxy ( Proxy(..) )
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)
......@@ -105,6 +109,12 @@ main = do
Just str ->
return (fromJust (simpleParse str))
with_ghc_version <- do
version <- programFindVersion ghcProgram normal with_ghc_path
case version of
Nothing -> error "Cannot determine version of GHC used for --with-ghc"
Just v -> return v
-- Package DBs are not guaranteed to be absolute, so make them so in
-- case a subprocess using the package DB needs a different CWD.
db_stack_env <- lookupEnv "CABAL_PACKAGETESTS_DB_STACK"
......@@ -151,6 +161,7 @@ main = do
, ghcVersion = ghc_version
, ghcPkgPath = ghc_pkg_path
, withGhcPath = with_ghc_path
, withGhcVersion = with_ghc_version
, packageDBStack = packageDBStack2
, suiteVerbosity = verbosity
, absoluteCWD = test_dir
......@@ -180,7 +191,7 @@ main = do
putStrLn $ "Building shared ./Setup executable"
rawCompileSetup verbosity suite [] "tests"
defaultMain $
defaultMainWithIngredients options $
runTestTree "Package Tests" (tests suite)
-- Reverse of 'interpretPackageDbFlags'.
......@@ -265,3 +276,8 @@ getPersistBuildConfig_ filename = do
show err
Left err -> return (throw err)
Right lbi -> return lbi
options :: [Ingredient]
options = includingOptions
[Option (Proxy :: Proxy OptionEnableAllTests)] :
defaultIngredients
{-# LANGUAGE DeriveDataTypeable #-}
module PackageTests.Options
( OptionEnableAllTests(..)
) where
import Data.Typeable (Typeable)
import Test.Tasty.Options (IsOption(..), flagCLParser, safeRead)
newtype OptionEnableAllTests = OptionEnableAllTests Bool
deriving Typeable
instance IsOption OptionEnableAllTests where
defaultValue = OptionEnableAllTests False
parseValue = fmap OptionEnableAllTests . safeRead
optionName = return "enable-all-tests"
optionHelp = return "Enable all tests"
optionCLParser = flagCLParser Nothing (OptionEnableAllTests True)
......@@ -56,6 +56,10 @@ module PackageTests.PackageTester
, testTree'
, groupTests
, mapTestTrees
, testWhen
, testUnless
, unlessWindows
, hasSharedLibraries
, getPersistBuildConfig
......@@ -66,9 +70,12 @@ module PackageTests.PackageTester
, module Text.Regex.Posix
) where
import PackageTests.Options
import Distribution.Compat.CreatePipe (createPipe)
import Distribution.Simple.Compiler (PackageDBStack, PackageDB(..))
import Distribution.Simple.Program.Run (getEffectiveEnvironment)
import Distribution.System (OS(Windows), buildOS)
import Distribution.Simple.Utils
( printRawCommandAndArgsAndEnv, withFileContents )
import Distribution.Simple.Configure
......@@ -86,6 +93,7 @@ import Text.Regex.Posix
import qualified Control.Exception as E
import Control.Monad
import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.Reader
import Control.Monad.Trans.Writer
import Control.Monad.IO.Class
......@@ -101,7 +109,7 @@ import System.FilePath
import System.IO
import System.IO.Error (isDoesNotExistError)
import System.Process (runProcess, waitForProcess, showCommandForUser)
import Test.Tasty (TestTree, testGroup)
import Test.Tasty (TestTree, askOption, testGroup)
-- | Our test monad maintains an environment recording the global test
-- suite configuration 'SuiteConfig', and the local per-test
......@@ -150,6 +158,8 @@ data SuiteConfig = SuiteConfig
, ghcPkgPath :: FilePath
-- | Path to GHC that we should use to "./Setup --with-ghc"
, withGhcPath :: FilePath
-- | Version of GHC at 'withGhcPath'.
, withGhcVersion :: Version
-- | The build directory that was used to build Cabal (used
-- to compile Setup scripts.)
, cabalDistPref :: FilePath
......@@ -617,10 +627,13 @@ concatOutput = unwords . lines . filter ((/=) '\r')
------------------------------------------------------------------------
-- * Test trees
type TestTreeM = Writer [TestTree]
-- | Monad for creating test trees. The option --enable-all-tests determines
-- whether to filter tests with 'testWhen' and 'testUnless'.
type TestTreeM = WriterT [TestTree] (Reader OptionEnableAllTests)
runTestTree :: String -> TestTreeM () -> TestTree
runTestTree name ts = testGroup name (execWriter ts)
runTestTree name ts = askOption $
testGroup name . runReader (execWriterT ts)
testTree :: SuiteConfig -> String -> Maybe String -> TestM a -> TestTreeM ()
testTree config name subname m =
......@@ -629,12 +642,29 @@ testTree config name subname m =
testTree' :: TestTree -> TestTreeM ()
testTree' tc = tell [tc]
-- | Create a test group from the output of the given action.
groupTests :: String -> TestTreeM () -> TestTreeM ()
groupTests name = censor (\ts -> [testGroup name ts])
-- | Apply a function to each top-level test tree.
mapTestTrees :: (TestTree -> TestTree) -> TestTreeM a -> TestTreeM a
mapTestTrees = censor . map
testWhen :: Bool -> TestTreeM () -> TestTreeM ()
testWhen c test = do
OptionEnableAllTests enableAll <- lift ask
when (enableAll || c) test
testUnless :: Bool -> TestTreeM () -> TestTreeM ()
testUnless = testWhen . not
unlessWindows :: TestTreeM () -> TestTreeM ()
unlessWindows = testUnless (buildOS == Windows)
hasSharedLibraries :: SuiteConfig -> Bool
hasSharedLibraries config =
buildOS /= Windows || withGhcVersion config < Version [7,8] []
------------------------------------------------------------------------
-- Verbosity
......
......@@ -85,7 +85,8 @@ hpcTestMatrix config = forM_ (choose4 [True, False]) $
| otherwise = Nothing
-- Ensure that both .tix file and markup are generated if coverage
-- is enabled.
tc name ("WithHpc-" ++ name) $ do
testUnless ((exeDyn || shared) && not (hasSharedLibraries config)) $
tc name ("WithHpc-" ++ name) $ do
isCorrectVersion <- liftIO $ correctHpcVersion
when isCorrectVersion $ do
dist_dir <- distDir
......
......@@ -153,7 +153,8 @@ tests config = do
-- Test building a dynamic library/executable which uses Template
-- Haskell
tc "TemplateHaskell/dynamic" $ cabal_build ["--enable-shared", "--enable-executable-dynamic"]
testWhen (hasSharedLibraries config) $
tc "TemplateHaskell/dynamic" $ cabal_build ["--enable-shared", "--enable-executable-dynamic"]
-- Test building an executable whose main() function is defined in a C
-- file
......@@ -252,14 +253,16 @@ tests config = do
assertOutputContains "Flags chosen: build-exe=False" r
cabal "build" []
tc "GhcPkgGuess/SameDirectory" $ ghc_pkg_guess "ghc"
tc "GhcPkgGuess/SameDirectoryVersion" $ ghc_pkg_guess "ghc-7.10"
tc "GhcPkgGuess/SameDirectoryGhcVersion" $ ghc_pkg_guess "ghc-7.10"
-- TODO: Enable these tests on Windows
unlessWindows $ do
tc "GhcPkgGuess/SameDirectory" $ ghc_pkg_guess "ghc"
tc "GhcPkgGuess/SameDirectoryVersion" $ ghc_pkg_guess "ghc-7.10"
tc "GhcPkgGuess/SameDirectoryGhcVersion" $ ghc_pkg_guess "ghc-7.10"
-- TODO: Disable these tests on Windows
tc "GhcPkgGuess/Symlink" $ ghc_pkg_guess "ghc"
tc "GhcPkgGuess/SymlinkVersion" $ ghc_pkg_guess "ghc"
tc "GhcPkgGuess/SymlinkGhcVersion" $ ghc_pkg_guess "ghc"
unlessWindows $ do
tc "GhcPkgGuess/Symlink" $ ghc_pkg_guess "ghc"
tc "GhcPkgGuess/SymlinkVersion" $ ghc_pkg_guess "ghc"
tc "GhcPkgGuess/SymlinkGhcVersion" $ ghc_pkg_guess "ghc"
where
ghc_pkg_guess bin_name = do
......
......@@ -14,7 +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
- Setup test package-tests --show-details=streaming
- 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