From 3b8589f1540bba40d64f57c30cb53c5cf0f58f2d Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 18 Nov 2016 19:32:54 -0800 Subject: [PATCH 01/56] Remove redundant import. Signed-off-by: Edward Z. Yang --- cabal-testsuite/Test/Cabal/Prelude.hs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cabal-testsuite/Test/Cabal/Prelude.hs b/cabal-testsuite/Test/Cabal/Prelude.hs index b98d2434514..48b1c569288 100644 --- a/cabal-testsuite/Test/Cabal/Prelude.hs +++ b/cabal-testsuite/Test/Cabal/Prelude.hs @@ -44,15 +44,14 @@ import Control.Monad.IO.Class import qualified Data.ByteString.Char8 as C import Data.List import Data.Maybe -import System.Directory import System.Exit import System.FilePath import Control.Concurrent (threadDelay) import qualified Data.Char as Char +import System.Directory #ifndef mingw32_HOST_OS import Control.Monad.Catch ( bracket_ ) -import System.Directory ( removeFile ) import System.Posix.Files ( createSymbolicLink ) #endif From 4c7f935645238e32c686a7b247895293c3e4a97f Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 25 Nov 2016 17:46:59 -0500 Subject: [PATCH 02/56] Make --builddir/--distdir/etc affect dist-newstyle. Previously, these flags had no affect on new-build. Now, they let you specify where the dist-newstyle directory should go. Note that if a relative path is provided, it is resolved relative to the *project root*. If this is undesirable, pass an absolute path instead. Fixes #4127. Signed-off-by: Edward Z. Yang --- cabal-install/Distribution/Client/CmdFreeze.hs | 2 +- cabal-install/Distribution/Client/DistDirLayout.hs | 11 +++++++---- .../Distribution/Client/ProjectOrchestration.hs | 2 +- cabal-install/tests/IntegrationTests2.hs | 4 ++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/cabal-install/Distribution/Client/CmdFreeze.hs b/cabal-install/Distribution/Client/CmdFreeze.hs index 3c7d1290829..462662defd5 100644 --- a/cabal-install/Distribution/Client/CmdFreeze.hs +++ b/cabal-install/Distribution/Client/CmdFreeze.hs @@ -87,7 +87,7 @@ freezeAction (configFlags, configExFlags, installFlags, haddockFlags) let cabalDirLayout = defaultCabalDirLayout cabalDir projectRootDir <- findProjectRoot - let distDirLayout = defaultDistDirLayout projectRootDir + let distDirLayout = defaultDistDirLayout configFlags projectRootDir let cliConfig = commandLineFlagsToProjectConfig globalFlags configFlags configExFlags diff --git a/cabal-install/Distribution/Client/DistDirLayout.hs b/cabal-install/Distribution/Client/DistDirLayout.hs index 79dad4b924e..6da0bda2a3e 100644 --- a/cabal-install/Distribution/Client/DistDirLayout.hs +++ b/cabal-install/Distribution/Client/DistDirLayout.hs @@ -17,6 +17,7 @@ module Distribution.Client.DistDirLayout ( ) where import System.FilePath +import Distribution.Simple.Setup (fromFlagOrDefault, ConfigFlags, configDistPref) import Distribution.Package ( PackageId, ComponentId, UnitId ) import Distribution.Compiler @@ -106,12 +107,14 @@ data CabalDirLayout = CabalDirLayout { cabalWorldFile :: FilePath } - -defaultDistDirLayout :: FilePath -> DistDirLayout -defaultDistDirLayout projectRootDirectory = +-- | Given the path to the root directory, create the 'DistDirLayout' +-- associated with it. Respects @--builddir@ setting. +defaultDistDirLayout :: ConfigFlags -> FilePath -> DistDirLayout +defaultDistDirLayout configFlags projectRootDirectory = DistDirLayout {..} where - distDirectory = projectRootDirectory "dist-newstyle" + distDirName = fromFlagOrDefault "dist-newstyle" (configDistPref configFlags) + distDirectory = projectRootDirectory distDirName --TODO: switch to just dist at some point, or some other new name distBuildRootDirectory = distDirectory "build" diff --git a/cabal-install/Distribution/Client/ProjectOrchestration.hs b/cabal-install/Distribution/Client/ProjectOrchestration.hs index 17d7818bf1e..d491acded98 100644 --- a/cabal-install/Distribution/Client/ProjectOrchestration.hs +++ b/cabal-install/Distribution/Client/ProjectOrchestration.hs @@ -173,7 +173,7 @@ runProjectPreBuildPhase let cabalDirLayout = defaultCabalDirLayout cabalDir projectRootDir <- findProjectRoot - let distDirLayout = defaultDistDirLayout projectRootDir + let distDirLayout = defaultDistDirLayout configFlags projectRootDir let cliConfig = commandLineFlagsToProjectConfig globalFlags configFlags configExFlags diff --git a/cabal-install/tests/IntegrationTests2.hs b/cabal-install/tests/IntegrationTests2.hs index 45bb5d2dc88..204c452ef45 100644 --- a/cabal-install/tests/IntegrationTests2.hs +++ b/cabal-install/tests/IntegrationTests2.hs @@ -249,7 +249,7 @@ planProject testdir cliConfig = do projectRootDir <- canonicalizePath ("tests" "IntegrationTests2" testdir) - let distDirLayout = defaultDistDirLayout projectRootDir + let distDirLayout = defaultDistDirLayout mempty projectRootDir -- Clear state between test runs. The state remains if the previous run -- ended in an exception (as we leave the files to help with debugging). @@ -313,7 +313,7 @@ cleanProject testdir = do when alreadyExists $ removeDirectoryRecursive distDir where projectRootDir = "tests" "IntegrationTests2" testdir - distDirLayout = defaultDistDirLayout projectRootDir + distDirLayout = defaultDistDirLayout mempty projectRootDir distDir = distDirectory distDirLayout From b74c03f3db0bac471740f4aea0c2dfcc373d389b Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 25 Nov 2016 17:52:02 -0500 Subject: [PATCH 03/56] Add --project-file global flag, for the name of cabal.project files. This is a global flag, so it can only be specified prior to the subcommand. It controls the name of the cabal.project file which new-build and related commands looks for. Signed-off-by: Edward Z. Yang --- .../Distribution/Client/CmdConfigure.hs | 9 +-- .../Distribution/Client/CmdFreeze.hs | 11 ++-- cabal-install/Distribution/Client/Config.hs | 3 +- .../Distribution/Client/ProjectConfig.hs | 65 +++++++++++-------- .../Client/ProjectConfig/Legacy.hs | 3 +- .../Client/ProjectOrchestration.hs | 4 +- .../Distribution/Client/ProjectPlanning.hs | 4 +- cabal-install/Distribution/Client/Setup.hs | 18 ++++- cabal-install/tests/IntegrationTests2.hs | 2 +- 9 files changed, 74 insertions(+), 45 deletions(-) diff --git a/cabal-install/Distribution/Client/CmdConfigure.hs b/cabal-install/Distribution/Client/CmdConfigure.hs index 9e6e2979348..5325c361dd4 100644 --- a/cabal-install/Distribution/Client/CmdConfigure.hs +++ b/cabal-install/Distribution/Client/CmdConfigure.hs @@ -31,9 +31,10 @@ configureCommand = Client.installCommand { commandUsage = usageAlternatives "new-configure" [ "[FLAGS]" ], commandDescription = Just $ \_ -> wrapText $ "Configures a Nix-local build project, downloading source from" - ++ " the network and writing out a cabal.project.local file which" - ++ " saves any FLAGS, to be reapplied on subsequent invocations to " - ++ "new-build.", + ++ " the network and writing out a cabal.project.local file" + ++ " (or $project_file.local, if --project-file is specified)" + ++ " which saves any FLAGS, to be reapplied on subsequent invocations to" + ++ " new-build.", commandNotes = Just $ \pname -> "Examples:\n" ++ " " ++ pname ++ " new-configure " @@ -65,7 +66,7 @@ configureAction (configFlags, configExFlags, installFlags, haddockFlags) hookPrePlanning = \rootDir _ cliConfig -> -- Write out the @cabal.project.local@ so it gets picked up by the -- planning phase. - writeProjectLocalExtraConfig rootDir cliConfig, + writeProjectLocalExtraConfig installFlags rootDir cliConfig, hookSelectPlanSubset = \buildSettings' elaboratedPlan -> do -- Select the same subset of targets as 'CmdBuild' would diff --git a/cabal-install/Distribution/Client/CmdFreeze.hs b/cabal-install/Distribution/Client/CmdFreeze.hs index 462662defd5..c84fc70cb99 100644 --- a/cabal-install/Distribution/Client/CmdFreeze.hs +++ b/cabal-install/Distribution/Client/CmdFreeze.hs @@ -11,7 +11,7 @@ import Distribution.Client.ProjectPlanning import Distribution.Client.ProjectConfig ( ProjectConfig(..), ProjectConfigShared(..) , commandLineFlagsToProjectConfig, writeProjectLocalFreezeConfig - , findProjectRoot ) + , findProjectRoot, getProjectFileName ) import Distribution.Client.Targets ( UserConstraint(..) ) import Distribution.Solver.Types.ConstraintSource @@ -60,6 +60,7 @@ freezeCommand = Client.installCommand { commandDescription = Just $ \_ -> wrapText $ "Performs dependency solving on a Nix-local build project, and" ++ " then writes out the precise dependency configuration to cabal.project.freeze" + ++ " (or $project_file.freeze if --project-file is specified)" ++ " so that the plan is always used in subsequent builds.", commandNotes = Just $ \pname -> "Examples:\n" @@ -86,7 +87,7 @@ freezeAction (configFlags, configExFlags, installFlags, haddockFlags) cabalDir <- defaultCabalDir let cabalDirLayout = defaultCabalDirLayout cabalDir - projectRootDir <- findProjectRoot + projectRootDir <- findProjectRoot installFlags let distDirLayout = defaultDistDirLayout configFlags projectRootDir let cliConfig = commandLineFlagsToProjectConfig @@ -95,14 +96,14 @@ freezeAction (configFlags, configExFlags, installFlags, haddockFlags) (_, elaboratedPlan, _, _) <- - rebuildInstallPlan verbosity + rebuildInstallPlan verbosity installFlags projectRootDir distDirLayout cabalDirLayout cliConfig let freezeConfig = projectFreezeConfig elaboratedPlan - writeProjectLocalFreezeConfig projectRootDir freezeConfig + writeProjectLocalFreezeConfig installFlags projectRootDir freezeConfig notice verbosity $ - "Wrote freeze file: " ++ projectRootDir "cabal.project.freeze" + "Wrote freeze file: " ++ projectRootDir getProjectFileName installFlags <.> "freeze" where verbosity = fromFlagOrDefault normal (configVerbosity configFlags) diff --git a/cabal-install/Distribution/Client/Config.hs b/cabal-install/Distribution/Client/Config.hs index bcd552c9204..fc80bdb987d 100644 --- a/cabal-install/Distribution/Client/Config.hs +++ b/cabal-install/Distribution/Client/Config.hs @@ -260,7 +260,8 @@ instance Semigroup SavedConfig where installNumJobs = combine installNumJobs, installKeepGoing = combine installKeepGoing, installRunTests = combine installRunTests, - installOfflineMode = combine installOfflineMode + installOfflineMode = combine installOfflineMode, + installProjectFileName = combine installProjectFileName } where combine = combine' savedInstallFlags diff --git a/cabal-install/Distribution/Client/ProjectConfig.hs b/cabal-install/Distribution/Client/ProjectConfig.hs index abe564e84b9..4b66ff5b2f8 100644 --- a/cabal-install/Distribution/Client/ProjectConfig.hs +++ b/cabal-install/Distribution/Client/ProjectConfig.hs @@ -37,6 +37,7 @@ module Distribution.Client.ProjectConfig ( resolveSolverSettings, BuildTimeSettings(..), resolveBuildTimeSettings, + getProjectFileName, -- * Checking configuration checkBadPerPackageCompilerPaths, @@ -84,7 +85,7 @@ import Distribution.Simple.Setup ( Flag(Flag), toFlag, flagToMaybe, flagToList , fromFlag, fromFlagOrDefault, AllowNewer(..), AllowOlder(..), RelaxDeps(..) ) import Distribution.Client.Setup - ( defaultSolver, defaultMaxBackjumps, ) + ( defaultSolver, defaultMaxBackjumps, InstallFlags, installProjectFileName ) import Distribution.Simple.InstallDirs ( PathTemplate, fromPathTemplate , toPathTemplate, substPathTemplate, initialPathTemplateEnv ) @@ -338,14 +339,20 @@ resolveBuildTimeSettings verbosity -- Reading and writing project config files -- +getProjectFileName :: InstallFlags -> FilePath +getProjectFileName installFlags = + fromFlagOrDefault "cabal.project" (installProjectFileName installFlags) + -- | Find the root of this project. -- -- Searches for an explicit @cabal.project@ file, in the current directory or -- parent directories. If no project file is found then the current dir is the -- project root (and the project will use an implicit config). -- -findProjectRoot :: IO FilePath -findProjectRoot = do +findProjectRoot :: InstallFlags -> IO FilePath +findProjectRoot installFlags = do + + let projectFileName = getProjectFileName installFlags curdir <- getCurrentDirectory homedir <- getHomeDirectory @@ -355,7 +362,7 @@ findProjectRoot = do let probe dir | isDrive dir || dir == homedir = return curdir -- implicit project root probe dir = do - exists <- doesFileExist (dir "cabal.project") + exists <- doesFileExist (dir projectFileName) if exists then return dir -- explicit project root else probe (takeDirectory dir) @@ -367,20 +374,20 @@ findProjectRoot = do -- | Read all the config relevant for a project. This includes the project -- file if any, plus other global config. -- -readProjectConfig :: Verbosity -> FilePath -> Rebuild ProjectConfig -readProjectConfig verbosity projectRootDir = do - global <- readGlobalConfig verbosity - local <- readProjectLocalConfig verbosity projectRootDir - freeze <- readProjectLocalFreezeConfig verbosity projectRootDir - extra <- readProjectLocalExtraConfig verbosity projectRootDir +readProjectConfig :: Verbosity -> InstallFlags -> FilePath -> Rebuild ProjectConfig +readProjectConfig verbosity installFlags projectRootDir = do + global <- readGlobalConfig verbosity + local <- readProjectLocalConfig verbosity installFlags projectRootDir + freeze <- readProjectLocalFreezeConfig verbosity installFlags projectRootDir + extra <- readProjectLocalExtraConfig verbosity installFlags projectRootDir return (global <> local <> freeze <> extra) -- | Reads an explicit @cabal.project@ file in the given project root dir, -- or returns the default project config for an implicitly defined project. -- -readProjectLocalConfig :: Verbosity -> FilePath -> Rebuild ProjectConfig -readProjectLocalConfig verbosity projectRootDir = do +readProjectLocalConfig :: Verbosity -> InstallFlags -> FilePath -> Rebuild ProjectConfig +readProjectLocalConfig verbosity installFlags projectRootDir = do usesExplicitProjectRoot <- liftIO $ doesFileExist projectFile if usesExplicitProjectRoot then do @@ -391,7 +398,7 @@ readProjectLocalConfig verbosity projectRootDir = do return defaultImplicitProjectConfig where - projectFile = projectRootDir "cabal.project" + projectFile = projectRootDir getProjectFileName installFlags readProjectFile = reportParseResult verbosity "project file" projectFile . parseProjectConfig @@ -419,25 +426,25 @@ readProjectLocalConfig verbosity projectRootDir = do -- or returns empty. This file gets written by @cabal configure@, or in -- principle can be edited manually or by other tools. -- -readProjectLocalExtraConfig :: Verbosity -> FilePath -> Rebuild ProjectConfig -readProjectLocalExtraConfig verbosity = - readProjectExtensionFile verbosity "local" +readProjectLocalExtraConfig :: Verbosity -> InstallFlags -> FilePath -> Rebuild ProjectConfig +readProjectLocalExtraConfig verbosity installFlags = + readProjectExtensionFile verbosity installFlags "local" "project local configuration file" -- | Reads a @cabal.project.freeze@ file in the given project root dir, -- or returns empty. This file gets written by @cabal freeze@, or in -- principle can be edited manually or by other tools. -- -readProjectLocalFreezeConfig :: Verbosity -> FilePath -> Rebuild ProjectConfig -readProjectLocalFreezeConfig verbosity = - readProjectExtensionFile verbosity "freeze" +readProjectLocalFreezeConfig :: Verbosity -> InstallFlags -> FilePath -> Rebuild ProjectConfig +readProjectLocalFreezeConfig verbosity installFlags = + readProjectExtensionFile verbosity installFlags "freeze" "project freeze file" -- | Reads a named config file in the given project root dir, or returns empty. -- -readProjectExtensionFile :: Verbosity -> String -> FilePath +readProjectExtensionFile :: Verbosity -> InstallFlags -> String -> FilePath -> FilePath -> Rebuild ProjectConfig -readProjectExtensionFile verbosity extensionName extensionDescription +readProjectExtensionFile verbosity installFlags extensionName extensionDescription projectRootDir = do exists <- liftIO $ doesFileExist extensionFile if exists @@ -446,7 +453,9 @@ readProjectExtensionFile verbosity extensionName extensionDescription else do monitorFiles [monitorNonExistentFile extensionFile] return mempty where - extensionFile = projectRootDir "cabal.project" <.> extensionName + extensionFile = projectRootDir projectFileName <.> extensionName + + projectFileName = getProjectFileName installFlags readExtensionFile = reportParseResult verbosity extensionDescription extensionFile @@ -477,20 +486,20 @@ showProjectConfig = -- | Write a @cabal.project.local@ file in the given project root dir. -- -writeProjectLocalExtraConfig :: FilePath -> ProjectConfig -> IO () -writeProjectLocalExtraConfig projectRootDir = +writeProjectLocalExtraConfig :: InstallFlags -> FilePath -> ProjectConfig -> IO () +writeProjectLocalExtraConfig installFlags projectRootDir = writeProjectConfigFile projectExtraConfigFile where - projectExtraConfigFile = projectRootDir "cabal.project.local" + projectExtraConfigFile = projectRootDir getProjectFileName installFlags <.> "local" -- | Write a @cabal.project.freeze@ file in the given project root dir. -- -writeProjectLocalFreezeConfig :: FilePath -> ProjectConfig -> IO () -writeProjectLocalFreezeConfig projectRootDir = +writeProjectLocalFreezeConfig :: InstallFlags -> FilePath -> ProjectConfig -> IO () +writeProjectLocalFreezeConfig installFlags projectRootDir = writeProjectConfigFile projectFreezeConfigFile where - projectFreezeConfigFile = projectRootDir "cabal.project.freeze" + projectFreezeConfigFile = projectRootDir getProjectFileName installFlags <.> "freeze" -- | Write in the @cabal.project@ format to the given file. diff --git a/cabal-install/Distribution/Client/ProjectConfig/Legacy.hs b/cabal-install/Distribution/Client/ProjectConfig/Legacy.hs index 3172d9081b2..a494825d0de 100644 --- a/cabal-install/Distribution/Client/ProjectConfig/Legacy.hs +++ b/cabal-install/Distribution/Client/ProjectConfig/Legacy.hs @@ -515,7 +515,8 @@ convertToLegacySharedConfig installNumJobs = projectConfigNumJobs, installKeepGoing = projectConfigKeepGoing, installRunTests = mempty, - installOfflineMode = projectConfigOfflineMode + installOfflineMode = projectConfigOfflineMode, + installProjectFileName = mempty } diff --git a/cabal-install/Distribution/Client/ProjectOrchestration.hs b/cabal-install/Distribution/Client/ProjectOrchestration.hs index d491acded98..b502e7c6b6d 100644 --- a/cabal-install/Distribution/Client/ProjectOrchestration.hs +++ b/cabal-install/Distribution/Client/ProjectOrchestration.hs @@ -172,7 +172,7 @@ runProjectPreBuildPhase cabalDir <- defaultCabalDir let cabalDirLayout = defaultCabalDirLayout cabalDir - projectRootDir <- findProjectRoot + projectRootDir <- findProjectRoot installFlags let distDirLayout = defaultDistDirLayout configFlags projectRootDir let cliConfig = commandLineFlagsToProjectConfig @@ -189,7 +189,7 @@ runProjectPreBuildPhase -- the user has asked for. -- (elaboratedPlan, _, elaboratedShared, projectConfig) <- - rebuildInstallPlan verbosity + rebuildInstallPlan verbosity installFlags projectRootDir distDirLayout cabalDirLayout cliConfig diff --git a/cabal-install/Distribution/Client/ProjectPlanning.hs b/cabal-install/Distribution/Client/ProjectPlanning.hs index c88ddb7812c..71e266a5666 100644 --- a/cabal-install/Distribution/Client/ProjectPlanning.hs +++ b/cabal-install/Distribution/Client/ProjectPlanning.hs @@ -284,6 +284,7 @@ sanityCheckElaboratedPackage ElaboratedConfiguredPackage{..} -- dependencies of executables and setup scripts. -- rebuildInstallPlan :: Verbosity + -> InstallFlags -> FilePath -> DistDirLayout -> CabalDirLayout -> ProjectConfig -> IO ( ElaboratedInstallPlan -- with store packages @@ -292,6 +293,7 @@ rebuildInstallPlan :: Verbosity , ProjectConfig ) -- ^ @(improvedPlan, elaboratedPlan, _, _)@ rebuildInstallPlan verbosity + installFlags projectRootDir distDirLayout@DistDirLayout { distDirectory, @@ -365,7 +367,7 @@ rebuildInstallPlan verbosity createDirectoryIfMissingVerbose verbosity True distDirectory createDirectoryIfMissingVerbose verbosity True distProjectCacheDirectory - projectConfig <- readProjectConfig verbosity projectRootDir + projectConfig <- readProjectConfig verbosity installFlags projectRootDir -- The project config comming from the command line includes "build only" -- flags that we don't cache persistently (because like all "build only" diff --git a/cabal-install/Distribution/Client/Setup.hs b/cabal-install/Distribution/Client/Setup.hs index ef3f0f99062..bada7a9aeb1 100644 --- a/cabal-install/Distribution/Client/Setup.hs +++ b/cabal-install/Distribution/Client/Setup.hs @@ -1250,7 +1250,15 @@ data InstallFlags = InstallFlags { installNumJobs :: Flag (Maybe Int), installKeepGoing :: Flag Bool, installRunTests :: Flag Bool, - installOfflineMode :: Flag Bool + installOfflineMode :: Flag Bool, + -- | The cabal project file name; defaults to @cabal.project@. + -- Th name itself denotes the cabal project file name, but it also + -- is the base of auxiliary project files, such as + -- @cabal.project.local@ and @cabal.project.freeze@ which are also + -- read and written out in some cases. If the path is not found + -- in the current working directory, we will successively probe + -- relative to parent directories until this name is found. + installProjectFileName :: Flag FilePath } deriving (Eq, Generic) @@ -1284,7 +1292,8 @@ defaultInstallFlags = InstallFlags { installNumJobs = mempty, installKeepGoing = Flag False, installRunTests = mempty, - installOfflineMode = Flag False + installOfflineMode = Flag False, + installProjectFileName = mempty } where docIndexFile = toPathTemplate ("$datadir" "doc" @@ -1514,6 +1523,11 @@ installOptions showOrParseArgs = "Don't download packages from the Internet." installOfflineMode (\v flags -> flags { installOfflineMode = v }) (yesNoOpt showOrParseArgs) + + , option [] ["project-file"] + "Set the name of the cabal.project file to search for in parent directories" + installProjectFileName (\v flags -> flags {installProjectFileName = v}) + (reqArgFlag "FILE") ] ++ case showOrParseArgs of -- TODO: remove when "cabal install" -- avoids ParseArgs -> diff --git a/cabal-install/tests/IntegrationTests2.hs b/cabal-install/tests/IntegrationTests2.hs index 204c452ef45..d0af0961048 100644 --- a/cabal-install/tests/IntegrationTests2.hs +++ b/cabal-install/tests/IntegrationTests2.hs @@ -256,7 +256,7 @@ planProject testdir cliConfig = do cleanProject testdir (elaboratedPlan, _, elaboratedShared, projectConfig) <- - rebuildInstallPlan verbosity + rebuildInstallPlan verbosity mempty projectRootDir distDirLayout cabalDirLayout cliConfig From 847d3f51f3c79882f01eaf41e6be4daa0a597601 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 25 Nov 2016 17:50:03 -0500 Subject: [PATCH 04/56] Documentation for --builddir and --project-file flags. Signed-off-by: Edward Z. Yang --- Cabal/doc/nix-local-build.rst | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/Cabal/doc/nix-local-build.rst b/Cabal/doc/nix-local-build.rst index 55ada8b0f9c..292c6d016f9 100644 --- a/Cabal/doc/nix-local-build.rst +++ b/Cabal/doc/nix-local-build.rst @@ -580,6 +580,32 @@ package, and thus apply globally: The command line variant of this field is ``--keep-going``. +.. option:: --builddir=DIR + + Specifies the name of the directory where build products for + build will be stored; defaults to ``dist-newstyle``. If a + relative name is specified, this directory is resolved relative + to the root of the project (i.e., where the ``cabal.project`` + file lives.) + + This option cannot be specified via a ``cabal.project`` file. + +.. option:: --project-file=FILE + + Specifies the name of the project file used to specify the + rest of the top-level configuration; defaults to ``cabal.project``. + This name not only specifies the name of the main project file, + but also the auxiliary project files ``cabal.project.freeze`` + and ``cabal.project.local``; for example, if you specify + ``--project-file=my.project``, then the other files that will + be probed are ``my.project.freeze`` and ``my.project.local``. + + If the specified project file is a relative path, we will + look for the file relative to the current working directory, + and then for the parent directory, until the project file is + found or we have hit the top of the user's home directory. + + This option cannot be specified via a ``cabal.project`` file. Solver configuration options ---------------------------- @@ -1697,5 +1723,4 @@ Most users generally won't need these. The command line variant of this field is ``--cabal-lib-version=1.24.0.1``. - .. include:: references.inc From fa3746abecb4f8d25a47a5128c6d142ba20ceffc Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sun, 20 Nov 2016 20:46:56 -0500 Subject: [PATCH 05/56] Use --project-file and --builddir in cabal new-build tests. Signed-off-by: Edward Z. Yang --- cabal-testsuite/Test/Cabal/Monad.hs | 5 ++++- cabal-testsuite/Test/Cabal/Prelude.hs | 13 +++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/cabal-testsuite/Test/Cabal/Monad.hs b/cabal-testsuite/Test/Cabal/Monad.hs index 879207bf0a5..26d1a59b8ac 100644 --- a/cabal-testsuite/Test/Cabal/Monad.hs +++ b/cabal-testsuite/Test/Cabal/Monad.hs @@ -178,7 +178,8 @@ runTestM m = do testShouldFail = False, testRelativeCurrentDir = ".", testHavePackageDb = False, - testCabalInstallAsSetup = False + testCabalInstallAsSetup = False, + testCabalProjectFile = "cabal.project" } runReaderT (cleanup >> m) env where @@ -235,6 +236,8 @@ data TestEnv = TestEnv , testHavePackageDb :: Bool -- | Says if we're testing cabal-install as setup , testCabalInstallAsSetup :: Bool + -- | Says what cabal.project file to use (probed) + , testCabalProjectFile :: FilePath } getTestEnv :: TestM TestEnv diff --git a/cabal-testsuite/Test/Cabal/Prelude.hs b/cabal-testsuite/Test/Cabal/Prelude.hs index 48b1c569288..277223422ec 100644 --- a/cabal-testsuite/Test/Cabal/Prelude.hs +++ b/cabal-testsuite/Test/Cabal/Prelude.hs @@ -217,17 +217,26 @@ cabal cmd args = void (cabal' cmd args) cabal' :: String -> [String] -> TestM Result cabal' cmd args = do env <- getTestEnv + ghc_path <- programPathM ghcProgram + let cabal_args = [ cmd, "-v" + , "--with-ghc", ghc_path + , "--builddir", testWorkDir env + , "--project-file", testCabalProjectFile env ] + ++ args -- TODO: prevent .cabal in HOME from interfering with tests - -- TODO: put in unique dist-newstyle to avoid clobbering r <- liftIO $ run (testVerbosity env) (Just (testCurrentDir env)) (testEnvironment env) (fromMaybe (error "No cabal-install path configured") (testCabalInstallPath env)) - (cmd : ["-v"] ++ args) + cabal_args record r requireSuccess r +withProjectFile :: FilePath -> TestM a -> TestM a +withProjectFile fp m = + withReaderT (\env -> env { testCabalProjectFile = fp }) m + ------------------------------------------------------------------------ -- * Running ghc-pkg From ef432a49d9d80c5041090f2cd10a221f810832eb Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sun, 20 Nov 2016 21:05:17 -0500 Subject: [PATCH 06/56] Add default-language pragmas to cabal-testsuite.cabal Signed-off-by: Edward Z. Yang --- cabal-testsuite/cabal-testsuite.cabal | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cabal-testsuite/cabal-testsuite.cabal b/cabal-testsuite/cabal-testsuite.cabal index a55f5f5fa03..851d2b541ef 100644 --- a/cabal-testsuite/cabal-testsuite.cabal +++ b/cabal-testsuite/cabal-testsuite.cabal @@ -46,6 +46,7 @@ library build-depends: unix, exceptions else build-depends: Win32 + default-language: Haskell2010 test-suite cabal-tests type: exitcode-stdio-1.0 @@ -61,6 +62,7 @@ test-suite cabal-tests process, optparse-applicative, cabal-testsuite + default-language: Haskell2010 custom-setup setup-depends: Cabal >= 1.25, From 7e7b4e9e9d46d33eb6cb0630a0609f9ef004afd7 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sun, 20 Nov 2016 21:06:12 -0500 Subject: [PATCH 07/56] Switch cabal-tests to executable so it is always configured. Signed-off-by: Edward Z. Yang --- cabal-testsuite/Test/Cabal/Script.hs | 2 +- cabal-testsuite/cabal-testsuite.cabal | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/cabal-testsuite/Test/Cabal/Script.hs b/cabal-testsuite/Test/Cabal/Script.hs index 8813898a368..7305527e0eb 100644 --- a/cabal-testsuite/Test/Cabal/Script.hs +++ b/cabal-testsuite/Test/Cabal/Script.hs @@ -68,7 +68,7 @@ mkScriptEnv verbosity lbi = do -- non-Backpack. cabalTestsPackages :: LocalBuildInfo -> [(OpenUnitId, ModuleRenaming)] cabalTestsPackages lbi = - case componentNameCLBIs lbi (CTestName (mkUnqualComponentName "cabal-tests")) of + case componentNameCLBIs lbi (CExeName (mkUnqualComponentName "cabal-tests")) of [clbi] -> componentIncludes clbi _ -> error "cabalTestsPackages" diff --git a/cabal-testsuite/cabal-testsuite.cabal b/cabal-testsuite/cabal-testsuite.cabal index 851d2b541ef..c248650a075 100644 --- a/cabal-testsuite/cabal-testsuite.cabal +++ b/cabal-testsuite/cabal-testsuite.cabal @@ -48,8 +48,7 @@ library build-depends: Win32 default-language: Haskell2010 -test-suite cabal-tests - type: exitcode-stdio-1.0 +executable cabal-tests main-is: cabal-tests.hs hs-source-dirs: main ghc-options: -threaded -Wall -fwarn-tabs From 65f8eec10153b800461f89c75e8b302de3c3cbc5 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 25 Nov 2016 19:24:46 -0500 Subject: [PATCH 08/56] Add support for reading plan.json from new-build in test suite. This information is useful for determining where the build products are placed, so we can, e.g., run the built executables. Signed-off-by: Edward Z. Yang --- cabal-testsuite/Test/Cabal/Monad.hs | 7 ++- cabal-testsuite/Test/Cabal/Plan.hs | 77 +++++++++++++++++++++++++++ cabal-testsuite/Test/Cabal/Prelude.hs | 31 +++++++++++ cabal-testsuite/cabal-testsuite.cabal | 4 ++ 4 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 cabal-testsuite/Test/Cabal/Plan.hs diff --git a/cabal-testsuite/Test/Cabal/Monad.hs b/cabal-testsuite/Test/Cabal/Monad.hs index 26d1a59b8ac..0e8fdf27803 100644 --- a/cabal-testsuite/Test/Cabal/Monad.hs +++ b/cabal-testsuite/Test/Cabal/Monad.hs @@ -31,6 +31,7 @@ module Test.Cabal.Monad ( ) where import Test.Cabal.Script +import Test.Cabal.Plan import Distribution.Simple.Compiler (PackageDBStack, PackageDB(..), compilerFlavor) import Distribution.Simple.Program.Db @@ -179,7 +180,8 @@ runTestM m = do testRelativeCurrentDir = ".", testHavePackageDb = False, testCabalInstallAsSetup = False, - testCabalProjectFile = "cabal.project" + testCabalProjectFile = "cabal.project", + testPlan = Nothing } runReaderT (cleanup >> m) env where @@ -238,6 +240,9 @@ data TestEnv = TestEnv , testCabalInstallAsSetup :: Bool -- | Says what cabal.project file to use (probed) , testCabalProjectFile :: FilePath + -- | Cached record of the plan metadata from a new-build + -- invocation; controlled by 'withPlan'. + , testPlan :: Maybe Plan } getTestEnv :: TestM TestEnv diff --git a/cabal-testsuite/Test/Cabal/Plan.hs b/cabal-testsuite/Test/Cabal/Plan.hs new file mode 100644 index 00000000000..085148f76de --- /dev/null +++ b/cabal-testsuite/Test/Cabal/Plan.hs @@ -0,0 +1,77 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +-- | Utilities for understanding @plan.json@. +module Test.Cabal.Plan ( + Plan, + planDistDir, +) where + +import Distribution.Text +import Distribution.Types.ComponentName +import Distribution.Package +import qualified Data.Text as Text +import Data.Aeson +import Data.Aeson.Types +import Control.Monad + +-- TODO: index this +data Plan = Plan { planInstallPlan :: [InstallItem] } + +data InstallItem + = APreExisting + | AConfigured Configured + +data Configured = Configured + { configuredDistDir :: FilePath + , configuredPackageName :: PackageName + , configuredComponentName :: Maybe ComponentName } + +instance FromJSON Plan where + parseJSON (Object v) = fmap Plan (v .: "install-plan") + parseJSON invalid = typeMismatch "Plan" invalid + +instance FromJSON InstallItem where + parseJSON obj@(Object v) = do + t <- v .: "type" + case t :: String of + "pre-existing" -> return APreExisting + "configured" -> AConfigured `fmap` parseJSON obj + _ -> fail "unrecognized value of 'type' field" + parseJSON invalid = typeMismatch "InstallItem" invalid + +instance FromJSON Configured where + parseJSON (Object v) = do + dist_dir <- v .: "dist-dir" + pkg_name <- v .: "pkg-name" + component_name <- v .:? "component-name" + return (Configured dist_dir pkg_name component_name) + parseJSON invalid = typeMismatch "Configured" invalid + +instance FromJSON PackageName where + parseJSON (String t) = return (mkPackageName (Text.unpack t)) + parseJSON invalid = typeMismatch "PackageName" invalid + +instance FromJSON ComponentName where + parseJSON (String t) = + case simpleParse s of + Nothing -> fail ("could not parse component-name: " ++ s) + Just r -> return r + where s = Text.unpack t + parseJSON invalid = typeMismatch "ComponentName" invalid + +planDistDir :: Plan -> PackageName -> ComponentName -> FilePath +planDistDir plan pkg_name cname = + case concatMap p (planInstallPlan plan) of + [x] -> x + [] -> error $ "planDistDir: could not find component " ++ display cname + ++ " of package " ++ display pkg_name ++ " in install plan" + _ -> error $ "planDistDir: found multiple copies of component " ++ display cname + ++ " of package " ++ display pkg_name ++ " in install plan" + where + p APreExisting = [] + p (AConfigured conf) = do + guard (configuredPackageName conf == pkg_name) + guard $ case configuredComponentName conf of + Nothing -> True + Just cname' -> cname == cname' + return (configuredDistDir conf) diff --git a/cabal-testsuite/Test/Cabal/Prelude.hs b/cabal-testsuite/Test/Cabal/Prelude.hs index 277223422ec..d298a4806cb 100644 --- a/cabal-testsuite/Test/Cabal/Prelude.hs +++ b/cabal-testsuite/Test/Cabal/Prelude.hs @@ -17,6 +17,7 @@ module Test.Cabal.Prelude ( import Test.Cabal.Script import Test.Cabal.Run import Test.Cabal.Monad +import Test.Cabal.Plan import Distribution.Compat.Time (calibrateMtimeChangeDelay) import Distribution.Simple.Compiler (PackageDBStack, PackageDB(..)) @@ -29,6 +30,8 @@ import Distribution.Simple.Utils import Distribution.Simple.Configure ( getPersistBuildConfig ) import Distribution.Version +import Distribution.Package +import Distribution.Types.UnqualComponentName import Distribution.Types.LocalBuildInfo import Distribution.PackageDescription import Distribution.PackageDescription.Parse @@ -38,6 +41,8 @@ import Distribution.Compat.Stack import Text.Regex.Posix +import qualified Data.Aeson as JSON +import qualified Data.ByteString.Lazy as BSL import Control.Monad import Control.Monad.Trans.Reader import Control.Monad.IO.Class @@ -237,6 +242,32 @@ withProjectFile :: FilePath -> TestM a -> TestM a withProjectFile fp m = withReaderT (\env -> env { testCabalProjectFile = fp }) m +-- | Assuming we've successfully configured a new-build project, +-- read out the plan metadata so that we can use it to do other +-- operations. +withPlan :: TestM a -> TestM a +withPlan m = do + env0 <- getTestEnv + Just plan <- JSON.decode `fmap` + liftIO (BSL.readFile (testWorkDir env0 "cache" "plan.json")) + withReaderT (\env -> env { testPlan = Just plan }) m + +-- | Run an executable from a package. Requires 'withPlan' to have +-- been run so that we can find the dist dir. +runPlanExe :: String {- package name -} -> String {- component name -} + -> [String] -> TestM () +runPlanExe pkg_name cname args = void $ runPlanExe' pkg_name cname args + +-- | Run an executable from a package. Requires 'withPlan' to have +-- been run so that we can find the dist dir. Also returns 'Result'. +runPlanExe' :: String {- package name -} -> String {- component name -} + -> [String] -> TestM Result +runPlanExe' pkg_name cname args = do + Just plan <- testPlan `fmap` getTestEnv + let dist_dir = planDistDir plan (mkPackageName pkg_name) + (CExeName (mkUnqualComponentName cname)) + runM (dist_dir "build" cname cname) args + ------------------------------------------------------------------------ -- * Running ghc-pkg diff --git a/cabal-testsuite/cabal-testsuite.cabal b/cabal-testsuite/cabal-testsuite.cabal index c248650a075..1b0ac417589 100644 --- a/cabal-testsuite/cabal-testsuite.cabal +++ b/cabal-testsuite/cabal-testsuite.cabal @@ -27,10 +27,13 @@ library Test.Cabal.Workdir Test.Cabal.Script Test.Cabal.Run + Test.Cabal.Plan Test.Cabal.Prelude Test.Cabal.Server Test.Cabal.Monad build-depends: + aeson, + attoparsec, async, base, bytestring, @@ -40,6 +43,7 @@ library directory, filepath, regex-posix, + text, Cabal >= 1.25 ghc-options: -Wall -fwarn-tabs if !os(windows) From dd7fa17f82d938ce29a561e8f38e8ab6cdb96b74 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sat, 26 Nov 2016 01:43:02 -0500 Subject: [PATCH 09/56] Enable cabal-install tests with cabal-testsuite in CI. Signed-off-by: Edward Z. Yang --- appveyor.yml | 2 ++ travis-script.sh | 2 ++ 2 files changed, 4 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index ba3b62113c6..e96654ff26a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -45,3 +45,5 @@ build_script: - ..\cabal test integration-tests2 --show-details=streaming --test-option=--hide-successes - ..\cabal test solver-quickcheck --show-details=streaming --test-option=--hide-successes --test-option=--quickcheck-tests=1000 - ..\cabal test memory-usage-tests --show-details=streaming + - cd ..\cabal-testsuite + - dist\build\cabal-tests\cabal-tests.exe -j3 --skip-setup-tests --with-cabal=..\cabal-install\dist\build\cabal\cabal.exe diff --git a/travis-script.sh b/travis-script.sh index 8f8412d68f0..11144edddb5 100755 --- a/travis-script.sh +++ b/travis-script.sh @@ -128,6 +128,8 @@ timed ${CABAL_INSTALL_BDIR}/build/cabal/cabal update (cd cabal-install && timed ${CABAL_INSTALL_BDIR}/build/integration-tests2/integration-tests2 $TEST_OPTIONS) || exit $? (cd cabal-install && timed ${CABAL_INSTALL_BDIR}/build/memory-usage-tests/memory-usage-tests $TEST_OPTIONS) || exit $? +(cd cabal-testsuite && timed ${CABAL_TESTSUITE_BDIR}/build/cabal-tests/cabal-tests -j3 --skip-setup-tests --with-cabal ${CABAL_INSTALL_BDIR}/build/cabal/cabal $TEST_OPTIONS) || exit $? + # Haddock (cd cabal-install && timed ${CABAL_INSTALL_SETUP} haddock --builddir=${CABAL_INSTALL_BDIR} ) || exit $? From e309598eff78aa1ac1939a0c914499380ec1ba11 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Thu, 24 Nov 2016 23:05:10 -0500 Subject: [PATCH 10/56] Port backpack/includes2 to new test suite. Signed-off-by: Edward Z. Yang --- .../backpack/includes2-external.sh | 9 ---- .../backpack/includes2-internal.sh | 9 ---- .../backpack/includes2/Includes2.cabal | 41 ------------------- .../backpack/includes2/exe/Main.hs | 3 -- .../backpack/includes2/exe/exe.cabal | 12 ------ .../backpack/includes2/mylib/Database.hsig | 3 -- .../backpack/includes2/mylib/Mine.hs | 4 -- .../backpack/includes2/mylib/mylib.cabal | 13 ------ .../includes2/mysql/Database/MySQL.hs | 3 -- .../backpack/includes2/mysql/mysql.cabal | 12 ------ .../postgresql/Database/PostgreSQL.hs | 3 -- .../includes2/postgresql/postgresql.cabal | 12 ------ .../backpack/includes2/src/App.hs | 7 ---- .../backpack/includes2/src/src.cabal | 15 ------- .../Backpack/Includes2/cabal-external.test.hs | 9 ++++ .../Backpack/Includes2/cabal-internal.test.hs | 9 ++++ .../Backpack/Includes2/cabal.external.project | 0 .../Backpack/Includes2/cabal.internal.project | 0 .../Includes2/setup-per-component.test.hs | 3 +- 19 files changed, 20 insertions(+), 147 deletions(-) delete mode 100644 cabal-install/tests/IntegrationTests/backpack/includes2-external.sh delete mode 100644 cabal-install/tests/IntegrationTests/backpack/includes2-internal.sh delete mode 100644 cabal-install/tests/IntegrationTests/backpack/includes2/Includes2.cabal delete mode 100644 cabal-install/tests/IntegrationTests/backpack/includes2/exe/Main.hs delete mode 100644 cabal-install/tests/IntegrationTests/backpack/includes2/exe/exe.cabal delete mode 100644 cabal-install/tests/IntegrationTests/backpack/includes2/mylib/Database.hsig delete mode 100644 cabal-install/tests/IntegrationTests/backpack/includes2/mylib/Mine.hs delete mode 100644 cabal-install/tests/IntegrationTests/backpack/includes2/mylib/mylib.cabal delete mode 100644 cabal-install/tests/IntegrationTests/backpack/includes2/mysql/Database/MySQL.hs delete mode 100644 cabal-install/tests/IntegrationTests/backpack/includes2/mysql/mysql.cabal delete mode 100644 cabal-install/tests/IntegrationTests/backpack/includes2/postgresql/Database/PostgreSQL.hs delete mode 100644 cabal-install/tests/IntegrationTests/backpack/includes2/postgresql/postgresql.cabal delete mode 100644 cabal-install/tests/IntegrationTests/backpack/includes2/src/App.hs delete mode 100644 cabal-install/tests/IntegrationTests/backpack/includes2/src/src.cabal create mode 100644 cabal-testsuite/PackageTests/Backpack/Includes2/cabal-external.test.hs create mode 100644 cabal-testsuite/PackageTests/Backpack/Includes2/cabal-internal.test.hs rename cabal-install/tests/IntegrationTests/backpack/includes2/cabal.project.external => cabal-testsuite/PackageTests/Backpack/Includes2/cabal.external.project (100%) rename cabal-install/tests/IntegrationTests/backpack/includes2/cabal.project.internal => cabal-testsuite/PackageTests/Backpack/Includes2/cabal.internal.project (100%) diff --git a/cabal-install/tests/IntegrationTests/backpack/includes2-external.sh b/cabal-install/tests/IntegrationTests/backpack/includes2-external.sh deleted file mode 100644 index 4c49bd6b244..00000000000 --- a/cabal-install/tests/IntegrationTests/backpack/includes2-external.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -. ./common.sh - -require_ghc_ge 801 - -cd includes2 -mv cabal.project.external cabal.project -cabal new-build exe -dist-newstyle/build/*/*/exe-*/c/exe/build/exe/exe | fgrep "minemysql minepostgresql" diff --git a/cabal-install/tests/IntegrationTests/backpack/includes2-internal.sh b/cabal-install/tests/IntegrationTests/backpack/includes2-internal.sh deleted file mode 100644 index cd3538280a7..00000000000 --- a/cabal-install/tests/IntegrationTests/backpack/includes2-internal.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -. ./common.sh - -require_ghc_ge 801 - -cd includes2 -mv cabal.project.internal cabal.project -cabal new-build exe -dist-newstyle/build/*/*/Includes2-*/c/exe/build/exe/exe | fgrep "minemysql minepostgresql" diff --git a/cabal-install/tests/IntegrationTests/backpack/includes2/Includes2.cabal b/cabal-install/tests/IntegrationTests/backpack/includes2/Includes2.cabal deleted file mode 100644 index 0c07c997d8d..00000000000 --- a/cabal-install/tests/IntegrationTests/backpack/includes2/Includes2.cabal +++ /dev/null @@ -1,41 +0,0 @@ -name: Includes2 -version: 0.1.0.0 -license: BSD3 -author: Edward Z. Yang -maintainer: ezyang@cs.stanford.edu -build-type: Simple -cabal-version: >=1.25 - -library mylib - build-depends: base - signatures: Database - exposed-modules: Mine - hs-source-dirs: mylib - default-language: Haskell2010 - -library mysql - build-depends: base - exposed-modules: Database.MySQL - hs-source-dirs: mysql - default-language: Haskell2010 - -library postgresql - build-depends: base - exposed-modules: Database.PostgreSQL - hs-source-dirs: postgresql - default-language: Haskell2010 - -library - build-depends: base, mysql, postgresql, mylib - mixins: - mylib (Mine as Mine.MySQL) requires (Database as Database.MySQL), - mylib (Mine as Mine.PostgreSQL) requires (Database as Database.PostgreSQL) - exposed-modules: App - hs-source-dirs: src - default-language: Haskell2010 - -executable exe - build-depends: base, Includes2 - main-is: Main.hs - hs-source-dirs: exe - default-language: Haskell2010 diff --git a/cabal-install/tests/IntegrationTests/backpack/includes2/exe/Main.hs b/cabal-install/tests/IntegrationTests/backpack/includes2/exe/Main.hs deleted file mode 100644 index 865b7f2b489..00000000000 --- a/cabal-install/tests/IntegrationTests/backpack/includes2/exe/Main.hs +++ /dev/null @@ -1,3 +0,0 @@ -import App - -main = print app diff --git a/cabal-install/tests/IntegrationTests/backpack/includes2/exe/exe.cabal b/cabal-install/tests/IntegrationTests/backpack/includes2/exe/exe.cabal deleted file mode 100644 index 707ea843e4c..00000000000 --- a/cabal-install/tests/IntegrationTests/backpack/includes2/exe/exe.cabal +++ /dev/null @@ -1,12 +0,0 @@ -name: exe -version: 0.1.0.0 -license: BSD3 -author: Edward Z. Yang -maintainer: ezyang@cs.stanford.edu -build-type: Simple -cabal-version: >=1.25 - -executable exe - build-depends: base, src - main-is: Main.hs - default-language: Haskell2010 diff --git a/cabal-install/tests/IntegrationTests/backpack/includes2/mylib/Database.hsig b/cabal-install/tests/IntegrationTests/backpack/includes2/mylib/Database.hsig deleted file mode 100644 index 725d795f94a..00000000000 --- a/cabal-install/tests/IntegrationTests/backpack/includes2/mylib/Database.hsig +++ /dev/null @@ -1,3 +0,0 @@ -signature Database where -data Database -databaseName :: String diff --git a/cabal-install/tests/IntegrationTests/backpack/includes2/mylib/Mine.hs b/cabal-install/tests/IntegrationTests/backpack/includes2/mylib/Mine.hs deleted file mode 100644 index 20b4c0d404c..00000000000 --- a/cabal-install/tests/IntegrationTests/backpack/includes2/mylib/Mine.hs +++ /dev/null @@ -1,4 +0,0 @@ -module Mine where -import Database -data Mine = Mine Database -mine = "mine" ++ databaseName diff --git a/cabal-install/tests/IntegrationTests/backpack/includes2/mylib/mylib.cabal b/cabal-install/tests/IntegrationTests/backpack/includes2/mylib/mylib.cabal deleted file mode 100644 index cc0e3e3ec28..00000000000 --- a/cabal-install/tests/IntegrationTests/backpack/includes2/mylib/mylib.cabal +++ /dev/null @@ -1,13 +0,0 @@ -name: mylib -version: 0.1.0.0 -license: BSD3 -author: Edward Z. Yang -maintainer: ezyang@cs.stanford.edu -build-type: Simple -cabal-version: >=1.25 - -library - build-depends: base - signatures: Database - exposed-modules: Mine - default-language: Haskell2010 diff --git a/cabal-install/tests/IntegrationTests/backpack/includes2/mysql/Database/MySQL.hs b/cabal-install/tests/IntegrationTests/backpack/includes2/mysql/Database/MySQL.hs deleted file mode 100644 index b49cdb42849..00000000000 --- a/cabal-install/tests/IntegrationTests/backpack/includes2/mysql/Database/MySQL.hs +++ /dev/null @@ -1,3 +0,0 @@ -module Database.MySQL where -data Database = Database Int -databaseName = "mysql" diff --git a/cabal-install/tests/IntegrationTests/backpack/includes2/mysql/mysql.cabal b/cabal-install/tests/IntegrationTests/backpack/includes2/mysql/mysql.cabal deleted file mode 100644 index bb331f5c836..00000000000 --- a/cabal-install/tests/IntegrationTests/backpack/includes2/mysql/mysql.cabal +++ /dev/null @@ -1,12 +0,0 @@ -name: mysql -version: 0.1.0.0 -license: BSD3 -author: Edward Z. Yang -maintainer: ezyang@cs.stanford.edu -build-type: Simple -cabal-version: >=1.25 - -library - build-depends: base - exposed-modules: Database.MySQL - default-language: Haskell2010 diff --git a/cabal-install/tests/IntegrationTests/backpack/includes2/postgresql/Database/PostgreSQL.hs b/cabal-install/tests/IntegrationTests/backpack/includes2/postgresql/Database/PostgreSQL.hs deleted file mode 100644 index 9cc64f12d61..00000000000 --- a/cabal-install/tests/IntegrationTests/backpack/includes2/postgresql/Database/PostgreSQL.hs +++ /dev/null @@ -1,3 +0,0 @@ -module Database.PostgreSQL where -data Database = Database Bool -databaseName = "postgresql" diff --git a/cabal-install/tests/IntegrationTests/backpack/includes2/postgresql/postgresql.cabal b/cabal-install/tests/IntegrationTests/backpack/includes2/postgresql/postgresql.cabal deleted file mode 100644 index 1ba91f5d81b..00000000000 --- a/cabal-install/tests/IntegrationTests/backpack/includes2/postgresql/postgresql.cabal +++ /dev/null @@ -1,12 +0,0 @@ -name: postgresql -version: 0.1.0.0 -license: BSD3 -author: Edward Z. Yang -maintainer: ezyang@cs.stanford.edu -build-type: Simple -cabal-version: >=1.25 - -library - build-depends: base - exposed-modules: Database.PostgreSQL - default-language: Haskell2010 diff --git a/cabal-install/tests/IntegrationTests/backpack/includes2/src/App.hs b/cabal-install/tests/IntegrationTests/backpack/includes2/src/App.hs deleted file mode 100644 index f5213de2c16..00000000000 --- a/cabal-install/tests/IntegrationTests/backpack/includes2/src/App.hs +++ /dev/null @@ -1,7 +0,0 @@ -module App where -import Database.MySQL -import Database.PostgreSQL -import qualified Mine.MySQL -import qualified Mine.PostgreSQL - -app = Mine.MySQL.mine ++ " " ++ Mine.PostgreSQL.mine diff --git a/cabal-install/tests/IntegrationTests/backpack/includes2/src/src.cabal b/cabal-install/tests/IntegrationTests/backpack/includes2/src/src.cabal deleted file mode 100644 index 3371a3c6df1..00000000000 --- a/cabal-install/tests/IntegrationTests/backpack/includes2/src/src.cabal +++ /dev/null @@ -1,15 +0,0 @@ -name: src -version: 0.1.0.0 -license: BSD3 -author: Edward Z. Yang -maintainer: ezyang@cs.stanford.edu -build-type: Simple -cabal-version: >=1.25 - -library - build-depends: base, mysql, postgresql, mylib - mixins: - mylib (Mine as Mine.MySQL) requires (Database as Database.MySQL), - mylib (Mine as Mine.PostgreSQL) requires (Database as Database.PostgreSQL) - exposed-modules: App - default-language: Haskell2010 diff --git a/cabal-testsuite/PackageTests/Backpack/Includes2/cabal-external.test.hs b/cabal-testsuite/PackageTests/Backpack/Includes2/cabal-external.test.hs new file mode 100644 index 00000000000..a82cb3b6bcb --- /dev/null +++ b/cabal-testsuite/PackageTests/Backpack/Includes2/cabal-external.test.hs @@ -0,0 +1,9 @@ +import Test.Cabal.Prelude + +main = cabalTest $ do + skipUnless =<< ghcVersionIs (>= mkVersion [8,1]) + withProjectFile "cabal.external.project" $ do + cabal "new-build" ["exe"] + withPlan $ do + r <- runPlanExe' "exe" "exe" [] + assertOutputContains "minemysql minepostgresql" r diff --git a/cabal-testsuite/PackageTests/Backpack/Includes2/cabal-internal.test.hs b/cabal-testsuite/PackageTests/Backpack/Includes2/cabal-internal.test.hs new file mode 100644 index 00000000000..b3b44cfcf33 --- /dev/null +++ b/cabal-testsuite/PackageTests/Backpack/Includes2/cabal-internal.test.hs @@ -0,0 +1,9 @@ +import Test.Cabal.Prelude + +main = cabalTest $ do + skipUnless =<< ghcVersionIs (>= mkVersion [8,1]) + withProjectFile "cabal.internal.project" $ do + cabal "new-build" ["exe"] + withPlan $ do + r <- runPlanExe' "Includes2" "exe" [] + assertOutputContains "minemysql minepostgresql" r diff --git a/cabal-install/tests/IntegrationTests/backpack/includes2/cabal.project.external b/cabal-testsuite/PackageTests/Backpack/Includes2/cabal.external.project similarity index 100% rename from cabal-install/tests/IntegrationTests/backpack/includes2/cabal.project.external rename to cabal-testsuite/PackageTests/Backpack/Includes2/cabal.external.project diff --git a/cabal-install/tests/IntegrationTests/backpack/includes2/cabal.project.internal b/cabal-testsuite/PackageTests/Backpack/Includes2/cabal.internal.project similarity index 100% rename from cabal-install/tests/IntegrationTests/backpack/includes2/cabal.project.internal rename to cabal-testsuite/PackageTests/Backpack/Includes2/cabal.internal.project diff --git a/cabal-testsuite/PackageTests/Backpack/Includes2/setup-per-component.test.hs b/cabal-testsuite/PackageTests/Backpack/Includes2/setup-per-component.test.hs index cc97a546de6..ed5700a2688 100644 --- a/cabal-testsuite/PackageTests/Backpack/Includes2/setup-per-component.test.hs +++ b/cabal-testsuite/PackageTests/Backpack/Includes2/setup-per-component.test.hs @@ -1,5 +1,6 @@ import Test.Cabal.Prelude -main = setupAndCabalTest $ do +main = setupTest $ do + -- No cabal test because per-component is broken with it skipUnless =<< ghcVersionIs (>= mkVersion [8,1]) withPackageDb $ do let setup_install' args = setup_install_with_docs (["--cabal-file", "Includes2.cabal"] ++ args) From 7b90a216e8ec51825abeba330eaab6a873805dd6 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 25 Nov 2016 11:09:42 -0500 Subject: [PATCH 11/56] Port backpack/includes3 to new test suite. Signed-off-by: Edward Z. Yang --- .../backpack/includes3-external.sh | 9 -------- .../backpack/includes3-internal.sh | 9 -------- .../backpack/includes3/Includes3.cabal | 23 ------------------- .../backpack/includes3/exe/Main.hs | 4 ---- .../backpack/includes3/exe/Setup.hs | 2 -- .../backpack/includes3/exe/exe.cabal | 12 ---------- .../backpack/includes3/indef/Foo.hs | 6 ----- .../backpack/includes3/indef/Setup.hs | 2 -- .../backpack/includes3/indef/indef.cabal | 11 --------- .../backpack/includes3/sigs/Data/Map.hsig | 5 ---- .../backpack/includes3/sigs/Setup.hs | 2 -- .../backpack/includes3/sigs/sigs.cabal | 11 --------- .../Backpack/Includes3/cabal-external.test.hs | 9 ++++++++ .../Backpack/Includes3/cabal-internal.test.hs | 9 ++++++++ .../Backpack/Includes3/cabal.external.project | 0 .../Backpack/Includes3/cabal.internal.project | 0 16 files changed, 18 insertions(+), 96 deletions(-) delete mode 100644 cabal-install/tests/IntegrationTests/backpack/includes3-external.sh delete mode 100644 cabal-install/tests/IntegrationTests/backpack/includes3-internal.sh delete mode 100644 cabal-install/tests/IntegrationTests/backpack/includes3/Includes3.cabal delete mode 100644 cabal-install/tests/IntegrationTests/backpack/includes3/exe/Main.hs delete mode 100644 cabal-install/tests/IntegrationTests/backpack/includes3/exe/Setup.hs delete mode 100644 cabal-install/tests/IntegrationTests/backpack/includes3/exe/exe.cabal delete mode 100644 cabal-install/tests/IntegrationTests/backpack/includes3/indef/Foo.hs delete mode 100644 cabal-install/tests/IntegrationTests/backpack/includes3/indef/Setup.hs delete mode 100644 cabal-install/tests/IntegrationTests/backpack/includes3/indef/indef.cabal delete mode 100644 cabal-install/tests/IntegrationTests/backpack/includes3/sigs/Data/Map.hsig delete mode 100644 cabal-install/tests/IntegrationTests/backpack/includes3/sigs/Setup.hs delete mode 100644 cabal-install/tests/IntegrationTests/backpack/includes3/sigs/sigs.cabal create mode 100644 cabal-testsuite/PackageTests/Backpack/Includes3/cabal-external.test.hs create mode 100644 cabal-testsuite/PackageTests/Backpack/Includes3/cabal-internal.test.hs rename cabal-install/tests/IntegrationTests/backpack/includes3/cabal.project.external => cabal-testsuite/PackageTests/Backpack/Includes3/cabal.external.project (100%) rename cabal-install/tests/IntegrationTests/backpack/includes3/cabal.project.internal => cabal-testsuite/PackageTests/Backpack/Includes3/cabal.internal.project (100%) diff --git a/cabal-install/tests/IntegrationTests/backpack/includes3-external.sh b/cabal-install/tests/IntegrationTests/backpack/includes3-external.sh deleted file mode 100644 index a13fc9deed4..00000000000 --- a/cabal-install/tests/IntegrationTests/backpack/includes3-external.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -. ./common.sh - -require_ghc_ge 801 - -cd includes3 -mv cabal.project.external cabal.project -cabal new-build exe -dist-newstyle/build/*/*/exe-*/c/exe/build/exe/exe | fgrep "fromList [(0,2),(2,4)]" diff --git a/cabal-install/tests/IntegrationTests/backpack/includes3-internal.sh b/cabal-install/tests/IntegrationTests/backpack/includes3-internal.sh deleted file mode 100644 index c1f41dbcace..00000000000 --- a/cabal-install/tests/IntegrationTests/backpack/includes3-internal.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -. ./common.sh - -require_ghc_ge 801 - -cd includes3 -mv cabal.project.internal cabal.project -cabal new-build exe -dist-newstyle/build/*/*/Includes3-*/c/exe/build/exe/exe | fgrep "fromList [(0,2),(2,4)]" diff --git a/cabal-install/tests/IntegrationTests/backpack/includes3/Includes3.cabal b/cabal-install/tests/IntegrationTests/backpack/includes3/Includes3.cabal deleted file mode 100644 index a2de17f2988..00000000000 --- a/cabal-install/tests/IntegrationTests/backpack/includes3/Includes3.cabal +++ /dev/null @@ -1,23 +0,0 @@ -name: Includes3 -version: 0.1.0.0 -license: BSD3 -author: Edward Z. Yang -maintainer: ezyang@cs.stanford.edu -build-type: Simple -cabal-version: >=1.25 - -library sigs - build-depends: base - signatures: Data.Map - hs-source-dirs: sigs - -library indef - build-depends: base, sigs - exposed-modules: Foo - hs-source-dirs: indef - -executable exe - build-depends: base, containers, indef - main-is: Main.hs - hs-source-dirs: exe - default-language: Haskell2010 diff --git a/cabal-install/tests/IntegrationTests/backpack/includes3/exe/Main.hs b/cabal-install/tests/IntegrationTests/backpack/includes3/exe/Main.hs deleted file mode 100644 index e0cb6d02c6e..00000000000 --- a/cabal-install/tests/IntegrationTests/backpack/includes3/exe/Main.hs +++ /dev/null @@ -1,4 +0,0 @@ -import qualified Data.Map as Map -import Data.Map (Map) -import Foo -main = print $ f (+1) (Map.fromList [(0,1),(2,3)] :: Map Int Int) diff --git a/cabal-install/tests/IntegrationTests/backpack/includes3/exe/Setup.hs b/cabal-install/tests/IntegrationTests/backpack/includes3/exe/Setup.hs deleted file mode 100644 index 9a994af677b..00000000000 --- a/cabal-install/tests/IntegrationTests/backpack/includes3/exe/Setup.hs +++ /dev/null @@ -1,2 +0,0 @@ -import Distribution.Simple -main = defaultMain diff --git a/cabal-install/tests/IntegrationTests/backpack/includes3/exe/exe.cabal b/cabal-install/tests/IntegrationTests/backpack/includes3/exe/exe.cabal deleted file mode 100644 index 2422fffc031..00000000000 --- a/cabal-install/tests/IntegrationTests/backpack/includes3/exe/exe.cabal +++ /dev/null @@ -1,12 +0,0 @@ -name: exe -version: 0.1.0.0 -license: BSD3 -author: Edward Z. Yang -maintainer: ezyang@cs.stanford.edu -build-type: Simple -cabal-version: >=1.25 - -executable exe - build-depends: base, containers, indef - main-is: Main.hs - default-language: Haskell2010 diff --git a/cabal-install/tests/IntegrationTests/backpack/includes3/indef/Foo.hs b/cabal-install/tests/IntegrationTests/backpack/includes3/indef/Foo.hs deleted file mode 100644 index 5be3e4b85b0..00000000000 --- a/cabal-install/tests/IntegrationTests/backpack/includes3/indef/Foo.hs +++ /dev/null @@ -1,6 +0,0 @@ -module Foo where - -import Data.Map - -f :: (a -> b) -> Map k a -> Map k b -f = fmap diff --git a/cabal-install/tests/IntegrationTests/backpack/includes3/indef/Setup.hs b/cabal-install/tests/IntegrationTests/backpack/includes3/indef/Setup.hs deleted file mode 100644 index 9a994af677b..00000000000 --- a/cabal-install/tests/IntegrationTests/backpack/includes3/indef/Setup.hs +++ /dev/null @@ -1,2 +0,0 @@ -import Distribution.Simple -main = defaultMain diff --git a/cabal-install/tests/IntegrationTests/backpack/includes3/indef/indef.cabal b/cabal-install/tests/IntegrationTests/backpack/includes3/indef/indef.cabal deleted file mode 100644 index ff1a4c512fa..00000000000 --- a/cabal-install/tests/IntegrationTests/backpack/includes3/indef/indef.cabal +++ /dev/null @@ -1,11 +0,0 @@ -name: indef -version: 0.1.0.0 -license: BSD3 -author: Edward Z. Yang -maintainer: ezyang@cs.stanford.edu -build-type: Simple -cabal-version: >=1.25 - -library - build-depends: base, sigs - exposed-modules: Foo diff --git a/cabal-install/tests/IntegrationTests/backpack/includes3/sigs/Data/Map.hsig b/cabal-install/tests/IntegrationTests/backpack/includes3/sigs/Data/Map.hsig deleted file mode 100644 index 997ec1aa576..00000000000 --- a/cabal-install/tests/IntegrationTests/backpack/includes3/sigs/Data/Map.hsig +++ /dev/null @@ -1,5 +0,0 @@ -{-# LANGUAGE RoleAnnotations #-} -signature Data.Map where -type role Map nominal representational -data Map k a -instance Functor (Map k) diff --git a/cabal-install/tests/IntegrationTests/backpack/includes3/sigs/Setup.hs b/cabal-install/tests/IntegrationTests/backpack/includes3/sigs/Setup.hs deleted file mode 100644 index 9a994af677b..00000000000 --- a/cabal-install/tests/IntegrationTests/backpack/includes3/sigs/Setup.hs +++ /dev/null @@ -1,2 +0,0 @@ -import Distribution.Simple -main = defaultMain diff --git a/cabal-install/tests/IntegrationTests/backpack/includes3/sigs/sigs.cabal b/cabal-install/tests/IntegrationTests/backpack/includes3/sigs/sigs.cabal deleted file mode 100644 index 0263fe2a742..00000000000 --- a/cabal-install/tests/IntegrationTests/backpack/includes3/sigs/sigs.cabal +++ /dev/null @@ -1,11 +0,0 @@ -name: sigs -version: 0.1.0.0 -license: BSD3 -author: Edward Z. Yang -maintainer: ezyang@cs.stanford.edu -build-type: Simple -cabal-version: >=1.25 - -library - build-depends: base - signatures: Data.Map diff --git a/cabal-testsuite/PackageTests/Backpack/Includes3/cabal-external.test.hs b/cabal-testsuite/PackageTests/Backpack/Includes3/cabal-external.test.hs new file mode 100644 index 00000000000..4f24832a439 --- /dev/null +++ b/cabal-testsuite/PackageTests/Backpack/Includes3/cabal-external.test.hs @@ -0,0 +1,9 @@ +import Test.Cabal.Prelude + +main = cabalTest $ do + skipUnless =<< ghcVersionIs (>= mkVersion [8,1]) + withProjectFile "cabal.external.project" $ do + cabal "new-build" ["exe"] + withPlan $ do + r <- runPlanExe' "exe" "exe" [] + assertOutputContains "fromList [(0,2),(2,4)]" r diff --git a/cabal-testsuite/PackageTests/Backpack/Includes3/cabal-internal.test.hs b/cabal-testsuite/PackageTests/Backpack/Includes3/cabal-internal.test.hs new file mode 100644 index 00000000000..6a20ed11051 --- /dev/null +++ b/cabal-testsuite/PackageTests/Backpack/Includes3/cabal-internal.test.hs @@ -0,0 +1,9 @@ +import Test.Cabal.Prelude + +main = cabalTest $ do + skipUnless =<< ghcVersionIs (>= mkVersion [8,1]) + withProjectFile "cabal.internal.project" $ do + cabal "new-build" ["exe"] + withPlan $ do + r <- runPlanExe' "Includes3" "exe" [] + assertOutputContains "fromList [(0,2),(2,4)]" r diff --git a/cabal-install/tests/IntegrationTests/backpack/includes3/cabal.project.external b/cabal-testsuite/PackageTests/Backpack/Includes3/cabal.external.project similarity index 100% rename from cabal-install/tests/IntegrationTests/backpack/includes3/cabal.project.external rename to cabal-testsuite/PackageTests/Backpack/Includes3/cabal.external.project diff --git a/cabal-install/tests/IntegrationTests/backpack/includes3/cabal.project.internal b/cabal-testsuite/PackageTests/Backpack/Includes3/cabal.internal.project similarity index 100% rename from cabal-install/tests/IntegrationTests/backpack/includes3/cabal.project.internal rename to cabal-testsuite/PackageTests/Backpack/Includes3/cabal.internal.project From c20c114a6799f239dfac3930a5324944c3d1ffbf Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 25 Nov 2016 18:51:46 -0500 Subject: [PATCH 12/56] Add accidentally dropped ConfigureComponent/SubLib test Signed-off-by: Edward Z. Yang --- .../SubLib/setup-explicit-fail.test.hs | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 cabal-testsuite/PackageTests/ConfigureComponent/SubLib/setup-explicit-fail.test.hs diff --git a/cabal-testsuite/PackageTests/ConfigureComponent/SubLib/setup-explicit-fail.test.hs b/cabal-testsuite/PackageTests/ConfigureComponent/SubLib/setup-explicit-fail.test.hs new file mode 100644 index 00000000000..ccae2152f9a --- /dev/null +++ b/cabal-testsuite/PackageTests/ConfigureComponent/SubLib/setup-explicit-fail.test.hs @@ -0,0 +1,11 @@ + +import Test.Cabal.Prelude +-- NB: The --dependency flag is not supported by cabal-install +main = setupTest $ do + withPackageDb $ do + base_id <- getIPID "base" + setup_install ["sublib", "--cid", "sublib-0.1-abc"] + r <- fails $ setup' "configure" + [ "exe", "--exact-configuration" + , "--dependency", "base=" ++ base_id ] + assertOutputContains "sublib" r From 20c0c2dce8971c962c038584d8535813f6d8f9d8 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 25 Nov 2016 18:51:55 -0500 Subject: [PATCH 13/56] Ignore Setup executables. Signed-off-by: Edward Z. Yang --- cabal-testsuite/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/cabal-testsuite/.gitignore b/cabal-testsuite/.gitignore index 22c886b85bc..eca4b1cdb12 100644 --- a/cabal-testsuite/.gitignore +++ b/cabal-testsuite/.gitignore @@ -1 +1,2 @@ *.dist +Setup From 40b27995bae78cc8047f695782b2988240f83853 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 25 Nov 2016 18:53:42 -0500 Subject: [PATCH 14/56] Update gitignore on Configure test. Signed-off-by: Edward Z. Yang --- cabal-testsuite/PackageTests/Configure/.gitignore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cabal-testsuite/PackageTests/Configure/.gitignore b/cabal-testsuite/PackageTests/Configure/.gitignore index 6adf7880145..0714c2e1e8a 100644 --- a/cabal-testsuite/PackageTests/Configure/.gitignore +++ b/cabal-testsuite/PackageTests/Configure/.gitignore @@ -1,6 +1,6 @@ -X11.buildinfo +zlib.buildinfo autom4te.cache/ *.log *.status -include/HsX11Config.h configure +include/HsZlibConfig.h From c855e3a6a08c8c2a36e451390f5bd3dd0c606324 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 25 Nov 2016 18:54:18 -0500 Subject: [PATCH 15/56] gitignore on ForeignLibs test Signed-off-by: Edward Z. Yang --- cabal-testsuite/PackageTests/ForeignLibs/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 cabal-testsuite/PackageTests/ForeignLibs/.gitignore diff --git a/cabal-testsuite/PackageTests/ForeignLibs/.gitignore b/cabal-testsuite/PackageTests/ForeignLibs/.gitignore new file mode 100644 index 00000000000..44fecbbc878 --- /dev/null +++ b/cabal-testsuite/PackageTests/ForeignLibs/.gitignore @@ -0,0 +1 @@ +uselib From 30ae89ccf01f6136b6cbc8a852f6d3db0c3f4df0 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 25 Nov 2016 19:22:36 -0500 Subject: [PATCH 16/56] Export Control.Monad from Test.Cabal.Prelude. Signed-off-by: Edward Z. Yang --- cabal-testsuite/Test/Cabal/Prelude.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/cabal-testsuite/Test/Cabal/Prelude.hs b/cabal-testsuite/Test/Cabal/Prelude.hs index d298a4806cb..c653250974e 100644 --- a/cabal-testsuite/Test/Cabal/Prelude.hs +++ b/cabal-testsuite/Test/Cabal/Prelude.hs @@ -10,6 +10,7 @@ module Test.Cabal.Prelude ( module Test.Cabal.Monad, module Test.Cabal.Run, module System.FilePath, + module Control.Monad, module Distribution.Version, module Distribution.Simple.Program, ) where From 4985a2b748e551ec0e96b0c6725c8328acf6f6e5 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 25 Nov 2016 19:22:45 -0500 Subject: [PATCH 17/56] Add isOSX test to Test.Cabal.Prelude. Signed-off-by: Edward Z. Yang --- cabal-testsuite/Test/Cabal/Prelude.hs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cabal-testsuite/Test/Cabal/Prelude.hs b/cabal-testsuite/Test/Cabal/Prelude.hs index c653250974e..88c39b34f8a 100644 --- a/cabal-testsuite/Test/Cabal/Prelude.hs +++ b/cabal-testsuite/Test/Cabal/Prelude.hs @@ -25,7 +25,7 @@ import Distribution.Simple.Compiler (PackageDBStack, PackageDB(..)) import Distribution.Simple.Program.Types import Distribution.Simple.Program.Db import Distribution.Simple.Program -import Distribution.System (OS(Windows), buildOS) +import Distribution.System (OS(Windows,OSX), buildOS) import Distribution.Simple.Utils ( withFileContents ) import Distribution.Simple.Configure @@ -455,6 +455,9 @@ ghcVersionIs f = do isWindows :: TestM Bool isWindows = return (buildOS == Windows) +isOSX :: TestM Bool +isOSX = return (buildOS == OSX) + hasCabalForGhc :: TestM Bool hasCabalForGhc = do env <- getTestEnv From 9935f161d2d81ba5ae39677e1f60376f1bd36233 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 25 Nov 2016 19:07:36 -0500 Subject: [PATCH 18/56] Port custom/plain to new testsuite Signed-off-by: Edward Z. Yang --- .../tests/IntegrationTests/custom/plain.sh | 15 --------------- .../tests/IntegrationTests/custom/plain/Setup.hs | 3 --- .../PackageTests/CustomPlain}/A.hs | 0 cabal-testsuite/PackageTests/CustomPlain/Setup.hs | 3 +++ .../PackageTests/CustomPlain}/plain.cabal | 0 .../PackageTests/CustomPlain/setup.test.hs | 9 +++++++++ 6 files changed, 12 insertions(+), 18 deletions(-) delete mode 100644 cabal-install/tests/IntegrationTests/custom/plain.sh delete mode 100644 cabal-install/tests/IntegrationTests/custom/plain/Setup.hs rename {cabal-install/tests/IntegrationTests/custom/plain => cabal-testsuite/PackageTests/CustomPlain}/A.hs (100%) create mode 100644 cabal-testsuite/PackageTests/CustomPlain/Setup.hs rename {cabal-install/tests/IntegrationTests/custom/plain => cabal-testsuite/PackageTests/CustomPlain}/plain.cabal (100%) create mode 100644 cabal-testsuite/PackageTests/CustomPlain/setup.test.hs diff --git a/cabal-install/tests/IntegrationTests/custom/plain.sh b/cabal-install/tests/IntegrationTests/custom/plain.sh deleted file mode 100644 index 163abd5b1d3..00000000000 --- a/cabal-install/tests/IntegrationTests/custom/plain.sh +++ /dev/null @@ -1,15 +0,0 @@ -. ./common.sh - -# On Travis OSX, Cabal shipped with GHC 7.8 does not work -# with error "setup: /usr/bin/ar: permission denied"; see -# also https://github.com/haskell/cabal/issues/3938 -# This is a hack to make the test not run in this case. -if [ "$TRAVIS_OS_NAME" = "osx" ]; then - require_ghc_ge 710 -fi - -cd plain -cabal configure 2> log -grep Custom log -cabal build 2> log -grep Custom log diff --git a/cabal-install/tests/IntegrationTests/custom/plain/Setup.hs b/cabal-install/tests/IntegrationTests/custom/plain/Setup.hs deleted file mode 100644 index 1403e9e767b..00000000000 --- a/cabal-install/tests/IntegrationTests/custom/plain/Setup.hs +++ /dev/null @@ -1,3 +0,0 @@ -import Distribution.Simple -import System.IO -main = hPutStrLn stderr "Custom" >> defaultMain diff --git a/cabal-install/tests/IntegrationTests/custom/plain/A.hs b/cabal-testsuite/PackageTests/CustomPlain/A.hs similarity index 100% rename from cabal-install/tests/IntegrationTests/custom/plain/A.hs rename to cabal-testsuite/PackageTests/CustomPlain/A.hs diff --git a/cabal-testsuite/PackageTests/CustomPlain/Setup.hs b/cabal-testsuite/PackageTests/CustomPlain/Setup.hs new file mode 100644 index 00000000000..20b960ede90 --- /dev/null +++ b/cabal-testsuite/PackageTests/CustomPlain/Setup.hs @@ -0,0 +1,3 @@ +import Distribution.Simple +import System.IO +main = hPutStrLn stderr "ThisIsCustomYeah" >> defaultMain diff --git a/cabal-install/tests/IntegrationTests/custom/plain/plain.cabal b/cabal-testsuite/PackageTests/CustomPlain/plain.cabal similarity index 100% rename from cabal-install/tests/IntegrationTests/custom/plain/plain.cabal rename to cabal-testsuite/PackageTests/CustomPlain/plain.cabal diff --git a/cabal-testsuite/PackageTests/CustomPlain/setup.test.hs b/cabal-testsuite/PackageTests/CustomPlain/setup.test.hs new file mode 100644 index 00000000000..6398982179f --- /dev/null +++ b/cabal-testsuite/PackageTests/CustomPlain/setup.test.hs @@ -0,0 +1,9 @@ +import Test.Cabal.Prelude +main = setupAndCabalTest $ do + -- On Travis OSX, Cabal shipped with GHC 7.8 does not work + -- with error "setup: /usr/bin/ar: permission denied"; see + -- also https://github.com/haskell/cabal/issues/3938 + -- This is a hack to make the test not run in this case. + skipIf =<< liftM2 (&&) isOSX (ghcVersionIs (< mkVersion [7,10])) + setup' "configure" [] >>= assertOutputContains "ThisIsCustomYeah" + setup' "build" [] >>= assertOutputContains "ThisIsCustomYeah" From 276fec3ecd70dedd87ac54d68202f7e9fd0770ba Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 25 Nov 2016 19:20:43 -0500 Subject: [PATCH 19/56] Add isLinux test to Test.Cabal.Prelude. Signed-off-by: Edward Z. Yang --- cabal-testsuite/Test/Cabal/Prelude.hs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cabal-testsuite/Test/Cabal/Prelude.hs b/cabal-testsuite/Test/Cabal/Prelude.hs index 88c39b34f8a..cf0da07be73 100644 --- a/cabal-testsuite/Test/Cabal/Prelude.hs +++ b/cabal-testsuite/Test/Cabal/Prelude.hs @@ -25,7 +25,7 @@ import Distribution.Simple.Compiler (PackageDBStack, PackageDB(..)) import Distribution.Simple.Program.Types import Distribution.Simple.Program.Db import Distribution.Simple.Program -import Distribution.System (OS(Windows,OSX), buildOS) +import Distribution.System (OS(Windows,Linux,OSX), buildOS) import Distribution.Simple.Utils ( withFileContents ) import Distribution.Simple.Configure @@ -458,6 +458,9 @@ isWindows = return (buildOS == Windows) isOSX :: TestM Bool isOSX = return (buildOS == OSX) +isLinux :: TestM Bool +isLinux = return (buildOS == Linux) + hasCabalForGhc :: TestM Bool hasCabalForGhc = do env <- getTestEnv From ca95eb89af20a75637759f639fc8ad58e9dac156 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 25 Nov 2016 19:20:37 -0500 Subject: [PATCH 20/56] Port custom/segfault to new test suite Signed-off-by: Edward Z. Yang --- .../tests/IntegrationTests/custom/segfault.sh | 10 ---------- cabal-testsuite/PackageTests/CustomSegfault/.gitignore | 1 + .../PackageTests/CustomSegfault}/Setup.hs | 0 .../PackageTests/CustomSegfault}/cabal.project | 0 .../PackageTests/CustomSegfault/cabal.test.hs | 6 ++++++ .../PackageTests/CustomSegfault}/plain.cabal | 0 6 files changed, 7 insertions(+), 10 deletions(-) delete mode 100644 cabal-install/tests/IntegrationTests/custom/segfault.sh create mode 100644 cabal-testsuite/PackageTests/CustomSegfault/.gitignore rename {cabal-install/tests/IntegrationTests/custom/segfault => cabal-testsuite/PackageTests/CustomSegfault}/Setup.hs (100%) rename {cabal-install/tests/IntegrationTests/custom/segfault => cabal-testsuite/PackageTests/CustomSegfault}/cabal.project (100%) create mode 100644 cabal-testsuite/PackageTests/CustomSegfault/cabal.test.hs rename {cabal-install/tests/IntegrationTests/custom/segfault => cabal-testsuite/PackageTests/CustomSegfault}/plain.cabal (100%) diff --git a/cabal-install/tests/IntegrationTests/custom/segfault.sh b/cabal-install/tests/IntegrationTests/custom/segfault.sh deleted file mode 100644 index a265b579a11..00000000000 --- a/cabal-install/tests/IntegrationTests/custom/segfault.sh +++ /dev/null @@ -1,10 +0,0 @@ -. ./common.sh -if [ "x$(uname)" != "xLinux" ]; then - exit -fi -# Older GHCs don't report exit via signal adequately -require_ghc_ge 708 -cd segfault -! cabal new-build 2> log -cat log -grep SIGSEGV log diff --git a/cabal-testsuite/PackageTests/CustomSegfault/.gitignore b/cabal-testsuite/PackageTests/CustomSegfault/.gitignore new file mode 100644 index 00000000000..43bde56b6ab --- /dev/null +++ b/cabal-testsuite/PackageTests/CustomSegfault/.gitignore @@ -0,0 +1 @@ +core* diff --git a/cabal-install/tests/IntegrationTests/custom/segfault/Setup.hs b/cabal-testsuite/PackageTests/CustomSegfault/Setup.hs similarity index 100% rename from cabal-install/tests/IntegrationTests/custom/segfault/Setup.hs rename to cabal-testsuite/PackageTests/CustomSegfault/Setup.hs diff --git a/cabal-install/tests/IntegrationTests/custom/segfault/cabal.project b/cabal-testsuite/PackageTests/CustomSegfault/cabal.project similarity index 100% rename from cabal-install/tests/IntegrationTests/custom/segfault/cabal.project rename to cabal-testsuite/PackageTests/CustomSegfault/cabal.project diff --git a/cabal-testsuite/PackageTests/CustomSegfault/cabal.test.hs b/cabal-testsuite/PackageTests/CustomSegfault/cabal.test.hs new file mode 100644 index 00000000000..f74834811dd --- /dev/null +++ b/cabal-testsuite/PackageTests/CustomSegfault/cabal.test.hs @@ -0,0 +1,6 @@ +import Test.Cabal.Prelude +main = cabalTest $ do + -- TODO: this test ought to work on Windows too + skipUnless =<< isLinux + skipUnless =<< ghcVersionIs (>= mkVersion [7,8]) + fails $ cabal' "new-build" [] >>= assertOutputContains "SIGSEGV" diff --git a/cabal-install/tests/IntegrationTests/custom/segfault/plain.cabal b/cabal-testsuite/PackageTests/CustomSegfault/plain.cabal similarity index 100% rename from cabal-install/tests/IntegrationTests/custom/segfault/plain.cabal rename to cabal-testsuite/PackageTests/CustomSegfault/plain.cabal From 282d73781db08810a09959ea899aecfa04d21964 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 25 Nov 2016 19:50:31 -0500 Subject: [PATCH 21/56] Port custom-setup/custom_setup_without_Cabal_doesnt_allow_Cabal_import to new test suite Signed-off-by: Edward Z. Yang --- ..._setup_without_Cabal_doesnt_allow_Cabal_import.sh | 12 ------------ .../CustomWithoutCabalDefaultMain}/Setup.hs | 0 .../CustomWithoutCabalDefaultMain/cabal.project | 1 + .../CustomWithoutCabalDefaultMain/cabal.test.hs | 10 ++++++++++ .../custom-setup-without-cabal-defaultMain.cabal | 0 5 files changed, 11 insertions(+), 12 deletions(-) delete mode 100644 cabal-install/tests/IntegrationTests/custom-setup/custom_setup_without_Cabal_doesnt_allow_Cabal_import.sh rename {cabal-install/tests/IntegrationTests/custom-setup/custom-setup-without-cabal-defaultMain => cabal-testsuite/PackageTests/CustomWithoutCabalDefaultMain}/Setup.hs (100%) create mode 100644 cabal-testsuite/PackageTests/CustomWithoutCabalDefaultMain/cabal.project create mode 100644 cabal-testsuite/PackageTests/CustomWithoutCabalDefaultMain/cabal.test.hs rename {cabal-install/tests/IntegrationTests/custom-setup/custom-setup-without-cabal-defaultMain => cabal-testsuite/PackageTests/CustomWithoutCabalDefaultMain}/custom-setup-without-cabal-defaultMain.cabal (100%) diff --git a/cabal-install/tests/IntegrationTests/custom-setup/custom_setup_without_Cabal_doesnt_allow_Cabal_import.sh b/cabal-install/tests/IntegrationTests/custom-setup/custom_setup_without_Cabal_doesnt_allow_Cabal_import.sh deleted file mode 100644 index ea81eb4fada..00000000000 --- a/cabal-install/tests/IntegrationTests/custom-setup/custom_setup_without_Cabal_doesnt_allow_Cabal_import.sh +++ /dev/null @@ -1,12 +0,0 @@ -. ./common.sh -cd custom-setup-without-cabal-defaultMain - -# This package has explicit setup dependencies that do not include Cabal. -# Compilation should fail because Setup.hs imports Distribution.Simple. -! cabal new-build custom-setup-without-cabal-defaultMain > output 2>&1 -cat output -grep -q "\(Could not find module\|Failed to load interface for\).*Distribution\\.Simple" output \ - || die "Should not have been able to import Cabal" - -grep -q "It is a member of the hidden package .*Cabal-" output \ - || die "Cabal should be available" diff --git a/cabal-install/tests/IntegrationTests/custom-setup/custom-setup-without-cabal-defaultMain/Setup.hs b/cabal-testsuite/PackageTests/CustomWithoutCabalDefaultMain/Setup.hs similarity index 100% rename from cabal-install/tests/IntegrationTests/custom-setup/custom-setup-without-cabal-defaultMain/Setup.hs rename to cabal-testsuite/PackageTests/CustomWithoutCabalDefaultMain/Setup.hs diff --git a/cabal-testsuite/PackageTests/CustomWithoutCabalDefaultMain/cabal.project b/cabal-testsuite/PackageTests/CustomWithoutCabalDefaultMain/cabal.project new file mode 100644 index 00000000000..e6fdbadb439 --- /dev/null +++ b/cabal-testsuite/PackageTests/CustomWithoutCabalDefaultMain/cabal.project @@ -0,0 +1 @@ +packages: . diff --git a/cabal-testsuite/PackageTests/CustomWithoutCabalDefaultMain/cabal.test.hs b/cabal-testsuite/PackageTests/CustomWithoutCabalDefaultMain/cabal.test.hs new file mode 100644 index 00000000000..b8cf28b547f --- /dev/null +++ b/cabal-testsuite/PackageTests/CustomWithoutCabalDefaultMain/cabal.test.hs @@ -0,0 +1,10 @@ +import Test.Cabal.Prelude +main = cabalTest $ do + r <- fails $ cabal' "new-build" [] + assertRegex "Should not have been able to import Cabal" + "(Could not find module|Failed to load interface for).*Distribution\\.Simple" r + -- When using --with-ghc, this message is not necessarily output + has_cabal <- hasCabalForGhc + when has_cabal $ + assertRegex "It is a member of the hidden package .*Cabal-" + "It is a member of the hidden package" r diff --git a/cabal-install/tests/IntegrationTests/custom-setup/custom-setup-without-cabal-defaultMain/custom-setup-without-cabal-defaultMain.cabal b/cabal-testsuite/PackageTests/CustomWithoutCabalDefaultMain/custom-setup-without-cabal-defaultMain.cabal similarity index 100% rename from cabal-install/tests/IntegrationTests/custom-setup/custom-setup-without-cabal-defaultMain/custom-setup-without-cabal-defaultMain.cabal rename to cabal-testsuite/PackageTests/CustomWithoutCabalDefaultMain/custom-setup-without-cabal-defaultMain.cabal From 9466758ab54fcb4051f7d5f907f8969d3b182ba1 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 25 Nov 2016 19:53:22 -0500 Subject: [PATCH 22/56] Port custom-setup/custom_setup_without_Cabal_doesnt_require_Cabal to new test suite Signed-off-by: Edward Z. Yang --- ...custom_setup_without_Cabal_doesnt_require_Cabal.sh | 11 ----------- .../PackageTests/CustomWithoutCabal}/Setup.hs | 0 .../PackageTests/CustomWithoutCabal/cabal.project | 1 + .../PackageTests/CustomWithoutCabal/cabal.test.hs | 4 ++++ .../custom-setup-without-cabal.cabal | 0 5 files changed, 5 insertions(+), 11 deletions(-) delete mode 100644 cabal-install/tests/IntegrationTests/custom-setup/custom_setup_without_Cabal_doesnt_require_Cabal.sh rename {cabal-install/tests/IntegrationTests/custom-setup/custom-setup-without-cabal => cabal-testsuite/PackageTests/CustomWithoutCabal}/Setup.hs (100%) create mode 100644 cabal-testsuite/PackageTests/CustomWithoutCabal/cabal.project create mode 100644 cabal-testsuite/PackageTests/CustomWithoutCabal/cabal.test.hs rename {cabal-install/tests/IntegrationTests/custom-setup/custom-setup-without-cabal => cabal-testsuite/PackageTests/CustomWithoutCabal}/custom-setup-without-cabal.cabal (100%) diff --git a/cabal-install/tests/IntegrationTests/custom-setup/custom_setup_without_Cabal_doesnt_require_Cabal.sh b/cabal-install/tests/IntegrationTests/custom-setup/custom_setup_without_Cabal_doesnt_require_Cabal.sh deleted file mode 100644 index 90d4fd6694b..00000000000 --- a/cabal-install/tests/IntegrationTests/custom-setup/custom_setup_without_Cabal_doesnt_require_Cabal.sh +++ /dev/null @@ -1,11 +0,0 @@ -. ./common.sh -cd custom-setup-without-cabal - -# This package has explicit setup dependencies that do not include Cabal. -# new-build should try to build it, even though the cabal-version cannot be -# satisfied by an installed version of Cabal (cabal-version: >= 99999). However, -# configure should fail because Setup.hs just prints an error message and exits. -! cabal new-build custom-setup-without-cabal > output 2>&1 -cat output -grep -q "My custom Setup" output \ - || die "Expected output from custom Setup" diff --git a/cabal-install/tests/IntegrationTests/custom-setup/custom-setup-without-cabal/Setup.hs b/cabal-testsuite/PackageTests/CustomWithoutCabal/Setup.hs similarity index 100% rename from cabal-install/tests/IntegrationTests/custom-setup/custom-setup-without-cabal/Setup.hs rename to cabal-testsuite/PackageTests/CustomWithoutCabal/Setup.hs diff --git a/cabal-testsuite/PackageTests/CustomWithoutCabal/cabal.project b/cabal-testsuite/PackageTests/CustomWithoutCabal/cabal.project new file mode 100644 index 00000000000..e6fdbadb439 --- /dev/null +++ b/cabal-testsuite/PackageTests/CustomWithoutCabal/cabal.project @@ -0,0 +1 @@ +packages: . diff --git a/cabal-testsuite/PackageTests/CustomWithoutCabal/cabal.test.hs b/cabal-testsuite/PackageTests/CustomWithoutCabal/cabal.test.hs new file mode 100644 index 00000000000..17c4c625332 --- /dev/null +++ b/cabal-testsuite/PackageTests/CustomWithoutCabal/cabal.test.hs @@ -0,0 +1,4 @@ +import Test.Cabal.Prelude +main = cabalTest $ do + r <- fails $ cabal' "new-build" [] + assertOutputContains "My custom Setup" r diff --git a/cabal-install/tests/IntegrationTests/custom-setup/custom-setup-without-cabal/custom-setup-without-cabal.cabal b/cabal-testsuite/PackageTests/CustomWithoutCabal/custom-setup-without-cabal.cabal similarity index 100% rename from cabal-install/tests/IntegrationTests/custom-setup/custom-setup-without-cabal/custom-setup-without-cabal.cabal rename to cabal-testsuite/PackageTests/CustomWithoutCabal/custom-setup-without-cabal.cabal From accb42f38601f59bdc7cad0daee9ea6cb5d33145 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 25 Nov 2016 19:55:57 -0500 Subject: [PATCH 23/56] When running cabalTest, interpret setup as cabal. Signed-off-by: Edward Z. Yang --- cabal-testsuite/Test/Cabal/Monad.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cabal-testsuite/Test/Cabal/Monad.hs b/cabal-testsuite/Test/Cabal/Monad.hs index 0e8fdf27803..8543814f5c5 100644 --- a/cabal-testsuite/Test/Cabal/Monad.hs +++ b/cabal-testsuite/Test/Cabal/Monad.hs @@ -134,7 +134,7 @@ cabalTest :: TestM () -> IO () cabalTest m = runTestM $ do env <- getTestEnv skipIf (isNothing (testCabalInstallPath env)) - m + withReaderT (\nenv -> nenv { testCabalInstallAsSetup = True }) m type TestM = ReaderT TestEnv IO From 4a0c940b66c780a03508f224347455f281dc9618 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 25 Nov 2016 20:30:59 -0500 Subject: [PATCH 24/56] Make testPrefixDir non-IO. Signed-off-by: Edward Z. Yang --- cabal-testsuite/Test/Cabal/Monad.hs | 10 ++++------ cabal-testsuite/Test/Cabal/Prelude.hs | 6 ++---- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/cabal-testsuite/Test/Cabal/Monad.hs b/cabal-testsuite/Test/Cabal/Monad.hs index 8543814f5c5..f1974a3ada2 100644 --- a/cabal-testsuite/Test/Cabal/Monad.hs +++ b/cabal-testsuite/Test/Cabal/Monad.hs @@ -15,7 +15,7 @@ module Test.Cabal.Monad ( -- * Derived values from 'TestEnv' testCurrentDir, testWorkDir, - testPrefixDirIO, + testPrefixDir, testDistDir, testPackageDbDir, -- * Skipping tests @@ -264,11 +264,9 @@ testWorkDir :: TestEnv -> FilePath testWorkDir env = testSourceDir env (testSubName env ++ ".dist") --- | The prefix where installs go. This lives in the IO monad --- because, conventionally, absolute paths must be specified --- when doing installations. -testPrefixDirIO :: MonadIO m => TestEnv -> m FilePath -testPrefixDirIO env = liftIO $ makeAbsolute (testWorkDir env "usr") +-- | The absolute prefix where installs go. +testPrefixDir :: TestEnv -> FilePath +testPrefixDir env = testWorkDir env "usr" -- | The absolute path to the build directory that should be used -- for the current package in a test. diff --git a/cabal-testsuite/Test/Cabal/Prelude.hs b/cabal-testsuite/Test/Cabal/Prelude.hs index cf0da07be73..221693d70d6 100644 --- a/cabal-testsuite/Test/Cabal/Prelude.hs +++ b/cabal-testsuite/Test/Cabal/Prelude.hs @@ -117,7 +117,6 @@ setup' cmd args = do env <- getTestEnv when ((cmd == "register" || cmd == "copy") && not (testHavePackageDb env)) $ error "Cannot register/copy without using 'withPackageDb'" - prefix_dir <- testPrefixDirIO env ghc_path <- programPathM ghcProgram let args' = case cmd of "configure" -> @@ -131,7 +130,7 @@ setup' cmd args = do -- , "--enable-executable-dynamic" -- , "--disable-optimization" -- Specify where we want our installed packages to go - , "--prefix=" ++ prefix_dir + , "--prefix=" ++ testPrefixDir env ] ++ packageDBParams (testPackageDBStack env) ++ args _ -> args @@ -342,8 +341,7 @@ runInstalledExe exe_name args = void (runInstalledExe' exe_name args) runInstalledExe' :: String -> [String] -> TestM Result runInstalledExe' exe_name args = do env <- getTestEnv - usr <- testPrefixDirIO env - runM (usr "bin" exe_name) args + runM (testPrefixDir env "bin" exe_name) args -- | Run a shell command in the current directory. shell :: String -> [String] -> TestM Result From aa0d8403a5a5b272a7b25eb79119c0f93919f83d Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 25 Nov 2016 20:38:47 -0500 Subject: [PATCH 25/56] Disable cabal-install test in ConfiguredComponent/Sublib/setup.test.hs cabal-install depsolver doesn't know how to pick up preinstalled internal components on a per-component build. Moral of the story: don't use cabal-install here; call Setup directly. Signed-off-by: Edward Z. Yang --- .../PackageTests/ConfigureComponent/SubLib/setup.test.hs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cabal-testsuite/PackageTests/ConfigureComponent/SubLib/setup.test.hs b/cabal-testsuite/PackageTests/ConfigureComponent/SubLib/setup.test.hs index 42774cd116d..bdc6ab2e602 100644 --- a/cabal-testsuite/PackageTests/ConfigureComponent/SubLib/setup.test.hs +++ b/cabal-testsuite/PackageTests/ConfigureComponent/SubLib/setup.test.hs @@ -1,5 +1,10 @@ import Test.Cabal.Prelude -main = setupAndCabalTest $ do +-- NB: This currently doesn't work with cabal-install, as the depsolver +-- doesn't know to compute a dependency for sublib in exe, resulting in +-- Setup not being called with enough dependencies. Shout if this is +-- a problem for you; the advised workaround is to use Setup directly +-- if you need per-component builds. +main = setupTest $ do withPackageDb $ do setup_install ["sublib"] setup_install ["exe"] From 0ec24958f570bda0c23ed0f159a65f97daace4a4 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 25 Nov 2016 20:52:03 -0500 Subject: [PATCH 26/56] Set HOME directory on tests to be more hermetic. Signed-off-by: Edward Z. Yang --- cabal-testsuite/Test/Cabal/Monad.hs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/cabal-testsuite/Test/Cabal/Monad.hs b/cabal-testsuite/Test/Cabal/Monad.hs index f1974a3ada2..4aa2aab5ce6 100644 --- a/cabal-testsuite/Test/Cabal/Monad.hs +++ b/cabal-testsuite/Test/Cabal/Monad.hs @@ -18,6 +18,7 @@ module Test.Cabal.Monad ( testPrefixDir, testDistDir, testPackageDbDir, + testHomeDir, -- * Skipping tests skip, skipIf, @@ -174,8 +175,11 @@ runTestM m = do testSetupPath = dist_dir "setup" "setup", testCabalInstallPath = argCabalInstallPath (testCommonArgs args), testSkipSetupTests = argSkipSetupTests (testCommonArgs args), - -- Try to avoid Unicode output - testEnvironment = [("LC_ALL", Just "C")], + testEnvironment = + -- Try to avoid Unicode output + [ ("LC_ALL", Just "C") + -- Hermetic builds (knot-tied) + , ("HOME", Just (testHomeDir env))], testShouldFail = False, testRelativeCurrentDir = ".", testHavePackageDb = False, @@ -186,7 +190,15 @@ runTestM m = do runReaderT (cleanup >> m) env where cleanup = do - onlyIfExists . removeDirectoryRecursive =<< fmap testWorkDir ask + env <- ask + onlyIfExists . removeDirectoryRecursive $ testWorkDir env + -- NB: it's important to initialize this ourselves, as + -- the default configuration hardcodes Hackage, which we do + -- NOT want to assume for these tests (no test should + -- hit Hackage.) + liftIO $ createDirectoryIfMissing True (testHomeDir env ".cabal") + -- TODO: This doesn't work on Windows + liftIO $ writeFile (testHomeDir env ".cabal" "config") "" -- | Run an IO action, and suppress a "does not exist" error. onlyIfExists :: MonadIO m => IO () -> m () @@ -277,3 +289,7 @@ testDistDir env = testWorkDir env testRelativeCurrentDir env "dist" -- be used by all packages in this test. testPackageDbDir :: TestEnv -> FilePath testPackageDbDir env = testWorkDir env "packagedb" + +-- | The absolute prefix where our simulated HOME directory is. +testHomeDir :: TestEnv -> FilePath +testHomeDir env = testWorkDir env "home" From 63252fb6868a7a3f07b7aab7f3a51824e11d3edf Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 25 Nov 2016 22:00:24 -0500 Subject: [PATCH 27/56] Sandbox support in the test suite. A bit of trickiness here. The high points: - We need to feed --with-compiler to cabal.config, NOT the flag, because sandbox doesn't know how to read in compilers except from the global config. This is arguably a bug but I can't be bothered to fix it. - We need to NOT provide certain commands when we're in sandbox mode; this is controlled by testHaveSandbox. - Use withSandbox to start a session in the sandbox. It inits the sandbox for you. Signed-off-by: Edward Z. Yang --- cabal-testsuite/Test/Cabal/Monad.hs | 34 +++++++++++++- cabal-testsuite/Test/Cabal/Prelude.hs | 66 ++++++++++++++++++++------- 2 files changed, 81 insertions(+), 19 deletions(-) diff --git a/cabal-testsuite/Test/Cabal/Monad.hs b/cabal-testsuite/Test/Cabal/Monad.hs index 4aa2aab5ce6..af12edb3411 100644 --- a/cabal-testsuite/Test/Cabal/Monad.hs +++ b/cabal-testsuite/Test/Cabal/Monad.hs @@ -9,6 +9,9 @@ module Test.Cabal.Monad ( -- * The monad TestM, runTestM, + -- * Helper functions + programPathM, + requireProgramM, -- * The test environment TestEnv(..), getTestEnv, @@ -19,6 +22,8 @@ module Test.Cabal.Monad ( testDistDir, testPackageDbDir, testHomeDir, + testSandboxDir, + testSandboxConfigFile, -- * Skipping tests skip, skipIf, @@ -36,6 +41,7 @@ import Test.Cabal.Plan import Distribution.Simple.Compiler (PackageDBStack, PackageDB(..), compilerFlavor) import Distribution.Simple.Program.Db +import Distribution.Simple.Program import Distribution.Simple.Configure ( getPersistBuildConfig, configCompilerEx ) import Distribution.Types.LocalBuildInfo @@ -183,6 +189,7 @@ runTestM m = do testShouldFail = False, testRelativeCurrentDir = ".", testHavePackageDb = False, + testHaveSandbox = False, testCabalInstallAsSetup = False, testCabalProjectFile = "cabal.project", testPlan = Nothing @@ -190,7 +197,7 @@ runTestM m = do runReaderT (cleanup >> m) env where cleanup = do - env <- ask + env <- getTestEnv onlyIfExists . removeDirectoryRecursive $ testWorkDir env -- NB: it's important to initialize this ourselves, as -- the default configuration hardcodes Hackage, which we do @@ -198,7 +205,20 @@ runTestM m = do -- hit Hackage.) liftIO $ createDirectoryIfMissing True (testHomeDir env ".cabal") -- TODO: This doesn't work on Windows - liftIO $ writeFile (testHomeDir env ".cabal" "config") "" + ghc_path <- programPathM ghcProgram + liftIO $ writeFile (testHomeDir env ".cabal" "config") + $ unlines [ "with-compiler: " ++ ghc_path ] + +requireProgramM :: Program -> TestM ConfiguredProgram +requireProgramM program = do + env <- getTestEnv + (configured_program, _) <- liftIO $ + requireProgram (testVerbosity env) program (testProgramDb env) + return configured_program + +programPathM :: Program -> TestM FilePath +programPathM program = do + fmap programPath (requireProgramM program) -- | Run an IO action, and suppress a "does not exist" error. onlyIfExists :: MonadIO m => IO () -> m () @@ -248,6 +268,8 @@ data TestEnv = TestEnv , testRelativeCurrentDir :: FilePath -- | Says if we've initialized the per-test package DB , testHavePackageDb :: Bool + -- | Says if we're working in a sandbox + , testHaveSandbox :: Bool -- | Says if we're testing cabal-install as setup , testCabalInstallAsSetup :: Bool -- | Says what cabal.project file to use (probed) @@ -293,3 +315,11 @@ testPackageDbDir env = testWorkDir env "packagedb" -- | The absolute prefix where our simulated HOME directory is. testHomeDir :: TestEnv -> FilePath testHomeDir env = testWorkDir env "home" + +-- | The absolute prefix of our sandbox directory +testSandboxDir :: TestEnv -> FilePath +testSandboxDir env = testWorkDir env "sandbox" + +-- | The sandbox configuration file +testSandboxConfigFile :: TestEnv -> FilePath +testSandboxConfigFile env = testWorkDir env "cabal.sandbox.config" diff --git a/cabal-testsuite/Test/Cabal/Prelude.hs b/cabal-testsuite/Test/Cabal/Prelude.hs index 221693d70d6..16adf194ed6 100644 --- a/cabal-testsuite/Test/Cabal/Prelude.hs +++ b/cabal-testsuite/Test/Cabal/Prelude.hs @@ -78,17 +78,6 @@ runProgramM prog args = do configured_prog <- requireProgramM prog runM (programPath configured_prog) args -requireProgramM :: Program -> TestM ConfiguredProgram -requireProgramM program = do - env <- getTestEnv - (configured_program, _) <- liftIO $ - requireProgram (testVerbosity env) program (testProgramDb env) - return configured_program - -programPathM :: Program -> TestM FilePath -programPathM program = do - fmap programPath (requireProgramM program) - getLocalBuildInfoM :: TestM LocalBuildInfo getLocalBuildInfoM = do env <- getTestEnv @@ -124,6 +113,9 @@ setup' cmd args = do -- here will make us error loudly if we try to install -- into a bad place. [ "--global" + -- NB: technically unnecessary with Cabal, but + -- definitely needed for Setup, which doesn't + -- respect cabal.config , "--with-ghc", ghc_path -- These flags make the test suite run faster -- Can't do this unless we LD_LIBRARY_PATH correctly @@ -217,18 +209,51 @@ packageDBParams dbs = "--package-db=clear" -- * Running cabal cabal :: String -> [String] -> TestM () +cabal "sandbox" _ = + error "Use cabal_sandbox instead" cabal cmd args = void (cabal' cmd args) cabal' :: String -> [String] -> TestM Result +cabal' "sandbox" _ = + -- NB: We don't just auto-pass this through, because it's + -- possible that the first argument isn't the sub-sub-command. + -- So make sure the user specifies it correctly. + error "Use cabal_sandbox' instead" cabal' cmd args = do env <- getTestEnv - ghc_path <- programPathM ghcProgram - let cabal_args = [ cmd, "-v" - , "--with-ghc", ghc_path - , "--builddir", testWorkDir env - , "--project-file", testCabalProjectFile env ] + let extra_args + | testHaveSandbox env + = [ ] + -- These flags are only understood by some subcommands + -- TODO: Make this tighter + | otherwise + = [ "--builddir", testWorkDir env + , "--project-file", testCabalProjectFile env ] + global_args + | testHaveSandbox env + = [ "--sandbox-config-file", testSandboxConfigFile env ] + | otherwise + = [] + cabal_args = global_args + ++ [ cmd, "-v" ] + ++ extra_args + ++ args + cabal_raw' cabal_args + +cabal_sandbox :: String -> [String] -> TestM () +cabal_sandbox cmd args = void $ cabal_sandbox' cmd args + +cabal_sandbox' :: String -> [String] -> TestM Result +cabal_sandbox' cmd args = do + env <- getTestEnv + let cabal_args = [ "--sandbox-config-file", testSandboxConfigFile env + , "sandbox", cmd, "-v" ] ++ args - -- TODO: prevent .cabal in HOME from interfering with tests + cabal_raw' cabal_args + +cabal_raw' :: [String] -> TestM Result +cabal_raw' cabal_args = do + env <- getTestEnv r <- liftIO $ run (testVerbosity env) (Just (testCurrentDir env)) (testEnvironment env) @@ -238,6 +263,13 @@ cabal' cmd args = do record r requireSuccess r +withSandbox :: TestM a -> TestM a +withSandbox m = do + env0 <- getTestEnv + -- void $ cabal_raw' ["sandbox", "init", "--sandbox", testSandboxDir env0] + cabal_sandbox "init" ["--sandbox", testSandboxDir env0] + withReaderT (\env -> env { testHaveSandbox = True }) m + withProjectFile :: FilePath -> TestM a -> TestM a withProjectFile fp m = withReaderT (\env -> env { testCabalProjectFile = fp }) m From c4b22e9f962cf7b03a465f36f91fe97aa2c557ed Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 25 Nov 2016 22:00:01 -0500 Subject: [PATCH 28/56] Port custom/custom_dep to new test suite. Signed-off-by: Edward Z. Yang --- .../IntegrationTests/custom/custom_dep.sh | 22 ------------------- .../PackageTests/CustomDep}/client/B.hs | 0 .../PackageTests/CustomDep}/client/Setup.hs | 0 .../CustomDep}/client/client.cabal | 0 .../PackageTests/CustomDep}/custom/A.hs | 0 .../PackageTests/CustomDep}/custom/Setup.hs | 0 .../CustomDep}/custom/custom.cabal | 0 .../PackageTests/CustomDep/sandbox.test.hs | 14 ++++++++++++ 8 files changed, 14 insertions(+), 22 deletions(-) delete mode 100644 cabal-install/tests/IntegrationTests/custom/custom_dep.sh rename {cabal-install/tests/IntegrationTests/custom/custom_dep => cabal-testsuite/PackageTests/CustomDep}/client/B.hs (100%) rename {cabal-install/tests/IntegrationTests/custom/custom_dep => cabal-testsuite/PackageTests/CustomDep}/client/Setup.hs (100%) rename {cabal-install/tests/IntegrationTests/custom/custom_dep => cabal-testsuite/PackageTests/CustomDep}/client/client.cabal (100%) rename {cabal-install/tests/IntegrationTests/custom/custom_dep => cabal-testsuite/PackageTests/CustomDep}/custom/A.hs (100%) rename {cabal-install/tests/IntegrationTests/custom/custom_dep => cabal-testsuite/PackageTests/CustomDep}/custom/Setup.hs (100%) rename {cabal-install/tests/IntegrationTests/custom/custom_dep => cabal-testsuite/PackageTests/CustomDep}/custom/custom.cabal (100%) create mode 100644 cabal-testsuite/PackageTests/CustomDep/sandbox.test.hs diff --git a/cabal-install/tests/IntegrationTests/custom/custom_dep.sh b/cabal-install/tests/IntegrationTests/custom/custom_dep.sh deleted file mode 100644 index f55301399f2..00000000000 --- a/cabal-install/tests/IntegrationTests/custom/custom_dep.sh +++ /dev/null @@ -1,22 +0,0 @@ -. ./common.sh - -# On Travis OSX, Cabal shipped with GHC 7.8 does not work -# with error "setup: /usr/bin/ar: permission denied"; see -# also https://github.com/haskell/cabal/issues/3938 -# This is a hack to make the test not run in this case. -if [ "$TRAVIS_OS_NAME" = "osx" ]; then - require_ghc_ge 710 -fi - -cd custom_dep -cabal sandbox init -cabal sandbox add-source custom -cabal sandbox add-source client -# Some care must be taken here: we want the Setup script -# to build against GHC's bundled Cabal, but passing -# --package-db=clear --package-db=global to cabal is -# insufficient, as these flags are NOT respected when -# building Setup scripts. Changing HOME to a location -# which definitely does not have a local .cabal -# directory works, the environment variable propagates to GHC. -HOME=`pwd` cabal install client diff --git a/cabal-install/tests/IntegrationTests/custom/custom_dep/client/B.hs b/cabal-testsuite/PackageTests/CustomDep/client/B.hs similarity index 100% rename from cabal-install/tests/IntegrationTests/custom/custom_dep/client/B.hs rename to cabal-testsuite/PackageTests/CustomDep/client/B.hs diff --git a/cabal-install/tests/IntegrationTests/custom/custom_dep/client/Setup.hs b/cabal-testsuite/PackageTests/CustomDep/client/Setup.hs similarity index 100% rename from cabal-install/tests/IntegrationTests/custom/custom_dep/client/Setup.hs rename to cabal-testsuite/PackageTests/CustomDep/client/Setup.hs diff --git a/cabal-install/tests/IntegrationTests/custom/custom_dep/client/client.cabal b/cabal-testsuite/PackageTests/CustomDep/client/client.cabal similarity index 100% rename from cabal-install/tests/IntegrationTests/custom/custom_dep/client/client.cabal rename to cabal-testsuite/PackageTests/CustomDep/client/client.cabal diff --git a/cabal-install/tests/IntegrationTests/custom/custom_dep/custom/A.hs b/cabal-testsuite/PackageTests/CustomDep/custom/A.hs similarity index 100% rename from cabal-install/tests/IntegrationTests/custom/custom_dep/custom/A.hs rename to cabal-testsuite/PackageTests/CustomDep/custom/A.hs diff --git a/cabal-install/tests/IntegrationTests/custom/custom_dep/custom/Setup.hs b/cabal-testsuite/PackageTests/CustomDep/custom/Setup.hs similarity index 100% rename from cabal-install/tests/IntegrationTests/custom/custom_dep/custom/Setup.hs rename to cabal-testsuite/PackageTests/CustomDep/custom/Setup.hs diff --git a/cabal-install/tests/IntegrationTests/custom/custom_dep/custom/custom.cabal b/cabal-testsuite/PackageTests/CustomDep/custom/custom.cabal similarity index 100% rename from cabal-install/tests/IntegrationTests/custom/custom_dep/custom/custom.cabal rename to cabal-testsuite/PackageTests/CustomDep/custom/custom.cabal diff --git a/cabal-testsuite/PackageTests/CustomDep/sandbox.test.hs b/cabal-testsuite/PackageTests/CustomDep/sandbox.test.hs new file mode 100644 index 00000000000..9c2111a6794 --- /dev/null +++ b/cabal-testsuite/PackageTests/CustomDep/sandbox.test.hs @@ -0,0 +1,14 @@ +import Test.Cabal.Prelude +main = cabalTest $ do + osx <- isOSX + -- On Travis OSX, Cabal shipped with GHC 7.8 does not work + -- with error "setup: /usr/bin/ar: permission denied"; see + -- also https://github.com/haskell/cabal/issues/3938 + -- This is a hack to make the test not run in this case. + when osx $ skipUnless =<< ghcVersionIs (>= mkVersion [7,10]) + withSandbox $ do + cabal_sandbox "add-source" ["custom"] + cabal_sandbox "add-source" ["client"] + -- NB: This test relies critically on the Setup script being + -- built against GHC's bundled Cabal. + cabal "install" ["client"] From ffec9421d198916a09bd6ab1467db1dc5868df25 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 25 Nov 2016 22:22:34 -0500 Subject: [PATCH 29/56] Port custom-setup/installs_Cabal_as_setup_dep to new test suite Signed-off-by: Edward Z. Yang --- .../custom-setup/installs_Cabal_as_setup_dep.sh | 15 --------------- .../Regression/T3436}/Cabal-99998/Cabal.cabal | 0 .../Regression/T3436}/Cabal-99998/CabalMessage.hs | 0 .../Regression/T3436}/Cabal-99999/Cabal.cabal | 0 .../Regression/T3436}/Cabal-99999/CabalMessage.hs | 0 .../PackageTests/Regression/T3436/cabal.project | 1 + .../PackageTests/Regression/T3436/cabal.test.hs | 8 ++++++++ .../Regression/T3436}/custom-setup/Setup.hs | 0 .../T3436}/custom-setup/custom-setup.cabal | 0 .../PackageTests/Regression/T3436/sandbox.test.hs | 7 +++++++ 10 files changed, 16 insertions(+), 15 deletions(-) delete mode 100644 cabal-install/tests/IntegrationTests/custom-setup/installs_Cabal_as_setup_dep.sh rename {cabal-install/tests/IntegrationTests/custom-setup => cabal-testsuite/PackageTests/Regression/T3436}/Cabal-99998/Cabal.cabal (100%) rename {cabal-install/tests/IntegrationTests/custom-setup => cabal-testsuite/PackageTests/Regression/T3436}/Cabal-99998/CabalMessage.hs (100%) rename {cabal-install/tests/IntegrationTests/custom-setup => cabal-testsuite/PackageTests/Regression/T3436}/Cabal-99999/Cabal.cabal (100%) rename {cabal-install/tests/IntegrationTests/custom-setup => cabal-testsuite/PackageTests/Regression/T3436}/Cabal-99999/CabalMessage.hs (100%) create mode 100644 cabal-testsuite/PackageTests/Regression/T3436/cabal.project create mode 100644 cabal-testsuite/PackageTests/Regression/T3436/cabal.test.hs rename {cabal-install/tests/IntegrationTests/custom-setup => cabal-testsuite/PackageTests/Regression/T3436}/custom-setup/Setup.hs (100%) rename {cabal-install/tests/IntegrationTests/custom-setup => cabal-testsuite/PackageTests/Regression/T3436}/custom-setup/custom-setup.cabal (100%) create mode 100644 cabal-testsuite/PackageTests/Regression/T3436/sandbox.test.hs diff --git a/cabal-install/tests/IntegrationTests/custom-setup/installs_Cabal_as_setup_dep.sh b/cabal-install/tests/IntegrationTests/custom-setup/installs_Cabal_as_setup_dep.sh deleted file mode 100644 index 00b756bd383..00000000000 --- a/cabal-install/tests/IntegrationTests/custom-setup/installs_Cabal_as_setup_dep.sh +++ /dev/null @@ -1,15 +0,0 @@ -# Regression test for issue #3436 - -. ./common.sh -cabal sandbox init -cabal install ./Cabal-99998 -cabal sandbox add-source Cabal-99999 - -# Install custom-setup, which has a setup dependency on Cabal-99999. -# cabal should build the setup script with Cabal-99999, but then -# configure should fail because Setup just prints an error message -# imported from Cabal and exits. -! cabal install custom-setup/ > output 2>&1 - -cat output -grep -q "This is Cabal-99999" output || die "Expected output from Cabal-99999" diff --git a/cabal-install/tests/IntegrationTests/custom-setup/Cabal-99998/Cabal.cabal b/cabal-testsuite/PackageTests/Regression/T3436/Cabal-99998/Cabal.cabal similarity index 100% rename from cabal-install/tests/IntegrationTests/custom-setup/Cabal-99998/Cabal.cabal rename to cabal-testsuite/PackageTests/Regression/T3436/Cabal-99998/Cabal.cabal diff --git a/cabal-install/tests/IntegrationTests/custom-setup/Cabal-99998/CabalMessage.hs b/cabal-testsuite/PackageTests/Regression/T3436/Cabal-99998/CabalMessage.hs similarity index 100% rename from cabal-install/tests/IntegrationTests/custom-setup/Cabal-99998/CabalMessage.hs rename to cabal-testsuite/PackageTests/Regression/T3436/Cabal-99998/CabalMessage.hs diff --git a/cabal-install/tests/IntegrationTests/custom-setup/Cabal-99999/Cabal.cabal b/cabal-testsuite/PackageTests/Regression/T3436/Cabal-99999/Cabal.cabal similarity index 100% rename from cabal-install/tests/IntegrationTests/custom-setup/Cabal-99999/Cabal.cabal rename to cabal-testsuite/PackageTests/Regression/T3436/Cabal-99999/Cabal.cabal diff --git a/cabal-install/tests/IntegrationTests/custom-setup/Cabal-99999/CabalMessage.hs b/cabal-testsuite/PackageTests/Regression/T3436/Cabal-99999/CabalMessage.hs similarity index 100% rename from cabal-install/tests/IntegrationTests/custom-setup/Cabal-99999/CabalMessage.hs rename to cabal-testsuite/PackageTests/Regression/T3436/Cabal-99999/CabalMessage.hs diff --git a/cabal-testsuite/PackageTests/Regression/T3436/cabal.project b/cabal-testsuite/PackageTests/Regression/T3436/cabal.project new file mode 100644 index 00000000000..edeb2ae3f65 --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T3436/cabal.project @@ -0,0 +1 @@ +packages: custom-setup Cabal-99999 diff --git a/cabal-testsuite/PackageTests/Regression/T3436/cabal.test.hs b/cabal-testsuite/PackageTests/Regression/T3436/cabal.test.hs new file mode 100644 index 00000000000..91437651703 --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T3436/cabal.test.hs @@ -0,0 +1,8 @@ +import Test.Cabal.Prelude +main = cabalTest $ do + -- NB: This test doesn't really test #3436, because Cabal-99998 + -- isn't in the system database and thus we can't see if the + -- depsolver incorrectly chooses it. Worth fixing if we figure + -- out how to simulate the "global" database without root. + r <- fails $ cabal' "new-build" [] + assertOutputContains "This is Cabal-99999" r diff --git a/cabal-install/tests/IntegrationTests/custom-setup/custom-setup/Setup.hs b/cabal-testsuite/PackageTests/Regression/T3436/custom-setup/Setup.hs similarity index 100% rename from cabal-install/tests/IntegrationTests/custom-setup/custom-setup/Setup.hs rename to cabal-testsuite/PackageTests/Regression/T3436/custom-setup/Setup.hs diff --git a/cabal-install/tests/IntegrationTests/custom-setup/custom-setup/custom-setup.cabal b/cabal-testsuite/PackageTests/Regression/T3436/custom-setup/custom-setup.cabal similarity index 100% rename from cabal-install/tests/IntegrationTests/custom-setup/custom-setup/custom-setup.cabal rename to cabal-testsuite/PackageTests/Regression/T3436/custom-setup/custom-setup.cabal diff --git a/cabal-testsuite/PackageTests/Regression/T3436/sandbox.test.hs b/cabal-testsuite/PackageTests/Regression/T3436/sandbox.test.hs new file mode 100644 index 00000000000..7129d79aad1 --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T3436/sandbox.test.hs @@ -0,0 +1,7 @@ +import Test.Cabal.Prelude +main = cabalTest $ do + withSandbox $ do + cabal "install" ["./Cabal-99998"] + cabal_sandbox "add-source" ["Cabal-99999"] + r <- fails $ cabal' "install" ["custom-setup/"] + assertOutputContains "This is Cabal-99999" r From a1a015c391a69f5fca241dcbe880349109867438 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 25 Nov 2016 22:27:03 -0500 Subject: [PATCH 30/56] Make assertOutputContains less chatty. Signed-off-by: Edward Z. Yang --- cabal-testsuite/Test/Cabal/Prelude.hs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/cabal-testsuite/Test/Cabal/Prelude.hs b/cabal-testsuite/Test/Cabal/Prelude.hs index 16adf194ed6..1666bd913ca 100644 --- a/cabal-testsuite/Test/Cabal/Prelude.hs +++ b/cabal-testsuite/Test/Cabal/Prelude.hs @@ -441,17 +441,13 @@ fails = withReaderT (\env -> env { testShouldFail = not (testShouldFail env) }) assertOutputContains :: MonadIO m => WithCallStack (String -> Result -> m ()) assertOutputContains needle result = unless (needle `isInfixOf` (concatOutput output)) $ - assertFailure $ - " expected: " ++ needle ++ "\n" ++ - " in output: " ++ output ++ "" + assertFailure $ " expected: " ++ needle where output = resultOutput result assertOutputDoesNotContain :: MonadIO m => WithCallStack (String -> Result -> m ()) assertOutputDoesNotContain needle result = when (needle `isInfixOf` (concatOutput output)) $ - assertFailure $ - "unexpected: " ++ needle ++ - " in output: " ++ output + assertFailure $ "unexpected: " ++ needle where output = resultOutput result assertFindInFile :: MonadIO m => WithCallStack (String -> FilePath -> m ()) From dadb89dcdaee8d3e662c665afdee1a05551a6602 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 25 Nov 2016 22:41:43 -0500 Subject: [PATCH 31/56] Port exec/adds_sandbox_bin_directory_to_path to new test suite Signed-off-by: Edward Z. Yang --- .../exec/adds_sandbox_bin_directory_to_path.out | 1 - .../exec/adds_sandbox_bin_directory_to_path.sh | 10 ---------- cabal-testsuite/PackageTests/Exec/Foo.hs | 4 ++++ cabal-testsuite/PackageTests/Exec/My.hs | 5 +++++ cabal-testsuite/PackageTests/Exec/my.cabal | 14 ++++++++++++++ .../PackageTests/Exec/sandbox-path.test.hs | 8 ++++++++ 6 files changed, 31 insertions(+), 11 deletions(-) delete mode 100644 cabal-install/tests/IntegrationTests/exec/adds_sandbox_bin_directory_to_path.out delete mode 100644 cabal-install/tests/IntegrationTests/exec/adds_sandbox_bin_directory_to_path.sh create mode 100644 cabal-testsuite/PackageTests/Exec/Foo.hs create mode 100644 cabal-testsuite/PackageTests/Exec/My.hs create mode 100644 cabal-testsuite/PackageTests/Exec/my.cabal create mode 100644 cabal-testsuite/PackageTests/Exec/sandbox-path.test.hs diff --git a/cabal-install/tests/IntegrationTests/exec/adds_sandbox_bin_directory_to_path.out b/cabal-install/tests/IntegrationTests/exec/adds_sandbox_bin_directory_to_path.out deleted file mode 100644 index 27df3614e94..00000000000 --- a/cabal-install/tests/IntegrationTests/exec/adds_sandbox_bin_directory_to_path.out +++ /dev/null @@ -1 +0,0 @@ -This is my-executable diff --git a/cabal-install/tests/IntegrationTests/exec/adds_sandbox_bin_directory_to_path.sh b/cabal-install/tests/IntegrationTests/exec/adds_sandbox_bin_directory_to_path.sh deleted file mode 100644 index cc344c69ae9..00000000000 --- a/cabal-install/tests/IntegrationTests/exec/adds_sandbox_bin_directory_to_path.sh +++ /dev/null @@ -1,10 +0,0 @@ -. ./common.sh - -cabal sandbox delete > /dev/null -cabal exec my-executable && die "Unexpectedly found executable" - -cabal sandbox init > /dev/null -cabal install > /dev/null - -# Execute indirectly via bash to ensure that we go through $PATH -cabal exec sh -- -c my-executable || die "Did not find executable" diff --git a/cabal-testsuite/PackageTests/Exec/Foo.hs b/cabal-testsuite/PackageTests/Exec/Foo.hs new file mode 100644 index 00000000000..5924b011a00 --- /dev/null +++ b/cabal-testsuite/PackageTests/Exec/Foo.hs @@ -0,0 +1,4 @@ +module Foo where + +foo :: String +foo = "foo" diff --git a/cabal-testsuite/PackageTests/Exec/My.hs b/cabal-testsuite/PackageTests/Exec/My.hs new file mode 100644 index 00000000000..b467ba86e09 --- /dev/null +++ b/cabal-testsuite/PackageTests/Exec/My.hs @@ -0,0 +1,5 @@ +module Main where + +main :: IO () +main = do + putStrLn "This is my-executable" diff --git a/cabal-testsuite/PackageTests/Exec/my.cabal b/cabal-testsuite/PackageTests/Exec/my.cabal new file mode 100644 index 00000000000..797a2c7d4f1 --- /dev/null +++ b/cabal-testsuite/PackageTests/Exec/my.cabal @@ -0,0 +1,14 @@ +name: my +version: 0.1 +license: BSD3 +cabal-version: >= 1.2 +build-type: Simple + +library + exposed-modules: Foo + build-depends: base + + +executable my-executable + main-is: My.hs + build-depends: base diff --git a/cabal-testsuite/PackageTests/Exec/sandbox-path.test.hs b/cabal-testsuite/PackageTests/Exec/sandbox-path.test.hs new file mode 100644 index 00000000000..ab4b666c6f7 --- /dev/null +++ b/cabal-testsuite/PackageTests/Exec/sandbox-path.test.hs @@ -0,0 +1,8 @@ +import Test.Cabal.Prelude +main = cabalTest $ do + withSandbox $ do + fails $ cabal "exec" ["my-executable"] + cabal "install" [] + -- Execute indirectly via bash to ensure that we go through $PATH + cabal' "exec" ["sh", "--", "-c", "my-executable"] + >>= assertOutputContains "This is my-executable" From f6303e757452f18acf2a678b98b7f4feda501bb6 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 25 Nov 2016 22:42:42 -0500 Subject: [PATCH 32/56] Remove some obsolete test gitignore entries. Signed-off-by: Edward Z. Yang --- .gitignore | 3 --- 1 file changed, 3 deletions(-) diff --git a/.gitignore b/.gitignore index 62ea9539374..15ef3689e36 100644 --- a/.gitignore +++ b/.gitignore @@ -53,10 +53,7 @@ tags progress.txt # test files -dist-test register.sh -/Cabal/tests/PackageTests/Configure/include/HsZlibConfig.h -/Cabal/tests/PackageTests/Configure/zlib.buildinfo # python artifacts from documentation builds *.pyc From c2008fd8faa5ce732101b642b4538a689f44163b Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 25 Nov 2016 22:46:27 -0500 Subject: [PATCH 33/56] Port exec/auto_configures_on_exec to new test suite Signed-off-by: Edward Z. Yang --- .../tests/IntegrationTests/exec/auto_configures_on_exec.out | 4 ---- .../tests/IntegrationTests/exec/auto_configures_on_exec.sh | 2 -- .../PackageTests/Exec/legacy-autoconfigure.test.hs | 4 ++++ 3 files changed, 4 insertions(+), 6 deletions(-) delete mode 100644 cabal-install/tests/IntegrationTests/exec/auto_configures_on_exec.out delete mode 100644 cabal-install/tests/IntegrationTests/exec/auto_configures_on_exec.sh create mode 100644 cabal-testsuite/PackageTests/Exec/legacy-autoconfigure.test.hs diff --git a/cabal-install/tests/IntegrationTests/exec/auto_configures_on_exec.out b/cabal-install/tests/IntegrationTests/exec/auto_configures_on_exec.out deleted file mode 100644 index b28a60dc6a3..00000000000 --- a/cabal-install/tests/IntegrationTests/exec/auto_configures_on_exec.out +++ /dev/null @@ -1,4 +0,0 @@ -Config file path source is commandline option. -Config file config-file not found. -Writing default configuration to config-file -find_me_in_output diff --git a/cabal-install/tests/IntegrationTests/exec/auto_configures_on_exec.sh b/cabal-install/tests/IntegrationTests/exec/auto_configures_on_exec.sh deleted file mode 100644 index 2e915375901..00000000000 --- a/cabal-install/tests/IntegrationTests/exec/auto_configures_on_exec.sh +++ /dev/null @@ -1,2 +0,0 @@ -. ./common.sh -cabal exec echo find_me_in_output diff --git a/cabal-testsuite/PackageTests/Exec/legacy-autoconfigure.test.hs b/cabal-testsuite/PackageTests/Exec/legacy-autoconfigure.test.hs new file mode 100644 index 00000000000..f72e3018710 --- /dev/null +++ b/cabal-testsuite/PackageTests/Exec/legacy-autoconfigure.test.hs @@ -0,0 +1,4 @@ +import Test.Cabal.Prelude +main = cabalTest $ do + cabal' "exec" ["echo", "find_me_in_output"] + >>= assertOutputContains "find_me_in_output" From 2ae93d3b13c2479f943a76b2176273a6bb0d87cf Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 25 Nov 2016 22:46:42 -0500 Subject: [PATCH 34/56] Tweaks for when to pass --builddir to cabal executable. Signed-off-by: Edward Z. Yang --- cabal-testsuite/Test/Cabal/Prelude.hs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cabal-testsuite/Test/Cabal/Prelude.hs b/cabal-testsuite/Test/Cabal/Prelude.hs index 1666bd913ca..cb5cf4f8a58 100644 --- a/cabal-testsuite/Test/Cabal/Prelude.hs +++ b/cabal-testsuite/Test/Cabal/Prelude.hs @@ -222,13 +222,15 @@ cabal' "sandbox" _ = cabal' cmd args = do env <- getTestEnv let extra_args + -- Sandboxes manage dist dir | testHaveSandbox env = [ ] - -- These flags are only understood by some subcommands - -- TODO: Make this tighter - | otherwise + -- new-build commands are affected by testCabalProjectFile + | "new-" `isPrefixOf` cmd = [ "--builddir", testWorkDir env , "--project-file", testCabalProjectFile env ] + | otherwise + = [ "--builddir", testWorkDir env ] global_args | testHaveSandbox env = [ "--sandbox-config-file", testSandboxConfigFile env ] From 322214cc858cd0966faab636a66b0fc3768594c8 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 25 Nov 2016 23:10:57 -0500 Subject: [PATCH 35/56] Teach cabal exec the --builddir option. Signed-off-by: Edward Z. Yang --- cabal-install/Distribution/Client/Setup.hs | 11 ++++++++--- cabal-install/Main.hs | 4 +++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cabal-install/Distribution/Client/Setup.hs b/cabal-install/Distribution/Client/Setup.hs index bada7a9aeb1..5ceb0a747cf 100644 --- a/cabal-install/Distribution/Client/Setup.hs +++ b/cabal-install/Distribution/Client/Setup.hs @@ -2058,12 +2058,14 @@ instance Semigroup SandboxFlags where -- ------------------------------------------------------------ data ExecFlags = ExecFlags { - execVerbosity :: Flag Verbosity + execVerbosity :: Flag Verbosity, + execDistPref :: Flag FilePath } deriving Generic defaultExecFlags :: ExecFlags defaultExecFlags = ExecFlags { - execVerbosity = toFlag normal + execVerbosity = toFlag normal, + execDistPref = NoFlag } execCommand :: CommandUI ExecFlags @@ -2104,9 +2106,12 @@ execCommand = CommandUI { "Usage: " ++ pname ++ " exec [FLAGS] [--] COMMAND [--] [ARGS]\n", commandDefaultFlags = defaultExecFlags, - commandOptions = \_ -> + commandOptions = \showOrParseArgs -> [ optionVerbosity execVerbosity (\v flags -> flags { execVerbosity = v }) + , Cabal.optionDistPref + execDistPref (\d flags -> flags { execDistPref = d }) + showOrParseArgs ] } diff --git a/cabal-install/Main.hs b/cabal-install/Main.hs index 00bfb00f356..ea7ff5b1eed 100644 --- a/cabal-install/Main.hs +++ b/cabal-install/Main.hs @@ -1095,8 +1095,10 @@ execAction :: ExecFlags -> [String] -> Action execAction execFlags extraArgs globalFlags = do let verbosity = fromFlag (execVerbosity execFlags) (useSandbox, config) <- loadConfigOrSandboxConfig verbosity globalFlags + distPref <- findSavedDistPref config (execDistPref execFlags) let configFlags = savedConfigureFlags config - (comp, platform, progdb) <- getPersistOrConfigCompiler configFlags + configFlags' = configFlags { configDistPref = Flag distPref } + (comp, platform, progdb) <- getPersistOrConfigCompiler configFlags' exec verbosity useSandbox comp platform progdb extraArgs userConfigAction :: UserConfigFlags -> [String] -> Action From 6d3a00a1c6f8827e0abf06bede97abf9d05217dd Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 25 Nov 2016 23:13:29 -0500 Subject: [PATCH 36/56] Port exec/can_run_executables_installed_in_sandbox to new test suite Signed-off-by: Edward Z. Yang --- .../exec/can_run_executables_installed_in_sandbox.out | 1 - .../exec/can_run_executables_installed_in_sandbox.sh | 9 --------- cabal-testsuite/PackageTests/Exec/sandbox.test.hs | 7 +++++++ 3 files changed, 7 insertions(+), 10 deletions(-) delete mode 100644 cabal-install/tests/IntegrationTests/exec/can_run_executables_installed_in_sandbox.out delete mode 100644 cabal-install/tests/IntegrationTests/exec/can_run_executables_installed_in_sandbox.sh create mode 100644 cabal-testsuite/PackageTests/Exec/sandbox.test.hs diff --git a/cabal-install/tests/IntegrationTests/exec/can_run_executables_installed_in_sandbox.out b/cabal-install/tests/IntegrationTests/exec/can_run_executables_installed_in_sandbox.out deleted file mode 100644 index 27df3614e94..00000000000 --- a/cabal-install/tests/IntegrationTests/exec/can_run_executables_installed_in_sandbox.out +++ /dev/null @@ -1 +0,0 @@ -This is my-executable diff --git a/cabal-install/tests/IntegrationTests/exec/can_run_executables_installed_in_sandbox.sh b/cabal-install/tests/IntegrationTests/exec/can_run_executables_installed_in_sandbox.sh deleted file mode 100644 index 1f7e812ae1c..00000000000 --- a/cabal-install/tests/IntegrationTests/exec/can_run_executables_installed_in_sandbox.sh +++ /dev/null @@ -1,9 +0,0 @@ -. ./common.sh - -cabal sandbox delete > /dev/null -cabal exec my-executable && die "Unexpectedly found executable" - -cabal sandbox init > /dev/null -cabal install > /dev/null - -cabal exec my-executable || die "Did not find executable" diff --git a/cabal-testsuite/PackageTests/Exec/sandbox.test.hs b/cabal-testsuite/PackageTests/Exec/sandbox.test.hs new file mode 100644 index 00000000000..13a77f07562 --- /dev/null +++ b/cabal-testsuite/PackageTests/Exec/sandbox.test.hs @@ -0,0 +1,7 @@ +import Test.Cabal.Prelude +main = cabalTest $ do + withSandbox $ do + fails $ cabal "exec" ["my-executable"] + cabal "install" [] + cabal' "exec" ["my-executable"] + >>= assertOutputContains "This is my-executable" From 158cc06ee692f2c31ed8158460e76967e15bf874 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sat, 26 Nov 2016 02:15:07 -0500 Subject: [PATCH 37/56] Port exec/configures_cabal_to_use_sandbox to use new test suite Signed-off-by: Edward Z. Yang --- .../exec/configures_cabal_to_use_sandbox.sh | 14 ------------ .../PackageTests/Exec/sandbox-hc-pkg.test.hs | 22 +++++++++++++++++++ .../PackageTests/Exec/subdir/.gitkeep | 0 3 files changed, 22 insertions(+), 14 deletions(-) delete mode 100644 cabal-install/tests/IntegrationTests/exec/configures_cabal_to_use_sandbox.sh create mode 100644 cabal-testsuite/PackageTests/Exec/sandbox-hc-pkg.test.hs create mode 100644 cabal-testsuite/PackageTests/Exec/subdir/.gitkeep diff --git a/cabal-install/tests/IntegrationTests/exec/configures_cabal_to_use_sandbox.sh b/cabal-install/tests/IntegrationTests/exec/configures_cabal_to_use_sandbox.sh deleted file mode 100644 index ab29dcd5ed2..00000000000 --- a/cabal-install/tests/IntegrationTests/exec/configures_cabal_to_use_sandbox.sh +++ /dev/null @@ -1,14 +0,0 @@ -. ./common.sh - -cabal sandbox delete > /dev/null -cabal exec my-executable && die "Unexpectedly found executable" - -cabal sandbox init > /dev/null -cabal install > /dev/null - -# The library should not be available outside the sandbox -"$GHC_PKG" list | grep -v "my-0.1" - -# When run inside 'cabal-exec' the 'sandbox hc-pkg list' sub-command -# should find the library. -cabal exec sh -- -c 'cd subdir && "$CABAL" sandbox hc-pkg list' | grep "my-0.1" diff --git a/cabal-testsuite/PackageTests/Exec/sandbox-hc-pkg.test.hs b/cabal-testsuite/PackageTests/Exec/sandbox-hc-pkg.test.hs new file mode 100644 index 00000000000..5bf979e6821 --- /dev/null +++ b/cabal-testsuite/PackageTests/Exec/sandbox-hc-pkg.test.hs @@ -0,0 +1,22 @@ +import Test.Cabal.Prelude +import Data.Maybe +main = cabalTest $ do + withPackageDb $ do + withSandbox $ do + fails $ cabal "exec" ["my-executable"] + cabal "install" [] + -- The library should not be available outside the sandbox + ghcPkg' "list" [] >>= assertOutputDoesNotContain "my-0.1" + -- When run inside 'cabal-exec' the 'sandbox hc-pkg list' sub-command + -- should find the library. + env <- getTestEnv + -- TODO: libify me + let cabal_path = fromMaybe (error "No cabal-install path configured") + (testCabalInstallPath env) + cabal' "exec" ["sh", "--", "-c" + , "cd subdir && " ++ show cabal_path ++ + -- TODO: Ugh. Test abstractions leaking + -- through + " --sandbox-config-file " ++ show (testSandboxConfigFile env) ++ + " sandbox hc-pkg list"] + >>= assertOutputContains "my-0.1" diff --git a/cabal-testsuite/PackageTests/Exec/subdir/.gitkeep b/cabal-testsuite/PackageTests/Exec/subdir/.gitkeep new file mode 100644 index 00000000000..e69de29bb2d From e8ce472c361275e26628e1d761b460f1a6b84ede Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sat, 26 Nov 2016 02:16:59 -0500 Subject: [PATCH 38/56] Port exec/configures_ghc_to_use_sandbox to new test suite. Signed-off-by: Edward Z. Yang --- .../exec/configures_ghc_to_use_sandbox.sh | 13 ------------- .../PackageTests/Exec/sandbox-ghc-pkg.test.hs | 12 ++++++++++++ 2 files changed, 12 insertions(+), 13 deletions(-) delete mode 100644 cabal-install/tests/IntegrationTests/exec/configures_ghc_to_use_sandbox.sh create mode 100644 cabal-testsuite/PackageTests/Exec/sandbox-ghc-pkg.test.hs diff --git a/cabal-install/tests/IntegrationTests/exec/configures_ghc_to_use_sandbox.sh b/cabal-install/tests/IntegrationTests/exec/configures_ghc_to_use_sandbox.sh deleted file mode 100644 index 507af82583d..00000000000 --- a/cabal-install/tests/IntegrationTests/exec/configures_ghc_to_use_sandbox.sh +++ /dev/null @@ -1,13 +0,0 @@ -. ./common.sh - -cabal sandbox delete > /dev/null -cabal exec my-executable && die "Unexpectedly found executable" - -cabal sandbox init > /dev/null -cabal install > /dev/null - -# The library should not be available outside the sandbox -"$GHC_PKG" list | grep -v "my-0.1" - -# Execute ghc-pkg inside the sandbox; it should find my-0.1 -cabal exec ghc-pkg list | grep "my-0.1" diff --git a/cabal-testsuite/PackageTests/Exec/sandbox-ghc-pkg.test.hs b/cabal-testsuite/PackageTests/Exec/sandbox-ghc-pkg.test.hs new file mode 100644 index 00000000000..175e7ff530c --- /dev/null +++ b/cabal-testsuite/PackageTests/Exec/sandbox-ghc-pkg.test.hs @@ -0,0 +1,12 @@ +import Test.Cabal.Prelude +import Data.Maybe +main = cabalTest $ do + withPackageDb $ do + withSandbox $ do + fails $ cabal "exec" ["my-executable"] + cabal "install" [] + -- The library should not be available outside the sandbox + ghcPkg' "list" [] >>= assertOutputDoesNotContain "my-0.1" + -- Execute ghc-pkg inside the sandbox; it should find my-0.1 + cabal' "exec" ["ghc-pkg", "list"] + >>= assertOutputContains "my-0.1" From ea0c3888ef2a01381217cc4fd060e1f66986486e Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sat, 26 Nov 2016 02:21:00 -0500 Subject: [PATCH 39/56] Port exec/exit_with_failure_without_args to new test suite. Signed-off-by: Edward Z. Yang --- .../IntegrationTests/exec/exit_with_failure_without_args.err | 1 - .../IntegrationTests/exec/exit_with_failure_without_args.sh | 3 --- cabal-testsuite/PackageTests/Exec/legacy-no-args.test.hs | 2 ++ 3 files changed, 2 insertions(+), 4 deletions(-) delete mode 100644 cabal-install/tests/IntegrationTests/exec/exit_with_failure_without_args.err delete mode 100644 cabal-install/tests/IntegrationTests/exec/exit_with_failure_without_args.sh create mode 100644 cabal-testsuite/PackageTests/Exec/legacy-no-args.test.hs diff --git a/cabal-install/tests/IntegrationTests/exec/exit_with_failure_without_args.err b/cabal-install/tests/IntegrationTests/exec/exit_with_failure_without_args.err deleted file mode 100644 index 14425a5f921..00000000000 --- a/cabal-install/tests/IntegrationTests/exec/exit_with_failure_without_args.err +++ /dev/null @@ -1 +0,0 @@ -RE:^cabal(\.exe)?: Please specify an executable to run$ diff --git a/cabal-install/tests/IntegrationTests/exec/exit_with_failure_without_args.sh b/cabal-install/tests/IntegrationTests/exec/exit_with_failure_without_args.sh deleted file mode 100644 index 0faf1dd5f06..00000000000 --- a/cabal-install/tests/IntegrationTests/exec/exit_with_failure_without_args.sh +++ /dev/null @@ -1,3 +0,0 @@ -. ./common.sh - -! cabal exec diff --git a/cabal-testsuite/PackageTests/Exec/legacy-no-args.test.hs b/cabal-testsuite/PackageTests/Exec/legacy-no-args.test.hs new file mode 100644 index 00000000000..e9a9469aa2d --- /dev/null +++ b/cabal-testsuite/PackageTests/Exec/legacy-no-args.test.hs @@ -0,0 +1,2 @@ +import Test.Cabal.Prelude +main = cabalTest $ fails (cabal' "exec" []) >>= assertOutputContains "Please specify an executable to run" From 768da11552c3f1e43a9bafa1e3e2e31032338d0b Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sat, 26 Nov 2016 02:22:17 -0500 Subject: [PATCH 40/56] Port exec/runs_given_command to new test suite. Signed-off-by: Edward Z. Yang --- .../tests/IntegrationTests/exec/runs_given_command.out | 1 - .../tests/IntegrationTests/exec/runs_given_command.sh | 3 --- cabal-testsuite/PackageTests/Exec/legacy.test.hs | 5 +++++ 3 files changed, 5 insertions(+), 4 deletions(-) delete mode 100644 cabal-install/tests/IntegrationTests/exec/runs_given_command.out delete mode 100644 cabal-install/tests/IntegrationTests/exec/runs_given_command.sh create mode 100644 cabal-testsuite/PackageTests/Exec/legacy.test.hs diff --git a/cabal-install/tests/IntegrationTests/exec/runs_given_command.out b/cabal-install/tests/IntegrationTests/exec/runs_given_command.out deleted file mode 100644 index 95908116346..00000000000 --- a/cabal-install/tests/IntegrationTests/exec/runs_given_command.out +++ /dev/null @@ -1 +0,0 @@ -this string diff --git a/cabal-install/tests/IntegrationTests/exec/runs_given_command.sh b/cabal-install/tests/IntegrationTests/exec/runs_given_command.sh deleted file mode 100644 index 62e683afc52..00000000000 --- a/cabal-install/tests/IntegrationTests/exec/runs_given_command.sh +++ /dev/null @@ -1,3 +0,0 @@ -. ./common.sh -cabal configure > /dev/null -cabal exec echo this string diff --git a/cabal-testsuite/PackageTests/Exec/legacy.test.hs b/cabal-testsuite/PackageTests/Exec/legacy.test.hs new file mode 100644 index 00000000000..fd14db4af78 --- /dev/null +++ b/cabal-testsuite/PackageTests/Exec/legacy.test.hs @@ -0,0 +1,5 @@ +import Test.Cabal.Prelude +main = cabalTest $ do + cabal "configure" [] + cabal' "exec" ["echo", "find_me_in_output"] + >>= assertOutputContains "find_me_in_output" From af26fb605cd351d5e39deda375c24a0dac80f9e0 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 25 Nov 2016 22:10:55 -0500 Subject: [PATCH 41/56] Add new-build variant of CustomDep test. TODO: This hacks HOME so that it works in CI which doesn't have old-time available in system GHC, remove that hack eventually. Signed-off-by: Edward Z. Yang --- cabal-testsuite/PackageTests/CustomDep/cabal.project | 1 + cabal-testsuite/PackageTests/CustomDep/cabal.test.hs | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 cabal-testsuite/PackageTests/CustomDep/cabal.project create mode 100644 cabal-testsuite/PackageTests/CustomDep/cabal.test.hs diff --git a/cabal-testsuite/PackageTests/CustomDep/cabal.project b/cabal-testsuite/PackageTests/CustomDep/cabal.project new file mode 100644 index 00000000000..d4198c181d9 --- /dev/null +++ b/cabal-testsuite/PackageTests/CustomDep/cabal.project @@ -0,0 +1 @@ +packages: client custom diff --git a/cabal-testsuite/PackageTests/CustomDep/cabal.test.hs b/cabal-testsuite/PackageTests/CustomDep/cabal.test.hs new file mode 100644 index 00000000000..18aba6cde90 --- /dev/null +++ b/cabal-testsuite/PackageTests/CustomDep/cabal.test.hs @@ -0,0 +1,7 @@ +import Test.Cabal.Prelude +main = cabalTest $ do + -- NB: This variant seems to use the bootstrapped Cabal? + skipUnless =<< hasCabalForGhc + -- TODO: Hack, delete me + withEnvFilter (/= "HOME") $ do + cabal "new-build" [] From 749fd0cb1a16f43c6cbcdc318d26a724969b881f Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sat, 26 Nov 2016 09:58:49 -0800 Subject: [PATCH 42/56] Remove unneeded files from extra-source-files (TODO: break this commit up) Signed-off-by: Edward Z. Yang --- cabal-install/cabal-install.cabal | 67 ------------------------------- 1 file changed, 67 deletions(-) diff --git a/cabal-install/cabal-install.cabal b/cabal-install/cabal-install.cabal index 2573810bb42..047f6eb65f2 100644 --- a/cabal-install/cabal-install.cabal +++ b/cabal-install/cabal-install.cabal @@ -22,62 +22,7 @@ Extra-Source-Files: -- Generated with '../Cabal/misc/gen-extra-source-files.sh' -- Do NOT edit this section manually; instead, run the script. -- BEGIN gen-extra-source-files - tests/IntegrationTests/backpack/includes2-external.sh - tests/IntegrationTests/backpack/includes2-internal.sh - tests/IntegrationTests/backpack/includes2/Includes2.cabal - tests/IntegrationTests/backpack/includes2/exe/Main.hs - tests/IntegrationTests/backpack/includes2/exe/exe.cabal - tests/IntegrationTests/backpack/includes2/mylib/Mine.hs - tests/IntegrationTests/backpack/includes2/mylib/mylib.cabal - tests/IntegrationTests/backpack/includes2/mysql/Database/MySQL.hs - tests/IntegrationTests/backpack/includes2/mysql/mysql.cabal - tests/IntegrationTests/backpack/includes2/postgresql/Database/PostgreSQL.hs - tests/IntegrationTests/backpack/includes2/postgresql/postgresql.cabal - tests/IntegrationTests/backpack/includes2/src/App.hs - tests/IntegrationTests/backpack/includes2/src/src.cabal - tests/IntegrationTests/backpack/includes3-external.sh - tests/IntegrationTests/backpack/includes3-internal.sh - tests/IntegrationTests/backpack/includes3/Includes3.cabal - tests/IntegrationTests/backpack/includes3/exe/Main.hs - tests/IntegrationTests/backpack/includes3/exe/Setup.hs - tests/IntegrationTests/backpack/includes3/exe/exe.cabal - tests/IntegrationTests/backpack/includes3/indef/Foo.hs - tests/IntegrationTests/backpack/includes3/indef/Setup.hs - tests/IntegrationTests/backpack/includes3/indef/indef.cabal - tests/IntegrationTests/backpack/includes3/sigs/Setup.hs - tests/IntegrationTests/backpack/includes3/sigs/sigs.cabal tests/IntegrationTests/common.sh - tests/IntegrationTests/custom-setup/Cabal-99998/Cabal.cabal - tests/IntegrationTests/custom-setup/Cabal-99998/CabalMessage.hs - tests/IntegrationTests/custom-setup/Cabal-99999/Cabal.cabal - tests/IntegrationTests/custom-setup/Cabal-99999/CabalMessage.hs - tests/IntegrationTests/custom-setup/custom-setup-old-cabal/Setup.hs - tests/IntegrationTests/custom-setup/custom-setup-old-cabal/custom-setup-old-cabal.cabal - tests/IntegrationTests/custom-setup/custom-setup-without-cabal-defaultMain/Setup.hs - tests/IntegrationTests/custom-setup/custom-setup-without-cabal-defaultMain/custom-setup-without-cabal-defaultMain.cabal - tests/IntegrationTests/custom-setup/custom-setup-without-cabal/Setup.hs - tests/IntegrationTests/custom-setup/custom-setup-without-cabal/custom-setup-without-cabal.cabal - tests/IntegrationTests/custom-setup/custom-setup/Setup.hs - tests/IntegrationTests/custom-setup/custom-setup/custom-setup.cabal - tests/IntegrationTests/custom-setup/custom_setup_without_Cabal_doesnt_allow_Cabal_import.sh - tests/IntegrationTests/custom-setup/custom_setup_without_Cabal_doesnt_require_Cabal.sh - tests/IntegrationTests/custom-setup/installs_Cabal_as_setup_dep.sh - tests/IntegrationTests/custom-setup/new_build_requires_Cabal_1_20.sh - tests/IntegrationTests/custom/custom_dep.sh - tests/IntegrationTests/custom/custom_dep/client/B.hs - tests/IntegrationTests/custom/custom_dep/client/Setup.hs - tests/IntegrationTests/custom/custom_dep/client/client.cabal - tests/IntegrationTests/custom/custom_dep/custom/A.hs - tests/IntegrationTests/custom/custom_dep/custom/Setup.hs - tests/IntegrationTests/custom/custom_dep/custom/custom.cabal - tests/IntegrationTests/custom/plain.sh - tests/IntegrationTests/custom/plain/A.hs - tests/IntegrationTests/custom/plain/Setup.hs - tests/IntegrationTests/custom/plain/plain.cabal - tests/IntegrationTests/custom/segfault.sh - tests/IntegrationTests/custom/segfault/Setup.hs - tests/IntegrationTests/custom/segfault/cabal.project - tests/IntegrationTests/custom/segfault/plain.cabal tests/IntegrationTests/exec/Foo.hs tests/IntegrationTests/exec/My.hs tests/IntegrationTests/exec/T4049.sh @@ -86,19 +31,7 @@ Extra-Source-Files: tests/IntegrationTests/exec/T4049/my-foreign-lib.cabal tests/IntegrationTests/exec/T4049/src/MyForeignLib/Hello.hs tests/IntegrationTests/exec/T4049/src/MyForeignLib/SomeBindings.hsc - tests/IntegrationTests/exec/adds_sandbox_bin_directory_to_path.out - tests/IntegrationTests/exec/adds_sandbox_bin_directory_to_path.sh - tests/IntegrationTests/exec/auto_configures_on_exec.out - tests/IntegrationTests/exec/auto_configures_on_exec.sh - tests/IntegrationTests/exec/can_run_executables_installed_in_sandbox.out - tests/IntegrationTests/exec/can_run_executables_installed_in_sandbox.sh - tests/IntegrationTests/exec/configures_cabal_to_use_sandbox.sh - tests/IntegrationTests/exec/configures_ghc_to_use_sandbox.sh - tests/IntegrationTests/exec/exit_with_failure_without_args.err - tests/IntegrationTests/exec/exit_with_failure_without_args.sh tests/IntegrationTests/exec/my.cabal - tests/IntegrationTests/exec/runs_given_command.out - tests/IntegrationTests/exec/runs_given_command.sh tests/IntegrationTests/freeze/disable_benchmarks_freezes_bench_deps.sh tests/IntegrationTests/freeze/disable_tests_freezes_test_deps.sh tests/IntegrationTests/freeze/does_not_freeze_nondeps.sh From 9c41ff024f067593bde35ecfd11f211e4b6e5875 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sat, 26 Nov 2016 14:32:25 -0800 Subject: [PATCH 43/56] Add support for known broken tests. Signed-off-by: Edward Z. Yang --- cabal-testsuite/Test/Cabal/Monad.hs | 21 +++++++++++++++++++ cabal-testsuite/Test/Cabal/Prelude.hs | 17 ++++++++++++++++ cabal-testsuite/main/cabal-tests.hs | 29 +++++++++++++++++++-------- 3 files changed, 59 insertions(+), 8 deletions(-) diff --git a/cabal-testsuite/Test/Cabal/Monad.hs b/cabal-testsuite/Test/Cabal/Monad.hs index af12edb3411..419fe35d21f 100644 --- a/cabal-testsuite/Test/Cabal/Monad.hs +++ b/cabal-testsuite/Test/Cabal/Monad.hs @@ -29,6 +29,11 @@ module Test.Cabal.Monad ( skipIf, skipUnless, skipExitCode, + -- * Known broken tests + expectedBroken, + unexpectedSuccess, + expectedBrokenExitCode, + unexpectedSuccessExitCode, -- whenHasSharedLibraries, -- * Arguments (TODO: move me) CommonArgs(..), @@ -115,9 +120,25 @@ skipIf b = when b skip skipUnless :: Bool -> TestM () skipUnless b = unless b skip +expectedBroken :: TestM () +expectedBroken = liftIO $ do + putStrLn "EXPECTED FAIL" + exitWith (ExitFailure expectedBrokenExitCode) + +unexpectedSuccess :: TestM () +unexpectedSuccess = liftIO $ do + putStrLn "UNEXPECTED OK" + exitWith (ExitFailure unexpectedSuccessExitCode) + skipExitCode :: Int skipExitCode = 64 +expectedBrokenExitCode :: Int +expectedBrokenExitCode = 65 + +unexpectedSuccessExitCode :: Int +unexpectedSuccessExitCode = 66 + setupAndCabalTest :: TestM () -> IO () setupAndCabalTest m = runTestM $ do env <- getTestEnv diff --git a/cabal-testsuite/Test/Cabal/Prelude.hs b/cabal-testsuite/Test/Cabal/Prelude.hs index cb5cf4f8a58..71fe6a7a481 100644 --- a/cabal-testsuite/Test/Cabal/Prelude.hs +++ b/cabal-testsuite/Test/Cabal/Prelude.hs @@ -42,6 +42,7 @@ import Distribution.Compat.Stack import Text.Regex.Posix +import Control.Concurrent.Async import qualified Data.Aeson as JSON import qualified Data.ByteString.Lazy as BSL import Control.Monad @@ -502,6 +503,22 @@ hasCabalForGhc = do -- will be picked up by the package db stack of ghc-program return (programPath ghc_program == programPath runner_ghc_program) +------------------------------------------------------------------------ +-- * Broken tests + +expectBroken :: Int -> TestM a -> TestM () +expectBroken ticket m = do + env <- getTestEnv + liftIO . withAsync (runReaderT m env) $ \a -> do + r <- waitCatch a + case r of + Left e -> do + putStrLn $ "This test is known broken, see #" ++ show ticket ++ ":" + print e + runReaderT expectedBroken env + Right _ -> do + runReaderT unexpectedSuccess env + ------------------------------------------------------------------------ -- * Miscellaneous diff --git a/cabal-testsuite/main/cabal-tests.hs b/cabal-testsuite/main/cabal-tests.hs index 89b4138d66c..61ebfa0fa0e 100644 --- a/cabal-testsuite/main/cabal-tests.hs +++ b/cabal-testsuite/main/cabal-tests.hs @@ -124,7 +124,8 @@ main = do -- for each. But for now, just run them earlier to avoid -- them straggling at the end work_queue <- newMVar all_tests - failed_tests <- newMVar [] + unexpected_fails_var <- newMVar [] + unexpected_passes_var <- newMVar [] chan <- newChan let logAll msg = writeChan chan (ServerLogMsg AllServers msg) @@ -160,6 +161,10 @@ main = do = "OK" | resultExitCode r == ExitFailure skipExitCode = "SKIP" + | resultExitCode r == ExitFailure expectedBrokenExitCode + = "KNOWN FAIL" + | resultExitCode r == ExitFailure unexpectedSuccessExitCode + = "UNEXPECTED OK" | otherwise = "FAIL" unless (mainArgHideSuccesses args && status /= "FAIL") $ do @@ -172,7 +177,11 @@ main = do logMeta $ "$ " ++ resultCommand r ++ "\n" ++ resultOutput r ++ "\n" ++ "FAILED " ++ path - modifyMVar_ failed_tests $ \paths -> return (path:paths) + modifyMVar_ unexpected_fails_var $ \paths -> + return (path:paths) + when (status == "UNEXPECTED OK") $ + modifyMVar_ unexpected_passes_var $ \paths -> + return (path:paths) go server mask $ \restore -> do @@ -208,12 +217,16 @@ main = do -- Propagate the exception throwIO (e :: SomeException) - failed <- takeMVar failed_tests - logAll $ - if not (null failed) - then "FAILED TESTS: " ++ intercalate " " failed - else "OK" - when (not (null failed)) exitFailure + unexpected_fails <- takeMVar unexpected_fails_var + unexpected_passes <- takeMVar unexpected_passes_var + if not (null (unexpected_fails ++ unexpected_passes)) + then do + unless (null unexpected_passes) . logAll $ + "UNEXPECTED OK: " ++ intercalate " " unexpected_passes + unless (null unexpected_fails) . logAll $ + "UNEXPECTED FAIL: " ++ intercalate " " unexpected_fails + exitFailure + else logAll "OK" findTests :: IO [FilePath] findTests = getDirectoryContentsRecursive "." From b5ee225eb94b94cdb3efd8b6bf399cbb5a8fdcbc Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sat, 26 Nov 2016 14:37:09 -0800 Subject: [PATCH 44/56] Add expectBrokenIf and expectBrokenUnless variants. Signed-off-by: Edward Z. Yang --- cabal-testsuite/Test/Cabal/Prelude.hs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cabal-testsuite/Test/Cabal/Prelude.hs b/cabal-testsuite/Test/Cabal/Prelude.hs index 71fe6a7a481..defe0f9f6b4 100644 --- a/cabal-testsuite/Test/Cabal/Prelude.hs +++ b/cabal-testsuite/Test/Cabal/Prelude.hs @@ -519,6 +519,13 @@ expectBroken ticket m = do Right _ -> do runReaderT unexpectedSuccess env +expectBrokenIf :: Bool -> Int -> TestM a -> TestM () +expectBrokenIf False _ m = void $ m +expectBrokenIf True ticket m = expectBroken ticket m + +expectBrokenUnless :: Bool -> Int -> TestM a -> TestM () +expectBrokenUnless b = expectBrokenIf (not b) + ------------------------------------------------------------------------ -- * Miscellaneous From 42e9018791a95da9ba439ba75bf2058f3beec848 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sat, 26 Nov 2016 15:20:59 -0800 Subject: [PATCH 45/56] Prefix testDistDir with work to disambiguate. Signed-off-by: Edward Z. Yang --- cabal-testsuite/Test/Cabal/Monad.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cabal-testsuite/Test/Cabal/Monad.hs b/cabal-testsuite/Test/Cabal/Monad.hs index 419fe35d21f..350e6d8100f 100644 --- a/cabal-testsuite/Test/Cabal/Monad.hs +++ b/cabal-testsuite/Test/Cabal/Monad.hs @@ -326,7 +326,7 @@ testPrefixDir env = testWorkDir env "usr" -- | The absolute path to the build directory that should be used -- for the current package in a test. testDistDir :: TestEnv -> FilePath -testDistDir env = testWorkDir env testRelativeCurrentDir env "dist" +testDistDir env = testWorkDir env "work" testRelativeCurrentDir env "dist" -- | The absolute path to the shared package database that should -- be used by all packages in this test. From 59f7943323eca04074334c2159556b3d9462a8c3 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sat, 26 Nov 2016 15:22:18 -0800 Subject: [PATCH 46/56] Swap from testWorkDir to testDistDir for cabal builddir. Signed-off-by: Edward Z. Yang --- cabal-testsuite/Test/Cabal/Prelude.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cabal-testsuite/Test/Cabal/Prelude.hs b/cabal-testsuite/Test/Cabal/Prelude.hs index defe0f9f6b4..a272ad51a23 100644 --- a/cabal-testsuite/Test/Cabal/Prelude.hs +++ b/cabal-testsuite/Test/Cabal/Prelude.hs @@ -228,10 +228,10 @@ cabal' cmd args = do = [ ] -- new-build commands are affected by testCabalProjectFile | "new-" `isPrefixOf` cmd - = [ "--builddir", testWorkDir env + = [ "--builddir", testDistDir env , "--project-file", testCabalProjectFile env ] | otherwise - = [ "--builddir", testWorkDir env ] + = [ "--builddir", testDistDir env ] global_args | testHaveSandbox env = [ "--sandbox-config-file", testSandboxConfigFile env ] @@ -284,7 +284,7 @@ withPlan :: TestM a -> TestM a withPlan m = do env0 <- getTestEnv Just plan <- JSON.decode `fmap` - liftIO (BSL.readFile (testWorkDir env0 "cache" "plan.json")) + liftIO (BSL.readFile (testDistDir env0 "cache" "plan.json")) withReaderT (\env -> env { testPlan = Just plan }) m -- | Run an executable from a package. Requires 'withPlan' to have From 09fc2a72cdfda690295f141e152fe7d465e737e3 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sat, 26 Nov 2016 16:56:37 -0800 Subject: [PATCH 47/56] Support for configuring repositories in tests. This is a pretty important new feature in the test suite, which is to construct a remote repository on the fly as part of the test suite. The general principle is that you create a directory full of folders for all of the packages you want available in the repo, and then the 'withRepo' function will initialize this into a secure repo you can do tests with. Fixes #4016. Signed-off-by: Edward Z. Yang --- cabal-testsuite/Test/Cabal/Monad.hs | 38 ++++++++- cabal-testsuite/Test/Cabal/Prelude.hs | 107 ++++++++++++++++++++++++++ 2 files changed, 142 insertions(+), 3 deletions(-) diff --git a/cabal-testsuite/Test/Cabal/Monad.hs b/cabal-testsuite/Test/Cabal/Monad.hs index 350e6d8100f..dd872f56ed6 100644 --- a/cabal-testsuite/Test/Cabal/Monad.hs +++ b/cabal-testsuite/Test/Cabal/Monad.hs @@ -24,6 +24,9 @@ module Test.Cabal.Monad ( testHomeDir, testSandboxDir, testSandboxConfigFile, + testRepoDir, + testKeysDir, + testUserCabalConfigFile, -- * Skipping tests skip, skipIf, @@ -70,6 +73,7 @@ import Options.Applicative data CommonArgs = CommonArgs { argCabalInstallPath :: Maybe FilePath, argGhcPath :: Maybe FilePath, + argHackageRepoToolPath :: FilePath, argSkipSetupTests :: Bool } @@ -86,12 +90,19 @@ commonArgParser = CommonArgs <> long "with-ghc" <> metavar "PATH" )) + <*> option str + ( help "Path to hackage-repo-tool to use for repository manipulation" + <> long "with-hackage-repo-tool" + <> metavar "PATH" + <> value "hackage-repo-tool" + ) <*> switch (long "skip-setup-tests" <> help "Skip setup tests") renderCommonArgs :: CommonArgs -> [String] renderCommonArgs args = maybe [] (\x -> ["--with-cabal", x]) (argCabalInstallPath args) ++ maybe [] (\x -> ["--with-ghc", x]) (argGhcPath args) ++ + ["--with-hackage-repo-tool", argHackageRepoToolPath args] ++ (if argSkipSetupTests args then ["--skip-setup-tests"] else []) data TestArgs = TestArgs { @@ -201,6 +212,7 @@ runTestM m = do testScriptEnv = senv, testSetupPath = dist_dir "setup" "setup", testCabalInstallPath = argCabalInstallPath (testCommonArgs args), + testHackageRepoToolPath = argHackageRepoToolPath (testCommonArgs args), testSkipSetupTests = argSkipSetupTests (testCommonArgs args), testEnvironment = -- Try to avoid Unicode output @@ -211,6 +223,7 @@ runTestM m = do testRelativeCurrentDir = ".", testHavePackageDb = False, testHaveSandbox = False, + testHaveRepo = False, testCabalInstallAsSetup = False, testCabalProjectFile = "cabal.project", testPlan = Nothing @@ -225,9 +238,8 @@ runTestM m = do -- NOT want to assume for these tests (no test should -- hit Hackage.) liftIO $ createDirectoryIfMissing True (testHomeDir env ".cabal") - -- TODO: This doesn't work on Windows ghc_path <- programPathM ghcProgram - liftIO $ writeFile (testHomeDir env ".cabal" "config") + liftIO $ writeFile (testUserCabalConfigFile env) $ unlines [ "with-compiler: " ++ ghc_path ] requireProgramM :: Program -> TestM ConfiguredProgram @@ -274,8 +286,12 @@ data TestEnv = TestEnv -- | Setup script path , testSetupPath :: FilePath -- | cabal-install path (or Nothing if we are not testing - -- cabal-install) + -- cabal-install). NB: This does NOT default to @cabal@ in PATH as + -- this is unlikely to be the cabal you want to test. , testCabalInstallPath :: Maybe FilePath + -- | hackage-repo-tool path (defaults to hackage-repo-tool found in + -- PATH) + , testHackageRepoToolPath :: FilePath -- | Skip Setup tests? , testSkipSetupTests :: Bool @@ -291,6 +307,8 @@ data TestEnv = TestEnv , testHavePackageDb :: Bool -- | Says if we're working in a sandbox , testHaveSandbox :: Bool + -- | Says if we've setup a repository + , testHaveRepo :: Bool -- | Says if we're testing cabal-install as setup , testCabalInstallAsSetup :: Bool -- | Says what cabal.project file to use (probed) @@ -344,3 +362,17 @@ testSandboxDir env = testWorkDir env "sandbox" -- | The sandbox configuration file testSandboxConfigFile :: TestEnv -> FilePath testSandboxConfigFile env = testWorkDir env "cabal.sandbox.config" + +-- | The absolute prefix of our local secure repository, which we +-- use to simulate "external" packages +testRepoDir :: TestEnv -> FilePath +testRepoDir env = testWorkDir env "repo" + +-- | The absolute prefix of keys for the test. +testKeysDir :: TestEnv -> FilePath +testKeysDir env = testWorkDir env "keys" + +-- | The user cabal config file +-- TODO: Not obviously working on Windows +testUserCabalConfigFile :: TestEnv -> FilePath +testUserCabalConfigFile env = testHomeDir env ".cabal" "config" diff --git a/cabal-testsuite/Test/Cabal/Prelude.hs b/cabal-testsuite/Test/Cabal/Prelude.hs index a272ad51a23..5099098c6f3 100644 --- a/cabal-testsuite/Test/Cabal/Prelude.hs +++ b/cabal-testsuite/Test/Cabal/Prelude.hs @@ -226,6 +226,8 @@ cabal' cmd args = do -- Sandboxes manage dist dir | testHaveSandbox env = [ ] + | cmd == "update" + = [ ] -- new-build commands are affected by testCabalProjectFile | "new-" `isPrefixOf` cmd = [ "--builddir", testDistDir env @@ -382,6 +384,111 @@ runInstalledExe' exe_name args = do shell :: String -> [String] -> TestM Result shell exe args = runM exe args +------------------------------------------------------------------------ +-- * Repository manipulation + +-- Workflows we support: +-- 1. Test comes with some packages (directories in repository) which +-- should be in the repository and available for depsolving/installing +-- into global store. +-- +-- Workflows we might want to support in the future +-- * Regression tests may want to test on Hackage index. They will +-- operate deterministically as they will be pinned to a timestamp. +-- (But should we allow this? Have to download the tarballs in that +-- case. Perhaps dep solver only!) +-- * We might sdist a local package, and then upload it to the +-- repository +-- * Some of our tests involve old versions of Cabal. This might +-- be one of the rare cases where we're willing to grab the entire +-- tarball. +-- +-- Properties we want to hold: +-- 1. Tests can be run offline. No dependence on hackage.haskell.org +-- beyond what we needed to actually get the build of Cabal working +-- itself +-- 2. Tests are deterministic. Updates to Hackage should not cause +-- tests to fail. (OTOH, it's good to run tests on most recent +-- Hackage index; some sort of canary test which is run nightly. +-- Point is it should NOT be tied to cabal source code.) +-- +-- Technical notes: +-- * We depend on hackage-repo-tool binary. It would better if it was +-- libified into hackage-security but this has not been done yet. +-- + +hackageRepoTool :: String -> [String] -> TestM () +hackageRepoTool cmd args = void $ hackageRepoTool' cmd args + +hackageRepoTool' :: String -> [String] -> TestM Result +hackageRepoTool' cmd args = do + env <- getTestEnv + r <- runM (testHackageRepoToolPath env) (cmd : args) + record r + _ <- requireSuccess r + return r + +tar :: [String] -> TestM () +tar args = void $ tar' args + +tar' :: [String] -> TestM Result +tar' = runProgramM tarProgram + +-- | Creates a tarball of a directory, such that if you +-- archive the directory "/foo/bar/baz" to "mine.tgz", @tar tf@ reports +-- @baz/file1@, @baz/file2@, etc. +archiveTo :: FilePath -> FilePath -> TestM () +src `archiveTo` dst = do + -- TODO: Consider using the @tar@ library? + let (src_parent, src_dir) = splitFileName src + -- TODO: --format ustar, like createArchive? + tar ["-czf", dst, "-C", src_parent, src_dir] + +infixr 4 `archiveTo` + +-- | Given a directory (relative to the 'testCurrentDir') containing +-- a series of directories representing packages, generate an +-- external repository corresponding to all of these packages +withRepo :: FilePath -> TestM a -> TestM a +withRepo repo_dir m = do + env <- getTestEnv + -- 1. Generate keys + hackageRepoTool "create-keys" ["--keys", testKeysDir env] + -- 2. Initialize repo directory + let package_dir = testRepoDir env "package" + liftIO $ createDirectoryIfMissing True (testRepoDir env "index") + liftIO $ createDirectoryIfMissing True package_dir + -- 3. Create tarballs + pkgs <- liftIO $ getDirectoryContents (testCurrentDir env repo_dir) + forM_ pkgs $ \pkg -> do + case pkg of + '.':_ -> return () + _ -> testCurrentDir env repo_dir pkg + `archiveTo` + package_dir pkg <.> "tar.gz" + -- 4. Initialize repository + hackageRepoTool "bootstrap" ["--keys", testKeysDir env, "--repo", testRepoDir env] + -- 5. Wire it up in .cabal/config + -- TODO: libify this + let package_cache = testHomeDir env ".cabal" "packages" + liftIO $ appendFile (testUserCabalConfigFile env) + $ unlines [ "repository test-local-repo" + , " url: file:" ++ testRepoDir env + , " secure: True" + -- TODO: Hypothetically, we could stick in the + -- correct key here + , " root-keys: " + , " key-threshold: 0" + , "remote-repo-cache: " ++ package_cache ] + -- 6. Create local directories (TODO: this is a bug #4136, once you + -- fix that this can be removed) + liftIO $ createDirectoryIfMissing True (package_cache "test-local-repo") + -- 7. Update our local index + cabal "update" [] + -- 8. Profit + withReaderT (\env' -> env' { testHaveRepo = True }) m + -- TODO: Arguably should undo everything when we're done... + ------------------------------------------------------------------------ -- * Subprocess run results From ae03fd0231c34440c5152ca4229964b26f2dbfa9 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sat, 26 Nov 2016 16:58:37 -0800 Subject: [PATCH 48/56] Enable hackage-repo-tool in CI Note: hackage-repo-tool doesn't build with Windows, so that support is commented out. Signed-off-by: Edward Z. Yang --- appveyor.yml | 3 +++ cabal.project.travis | 7 +++++++ travis-common.sh | 1 + travis-script.sh | 13 +++++++++++-- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index e96654ff26a..4458c383f99 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -20,6 +20,9 @@ build_script: - Setup build - Setup test --show-details=streaming --test-option=--hide-successes - Setup install + # hackage-repo-tool doesn't build on Windows: + # https://github.com/well-typed/hackage-security/issues/175 + # - echo "" | ..\cabal install hackage-repo-tool --allow-newer=Cabal,time --constraint="Cabal == 1.25.0.0" - cd ..\cabal-testsuite - ghc --make -threaded -i Setup.hs -package Cabal-1.25.0.0 - echo "" | ..\cabal install --only-dependencies --enable-tests diff --git a/cabal.project.travis b/cabal.project.travis index 300a364f38b..e19027f8579 100644 --- a/cabal.project.travis +++ b/cabal.project.travis @@ -3,6 +3,13 @@ -- Turn off parallelization to get good errors. jobs: 1 +-- We vendor a copy of hackage-repo-tool so that we can +-- build it reliably. If we eventually get new-install +-- in the bootstrap, this can go away. +optional-packages: hackage-repo-tool-*/ +-- hackage-repo-tool has upper bound on Cabal +allow-newer: hackage-repo-tool:Cabal, hackage-repo-tool:time + -- The -fno-warn-orphans is a hack to make Cabal-1.24 -- build properly (unfortunately the flags here get applied -- to the dependencies too!) diff --git a/travis-common.sh b/travis-common.sh index f099dc463c0..e9def1faddb 100644 --- a/travis-common.sh +++ b/travis-common.sh @@ -1,5 +1,6 @@ set -e +HACKAGE_REPO_TOOL_VERSION="0.1.1" CABAL_VERSION="1.25.0.0" # --------------------------------------------------------------------- diff --git a/travis-script.sh b/travis-script.sh index 11144edddb5..b3e9cc01ea4 100755 --- a/travis-script.sh +++ b/travis-script.sh @@ -15,6 +15,7 @@ CABAL_BDIR="${PWD}/dist-newstyle/build/Cabal-${CABAL_VERSION}" CABAL_TESTSUITE_BDIR="${PWD}/dist-newstyle/build/cabal-testsuite-${CABAL_VERSION}" CABAL_INSTALL_BDIR="${PWD}/dist-newstyle/build/cabal-install-${CABAL_VERSION}" CABAL_INSTALL_SETUP="${CABAL_INSTALL_BDIR}/setup/setup" +HACKAGE_REPO_TOOL_BDIR="${PWD}/dist-newstyle/build/hackage-repo-tool-${HACKAGE_REPO_TOOL_VERSION}" # --hide-successes uses terminal control characters which mess up # Travis's log viewer. So just print them all! TEST_OPTIONS="" @@ -26,7 +27,7 @@ TEST_OPTIONS="" timed cabal update # --------------------------------------------------------------------- -# Install happy if necessary +# Install executables if necessary # --------------------------------------------------------------------- if ! command -v happy; then @@ -39,6 +40,12 @@ fi cp cabal.project.travis cabal.project.local +# hackage-repo-tool is a bit touchy to install on GHC 8.0, so instead we +# do it via new-build. See also cabal.project.travis. The downside of +# doing it this way is that the build product cannot be cached, but +# hackage-repo-tool is a relatively small package so it's good. +cabal unpack hackage-repo-tool-${HACKAGE_REPO_TOOL_VERSION} + # --------------------------------------------------------------------- # Cabal # --------------------------------------------------------------------- @@ -128,7 +135,9 @@ timed ${CABAL_INSTALL_BDIR}/build/cabal/cabal update (cd cabal-install && timed ${CABAL_INSTALL_BDIR}/build/integration-tests2/integration-tests2 $TEST_OPTIONS) || exit $? (cd cabal-install && timed ${CABAL_INSTALL_BDIR}/build/memory-usage-tests/memory-usage-tests $TEST_OPTIONS) || exit $? -(cd cabal-testsuite && timed ${CABAL_TESTSUITE_BDIR}/build/cabal-tests/cabal-tests -j3 --skip-setup-tests --with-cabal ${CABAL_INSTALL_BDIR}/build/cabal/cabal $TEST_OPTIONS) || exit $? +timed cabal new-build hackage-repo-tool + +(cd cabal-testsuite && timed ${CABAL_TESTSUITE_BDIR}/build/cabal-tests/cabal-tests -j3 --skip-setup-tests --with-cabal ${CABAL_INSTALL_BDIR}/build/cabal/cabal --with-hackage-repo-tool ${HACKAGE_REPO_TOOL_BDIR}/build/hackage-repo-tool/hackage-repo-tool $TEST_OPTIONS) || exit $? # Haddock (cd cabal-install && timed ${CABAL_INSTALL_SETUP} haddock --builddir=${CABAL_INSTALL_BDIR} ) || exit $? From c1caede32392fd3fc846e58bb68e4dae949bcfd5 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 25 Nov 2016 22:36:06 -0500 Subject: [PATCH 49/56] Port custom-setup/new_build_requires_Cabal_1_20 to new test suite. Signed-off-by: Edward Z. Yang --- .../custom-setup/new_build_requires_Cabal_1_20.sh | 9 --------- .../PackageTests/Regression/T3932}/Setup.hs | 0 .../PackageTests/Regression/T3932/cabal.project | 1 + .../PackageTests/Regression/T3932/cabal.test.hs | 10 ++++++++++ .../Regression/T3932}/custom-setup-old-cabal.cabal | 0 .../Regression/T3932/repo/Cabal-1.18.0.0/Cabal.cabal | 6 ++++++ cabal-testsuite/Test/Cabal/Prelude.hs | 4 ++++ 7 files changed, 21 insertions(+), 9 deletions(-) delete mode 100644 cabal-install/tests/IntegrationTests/custom-setup/new_build_requires_Cabal_1_20.sh rename {cabal-install/tests/IntegrationTests/custom-setup/custom-setup-old-cabal => cabal-testsuite/PackageTests/Regression/T3932}/Setup.hs (100%) create mode 100644 cabal-testsuite/PackageTests/Regression/T3932/cabal.project create mode 100644 cabal-testsuite/PackageTests/Regression/T3932/cabal.test.hs rename {cabal-install/tests/IntegrationTests/custom-setup/custom-setup-old-cabal => cabal-testsuite/PackageTests/Regression/T3932}/custom-setup-old-cabal.cabal (100%) create mode 100644 cabal-testsuite/PackageTests/Regression/T3932/repo/Cabal-1.18.0.0/Cabal.cabal diff --git a/cabal-install/tests/IntegrationTests/custom-setup/new_build_requires_Cabal_1_20.sh b/cabal-install/tests/IntegrationTests/custom-setup/new_build_requires_Cabal_1_20.sh deleted file mode 100644 index bf1275acb23..00000000000 --- a/cabal-install/tests/IntegrationTests/custom-setup/new_build_requires_Cabal_1_20.sh +++ /dev/null @@ -1,9 +0,0 @@ -# Regression test for issue #3932 - -. ./common.sh - -cd custom-setup-old-cabal -! cabal new-build > output 2>&1 - -cat output -grep -q "(issue #3932) requires >=1.20" output || die "Expect constraint failure" diff --git a/cabal-install/tests/IntegrationTests/custom-setup/custom-setup-old-cabal/Setup.hs b/cabal-testsuite/PackageTests/Regression/T3932/Setup.hs similarity index 100% rename from cabal-install/tests/IntegrationTests/custom-setup/custom-setup-old-cabal/Setup.hs rename to cabal-testsuite/PackageTests/Regression/T3932/Setup.hs diff --git a/cabal-testsuite/PackageTests/Regression/T3932/cabal.project b/cabal-testsuite/PackageTests/Regression/T3932/cabal.project new file mode 100644 index 00000000000..e6fdbadb439 --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T3932/cabal.project @@ -0,0 +1 @@ +packages: . diff --git a/cabal-testsuite/PackageTests/Regression/T3932/cabal.test.hs b/cabal-testsuite/PackageTests/Regression/T3932/cabal.test.hs new file mode 100644 index 00000000000..867cd707d24 --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T3932/cabal.test.hs @@ -0,0 +1,10 @@ +import Test.Cabal.Prelude +main = cabalTest $ + -- This repository contains a Cabal-1.18.0.0 option, which would + -- normally would satisfy the repository, except for new-build's + -- extra constraint that setup Cabal must be 1.20. If we don't + -- have a choice like this available, the unsatisfied constraint + -- won't be reported. + withRepo "repo" $ do + fails (cabal' "new-build" []) >>= + assertOutputContains "(issue #3932) requires >=1.20" diff --git a/cabal-install/tests/IntegrationTests/custom-setup/custom-setup-old-cabal/custom-setup-old-cabal.cabal b/cabal-testsuite/PackageTests/Regression/T3932/custom-setup-old-cabal.cabal similarity index 100% rename from cabal-install/tests/IntegrationTests/custom-setup/custom-setup-old-cabal/custom-setup-old-cabal.cabal rename to cabal-testsuite/PackageTests/Regression/T3932/custom-setup-old-cabal.cabal diff --git a/cabal-testsuite/PackageTests/Regression/T3932/repo/Cabal-1.18.0.0/Cabal.cabal b/cabal-testsuite/PackageTests/Regression/T3932/repo/Cabal-1.18.0.0/Cabal.cabal new file mode 100644 index 00000000000..363db88cf3f --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T3932/repo/Cabal-1.18.0.0/Cabal.cabal @@ -0,0 +1,6 @@ +name: Cabal +version: 1.18.0.0 +build-type: Simple +cabal-version: >= 1.10 + +library diff --git a/cabal-testsuite/Test/Cabal/Prelude.hs b/cabal-testsuite/Test/Cabal/Prelude.hs index 5099098c6f3..dc0889ae419 100644 --- a/cabal-testsuite/Test/Cabal/Prelude.hs +++ b/cabal-testsuite/Test/Cabal/Prelude.hs @@ -96,6 +96,10 @@ withDirectory f = withReaderT withEnv :: [(String, Maybe String)] -> TestM a -> TestM a withEnv e = withReaderT (\env -> env { testEnvironment = testEnvironment env ++ e }) +-- HACK please don't use me +withEnvFilter :: (String -> Bool) -> TestM a -> TestM a +withEnvFilter p = withReaderT (\env -> env { testEnvironment = filter (p . fst) (testEnvironment env) }) + ------------------------------------------------------------------------ -- * Running Setup From f8ba8584ec245cd97787793dbb82a18e565ab315 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sun, 27 Nov 2016 00:26:00 -0800 Subject: [PATCH 50/56] Program-ify everything in test suite. Previously, in some cases we would carry around an explicit FilePath for an executable that we wanted to invoke subsequently. In this new scheme, any executable we want to execute gets registered to the ProgramDb we are carrying around. Now we can uniformly use runProgramM in all cases. Great! Signed-off-by: Edward Z. Yang --- Cabal/Distribution/Simple/Program/Db.hs | 8 ++ .../PackageTests/Exec/sandbox-hc-pkg.test.hs | 9 +- cabal-testsuite/Test/Cabal/Monad.hs | 126 +++++++++++++----- cabal-testsuite/Test/Cabal/Prelude.hs | 18 +-- 4 files changed, 110 insertions(+), 51 deletions(-) diff --git a/Cabal/Distribution/Simple/Program/Db.hs b/Cabal/Distribution/Simple/Program/Db.hs index d15368d6e16..18c35ce9b09 100644 --- a/Cabal/Distribution/Simple/Program/Db.hs +++ b/Cabal/Distribution/Simple/Program/Db.hs @@ -52,6 +52,7 @@ module Distribution.Simple.Program.Db ( -- ** Query and manipulate the program db configureProgram, configureAllKnownPrograms, + unconfigureProgram, lookupProgramVersion, reconfigurePrograms, requireProgram, @@ -365,6 +366,13 @@ configurePrograms verbosity progs progdb = foldM (flip (configureProgram verbosity)) progdb progs +-- | Unconfigure a program. This is basically a hack and you shouldn't +-- use it, but it can be handy for making sure a 'requireProgram' +-- actually reconfigures. +unconfigureProgram :: String -> ProgramDb -> ProgramDb +unconfigureProgram progname = + updateConfiguredProgs $ Map.delete progname + -- | Try to configure all the known programs that have not yet been configured. -- configureAllKnownPrograms :: Verbosity diff --git a/cabal-testsuite/PackageTests/Exec/sandbox-hc-pkg.test.hs b/cabal-testsuite/PackageTests/Exec/sandbox-hc-pkg.test.hs index 5bf979e6821..dee03490f88 100644 --- a/cabal-testsuite/PackageTests/Exec/sandbox-hc-pkg.test.hs +++ b/cabal-testsuite/PackageTests/Exec/sandbox-hc-pkg.test.hs @@ -1,5 +1,7 @@ import Test.Cabal.Prelude import Data.Maybe +import System.Directory +import Control.Monad.IO.Class main = cabalTest $ do withPackageDb $ do withSandbox $ do @@ -10,9 +12,10 @@ main = cabalTest $ do -- When run inside 'cabal-exec' the 'sandbox hc-pkg list' sub-command -- should find the library. env <- getTestEnv - -- TODO: libify me - let cabal_path = fromMaybe (error "No cabal-install path configured") - (testCabalInstallPath env) + -- NB: cabal_path might be relative, so we have to + -- turn it absolute + rel_cabal_path <- programPathM cabalProgram + cabal_path <- liftIO $ makeAbsolute rel_cabal_path cabal' "exec" ["sh", "--", "-c" , "cd subdir && " ++ show cabal_path ++ -- TODO: Ugh. Test abstractions leaking diff --git a/cabal-testsuite/Test/Cabal/Monad.hs b/cabal-testsuite/Test/Cabal/Monad.hs index dd872f56ed6..46e85d60c1e 100644 --- a/cabal-testsuite/Test/Cabal/Monad.hs +++ b/cabal-testsuite/Test/Cabal/Monad.hs @@ -12,6 +12,9 @@ module Test.Cabal.Monad ( -- * Helper functions programPathM, requireProgramM, + isAvailableProgram, + hackageRepoToolProgram, + cabalProgram, -- * The test environment TestEnv(..), getTestEnv, @@ -54,7 +57,6 @@ import Distribution.Simple.Configure ( getPersistBuildConfig, configCompilerEx ) import Distribution.Types.LocalBuildInfo - import Distribution.Verbosity import qualified Control.Exception as E @@ -71,10 +73,10 @@ import System.IO.Error (isDoesNotExistError) import Options.Applicative data CommonArgs = CommonArgs { - argCabalInstallPath :: Maybe FilePath, - argGhcPath :: Maybe FilePath, - argHackageRepoToolPath :: FilePath, - argSkipSetupTests :: Bool + argCabalInstallPath :: Maybe FilePath, + argGhcPath :: Maybe FilePath, + argHackageRepoToolPath :: Maybe FilePath, + argSkipSetupTests :: Bool } commonArgParser :: Parser CommonArgs @@ -90,25 +92,24 @@ commonArgParser = CommonArgs <> long "with-ghc" <> metavar "PATH" )) - <*> option str + <*> optional (option str ( help "Path to hackage-repo-tool to use for repository manipulation" <> long "with-hackage-repo-tool" <> metavar "PATH" - <> value "hackage-repo-tool" - ) + )) <*> switch (long "skip-setup-tests" <> help "Skip setup tests") renderCommonArgs :: CommonArgs -> [String] renderCommonArgs args = - maybe [] (\x -> ["--with-cabal", x]) (argCabalInstallPath args) ++ - maybe [] (\x -> ["--with-ghc", x]) (argGhcPath args) ++ - ["--with-hackage-repo-tool", argHackageRepoToolPath args] ++ + maybe [] (\x -> ["--with-cabal", x]) (argCabalInstallPath args) ++ + maybe [] (\x -> ["--with-ghc", x]) (argGhcPath args) ++ + maybe [] (\x -> ["--with-hackage-repo-tool", x]) (argHackageRepoToolPath args) ++ (if argSkipSetupTests args then ["--skip-setup-tests"] else []) data TestArgs = TestArgs { - testArgDistDir :: FilePath, + testArgDistDir :: FilePath, testArgScriptPath :: FilePath, - testCommonArgs :: CommonArgs + testCommonArgs :: CommonArgs } testArgParser :: Parser TestArgs @@ -153,15 +154,14 @@ unexpectedSuccessExitCode = 66 setupAndCabalTest :: TestM () -> IO () setupAndCabalTest m = runTestM $ do env <- getTestEnv - skipIf (testSkipSetupTests env && isNothing (testCabalInstallPath env)) + have_cabal <- isAvailableProgram cabalProgram + skipIf (testSkipSetupTests env && not have_cabal) when (not (testSkipSetupTests env)) $ do liftIO $ putStrLn "Test with Setup:" m - case testCabalInstallPath env of - Nothing -> return () - Just _ -> do - liftIO $ putStrLn "Test with cabal-install:" - withReaderT (\nenv -> nenv { testCabalInstallAsSetup = True }) m + when have_cabal $ do + liftIO $ putStrLn "Test with cabal-install:" + withReaderT (\nenv -> nenv { testCabalInstallAsSetup = True }) m setupTest :: TestM () -> IO () setupTest m = runTestM $ do @@ -171,12 +171,20 @@ setupTest m = runTestM $ do cabalTest :: TestM () -> IO () cabalTest m = runTestM $ do - env <- getTestEnv - skipIf (isNothing (testCabalInstallPath env)) + skipUnless =<< isAvailableProgram cabalProgram withReaderT (\nenv -> nenv { testCabalInstallAsSetup = True }) m type TestM = ReaderT TestEnv IO +hackageRepoToolProgram :: Program +hackageRepoToolProgram = simpleProgram "hackage-repo-tool" + +cabalProgram :: Program +cabalProgram = (simpleProgram "cabal") { + -- Do NOT search for executable named cabal + programFindLocation = \_ _ -> return Nothing + } + -- | Run a test in the test monad according to program's arguments. runTestM :: TestM () -> IO () runTestM m = do @@ -189,20 +197,61 @@ runTestM m = do lbi <- getPersistBuildConfig dist_dir let verbosity = normal -- TODO: configurable senv <- mkScriptEnv verbosity lbi - (program_db, db_stack) <- case argGhcPath (testCommonArgs args) of - Nothing -> return (withPrograms lbi, withPackageDB lbi) + -- Add test suite specific programs + let program_db0 = + addKnownPrograms + ([hackageRepoToolProgram, cabalProgram] ++ builtinPrograms) + (withPrograms lbi) + -- Reconfigure according to user flags + let cargs = testCommonArgs args + program_db1 <- + reconfigurePrograms verbosity + ([("cabal", p) | p <- maybeToList (argCabalInstallPath cargs)] ++ + [("ghc", p) | p <- maybeToList (argGhcPath cargs)] ++ + [("hackage-repo-tool", p) + | p <- maybeToList (argHackageRepoToolPath cargs)]) + [] -- --prog-options not supported ATM + program_db0 + + -- Reconfigure the rest of GHC + program_db <- case argGhcPath cargs of + Nothing -> return program_db1 Just ghc_path -> do + -- All the things that get updated paths from + -- configCompilerEx. The point is to make sure + -- we reconfigure these when we need them. + let program_db2 = unconfigureProgram "ghc" + . unconfigureProgram "ghc-pkg" + . unconfigureProgram "hsc2hs" + . unconfigureProgram "haddock" + . unconfigureProgram "hpc" + . unconfigureProgram "runghc" + . unconfigureProgram "gcc" + . unconfigureProgram "ld" + . unconfigureProgram "ar" + . unconfigureProgram "strip" + $ program_db1 (_, _, program_db) <- configCompilerEx (Just (compilerFlavor (compiler lbi))) (Just ghc_path) Nothing - defaultProgramDb -- don't use lbi; it won't reconfigure + program_db2 verbosity - -- TODO: configurable - let db_stack = [GlobalPackageDB] - return (program_db, db_stack) - let env = TestEnv { + -- TODO: this actually leaves a pile of things unconfigured. + -- Optimal strategy for us is to lazily configure them, so + -- we don't pay for things we don't need. A bit difficult + -- to do in the current design. + return program_db + + let db_stack = + case argGhcPath (testCommonArgs args) of + Nothing -> withPackageDB lbi + -- Can't use the build package db stack since they + -- are all for the wrong versions! TODO: Make + -- this configurable + Just _ -> [GlobalPackageDB] + env = TestEnv { testSourceDir = script_dir, testSubName = script_base, testProgramDb = program_db, @@ -211,8 +260,6 @@ runTestM m = do testMtimeChangeDelay = Nothing, testScriptEnv = senv, testSetupPath = dist_dir "setup" "setup", - testCabalInstallPath = argCabalInstallPath (testCommonArgs args), - testHackageRepoToolPath = argHackageRepoToolPath (testCommonArgs args), testSkipSetupTests = argSkipSetupTests (testCommonArgs args), testEnvironment = -- Try to avoid Unicode output @@ -253,6 +300,18 @@ programPathM :: Program -> TestM FilePath programPathM program = do fmap programPath (requireProgramM program) +isAvailableProgram :: Program -> TestM Bool +isAvailableProgram program = do + env <- getTestEnv + case lookupProgram program (testProgramDb env) of + Just _ -> return True + Nothing -> do + -- It might not have been configured. Try to configure. + progdb <- liftIO $ configureProgram (testVerbosity env) program (testProgramDb env) + case lookupProgram program progdb of + Just _ -> return True + Nothing -> return False + -- | Run an IO action, and suppress a "does not exist" error. onlyIfExists :: MonadIO m => IO () -> m () onlyIfExists m = @@ -285,13 +344,6 @@ data TestEnv = TestEnv , testScriptEnv :: ScriptEnv -- | Setup script path , testSetupPath :: FilePath - -- | cabal-install path (or Nothing if we are not testing - -- cabal-install). NB: This does NOT default to @cabal@ in PATH as - -- this is unlikely to be the cabal you want to test. - , testCabalInstallPath :: Maybe FilePath - -- | hackage-repo-tool path (defaults to hackage-repo-tool found in - -- PATH) - , testHackageRepoToolPath :: FilePath -- | Skip Setup tests? , testSkipSetupTests :: Bool diff --git a/cabal-testsuite/Test/Cabal/Prelude.hs b/cabal-testsuite/Test/Cabal/Prelude.hs index dc0889ae419..6e068c69747 100644 --- a/cabal-testsuite/Test/Cabal/Prelude.hs +++ b/cabal-testsuite/Test/Cabal/Prelude.hs @@ -135,8 +135,7 @@ setup' cmd args = do full_args = cmd : ["-v", "--distdir", rel_dist_dir] ++ args' r <- if testCabalInstallAsSetup env - then runM (fromMaybe (error "No cabal-install path configured") - (testCabalInstallPath env)) full_args + then runProgramM cabalProgram full_args else do pdfile <- liftIO $ tryFindPackageDesc (testCurrentDir env) pdesc <- liftIO $ readPackageDescription (testVerbosity env) pdfile @@ -262,13 +261,7 @@ cabal_sandbox' cmd args = do cabal_raw' :: [String] -> TestM Result cabal_raw' cabal_args = do - env <- getTestEnv - r <- liftIO $ run (testVerbosity env) - (Just (testCurrentDir env)) - (testEnvironment env) - (fromMaybe (error "No cabal-install path configured") - (testCabalInstallPath env)) - cabal_args + r <- runProgramM cabalProgram cabal_args record r requireSuccess r @@ -426,8 +419,7 @@ hackageRepoTool cmd args = void $ hackageRepoTool' cmd args hackageRepoTool' :: String -> [String] -> TestM Result hackageRepoTool' cmd args = do - env <- getTestEnv - r <- runM (testHackageRepoToolPath env) (cmd : args) + r <- runProgramM hackageRepoToolProgram (cmd : args) record r _ <- requireSuccess r return r @@ -456,6 +448,10 @@ infixr 4 `archiveTo` withRepo :: FilePath -> TestM a -> TestM a withRepo repo_dir m = do env <- getTestEnv + + -- Check if hackage-repo-tool is available, and skip if not + skipUnless =<< isAvailableProgram hackageRepoToolProgram + -- 1. Generate keys hackageRepoTool "create-keys" ["--keys", testKeysDir env] -- 2. Initialize repo directory From 326da71cb646205ee12443cb22db5c1a11275a1c Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sun, 27 Nov 2016 00:28:14 -0800 Subject: [PATCH 51/56] Centralize use of record/require. Previously, clients of runM had to explicitly record and check the exit code of a run subcommand. This has now been folded into runM, so this is done always (which is what you wanted anyway.) Signed-off-by: Edward Z. Yang --- cabal-testsuite/Test/Cabal/Prelude.hs | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/cabal-testsuite/Test/Cabal/Prelude.hs b/cabal-testsuite/Test/Cabal/Prelude.hs index 6e068c69747..2bb5dfe042d 100644 --- a/cabal-testsuite/Test/Cabal/Prelude.hs +++ b/cabal-testsuite/Test/Cabal/Prelude.hs @@ -68,11 +68,13 @@ import System.Posix.Files ( createSymbolicLink ) runM :: FilePath -> [String] -> TestM Result runM path args = do env <- getTestEnv - liftIO $ run (testVerbosity env) + r <- liftIO $ run (testVerbosity env) (Just (testCurrentDir env)) (testEnvironment env) path args + record r + requireSuccess r runProgramM :: Program -> [String] -> TestM Result runProgramM prog args = do @@ -133,8 +135,7 @@ setup' cmd args = do _ -> args let rel_dist_dir = definitelyMakeRelative (testCurrentDir env) (testDistDir env) full_args = cmd : ["-v", "--distdir", rel_dist_dir] ++ args' - r <- - if testCabalInstallAsSetup env + if testCabalInstallAsSetup env then runProgramM cabalProgram full_args else do pdfile <- liftIO $ tryFindPackageDesc (testCurrentDir env) @@ -157,9 +158,8 @@ setup' cmd args = do (testEnvironment env) "Setup.hs" (cmd : ["-v", "--distdir", testDistDir env] ++ args') + -- don't forget to check results... -} - record r - requireSuccess r definitelyMakeRelative :: FilePath -> FilePath -> FilePath definitelyMakeRelative base0 path0 = @@ -260,10 +260,7 @@ cabal_sandbox' cmd args = do cabal_raw' cabal_args cabal_raw' :: [String] -> TestM Result -cabal_raw' cabal_args = do - r <- runProgramM cabalProgram cabal_args - record r - requireSuccess r +cabal_raw' cabal_args = runProgramM cabalProgram cabal_args withSandbox :: TestM a -> TestM a withSandbox m = do @@ -418,11 +415,7 @@ hackageRepoTool :: String -> [String] -> TestM () hackageRepoTool cmd args = void $ hackageRepoTool' cmd args hackageRepoTool' :: String -> [String] -> TestM Result -hackageRepoTool' cmd args = do - r <- runProgramM hackageRepoToolProgram (cmd : args) - record r - _ <- requireSuccess r - return r +hackageRepoTool' cmd args = runProgramM hackageRepoToolProgram (cmd : args) tar :: [String] -> TestM () tar args = void $ tar' args From 9a3cd9185813e38065584ca4df2cb9170d534f60 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sun, 27 Nov 2016 00:49:15 -0800 Subject: [PATCH 52/56] Cleanup between setup and cabal tests TODO: This seems to cause Windows failure Signed-off-by: Edward Z. Yang --- cabal-testsuite/Test/Cabal/Monad.hs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/cabal-testsuite/Test/Cabal/Monad.hs b/cabal-testsuite/Test/Cabal/Monad.hs index 46e85d60c1e..b4066d0a22b 100644 --- a/cabal-testsuite/Test/Cabal/Monad.hs +++ b/cabal-testsuite/Test/Cabal/Monad.hs @@ -152,16 +152,19 @@ unexpectedSuccessExitCode :: Int unexpectedSuccessExitCode = 66 setupAndCabalTest :: TestM () -> IO () -setupAndCabalTest m = runTestM $ do - env <- getTestEnv - have_cabal <- isAvailableProgram cabalProgram - skipIf (testSkipSetupTests env && not have_cabal) - when (not (testSkipSetupTests env)) $ do - liftIO $ putStrLn "Test with Setup:" - m - when have_cabal $ do - liftIO $ putStrLn "Test with cabal-install:" - withReaderT (\nenv -> nenv { testCabalInstallAsSetup = True }) m +setupAndCabalTest m = do + runTestM $ do + env <- getTestEnv + have_cabal <- isAvailableProgram cabalProgram + skipIf (testSkipSetupTests env && not have_cabal) + when (not (testSkipSetupTests env)) $ do + liftIO $ putStrLn "Test with Setup:" + m + runTestM $ do + have_cabal <- isAvailableProgram cabalProgram + when have_cabal $ do + liftIO $ putStrLn "Test with cabal-install:" + withReaderT (\nenv -> nenv { testCabalInstallAsSetup = True }) m setupTest :: TestM () -> IO () setupTest m = runTestM $ do From 99d0bdf7d2559462ef43bdead9b893a24666c1c4 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sun, 27 Nov 2016 01:21:45 -0800 Subject: [PATCH 53/56] Reuse packagedb in InternalLibraries/Executable/setup-static.test.hs Otherwise, ghc-pkg will complain that it's reinitializing the package database. Possibly there is some refactor to make withPackageDb more robust if it is called multiple times. Signed-off-by: Edward Z. Yang --- .../Executable/setup-static.test.hs | 64 ++++++++++--------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/cabal-testsuite/PackageTests/InternalLibraries/Executable/setup-static.test.hs b/cabal-testsuite/PackageTests/InternalLibraries/Executable/setup-static.test.hs index 46bff1b4f50..34fec34f3f4 100644 --- a/cabal-testsuite/PackageTests/InternalLibraries/Executable/setup-static.test.hs +++ b/cabal-testsuite/PackageTests/InternalLibraries/Executable/setup-static.test.hs @@ -18,34 +18,36 @@ import System.Directory -- don't get installed, so this test doesn't work on Windows.) main = setupAndCabalTest $ do skipUnless =<< hasSharedLibraries - forM_ [False, True] $ \is_dynamic -> withPackageDb $ do - setup_install $ [ if is_dynamic then "--enable-executable-dynamic" - else "--disable-executable-dynamic" - , "--enable-shared"] - dist_dir <- fmap testDistDir getTestEnv - lbi <- liftIO $ getPersistBuildConfig dist_dir - let pkg_descr = localPkgDescr lbi - compiler_id = compilerId (compiler lbi) - cname = CSubLibName $ mkUnqualComponentName "foo-internal" - [target] = componentNameTargets' pkg_descr lbi cname - uid = componentUnitId (targetCLBI target) - InstallDirs{libdir=dir,dynlibdir=dyndir} = - absoluteComponentInstallDirs pkg_descr lbi uid NoCopyDest - assertBool "interface files should be installed" - =<< liftIO (doesFileExist (dir "Foo.hi")) - assertBool "static library should be installed" - =<< liftIO (doesFileExist (dir mkLibName uid)) - if is_dynamic - then - assertBool "dynamic library MUST be installed" - =<< liftIO (doesFileExist (dyndir mkSharedLibName - compiler_id uid)) - else - assertBool "dynamic library should be installed" - =<< liftIO (doesFileExist (dyndir mkSharedLibName - compiler_id uid)) - fails $ ghcPkg "describe" ["foo"] - -- clean away the dist directory so that we catch accidental - -- dependence on the inplace files - setup "clean" [] - runInstalledExe' "foo" [] >>= assertOutputContains "46" + withPackageDb $ do + -- MULTI + forM_ [False, True] $ \is_dynamic -> do + setup_install $ [ if is_dynamic then "--enable-executable-dynamic" + else "--disable-executable-dynamic" + , "--enable-shared"] + dist_dir <- fmap testDistDir getTestEnv + lbi <- liftIO $ getPersistBuildConfig dist_dir + let pkg_descr = localPkgDescr lbi + compiler_id = compilerId (compiler lbi) + cname = CSubLibName $ mkUnqualComponentName "foo-internal" + [target] = componentNameTargets' pkg_descr lbi cname + uid = componentUnitId (targetCLBI target) + InstallDirs{libdir=dir,dynlibdir=dyndir} = + absoluteComponentInstallDirs pkg_descr lbi uid NoCopyDest + assertBool "interface files should be installed" + =<< liftIO (doesFileExist (dir "Foo.hi")) + assertBool "static library should be installed" + =<< liftIO (doesFileExist (dir mkLibName uid)) + if is_dynamic + then + assertBool "dynamic library MUST be installed" + =<< liftIO (doesFileExist (dyndir mkSharedLibName + compiler_id uid)) + else + assertBool "dynamic library should be installed" + =<< liftIO (doesFileExist (dyndir mkSharedLibName + compiler_id uid)) + fails $ ghcPkg "describe" ["foo"] + -- clean away the dist directory so that we catch accidental + -- dependence on the inplace files + setup "clean" [] + runInstalledExe' "foo" [] >>= assertOutputContains "46" From b43176572ae5b422aa44ae7b7c24f88da1ed18b3 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sun, 27 Nov 2016 01:59:39 -0800 Subject: [PATCH 54/56] Try harder not to runTestM twice when it can be avoided. This fixes some "permission denied" failures on Windows, but it would be a lot better to fix properly. See the comment in Test.Cabal.Monad for more details. Signed-off-by: Edward Z. Yang --- cabal-testsuite/Test/Cabal/Monad.hs | 31 +++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/cabal-testsuite/Test/Cabal/Monad.hs b/cabal-testsuite/Test/Cabal/Monad.hs index b4066d0a22b..9c566d05239 100644 --- a/cabal-testsuite/Test/Cabal/Monad.hs +++ b/cabal-testsuite/Test/Cabal/Monad.hs @@ -153,18 +153,37 @@ unexpectedSuccessExitCode = 66 setupAndCabalTest :: TestM () -> IO () setupAndCabalTest m = do - runTestM $ do + run_cabal <- runTestM $ do env <- getTestEnv have_cabal <- isAvailableProgram cabalProgram skipIf (testSkipSetupTests env && not have_cabal) - when (not (testSkipSetupTests env)) $ do + if not (testSkipSetupTests env) + then do liftIO $ putStrLn "Test with Setup:" m - runTestM $ do - have_cabal <- isAvailableProgram cabalProgram - when have_cabal $ do + return have_cabal + else do liftIO $ putStrLn "Test with cabal-install:" withReaderT (\nenv -> nenv { testCabalInstallAsSetup = True }) m + return False + -- NB: This code is written in a slightly convoluted way + -- so as to ensure that 'runTestM' is only called once if + -- we are running without cabal, or running with + -- @--skip-setup-tests@. This is important on Windows, + -- where the second invocation of 'runTestM' will blow + -- away our previous working dir, but it doesn't work + -- on Windows Server 2012 because someone still has + -- a handle on the directory (permission denied.) + -- + -- The CORRECT way to fix this problem is to allocate a + -- distinct working directory for setup versus Cabal. Would + -- nicely tie into to properly supporting "modes" as a thing + -- for test scripts (the idea is that a test script has a + -- number of modes which can be run separately as distinct + -- tests.) + when run_cabal $ do + liftIO $ putStrLn "Test with cabal-install:" + cabalTest m setupTest :: TestM () -> IO () setupTest m = runTestM $ do @@ -189,7 +208,7 @@ cabalProgram = (simpleProgram "cabal") { } -- | Run a test in the test monad according to program's arguments. -runTestM :: TestM () -> IO () +runTestM :: TestM a -> IO a runTestM m = do args <- execParser (info testArgParser mempty) let dist_dir = testArgDistDir args From ca6f056b26bb8613b9453e93496501645fec7a44 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sun, 27 Nov 2016 10:21:00 -0800 Subject: [PATCH 55/56] Split up OS X tests to get them under the time. Signed-off-by: Edward Z. Yang --- .travis.yml | 13 +++++++-- travis-script.sh | 76 +++++++++++++++++++++++++++--------------------- 2 files changed, 53 insertions(+), 36 deletions(-) diff --git a/.travis.yml b/.travis.yml index 770a53bccf8..877f22d6c61 100644 --- a/.travis.yml +++ b/.travis.yml @@ -56,15 +56,22 @@ matrix: # We axed GHC 7.6 and earlier because it's not worth the trouble to # make older GHC work with clang's cpp. See # https://ghc.haskell.org/trac/ghc/ticket/8493 - - env: GHCVER=7.8.4 SCRIPT=script + - env: GHCVER=7.8.4 SCRIPT=script CABAL_LIB_ONLY=YES os: osx osx_image: xcode6.4 # We need 10.10 + - env: GHCVER=7.8.4 SCRIPT=script CABAL_INSTALL_ONLY=YES + os: osx + osx_image: xcode6.4 # TODO: We might want to specify OSX version # https://docs.travis-ci.com/user/osx-ci-environment/#OS-X-Version - - env: GHCVER=7.10.3 SCRIPT=script + - env: GHCVER=7.10.3 SCRIPT=script CABAL_LIB_ONLY=YES + os: osx + - env: GHCVER=7.10.3 SCRIPT=script CABAL_INSTALL_ONLY=YES + os: osx + - env: GHCVER=8.0.1 SCRIPT=script CABAL_LIB_ONLY=YES os: osx - - env: GHCVER=8.0.1 SCRIPT=script + - env: GHCVER=8.0.1 SCRIPT=script CABAL_INSTALL_ONLY=YES os: osx - env: GHCVER=8.0.1 SCRIPT=bootstrap os: osx diff --git a/travis-script.sh b/travis-script.sh index b3e9cc01ea4..e836d2125f5 100755 --- a/travis-script.sh +++ b/travis-script.sh @@ -44,7 +44,7 @@ cp cabal.project.travis cabal.project.local # do it via new-build. See also cabal.project.travis. The downside of # doing it this way is that the build product cannot be cached, but # hackage-repo-tool is a relatively small package so it's good. -cabal unpack hackage-repo-tool-${HACKAGE_REPO_TOOL_VERSION} +timed cabal unpack hackage-repo-tool-${HACKAGE_REPO_TOOL_VERSION} # --------------------------------------------------------------------- # Cabal @@ -53,35 +53,39 @@ cabal unpack hackage-repo-tool-${HACKAGE_REPO_TOOL_VERSION} # Needed to work around some bugs in nix-local-build code. export CABAL_BUILDDIR="${CABAL_BDIR}" -# NB: Best to do everything for a single package together as it's -# more efficient (since new-build will uselessly try to rebuild -# Cabal otherwise). -if [ "x$PARSEC" = "xYES" ]; then - timed cabal new-build -fparsec Cabal Cabal:unit-tests Cabal:parser-tests Cabal:parser-hackage-tests -else - timed cabal new-build Cabal Cabal:unit-tests -fi +if [ "x$CABAL_INSTALL_ONLY" != "xYES" ] ; then + # We're doing a full build and test of Cabal -# NB: the '|| exit $?' workaround is required on old broken versions of bash -# that ship with OS X. See https://github.com/haskell/cabal/pull/3624 and -# http://stackoverflow.com/questions/14970663/why-doesnt-bash-flag-e-exit-when-a-subshell-fails + # NB: Best to do everything for a single package together as it's + # more efficient (since new-build will uselessly try to rebuild + # Cabal otherwise). + if [ "x$PARSEC" = "xYES" ]; then + timed cabal new-build -fparsec Cabal Cabal:unit-tests Cabal:parser-tests Cabal:parser-hackage-tests + else + timed cabal new-build Cabal Cabal:unit-tests + fi -# Run tests -(cd Cabal && timed ${CABAL_BDIR}/build/unit-tests/unit-tests $TEST_OPTIONS) || exit $? + # NB: the '|| exit $?' workaround is required on old broken versions of bash + # that ship with OS X. See https://github.com/haskell/cabal/pull/3624 and + # http://stackoverflow.com/questions/14970663/why-doesnt-bash-flag-e-exit-when-a-subshell-fails -if [ "x$PARSEC" = "xYES" ]; then - # Parser unit tests - (cd Cabal && timed ${CABAL_BDIR}/build/parser-tests/parser-tests $TEST_OPTIONS) || exit $? + # Run tests + (cd Cabal && timed ${CABAL_BDIR}/build/unit-tests/unit-tests $TEST_OPTIONS) || exit $? - # Test we can parse Hackage - (cd Cabal && timed ${CABAL_BDIR}/build/parser-tests/parser-hackage-tests $TEST_OPTIONS) | tail || exit $? -fi + if [ "x$PARSEC" = "xYES" ]; then + # Parser unit tests + (cd Cabal && timed ${CABAL_BDIR}/build/parser-tests/parser-tests $TEST_OPTIONS) || exit $? -# Run haddock -(cd Cabal && timed cabal act-as-setup --build-type=Simple -- haddock --builddir=${CABAL_BDIR}) || exit $? + # Test we can parse Hackage + (cd Cabal && timed ${CABAL_BDIR}/build/parser-tests/parser-hackage-tests $TEST_OPTIONS) | tail || exit $? + fi -# Check for package warnings -(cd Cabal && timed cabal check) || exit $? + # Run haddock + (cd Cabal && timed cabal act-as-setup --build-type=Simple -- haddock --builddir=${CABAL_BDIR}) || exit $? + + # Check for package warnings + (cd Cabal && timed cabal check) || exit $? +fi unset CABAL_BUILDDIR @@ -89,18 +93,24 @@ unset CABAL_BUILDDIR export CABAL_BUILDDIR="${CABAL_TESTSUITE_BDIR}" +# NB: We always build this test runner, because it is used +# both by Cabal and cabal-install timed cabal new-build cabal-testsuite:cabal-tests -(cd cabal-testsuite && timed ${CABAL_TESTSUITE_BDIR}/build/cabal-tests/cabal-tests -j3 $TEST_OPTIONS) || exit $? +if [ "x$CABAL_INSTALL_ONLY" != "xYES" ] ; then + # We're doing a full build and test of Cabal + + (cd cabal-testsuite && timed ${CABAL_TESTSUITE_BDIR}/build/cabal-tests/cabal-tests -j3 $TEST_OPTIONS) || exit $? -# Redo the package tests with different versions of GHC -if [ "x$TEST_OTHER_VERSIONS" = "xYES" ]; then - (export CABAL_PACKAGETESTS_WITH_GHC="/opt/ghc/7.0.4/bin/ghc"; \ - cd cabal-testsuite && timed ${CABAL_TESTSUITE_BDIR}/build/cabal-tests/cabal-tests $TEST_OPTIONS) - (export CABAL_PACKAGETESTS_WITH_GHC="/opt/ghc/7.2.2/bin/ghc"; \ - cd cabal-testsuite && timed ${CABAL_TESTSUITE_BDIR}/build/cabal-tests/cabal-tests $TEST_OPTIONS) - (export CABAL_PACKAGETESTS_WITH_GHC="/opt/ghc/head/bin/ghc"; \ - cd cabal-testsuite && timed ${CABAL_TESTSUITE_BDIR}/build/cabal-tests/cabal-tests $TEST_OPTIONS) + # Redo the package tests with different versions of GHC + if [ "x$TEST_OTHER_VERSIONS" = "xYES" ]; then + (export CABAL_PACKAGETESTS_WITH_GHC="/opt/ghc/7.0.4/bin/ghc"; \ + cd cabal-testsuite && timed ${CABAL_TESTSUITE_BDIR}/build/cabal-tests/cabal-tests $TEST_OPTIONS) + (export CABAL_PACKAGETESTS_WITH_GHC="/opt/ghc/7.2.2/bin/ghc"; \ + cd cabal-testsuite && timed ${CABAL_TESTSUITE_BDIR}/build/cabal-tests/cabal-tests $TEST_OPTIONS) + (export CABAL_PACKAGETESTS_WITH_GHC="/opt/ghc/head/bin/ghc"; \ + cd cabal-testsuite && timed ${CABAL_TESTSUITE_BDIR}/build/cabal-tests/cabal-tests $TEST_OPTIONS) + fi fi unset CABAL_BUILDDIR From b1a5ae87c80f6fc426f0ecaca2256a8524ac93e2 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sun, 27 Nov 2016 11:46:40 -0800 Subject: [PATCH 56/56] 8.0.1 builds are bumping limit, so move TEST_OTHER_VERSIONS to 7.4.2 Signed-off-by: Edward Z. Yang --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 877f22d6c61..a3aef02982d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,7 +24,7 @@ matrix: sudo: required # These don't have -dyn/-prof whitelisted yet, so we have to # do the old-style installation - - env: GHCVER=7.4.2 SCRIPT=script CABAL_LIB_ONLY=YES + - env: GHCVER=7.4.2 SCRIPT=script CABAL_LIB_ONLY=YES TEST_OTHER_VERSIONS=YES os: linux sudo: required - env: GHCVER=7.6.3 SCRIPT=script @@ -40,13 +40,13 @@ matrix: - env: GHCVER=7.10.3 SCRIPT=script os: linux sudo: required - - env: GHCVER=8.0.1 SCRIPT=script DEPLOY_DOCS=YES TEST_OTHER_VERSIONS=YES + - env: GHCVER=8.0.1 SCRIPT=script DEPLOY_DOCS=YES sudo: required os: linux - env: GHCVER=8.0.1 SCRIPT=solver-debug-flags sudo: required os: linux - - env: GHCVER=8.0.1 SCRIPT=script PARSEC=YES TEST_OTHER_VERSIONS=YES + - env: GHCVER=8.0.1 SCRIPT=script PARSEC=YES os: linux sudo: required - env: GHCVER=8.0.1 SCRIPT=bootstrap