Skip to content

Commit cac6174

Browse files
mpickeringMikolaj
authored andcommitted
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. Also force the test to run sequentially, they fail if you try to run them concurrently. I think that there are probably issues to do with setting the working directory when using cabal-install as a library. Fixes #8419
1 parent 703582f commit cac6174

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

cabal-install/cabal-install.cabal

+3-1
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,10 @@ test-suite integration-tests2
423423
, directory
424424
, filepath
425425
, process
426-
, tasty >= 1.2.3 && <1.6
426+
, tasty >= 1.5 && <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

+36-10
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 Test.Tasty.ExpectedFailure
93+
import Test.Tasty.HUnit hiding (testCase)
94+
import qualified Test.Tasty.HUnit as T (testCase)
9395
import Test.Tasty.Options
96+
import Test.Tasty.Runners
97+
98+
import System.IO.Silently
9499

95100
import qualified Data.ByteString as BS
96101
import Data.Maybe (fromJust)
@@ -112,23 +117,43 @@ main = do
112117
callProcess "cabal" ["update"]
113118
defaultMainWithIngredients
114119
(defaultIngredients ++ [includingOptions projectConfigOptionDescriptions])
115-
( withProjectConfig $ \config ->
116-
testGroup
120+
( localOption (NumThreads 1) $ withProjectConfig $ \config ->
121+
sequentialTestGroup
117122
"Integration tests (internal)"
123+
AllFinish
118124
(tests config)
119125
)
120126

127+
-- Tests are run silently, unless they fail. Firstly because it is annoying to
128+
-- see lots of stderr from your unit tests. Secondly because this output
129+
-- leaks into the result of github actions (#8419)
130+
--
131+
-- Note that this capture is safe to use as the testsuite runs sequentially.
132+
silentTest :: TestTree -> TestTree
133+
silentTest = wrapTest silentHelper
134+
where
135+
silentHelper t = do
136+
(out, res) <- hCapture [stderr] t
137+
138+
return $
139+
if not (resultSuccessful res)
140+
then res{resultDescription = resultDescription res <> "\nCaptured output:\n" <> out}
141+
else res
142+
143+
testCase :: String -> Assertion -> TestTree
144+
testCase desc action = (T.testCase desc action)
145+
121146
tests :: ProjectConfig -> [TestTree]
122147
tests config =
123148
-- TODO: tests for:
124149
-- \* normal success
125150
-- \* dry-run tests with changes
126-
[ testGroup "Discovery and planning" $
151+
[ sequentialTestGroup "Discovery and planning" AllFinish $
127152
[ testCase "no package" (testExceptionInFindingPackage config)
128153
, testCase "no package2" (testExceptionInFindingPackage2 config)
129154
, testCase "proj conf1" (testExceptionInProjectConfig config)
130155
]
131-
, testGroup "Target selectors" $
156+
, sequentialTestGroup "Target selectors" AllFinish $
132157
[ testCaseSteps "valid" testTargetSelectors
133158
, testCase "bad syntax" testTargetSelectorBadSyntax
134159
, testCaseSteps "ambiguous syntax" testTargetSelectorAmbiguous
@@ -145,7 +170,7 @@ tests config =
145170
, testCaseSteps "problems (bench)" (testTargetProblemsBench config)
146171
, testCaseSteps "problems (haddock)" (testTargetProblemsHaddock config)
147172
]
148-
, testGroup "Exceptions during building (local inplace)" $
173+
, sequentialTestGroup "Exceptions during building (local inplace)" AllFinish $
149174
[ testCase "configure" (testExceptionInConfigureStep config)
150175
, testCase "build" (testExceptionInBuildStep config)
151176
-- , testCase "register" testExceptionInRegisterStep
@@ -154,7 +179,7 @@ tests config =
154179
-- TODO: need to check we can build sub-libs, foreign libs and exes
155180
-- components for non-local packages / packages in the store.
156181

157-
testGroup "Successful builds" $
182+
sequentialTestGroup "Successful builds" AllFinish $
158183
[ testCaseSteps "Setup script styles" (testSetupScriptStyles config)
159184
, testCase "keep-going" (testBuildKeepGoing config)
160185
]
@@ -164,19 +189,20 @@ tests config =
164189
else
165190
[ testCase "local tarball" (testBuildLocalTarball config)
166191
]
167-
, testGroup "Regression tests" $
192+
, sequentialTestGroup "Regression tests" AllFinish $
168193
[ testCase "issue #3324" (testRegressionIssue3324 config)
169194
, testCase "program options scope all" (testProgramOptionsAll config)
170195
, testCase "program options scope local" (testProgramOptionsLocal config)
171196
, testCase "program options scope specific" (testProgramOptionsSpecific config)
172197
]
173-
, testGroup "Flag tests" $
198+
, sequentialTestGroup "Flag tests" AllFinish $
174199
[ testCase "Test Nix Flag" testNixFlags
175200
, testCase "Test Config options for commented options" testConfigOptionComments
176201
, testCase "Test Ignore Project Flag" testIgnoreProjectFlag
177202
]
178-
, testGroup
203+
, sequentialTestGroup
179204
"haddock-project"
205+
AllFinish
180206
[ testCase "dependencies" (testHaddockProjectDependencies config)
181207
]
182208
]

0 commit comments

Comments
 (0)