Skip to content

Commit ead27c2

Browse files
sergvBodigrim
authored andcommitted
Improve ‘filterByPattern’ to not keep empty subtrees
This way console reporter will not need to print group headings when group contains no tests, amoung other things.
1 parent b152a0b commit ead27c2

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

core/Test/Tasty/Core.hs

+15-7
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ annotatePath = go mempty
540540
go :: Seq.Seq TestName -> AnnTestTree OptionSet -> AnnTestTree (OptionSet, Path)
541541
go path = \case
542542
AnnEmptyTestTree -> AnnEmptyTestTree
543-
AnnSingleTest opts name tree ->
543+
AnnSingleTest opts name tree ->
544544
AnnSingleTest (opts, path |> name) name tree
545545
AnnTestGroup opts name trees ->
546546
let newPath = path |> name in
@@ -554,7 +554,15 @@ annotatePath = go mempty
554554
filterByPattern :: AnnTestTree (OptionSet, Path) -> AnnTestTree OptionSet
555555
filterByPattern = snd . go (Any False)
556556
where
557-
go
557+
mkGroup opts name xs = case filter isNonEmpty xs of
558+
[] -> AnnEmptyTestTree
559+
ys -> AnnTestGroup opts name ys
560+
561+
isNonEmpty = \case
562+
AnnEmptyTestTree -> False
563+
_ -> True
564+
565+
go
558566
:: ForceTestMatch
559567
-> AnnTestTree (OptionSet, Path)
560568
-> (TestMatched, AnnTestTree OptionSet)
@@ -565,22 +573,22 @@ filterByPattern = snd . go (Any False)
565573
AnnSingleTest (opts, path) name tree
566574
| getAny forceMatch || testPatternMatches (lookupOption opts) path
567575
-> (Any True, AnnSingleTest opts name tree)
568-
| otherwise
576+
| otherwise
569577
-> (Any False, AnnEmptyTestTree)
570578

571-
AnnTestGroup (opts, _) name [] ->
572-
(forceMatch, AnnTestGroup opts name [])
579+
AnnTestGroup _ _ [] ->
580+
(forceMatch, AnnEmptyTestTree)
573581

574582
AnnTestGroup (opts, _) name trees ->
575583
case lookupOption opts of
576584
Parallel ->
577585
bimap
578586
mconcat
579-
(AnnTestGroup opts name)
587+
(mkGroup opts name)
580588
(unzip (map (go forceMatch) trees))
581589
Sequential _ ->
582590
second
583-
(AnnTestGroup opts name)
591+
(mkGroup opts name)
584592
(mapAccumR go forceMatch trees)
585593

586594
AnnWithResource (opts, _) res0 tree ->

0 commit comments

Comments
 (0)