Commit 0d83e52c authored by Mikhail Glushenkov's avatar Mikhail Glushenkov
Browse files

Merge pull request #2087 from benarmston/improve-cabal-install-tests

Improve cabal install tests
parents 430e852e 76e52c75
......@@ -46,9 +46,10 @@ script:
- cd ../cabal-install
- cabal sandbox init
- cabal sandbox add-source ../Cabal
- cabal install --dependencies-only
- cabal configure
- cabal install --dependencies-only --enable-tests
- cabal configure --enable-tests
- cabal build
- cabal test
- cabal check
- cabal sdist
- install_from_tarball
......
......@@ -8,7 +8,10 @@ module Main
-- Modules from Cabal.
import Distribution.Simple.Program.Builtin (ghcPkgProgram)
import Distribution.Simple.Program.Db (defaultProgramDb, requireProgram)
import Distribution.Simple.Program.Db
(defaultProgramDb, requireProgram, setProgramSearchPath)
import Distribution.Simple.Program.Find
(ProgramSearchPathEntry(ProgramSearchPathDir), defaultProgramSearchPath)
import Distribution.Simple.Program.Types
( Program(..), simpleProgram, programPath)
import Distribution.Simple.Utils ( findProgramVersion )
......@@ -16,7 +19,8 @@ import Distribution.Verbosity (normal)
-- Third party modules.
import qualified Control.Exception.Extensible as E
import System.Directory (getCurrentDirectory, setCurrentDirectory)
import System.Directory
(canonicalizePath, getCurrentDirectory, setCurrentDirectory)
import Test.Framework (Test, defaultMain, testGroup)
-- Modules containing the tests.
......@@ -38,10 +42,14 @@ cabalProgram = (simpleProgram "cabal") {
main :: IO ()
main = do
(cabal, _) <- requireProgram normal cabalProgram defaultProgramDb
(ghcPkg, _) <- requireProgram normal ghcPkgProgram defaultProgramDb
buildDir <- canonicalizePath "dist/build/cabal"
let programSearchPath = ProgramSearchPathDir buildDir : defaultProgramSearchPath
(cabal, _) <- requireProgram normal cabalProgram
(setProgramSearchPath programSearchPath defaultProgramDb)
let cabalPath = programPath cabal
ghcPkgPath = programPath ghcPkg
(ghcPkg, _) <- requireProgram normal ghcPkgProgram defaultProgramDb
let ghcPkgPath = programPath ghcPkg
putStrLn $ "Using cabal: " ++ cabalPath
putStrLn $ "Using ghc-pkg: " ++ ghcPkgPath
cwd <- getCurrentDirectory
......
......@@ -9,8 +9,11 @@ import Test.Framework as TF (Test)
import Test.Framework.Providers.HUnit (testCase)
import Test.HUnit (assertBool)
import Control.Applicative ((<$>))
import Control.Monad (when)
import Data.List (intercalate, isInfixOf)
import System.FilePath ((</>))
import System.Directory (getDirectoryContents)
dir :: FilePath
dir = "PackageTests" </> "Exec"
......@@ -46,11 +49,9 @@ tests cabalPath ghcPkgPath =
-- executable cannot be found. Creating a new sandbox. Installing
-- the executable and checking it can be run.
assertCleanSucceeded =<< cabal_clean dir [] cabalPath
assertSandboxSucceeded =<< cabal_sandbox dir ["delete"] cabalPath
cleanPreviousBuilds cabalPath
assertMyExecutableNotFound cabalPath
assertSandboxSucceeded =<< cabal_sandbox dir ["init"] cabalPath
assertInstallSucceeded =<< cabal_install dir [] cabalPath
assertPackageInstall cabalPath
result <- cabal_exec dir ["my-executable"] cabalPath
assertExecSucceeded result
......@@ -61,11 +62,9 @@ tests cabalPath ghcPkgPath =
expected `isInfixOf` (intercalate " " . lines $ output)
, testCase "adds the sandbox bin directory to the PATH" $ do
assertCleanSucceeded =<< cabal_clean dir [] cabalPath
assertSandboxSucceeded =<< cabal_sandbox dir ["delete"] cabalPath
cleanPreviousBuilds cabalPath
assertMyExecutableNotFound cabalPath
assertSandboxSucceeded =<< cabal_sandbox dir ["init"] cabalPath
assertInstallSucceeded =<< cabal_install dir [] cabalPath
assertPackageInstall cabalPath
result <- cabal_exec dir ["bash", "--", "-c", "my-executable"] cabalPath
assertExecSucceeded result
......@@ -78,10 +77,8 @@ tests cabalPath ghcPkgPath =
, testCase "configures GHC to use the sandbox" $ do
let libNameAndVersion = "my-0.1"
assertCleanSucceeded =<< cabal_clean dir [] cabalPath
assertSandboxSucceeded =<< cabal_sandbox dir ["delete"] cabalPath
assertSandboxSucceeded =<< cabal_sandbox dir ["init"] cabalPath
assertInstallSucceeded =<< cabal_install dir [] cabalPath
cleanPreviousBuilds cabalPath
assertPackageInstall cabalPath
assertMyLibIsNotAvailableOutsideofSandbox ghcPkgPath libNameAndVersion
......@@ -98,6 +95,20 @@ tests cabalPath ghcPkgPath =
]
cleanPreviousBuilds :: FilePath -> IO ()
cleanPreviousBuilds cabalPath = do
sandboxExists <- not . null . filter (== "cabal.sandbox.config") <$>
getDirectoryContents dir
assertCleanSucceeded =<< cabal_clean dir [] cabalPath
when sandboxExists $ do
assertSandboxSucceeded =<< cabal_sandbox dir ["delete"] cabalPath
assertPackageInstall :: FilePath -> IO ()
assertPackageInstall cabalPath = do
assertSandboxSucceeded =<< cabal_sandbox dir ["init"] cabalPath
assertInstallSucceeded =<< cabal_install dir [] cabalPath
assertMyExecutableNotFound :: FilePath -> IO ()
assertMyExecutableNotFound cabalPath = do
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment