Skip to content

Commit 277902b

Browse files
authored
Rollup merge of #138834 - Kobzol:test-diff-group-by-stage, r=marcoieni
Group test diffs by stage in post-merge analysis I think that this is clearer than including the stage in the test name. To test e.g. on [this PR](#138523): ```bash $ curl https://ci-artifacts.rust-lang.org/rustc-builds/282865097d138c7f0f7a7566db5b761312dd145c/metrics-aarch64-gnu.json > metrics.json $ cargo run --manifest-path src/ci/citool/Cargo.toml postprocess-metrics metrics.json --job-name aarch64-gnu --parent d9e5539 > out.md ``` r? `@marcoieni`
2 parents 1c84c06 + e9ddf54 commit 277902b

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

src/ci/citool/src/analysis.rs

+25-18
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ struct TestSuiteData {
210210
#[derive(Hash, PartialEq, Eq, Debug, Clone)]
211211
struct Test {
212212
name: String,
213+
stage: u8,
213214
is_doctest: bool,
214215
}
215216

@@ -218,27 +219,24 @@ fn aggregate_tests(metrics: &JsonRoot) -> TestSuiteData {
218219
let mut tests = HashMap::new();
219220
let test_suites = get_test_suites(&metrics);
220221
for suite in test_suites {
222+
let stage = match suite.metadata {
223+
TestSuiteMetadata::CargoPackage { stage, .. } => stage,
224+
TestSuiteMetadata::Compiletest { stage, .. } => stage,
225+
} as u8;
221226
for test in &suite.tests {
222227
// Poor man's detection of doctests based on the "(line XYZ)" suffix
223228
let is_doctest = matches!(suite.metadata, TestSuiteMetadata::CargoPackage { .. })
224229
&& test.name.contains("(line");
225-
let test_entry = Test { name: generate_test_name(&test.name, &suite), is_doctest };
230+
let test_entry = Test { name: generate_test_name(&test.name), stage, is_doctest };
226231
tests.insert(test_entry, test.outcome.clone());
227232
}
228233
}
229234
TestSuiteData { tests }
230235
}
231236

232-
/// Normalizes Windows-style path delimiters to Unix-style paths
233-
/// and adds suite metadata to the test name.
234-
fn generate_test_name(name: &str, suite: &TestSuite) -> String {
235-
let name = name.replace('\\', "/");
236-
let stage = match suite.metadata {
237-
TestSuiteMetadata::CargoPackage { stage, .. } => stage,
238-
TestSuiteMetadata::Compiletest { stage, .. } => stage,
239-
};
240-
241-
format!("{name} (stage {stage})")
237+
/// Normalizes Windows-style path delimiters to Unix-style paths.
238+
fn generate_test_name(name: &str) -> String {
239+
name.replace('\\', "/")
242240
}
243241

244242
/// Prints test changes in Markdown format to stdout.
@@ -321,16 +319,25 @@ fn report_test_diffs(diff: AggregatedTestDiffs) {
321319
// Sort diffs by job group and test name
322320
grouped_diffs.sort_by(|(d1, g1), (d2, g2)| g1.cmp(&g2).then(d1.test.name.cmp(&d2.test.name)));
323321

322+
// Now group the tests by stage
323+
let mut grouped_by_stage: BTreeMap<u8, Vec<(&TestDiff, u64)>> = Default::default();
324+
for (diff, group) in grouped_diffs {
325+
grouped_by_stage.entry(diff.test.stage).or_default().push((diff, group))
326+
}
327+
324328
output_details(
325329
&format!("Show {} test {}\n", original_diff_count, pluralize("diff", original_diff_count)),
326330
|| {
327-
for (diff, job_group) in grouped_diffs {
328-
println!(
329-
"- `{}`: {} ({})",
330-
diff.test.name,
331-
format_diff(&diff.diff),
332-
format_job_group(job_group)
333-
);
331+
for (stage, diffs) in grouped_by_stage {
332+
println!("## Stage {stage}");
333+
for (diff, job_group) in diffs {
334+
println!(
335+
"- `{}`: {} ({})",
336+
diff.test.name,
337+
format_diff(&diff.diff),
338+
format_job_group(job_group)
339+
);
340+
}
334341
}
335342

336343
let extra_diffs = diffs.len().saturating_sub(max_diff_count);

0 commit comments

Comments
 (0)