Skip to content

Commit

Permalink
Improve ‘filterByPattern’ to not keep empty subtrees
Browse files Browse the repository at this point in the history
This way console reporter will not need to print group headings when
group contains no tests, amoung other things.
  • Loading branch information
sergv authored and Bodigrim committed Dec 11, 2023
1 parent b152a0b commit ead27c2
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions core/Test/Tasty/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ annotatePath = go mempty
go :: Seq.Seq TestName -> AnnTestTree OptionSet -> AnnTestTree (OptionSet, Path)
go path = \case
AnnEmptyTestTree -> AnnEmptyTestTree
AnnSingleTest opts name tree ->
AnnSingleTest opts name tree ->
AnnSingleTest (opts, path |> name) name tree
AnnTestGroup opts name trees ->
let newPath = path |> name in
Expand All @@ -554,7 +554,15 @@ annotatePath = go mempty
filterByPattern :: AnnTestTree (OptionSet, Path) -> AnnTestTree OptionSet
filterByPattern = snd . go (Any False)
where
go
mkGroup opts name xs = case filter isNonEmpty xs of
[] -> AnnEmptyTestTree
ys -> AnnTestGroup opts name ys

isNonEmpty = \case
AnnEmptyTestTree -> False
_ -> True

go
:: ForceTestMatch
-> AnnTestTree (OptionSet, Path)
-> (TestMatched, AnnTestTree OptionSet)
Expand All @@ -565,22 +573,22 @@ filterByPattern = snd . go (Any False)
AnnSingleTest (opts, path) name tree
| getAny forceMatch || testPatternMatches (lookupOption opts) path
-> (Any True, AnnSingleTest opts name tree)
| otherwise
| otherwise
-> (Any False, AnnEmptyTestTree)

AnnTestGroup (opts, _) name [] ->
(forceMatch, AnnTestGroup opts name [])
AnnTestGroup _ _ [] ->
(forceMatch, AnnEmptyTestTree)

AnnTestGroup (opts, _) name trees ->
case lookupOption opts of
Parallel ->
bimap
mconcat
(AnnTestGroup opts name)
(mkGroup opts name)
(unzip (map (go forceMatch) trees))
Sequential _ ->
second
(AnnTestGroup opts name)
(mkGroup opts name)
(mapAccumR go forceMatch trees)

AnnWithResource (opts, _) res0 tree ->
Expand Down

0 comments on commit ead27c2

Please sign in to comment.