|
| 1 | +// Benchmarks, when ran as tests, would cause strange indentations |
| 2 | +// to appear in the output. This was because padding formatting was |
| 3 | +// applied before the conversion from bench to test, and not afterwards. |
| 4 | +// Now that this bug has been fixed in #118548, this test checks that it |
| 5 | +// does not make a resurgence by comparing the output of --bench with an |
| 6 | +// example stdout file. |
| 7 | +// See https://github.com/rust-lang/rust/issues/104092 |
| 8 | + |
| 9 | +//@ ignore-cross-compile |
| 10 | +// Reason: the compiled code is ran |
| 11 | +//@ needs-unwind |
| 12 | +// Reason: #[bench] requires -Z panic-abort-tests |
| 13 | + |
| 14 | +use run_make_support::{diff, run_with_args, rustc}; |
| 15 | + |
| 16 | +fn main() { |
| 17 | + rustc().arg("--test").input("tests.rs").run(); |
| 18 | + let out = run_with_args("tests", &["--test-threads=1"]).stdout_utf8(); |
| 19 | + diff() |
| 20 | + .expected_file("test.stdout") |
| 21 | + .actual_text("actual-test-stdout", out) |
| 22 | + .normalize( |
| 23 | + // Replace all instances of (arbitrary numbers) |
| 24 | + // [1.2345 ns/iter (+/- 0.1234)] |
| 25 | + // with |
| 26 | + // [?? ns/iter (+/- ??)] |
| 27 | + r#"(\d+(?:[.,]\d+)*)\s*ns/iter\s*\(\+/-\s*(\d+(?:[.,]\d+)*)\)"#, |
| 28 | + "?? ns/iter (+/- ??)", |
| 29 | + ) |
| 30 | + // Replace all instances of (arbitrary numbers) |
| 31 | + // finished in 8.0000 s |
| 32 | + // with |
| 33 | + // finished in ?? |
| 34 | + .normalize(r#"finished\s+in\s+(\d+(?:\.\d+)*)"#, "finished in ??") |
| 35 | + .run(); |
| 36 | + let out = run_with_args("tests", &["--test-threads=1", "--bench"]).stdout_utf8(); |
| 37 | + diff() |
| 38 | + .expected_file("bench.stdout") |
| 39 | + .actual_text("actual-bench-stdout", out) |
| 40 | + .normalize( |
| 41 | + r#"(\d+(?:[.,]\d+)*)\s*ns/iter\s*\(\+/-\s*(\d+(?:[.,]\d+)*)\)"#, |
| 42 | + "?? ns/iter (+/- ??)", |
| 43 | + ) |
| 44 | + .normalize(r#"finished\s+in\s+(\d+(?:\.\d+)*)"#, "finished in ??") |
| 45 | + .run(); |
| 46 | +} |
0 commit comments