Commit 4b364b93 authored by barmston's avatar barmston
Browse files

Exec tests no longer fail if there isn't a sandbox

The tests which delete the sandbox, now check for its existence before
deleting it. This prevents erroneous test failures when the tests are first
run or any time that the sandbox has been deleted.
parent 430e852e
......@@ -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