Skip to content

Commit 2004a73

Browse files
committed
coverage: Anonymize line numbers in branch views
The existing line-number anonymizer code didn't support the different line number syntax used by branch regions.
1 parent d526069 commit 2004a73

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/tools/compiletest/src/runtest.rs

+21-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use miropt_test_tools::{files_for_miropt_test, MiroptTest, MiroptTestFile};
1919
use regex::{Captures, Regex};
2020
use rustfix::{apply_suggestions, get_suggestions_from_json, Filter};
2121

22-
use std::borrow::Cow;
2322
use std::collections::{HashMap, HashSet};
2423
use std::env;
2524
use std::ffi::{OsStr, OsString};
@@ -730,17 +729,36 @@ impl<'test> TestCx<'test> {
730729

731730
/// Replace line numbers in coverage reports with the placeholder `LL`,
732731
/// so that the tests are less sensitive to lines being added/removed.
733-
fn anonymize_coverage_line_numbers(coverage: &str) -> Cow<'_, str> {
732+
fn anonymize_coverage_line_numbers(coverage: &str) -> String {
734733
// The coverage reporter prints line numbers at the start of a line.
735734
// They are truncated or left-padded to occupy exactly 5 columns.
736735
// (`LineNumberColumnWidth` in `SourceCoverageViewText.cpp`.)
737736
// A pipe character `|` appears immediately after the final digit.
738737
//
739738
// Line numbers that appear inside expansion/instantiation subviews
740739
// have an additional prefix of ` |` for each nesting level.
740+
//
741+
// Branch views also include the relevant line number, so we want to
742+
// redact those too. (These line numbers don't have padding.)
743+
//
744+
// Note: The pattern `(?m:^)` matches the start of a line.
745+
746+
// ` 1|` => ` LL|`
747+
// ` 10|` => ` LL|`
748+
// ` 100|` => ` LL|`
749+
// ` | 1000|` => ` | LL|`
750+
// ` | | 1000|` => ` | | LL|`
741751
static LINE_NUMBER_RE: Lazy<Regex> =
742752
Lazy::new(|| Regex::new(r"(?m:^)(?<prefix>(?: \|)*) *[0-9]+\|").unwrap());
743-
LINE_NUMBER_RE.replace_all(coverage, "$prefix LL|")
753+
let coverage = LINE_NUMBER_RE.replace_all(&coverage, "${prefix} LL|");
754+
755+
// ` | Branch (1:` => ` | Branch (LL:`
756+
// ` | | Branch (10:` => ` | | Branch (LL:`
757+
static BRANCH_LINE_NUMBER_RE: Lazy<Regex> =
758+
Lazy::new(|| Regex::new(r"(?m:^)(?<prefix>(?: \|)+ Branch \()[0-9]+:").unwrap());
759+
let coverage = BRANCH_LINE_NUMBER_RE.replace_all(&coverage, "${prefix}LL:");
760+
761+
coverage.into_owned()
744762
}
745763

746764
/// Coverage reports can describe multiple source files, separated by

0 commit comments

Comments
 (0)