Skip to content

Commit 3528adb

Browse files
committed
Introduce test-utils for marking tests as flaky
1 parent 729af31 commit 3528adb

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

ghcide/src/Development/IDE/GHC/Compat.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ data GhcVersion
616616
| GHC92
617617
| GHC94
618618
| GHC96
619-
deriving (Eq, Ord, Show)
619+
deriving (Eq, Ord, Show, Enum, Bounded)
620620

621621
ghcVersionStr :: String
622622
ghcVersionStr = VERSION_ghc

ghcide/test/exe/Main.hs

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,7 @@ import Development.IDE.Types.Logger (Logger (Logger),
138138
WithPriority (WithPriority, priority),
139139
cfilter,
140140
cmapWithPrio,
141-
makeDefaultStderrRecorder,
142-
toCologActionWithPrio)
141+
makeDefaultStderrRecorder)
143142
import qualified FuzzySearch
144143
import GHC.Stack (emptyCallStack)
145144
import qualified HieDbRetry
@@ -151,12 +150,11 @@ import Language.LSP.Types.Lens (didChangeWatchedFiles
151150
import qualified Language.LSP.Types.Lens as L
152151
import qualified Progress
153152
import System.Time.Extra
154-
import qualified Test.QuickCheck.Monadic as MonadicQuickCheck
155-
import Test.QuickCheck.Monadic (forAllM, monadicIO)
156153
import Test.Tasty
157154
import Test.Tasty.ExpectedFailure
158155
import Test.Tasty.HUnit
159156
import Test.Tasty.Ingredients.Rerun
157+
import Test.Tasty.Runners as Runners
160158
import Test.Tasty.QuickCheck
161159
import Text.Printf (printf)
162160
import Text.Regex.TDFA ((=~))
@@ -2084,7 +2082,6 @@ completionDocTests =
20842082
test doc (Position 1 7) "id" (Just $ T.length expected) [expected]
20852083
]
20862084
where
2087-
brokenForGhc9 = knownBrokenFor (BrokenForGHC [GHC90, GHC92, GHC94, GHC96]) "Completion doc doesn't support ghc9"
20882085
brokenForWinGhc9 = knownBrokenFor (BrokenSpecific Windows [GHC90, GHC92]) "Extern doc doesn't support Windows for ghc9.2"
20892086
-- https://gitlab.haskell.org/ghc/ghc/-/issues/20903
20902087
brokenForMacGhc9 = knownBrokenFor (BrokenSpecific MacOS [GHC90, GHC92, GHC94, GHC96]) "Extern doc doesn't support MacOS for ghc9"
@@ -2373,7 +2370,7 @@ knownBrokenForGhcVersions ghcVers = knownBrokenFor (BrokenForGHC ghcVers)
23732370

23742371
data BrokenOS = Linux | MacOS | Windows deriving (Show)
23752372

2376-
data IssueSolution = Broken | Ignore deriving (Show)
2373+
data IssueSolution = Broken | Ignore | Flaky deriving (Show)
23772374

23782375
data BrokenTarget =
23792376
BrokenSpecific BrokenOS [GhcVersion]
@@ -2392,6 +2389,14 @@ ignoreFor = knownIssueFor Ignore
23922389
knownBrokenFor :: BrokenTarget -> String -> TestTree -> TestTree
23932390
knownBrokenFor = knownIssueFor Broken
23942391

2392+
-- | Mark test as flaky for a specific target
2393+
knownFlakyFor :: BrokenTarget -> String -> TestTree -> TestTree
2394+
knownFlakyFor = knownIssueFor Flaky
2395+
2396+
-- | Mark test as flaky for all GHC versions
2397+
knownFlaky :: String -> TestTree -> TestTree
2398+
knownFlaky = knownIssueFor Flaky (BrokenForGHC [minBound .. maxBound])
2399+
23952400
-- | Deal with `IssueSolution` for specific OS and GHC.
23962401
knownIssueFor :: IssueSolution -> BrokenTarget -> String -> TestTree -> TestTree
23972402
knownIssueFor solution = go . \case
@@ -2409,8 +2414,30 @@ knownIssueFor solution = go . \case
24092414
go True = case solution of
24102415
Broken -> expectFailBecause
24112416
Ignore -> ignoreTestBecause
2417+
Flaky -> knownFlakyBecause
24122418
go False = \_ -> id
24132419

2420+
-- | The test can no longer fail and is marked as flaky.
2421+
-- Flaky tests are tests that sometimes fail but sometimes also succeed.
2422+
-- Ideally, such test cases should not exist at all, but at least in this codebase,
2423+
-- the reality is, that we do have a number of flaky test cases.
2424+
--
2425+
-- The code is basically copy-pasted from 'tasty-expected-failure' and if this
2426+
-- function proves useful in practice, we will upstream it.
2427+
knownFlakyBecause :: String -> TestTree -> TestTree
2428+
knownFlakyBecause info = wrapTest (fmap change)
2429+
where
2430+
change r
2431+
| resultSuccessful r
2432+
= r { resultDescription = resultDescription r <> " (flaky testcase: " <> info <> ")"
2433+
, resultShortDescription = resultShortDescription r <> " (flaky testcase)"
2434+
}
2435+
| otherwise
2436+
= r { resultOutcome = Runners.Success
2437+
, resultDescription = resultDescription r <> " (failed flaky testcase failed: " <> info <> ")"
2438+
, resultShortDescription = resultShortDescription r <> " (failed flaky testcase)"
2439+
}
2440+
24142441
data Expect
24152442
= ExpectRange Range -- Both gotoDef and hover should report this range
24162443
| ExpectLocation Location

0 commit comments

Comments
 (0)