Skip to content

Commit 4074c89

Browse files
committed
testsuite: Supress stderr when running integration tests
This fixes a problem where test output was leaking into GitHub Actions results (#8419), making the output unnecessarily verbose and harder to read. This makes the test output much cleaner while still preserving all the diagnostic information when tests fail. Fixes #8419
1 parent d4d92e9 commit 4074c89

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

cabal-install/cabal-install.cabal

+2
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,8 @@ test-suite integration-tests2
425425
, process
426426
, tasty >= 1.2.3 && <1.6
427427
, tasty-hunit >= 0.10
428+
, tasty-expected-failure
429+
, silently
428430
, tagged
429431

430432
test-suite long-tests

cabal-install/tests/IntegrationTests2.hs

+26-4
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,13 @@ import System.Process (callProcess)
8989

9090
import Data.Tagged (Tagged (..))
9191
import Test.Tasty
92-
import Test.Tasty.HUnit
92+
import qualified Test.Tasty.HUnit as T ( testCase )
93+
import Test.Tasty.HUnit hiding ( testCase )
9394
import Test.Tasty.Options
95+
import Test.Tasty.Runners
96+
import Test.Tasty.ExpectedFailure
97+
98+
import System.IO.Silently
9499

95100
import qualified Data.ByteString as BS
96101
import Data.Maybe (fromJust)
@@ -113,11 +118,28 @@ main = do
113118
defaultMainWithIngredients
114119
(defaultIngredients ++ [includingOptions projectConfigOptionDescriptions])
115120
( withProjectConfig $ \config ->
116-
testGroup
117-
"Integration tests (internal)"
118-
(tests config)
121+
testGroup
122+
"Integration tests (internal)"
123+
(tests config)
119124
)
120125

126+
-- Tests are run silently, unless they fail. Firstly because it is annoying to
127+
-- see lots of stderr from your unit tests. Secondly becaus this output
128+
-- leaks into the result of github actions (#8419)
129+
silentTest :: TestTree -> TestTree
130+
silentTest = wrapTest silentHelper
131+
where
132+
silentHelper t = do
133+
(out, res) <- hCapture [stderr] t
134+
135+
return $ if not (resultSuccessful res)
136+
then res { resultDescription = resultDescription res <> "\nCaptured output:\n" <> out }
137+
else res
138+
139+
testCase :: String -> Assertion -> TestTree
140+
testCase desc action = silentTest (T.testCase desc action)
141+
142+
121143
tests :: ProjectConfig -> [TestTree]
122144
tests config =
123145
-- TODO: tests for:

0 commit comments

Comments
 (0)