From c812e17792d0c99d0a4d651ab7ccc9e302547bb1 Mon Sep 17 00:00:00 2001 From: Johan Tibell <johan.tibell@gmail.com> Date: Wed, 26 Sep 2012 14:53:56 +0200 Subject: [PATCH] Fix test output of even more tests --- .../BuildDeps/InternalLibrary0/Check.hs | 15 ++++------- .../BuildDeps/InternalLibrary1/Check.hs | 6 +---- .../BuildDeps/InternalLibrary2/Check.hs | 12 ++------- .../BuildDeps/InternalLibrary3/Check.hs | 12 ++------- .../BuildDeps/InternalLibrary4/Check.hs | 12 ++------- Cabal/tests/PackageTests/PackageTester.hs | 25 ++++++++++++++++++- 6 files changed, 36 insertions(+), 46 deletions(-) diff --git a/Cabal/tests/PackageTests/BuildDeps/InternalLibrary0/Check.hs b/Cabal/tests/PackageTests/BuildDeps/InternalLibrary0/Check.hs index eddc994434..059ebf301f 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 86d378e069..4c885694f1 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 b10dfd9c14..d631987503 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 605b3f2008..67ced0575a 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 ef5a5c7141..331e592ce3 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 f4aef62d4a..bfbe421d75 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 -- GitLab