Skip to content

Commit 4856a47

Browse files
committed
Auto merge of rust-lang#118548 - Enselic:bench-padding, r=thomcc,ChrisDenton
libtest: Fix padding of benchmarks run as tests ### Summary The first commit adds regression tests for libtest padding. The second commit fixes padding for benches run as tests and updates the blessed output of the regression tests to make it clear what effect the fix has on padding. Closes rust-lang#104092 which is **E-help-wanted** and **regression-from-stable-to-stable** ### More details Before this fix we applied padding _before_ manually doing what `convert_benchmarks_to_tests()` does which affects padding calculations. Instead use `convert_benchmarks_to_tests()` first if applicable and then apply padding afterwards so it becomes correct. Benches should only be padded when run as benches to make it easy to compare the benchmark numbers. Not when run as tests. r? `@ghost` until CI passes.
2 parents 71d0c34 + ff8225c commit 4856a47

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

test/src/lib.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -298,24 +298,18 @@ where
298298

299299
let mut filtered = FilteredTests { tests: Vec::new(), benches: Vec::new(), next_id: 0 };
300300

301-
for test in filter_tests(opts, tests) {
301+
let mut filtered_tests = filter_tests(opts, tests);
302+
if !opts.bench_benchmarks {
303+
filtered_tests = convert_benchmarks_to_tests(filtered_tests);
304+
}
305+
306+
for test in filtered_tests {
302307
let mut desc = test.desc;
303308
desc.name = desc.name.with_padding(test.testfn.padding());
304309

305310
match test.testfn {
306-
DynBenchFn(benchfn) => {
307-
if opts.bench_benchmarks {
308-
filtered.add_bench(desc, DynBenchFn(benchfn));
309-
} else {
310-
filtered.add_test(desc, DynBenchAsTestFn(benchfn));
311-
}
312-
}
313-
StaticBenchFn(benchfn) => {
314-
if opts.bench_benchmarks {
315-
filtered.add_bench(desc, StaticBenchFn(benchfn));
316-
} else {
317-
filtered.add_test(desc, StaticBenchAsTestFn(benchfn));
318-
}
311+
DynBenchFn(_) | StaticBenchFn(_) => {
312+
filtered.add_bench(desc, test.testfn);
319313
}
320314
testfn => {
321315
filtered.add_test(desc, testfn);

0 commit comments

Comments
 (0)