@@ -19,7 +19,6 @@ use miropt_test_tools::{files_for_miropt_test, MiroptTest, MiroptTestFile};
19
19
use regex:: { Captures , Regex } ;
20
20
use rustfix:: { apply_suggestions, get_suggestions_from_json, Filter } ;
21
21
22
- use std:: borrow:: Cow ;
23
22
use std:: collections:: { HashMap , HashSet } ;
24
23
use std:: env;
25
24
use std:: ffi:: { OsStr , OsString } ;
@@ -725,17 +724,36 @@ impl<'test> TestCx<'test> {
725
724
726
725
/// Replace line numbers in coverage reports with the placeholder `LL`,
727
726
/// so that the tests are less sensitive to lines being added/removed.
728
- fn anonymize_coverage_line_numbers ( coverage : & str ) -> Cow < ' _ , str > {
727
+ fn anonymize_coverage_line_numbers ( coverage : & str ) -> String {
729
728
// The coverage reporter prints line numbers at the start of a line.
730
729
// They are truncated or left-padded to occupy exactly 5 columns.
731
730
// (`LineNumberColumnWidth` in `SourceCoverageViewText.cpp`.)
732
731
// A pipe character `|` appears immediately after the final digit.
733
732
//
734
733
// Line numbers that appear inside expansion/instantiation subviews
735
734
// have an additional prefix of ` |` for each nesting level.
735
+ //
736
+ // Branch views also include the relevant line number, so we want to
737
+ // redact those too. (These line numbers don't have padding.)
738
+ //
739
+ // Note: The pattern `(?m:^)` matches the start of a line.
740
+
741
+ // ` 1|` => ` LL|`
742
+ // ` 10|` => ` LL|`
743
+ // ` 100|` => ` LL|`
744
+ // ` | 1000|` => ` | LL|`
745
+ // ` | | 1000|` => ` | | LL|`
736
746
static LINE_NUMBER_RE : Lazy < Regex > =
737
747
Lazy :: new ( || Regex :: new ( r"(?m:^)(?<prefix>(?: \|)*) *[0-9]+\|" ) . unwrap ( ) ) ;
738
- LINE_NUMBER_RE . replace_all ( coverage, "$prefix LL|" )
748
+ let coverage = LINE_NUMBER_RE . replace_all ( & coverage, "${prefix} LL|" ) ;
749
+
750
+ // ` | Branch (1:` => ` | Branch (LL:`
751
+ // ` | | Branch (10:` => ` | | Branch (LL:`
752
+ static BRANCH_LINE_NUMBER_RE : Lazy < Regex > =
753
+ Lazy :: new ( || Regex :: new ( r"(?m:^)(?<prefix>(?: \|)+ Branch \()[0-9]+:" ) . unwrap ( ) ) ;
754
+ let coverage = BRANCH_LINE_NUMBER_RE . replace_all ( & coverage, "${prefix}LL:" ) ;
755
+
756
+ coverage. into_owned ( )
739
757
}
740
758
741
759
/// Coverage reports can describe multiple source files, separated by
0 commit comments