@@ -21,6 +21,8 @@ module Test.Hls.Util
21
21
, knownBrokenForGhcVersions
22
22
, knownBrokenInEnv
23
23
, onlyWorkForGhcVersions
24
+ , knownFlakyInEnv
25
+ , knownFlaky
24
26
-- * Extract code actions
25
27
, fromAction
26
28
, fromCommand
@@ -71,9 +73,11 @@ import System.IO.Temp
71
73
import System.Time.Extra (Seconds , sleep )
72
74
import Test.Tasty (TestTree )
73
75
import Test.Tasty.ExpectedFailure (expectFailBecause ,
74
- ignoreTestBecause )
76
+ ignoreTestBecause , wrapTest )
75
77
import Test.Tasty.HUnit (Assertion , assertFailure ,
76
78
(@?=) )
79
+ import Test.Tasty.Runners (Result (.. ), resultSuccessful )
80
+ import qualified Test.Tasty.Runners as Runners
77
81
78
82
noLiteralCaps :: C. ClientCapabilities
79
83
noLiteralCaps = def & textDocument ?~ textDocumentCaps
@@ -143,6 +147,57 @@ onlyRunForGhcVersions vers =
143
147
then const id
144
148
else ignoreTestBecause
145
149
150
+ -- | Mark test as flaky for a specific target.
151
+ -- This runs the test, but its result does not matter for the test suite.
152
+ --
153
+ -- We define a test as flaky if it is fundamentally correct, but
154
+ -- fails occasionally due to lsp-test shenanigans. In particular, when the
155
+ -- test times out *sometimes*, but not always.
156
+ --
157
+ -- A flaky test is a bug, which we are only not fixing right away
158
+ -- because it might be difficult to fix with lsp-test.
159
+ -- If your test isn't using lsp-test, then using this function
160
+ -- is not permitted.
161
+ knownFlakyInEnv :: [EnvSpec ] -> String -> TestTree -> TestTree
162
+ knownFlakyInEnv envSpecs reason
163
+ | any matchesCurrentEnv envSpecs = knownFlakyBecause reason
164
+ | otherwise = id
165
+
166
+ -- | Mark test as flaky for all supported GHC versions.
167
+ -- This runs the test, but its result does not matter for the test suite.
168
+ --
169
+ -- We define a test as flaky if it is fundamentally correct, but
170
+ -- fails occasionally due to lsp-test shenanigans. In particular, when the
171
+ -- test times out *sometimes*, but not always.
172
+ --
173
+ -- A flaky test is a bug, which we are only not fixing right away
174
+ -- because it might be difficult to fix with lsp-test.
175
+ -- If your test isn't using lsp-test, then using this function
176
+ -- is not permitted.
177
+ knownFlaky :: String -> TestTree -> TestTree
178
+ knownFlaky = knownFlakyInEnv (map GhcVer [minBound .. maxBound ])
179
+
180
+ -- | The test can no longer fail and is marked as flaky.
181
+ -- Flaky tests are tests that sometimes fail but sometimes also succeed.
182
+ -- Ideally, such test cases should not exist at all, but at least in this codebase,
183
+ -- the reality is, that we do have a number of flaky test cases.
184
+ --
185
+ -- The code is basically copy-pasted from 'tasty-expected-failure' and if this
186
+ -- function proves useful in practice, we will upstream it.
187
+ knownFlakyBecause :: String -> TestTree -> TestTree
188
+ knownFlakyBecause info = wrapTest (fmap change)
189
+ where
190
+ change r
191
+ | resultSuccessful r
192
+ = r { resultDescription = resultDescription r <> " (flaky testcase: " <> info <> " )"
193
+ , resultShortDescription = resultShortDescription r <> " (flaky testcase)"
194
+ }
195
+ | otherwise
196
+ = r { resultOutcome = Runners. Success
197
+ , resultDescription = resultDescription r <> " (failed flaky testcase failed: " <> info <> " )"
198
+ , resultShortDescription = resultShortDescription r <> " (failed flaky testcase)"
199
+ }
200
+
146
201
-- ---------------------------------------------------------------------
147
202
148
203
-- | Like 'withCurrentDirectory', but will copy the directory over to the system
0 commit comments