Skip to content

Commit 83585fa

Browse files
committed
Add the directive compare-output-by-lines
1 parent 898aff7 commit 83585fa

14 files changed

+51
-19
lines changed

src/doc/rustc-dev-guide/src/tests/directives.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ for more details.
111111
| `forbid-output` | A pattern which must not appear in stderr/`cfail` output | `ui`, `incremental` | Regex pattern |
112112
| `run-flags` | Flags passed to the test executable | `ui` | Arbitrary flags |
113113
| `known-bug` | No error annotation needed due to known bug | `ui`, `crashes`, `incremental` | Issue number `#123456` |
114+
| `compare-output-by-lines` | Compare the output by lines, rather than as a single string | All | N/A |
114115

115116
[^check_stdout]: presently <!-- date-check: Oct 2024 --> this has a weird quirk
116117
where the test binary's stdout and stderr gets concatenated and then

src/doc/rustc-dev-guide/src/tests/ui.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ will check for output files:
9595
[Normalization](#normalization)).
9696
- `dont-check-compiler-stderr` — Ignores stderr from the compiler.
9797
- `dont-check-compiler-stdout` — Ignores stdout from the compiler.
98+
- `compare-output-by-lines` — Some tests have non-deterministic orders of output, so we need to compare by lines.
9899

99100
UI tests run with `-Zdeduplicate-diagnostics=no` flag which disables rustc's
100101
built-in diagnostic deduplication mechanism. This means you may see some

src/tools/compiletest/src/directives.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ pub struct TestProps {
205205
pub dont_require_annotations: HashSet<ErrorKind>,
206206
/// Whether pretty printers should be disabled in gdb.
207207
pub disable_gdb_pretty_printers: bool,
208+
/// Compare the output by lines, rather than as a single string.
209+
pub compare_output_by_lines: bool,
208210
}
209211

210212
mod directives {
@@ -254,6 +256,7 @@ mod directives {
254256
// This isn't a real directive, just one that is probably mistyped often
255257
pub const INCORRECT_COMPILER_FLAGS: &'static str = "compiler-flags";
256258
pub const DISABLE_GDB_PRETTY_PRINTERS: &'static str = "disable-gdb-pretty-printers";
259+
pub const COMPARE_OUTPUT_BY_LINES: &'static str = "compare-output-by-lines";
257260
}
258261

259262
impl TestProps {
@@ -310,6 +313,7 @@ impl TestProps {
310313
add_core_stubs: false,
311314
dont_require_annotations: Default::default(),
312315
disable_gdb_pretty_printers: false,
316+
compare_output_by_lines: false,
313317
}
314318
}
315319

@@ -664,6 +668,11 @@ impl TestProps {
664668
DISABLE_GDB_PRETTY_PRINTERS,
665669
&mut self.disable_gdb_pretty_printers,
666670
);
671+
config.set_name_directive(
672+
ln,
673+
COMPARE_OUTPUT_BY_LINES,
674+
&mut self.compare_output_by_lines,
675+
);
667676
},
668677
);
669678

src/tools/compiletest/src/directives/directive_names.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub(crate) const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
1717
"check-run-results",
1818
"check-stdout",
1919
"check-test-line-numbers-match",
20+
"compare-output-by-lines",
2021
"compile-flags",
2122
"disable-gdb-pretty-printers",
2223
"doc-flags",

src/tools/compiletest/src/runtest.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2749,7 +2749,11 @@ impl<'test> TestCx<'test> {
27492749
// Wrapper tools set by `runner` might provide extra output on failure,
27502750
// for example a WebAssembly runtime might print the stack trace of an
27512751
// `unreachable` instruction by default.
2752-
let compare_output_by_lines = self.config.runner.is_some();
2752+
//
2753+
// Also, some tests like `ui/parallel-rustc` have non-deterministic
2754+
// orders of output, so we need to compare by lines.
2755+
let compare_output_by_lines =
2756+
self.props.compare_output_by_lines || self.config.runner.is_some();
27532757

27542758
let tmp;
27552759
let (expected, actual): (&str, &str) = if compare_output_by_lines {
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1+
// Test for #111528, the ice issue cause waiting on a query that panicked
2+
//
13
//@ compile-flags: -Z threads=16
24
//@ build-fail
5+
//@ compare-output-by-lines
36

4-
#![crate_type="rlib"]
7+
#![crate_type = "rlib"]
58
#![allow(warnings)]
69

7-
#[export_name="fail"]
8-
pub fn a() {
9-
}
10+
#[export_name = "fail"]
11+
pub fn a() {}
1012

11-
#[export_name="fail"]
13+
#[export_name = "fail"]
1214
pub fn b() {
13-
//~^ ERROR symbol `fail` is already defined
15+
//~^ ERROR symbol `fail` is already defined
1416
}
1517

1618
fn main() {}

tests/ui/parallel-rustc/cache-after-waiting-issue-111528.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: symbol `fail` is already defined
2-
--> $DIR/cache-after-waiting-issue-111528.rs:12:1
2+
--> $DIR/cache-after-waiting-issue-111528.rs:14:1
33
|
44
LL | pub fn b() {
55
| ^^^^^^^^^^
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Test for #135870, which causes a deadlock bug
2+
//
3+
//@ compile-flags: -Z threads=2
4+
//@ compare-output-by-lines
5+
6+
const FOO: usize = FOO; //~ ERROR cycle detected when simplifying constant for the type system `FOO`
7+
8+
fn main() {}

tests/ui/parallel-rustc/cycle_crash.stderr renamed to tests/ui/parallel-rustc/cycle_crash-issue-135870.stderr

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
error[E0391]: cycle detected when simplifying constant for the type system `FOO`
2-
--> $DIR/cycle_crash.rs:3:1
32
|
43
LL | const FOO: usize = FOO;
54
| ^^^^^^^^^^^^^^^^
65
|
76
note: ...which requires const-evaluating + checking `FOO`...
8-
--> $DIR/cycle_crash.rs:3:20
97
|
108
LL | const FOO: usize = FOO;
119
| ^^^

tests/ui/parallel-rustc/cycle_crash.rs

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)