Skip to content

testsuite: Supress stderr when running integration tests #10837

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cabal-install/cabal-install.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,10 @@ test-suite integration-tests2
, directory
, filepath
, process
, tasty >= 1.2.3 && <1.6
, tasty >= 1.5 && <1.6
, tasty-hunit >= 0.10
, tasty-expected-failure
, silently
, tagged

test-suite long-tests
Expand Down
46 changes: 36 additions & 10 deletions cabal-install/tests/IntegrationTests2.hs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,13 @@ import System.Process (callProcess)

import Data.Tagged (Tagged (..))
import Test.Tasty
import Test.Tasty.HUnit
import Test.Tasty.ExpectedFailure
import Test.Tasty.HUnit hiding (testCase)
import qualified Test.Tasty.HUnit as T (testCase)
import Test.Tasty.Options
import Test.Tasty.Runners

import System.IO.Silently

import qualified Data.ByteString as BS
import Data.Maybe (fromJust)
Expand All @@ -112,23 +117,43 @@ main = do
callProcess "cabal" ["update"]
defaultMainWithIngredients
(defaultIngredients ++ [includingOptions projectConfigOptionDescriptions])
( withProjectConfig $ \config ->
testGroup
( localOption (NumThreads 1) $ withProjectConfig $ \config ->
sequentialTestGroup
"Integration tests (internal)"
AllFinish
(tests config)
)

-- Tests are run silently, unless they fail. Firstly because it is annoying to
-- see lots of stderr from your unit tests. Secondly because this output
-- leaks into the result of github actions (#8419)
--
-- Note that this capture is safe to use as the testsuite runs sequentially.
silentTest :: TestTree -> TestTree
silentTest = wrapTest silentHelper
where
silentHelper t = do
(out, res) <- hCapture [stderr] t

return $
if not (resultSuccessful res)
then res{resultDescription = resultDescription res <> "\nCaptured output:\n" <> out}
else res

testCase :: String -> Assertion -> TestTree
testCase desc action = (T.testCase desc action)

tests :: ProjectConfig -> [TestTree]
tests config =
-- TODO: tests for:
-- \* normal success
-- \* dry-run tests with changes
[ testGroup "Discovery and planning" $
[ sequentialTestGroup "Discovery and planning" AllFinish $
[ testCase "no package" (testExceptionInFindingPackage config)
, testCase "no package2" (testExceptionInFindingPackage2 config)
, testCase "proj conf1" (testExceptionInProjectConfig config)
]
, testGroup "Target selectors" $
, sequentialTestGroup "Target selectors" AllFinish $
[ testCaseSteps "valid" testTargetSelectors
, testCase "bad syntax" testTargetSelectorBadSyntax
, testCaseSteps "ambiguous syntax" testTargetSelectorAmbiguous
Expand All @@ -145,7 +170,7 @@ tests config =
, testCaseSteps "problems (bench)" (testTargetProblemsBench config)
, testCaseSteps "problems (haddock)" (testTargetProblemsHaddock config)
]
, testGroup "Exceptions during building (local inplace)" $
, sequentialTestGroup "Exceptions during building (local inplace)" AllFinish $
[ testCase "configure" (testExceptionInConfigureStep config)
, testCase "build" (testExceptionInBuildStep config)
-- , testCase "register" testExceptionInRegisterStep
Expand All @@ -154,7 +179,7 @@ tests config =
-- TODO: need to check we can build sub-libs, foreign libs and exes
-- components for non-local packages / packages in the store.

testGroup "Successful builds" $
sequentialTestGroup "Successful builds" AllFinish $
[ testCaseSteps "Setup script styles" (testSetupScriptStyles config)
, testCase "keep-going" (testBuildKeepGoing config)
]
Expand All @@ -164,19 +189,20 @@ tests config =
else
[ testCase "local tarball" (testBuildLocalTarball config)
]
, testGroup "Regression tests" $
, sequentialTestGroup "Regression tests" AllFinish $
[ testCase "issue #3324" (testRegressionIssue3324 config)
, testCase "program options scope all" (testProgramOptionsAll config)
, testCase "program options scope local" (testProgramOptionsLocal config)
, testCase "program options scope specific" (testProgramOptionsSpecific config)
]
, testGroup "Flag tests" $
, sequentialTestGroup "Flag tests" AllFinish $
[ testCase "Test Nix Flag" testNixFlags
, testCase "Test Config options for commented options" testConfigOptionComments
, testCase "Test Ignore Project Flag" testIgnoreProjectFlag
]
, testGroup
, sequentialTestGroup
"haddock-project"
AllFinish
[ testCase "dependencies" (testHaddockProjectDependencies config)
]
]
Expand Down
Loading