diff --git a/Cabal/tests/PackageTests/BuildDeps/InternalLibrary0/Check.hs b/Cabal/tests/PackageTests/BuildDeps/InternalLibrary0/Check.hs index eddc994434356ea489a14d48b389f2f2c7fc615e..059ebf301f386094391ef07a2c8572622d8af0c6 100644 --- a/Cabal/tests/PackageTests/BuildDeps/InternalLibrary0/Check.hs +++ b/Cabal/tests/PackageTests/BuildDeps/InternalLibrary0/Check.hs @@ -14,13 +14,8 @@ suite :: Version -> Test suite cabalVersion = TestCase $ do let spec = PackageSpec ("PackageTests" </> "BuildDeps" </> "InternalLibrary0") [] result <- cabal_build spec - do - assertEqual "cabal build should fail" False (successful result) - when (cabalVersion >= Version [1, 7] []) $ do - let sb = "library which is defined within the same package." - -- In 1.7 it should tell you how to enable the desired behaviour. - assertEqual ("cabal output should say "++show sb) True $ - sb `isInfixOf` (intercalate " " $ lines $ outputText result) - `catch` \exc -> do - putStrLn $ "Cabal result was "++show result - throwIO (exc :: SomeException) + assertBuildFailed result + when (cabalVersion >= Version [1, 7] []) $ do + let sb = "library which is defined within the same package." + -- In 1.7 it should tell you how to enable the desired behaviour. + assertOutputContains sb result diff --git a/Cabal/tests/PackageTests/BuildDeps/InternalLibrary1/Check.hs b/Cabal/tests/PackageTests/BuildDeps/InternalLibrary1/Check.hs index 86d378e069cf2eb83261d7f6b04a01a1cece0e24..4c885694f1633954c82dae9da7cd473a84927d75 100644 --- a/Cabal/tests/PackageTests/BuildDeps/InternalLibrary1/Check.hs +++ b/Cabal/tests/PackageTests/BuildDeps/InternalLibrary1/Check.hs @@ -11,8 +11,4 @@ suite :: Test suite = TestCase $ do let spec = PackageSpec ("PackageTests" </> "BuildDeps" </> "InternalLibrary1") [] result <- cabal_build spec - do - assertEqual "cabal build should succeed - see test-log.txt" True (successful result) - `catch` \exc -> do - putStrLn $ "Cabal result was "++show result - throwIO (exc :: SomeException) + assertBuildSucceeded result diff --git a/Cabal/tests/PackageTests/BuildDeps/InternalLibrary2/Check.hs b/Cabal/tests/PackageTests/BuildDeps/InternalLibrary2/Check.hs index b10dfd9c1499896d201c1776bc8bdd4d0446eba7..d6319875037bffe37440533888322e3dd3602155 100644 --- a/Cabal/tests/PackageTests/BuildDeps/InternalLibrary2/Check.hs +++ b/Cabal/tests/PackageTests/BuildDeps/InternalLibrary2/Check.hs @@ -15,17 +15,9 @@ suite = TestCase $ do unregister "InternalLibrary2" iResult <- cabal_install specTI - do - assertEqual "cabal install should succeed" True (successful iResult) - `catch` \exc -> do - putStrLn $ "Cabal result was "++show iResult - throwIO (exc :: SomeException) + assertInstallSucceeded iResult bResult <- cabal_build spec - do - assertEqual "cabal build should succeed" True (successful bResult) - `catch` \exc -> do - putStrLn $ "Cabal result was "++show bResult - throwIO (exc :: SomeException) + assertBuildSucceeded bResult unregister "InternalLibrary2" (_, _, output) <- run (Just $ directory spec) "dist/build/lemon/lemon" [] diff --git a/Cabal/tests/PackageTests/BuildDeps/InternalLibrary3/Check.hs b/Cabal/tests/PackageTests/BuildDeps/InternalLibrary3/Check.hs index 605b3f20085cd7a36b7c032a73c227f07248b5cf..67ced0575afe987d80f8e47008b25daa712a2590 100644 --- a/Cabal/tests/PackageTests/BuildDeps/InternalLibrary3/Check.hs +++ b/Cabal/tests/PackageTests/BuildDeps/InternalLibrary3/Check.hs @@ -15,17 +15,9 @@ suite = TestCase $ do unregister "InternalLibrary3" iResult <- cabal_install specTI - do - assertEqual "cabal install should succeed - see to-install/test-log.txt" True (successful iResult) - `catch` \exc -> do - putStrLn $ "Cabal result was "++show iResult - throwIO (exc :: SomeException) + assertInstallSucceeded iResult bResult <- cabal_build spec - do - assertEqual "cabal build should succeed - see test-log.txt" True (successful bResult) - `catch` \exc -> do - putStrLn $ "Cabal result was "++show bResult - throwIO (exc :: SomeException) + assertBuildSucceeded bResult unregister "InternalLibrary3" (_, _, output) <- run (Just $ directory spec) "dist/build/lemon/lemon" [] diff --git a/Cabal/tests/PackageTests/BuildDeps/InternalLibrary4/Check.hs b/Cabal/tests/PackageTests/BuildDeps/InternalLibrary4/Check.hs index ef5a5c714191eb791ce7d41b3442b6c5f7578add..331e592ce3e3de94f3f0d34a49a0221038a9da5f 100644 --- a/Cabal/tests/PackageTests/BuildDeps/InternalLibrary4/Check.hs +++ b/Cabal/tests/PackageTests/BuildDeps/InternalLibrary4/Check.hs @@ -15,17 +15,9 @@ suite = TestCase $ do unregister "InternalLibrary4" iResult <- cabal_install specTI - do - assertEqual "cabal install should succeed - see to-install/test-log.txt" True (successful iResult) - `catch` \exc -> do - putStrLn $ "Cabal result was "++show iResult - throwIO (exc :: SomeException) + assertInstallSucceeded iResult bResult <- cabal_build spec - do - assertEqual "cabal build should succeed - see test-log.txt" True (successful bResult) - `catch` \exc -> do - putStrLn $ "Cabal result was "++show bResult - throwIO (exc :: SomeException) + assertBuildSucceeded bResult unregister "InternalLibrary4" (_, _, output) <- run (Just $ directory spec) "dist/build/lemon/lemon" [] diff --git a/Cabal/tests/PackageTests/PackageTester.hs b/Cabal/tests/PackageTests/PackageTester.hs index f4aef62d4a054bd5d86e4a3d68468150cb083787..bfbe421d75c5b6884fc41eff8135d03f1b7db052 100644 --- a/Cabal/tests/PackageTests/PackageTester.hs +++ b/Cabal/tests/PackageTests/PackageTester.hs @@ -10,7 +10,10 @@ module PackageTests.PackageTester ( unregister, run, assertBuildSucceeded, - assertTestSucceeded + assertBuildFailed, + assertTestSucceeded, + assertInstallSucceeded, + assertOutputContains ) where import qualified Control.Exception.Extensible as E @@ -188,8 +191,28 @@ assertBuildSucceeded result = unless (successful result) $ "expected: \'setup build\' should succeed\n" ++ " output: " ++ outputText result +assertBuildFailed :: Result -> Assertion +assertBuildFailed result = when (successful result) $ + assertFailure $ + "expected: \'setup build\' should fail\n" ++ + " output: " ++ outputText result + assertTestSucceeded :: Result -> Assertion assertTestSucceeded result = unless (successful result) $ assertFailure $ "expected: \'setup test\' should succeed\n" ++ " output: " ++ outputText result + +assertInstallSucceeded :: Result -> Assertion +assertInstallSucceeded result = unless (successful result) $ + assertFailure $ + "expected: \'setup install\' should succeed\n" ++ + " output: " ++ outputText result + +assertOutputContains :: String -> Result -> Assertion +assertOutputContains needle result = + unless (needle `isInfixOf` (intercalate " " $ lines output)) $ + assertFailure $ + " expected: " ++ needle ++ + "in output: " ++ output + where output = outputText result