Skip to content

Commit 1a19077

Browse files
committed
Error if a legacy-style directive is detected in any ui tests
1 parent c633baa commit 1a19077

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

src/tools/compiletest/src/header.rs

+39-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ impl EarlyProps {
4646

4747
pub fn from_reader<R: Read>(config: &Config, testfile: &Path, rdr: R) -> Self {
4848
let mut props = EarlyProps::default();
49-
iter_header(config.mode, testfile, rdr, &mut |_, ln, _| {
49+
let mut poisoned = false;
50+
iter_header(config.mode, &mut poisoned, testfile, rdr, &mut |_, ln, _| {
5051
config.push_name_value_directive(ln, directives::AUX_BUILD, &mut props.aux, |r| {
5152
r.trim().to_string()
5253
});
@@ -58,6 +59,12 @@ impl EarlyProps {
5859
);
5960
config.parse_and_update_revisions(ln, &mut props.revisions);
6061
});
62+
63+
if poisoned {
64+
eprintln!("errors encountered during EarlyProps parsing: {}", testfile.display());
65+
panic!("errors encountered during EarlyProps parsing");
66+
}
67+
6168
return props;
6269
}
6370
}
@@ -306,7 +313,9 @@ impl TestProps {
306313
if !testfile.is_dir() {
307314
let file = File::open(testfile).unwrap();
308315

309-
iter_header(self.config.mode, testfile, file, &mut |revision, ln, _| {
316+
let mut poisoned = false;
317+
318+
iter_header(config.mode, &mut poisoned, testfile, file, &mut |revision, ln, _| {
310319
if revision.is_some() && revision != cfg {
311320
return;
312321
}
@@ -505,6 +514,11 @@ impl TestProps {
505514
self.llvm_cov_flags.extend(split_flags(&flags));
506515
}
507516
});
517+
518+
if poisoned {
519+
eprintln!("errors encountered during TestProps parsing: {}", testfile.display());
520+
panic!("errors encountered during TestProps parsing");
521+
}
508522
}
509523

510524
if self.should_ice {
@@ -630,15 +644,17 @@ pub fn line_directive<'line>(
630644

631645
fn iter_header<R: Read>(
632646
mode: Mode,
647+
poisoned: &mut bool,
633648
testfile: &Path,
634649
rdr: R,
635650
it: &mut dyn FnMut(Option<&str>, &str, usize),
636651
) {
637-
iter_header_extra(mode, testfile, rdr, &[], it)
652+
iter_header_extra(mode, poisoned, testfile, rdr, &[], it)
638653
}
639654

640655
fn iter_header_extra(
641656
mode: Mode,
657+
poisoned: &mut bool,
642658
testfile: &Path,
643659
rdr: impl Read,
644660
extra_directives: &[&str],
@@ -677,8 +693,20 @@ fn iter_header_extra(
677693
let ln = ln.trim();
678694
if ln.starts_with("fn") || ln.starts_with("mod") {
679695
return;
696+
697+
// First try to accept `ui_test` style comments
680698
} else if let Some((lncfg, ln)) = line_directive(comment, ln) {
681699
it(lncfg, ln, line_number);
700+
} else if mode == Mode::Ui && line_directive("//", ln).is_some() {
701+
// We have a comment that's *successfully* parsed as an legacy-style directive.
702+
// We emit an error here to warn the user.
703+
*poisoned = true;
704+
eprintln!(
705+
"error: detected legacy-style directives in ui test: {}:{}, please use `ui_test`-style directives `//@` instead",
706+
testfile.display(),
707+
line_number,
708+
);
709+
return;
682710
}
683711
}
684712
}
@@ -956,8 +984,11 @@ pub fn make_test_description<R: Read>(
956984
_ => &[],
957985
};
958986

987+
let mut local_poisoned = false;
988+
959989
iter_header_extra(
960990
config.mode,
991+
&mut local_poisoned,
961992
path,
962993
src,
963994
extra_directives,
@@ -1006,6 +1037,11 @@ pub fn make_test_description<R: Read>(
10061037
},
10071038
);
10081039

1040+
if local_poisoned {
1041+
eprintln!("errors encountered when trying to make test description: {}", path.display());
1042+
panic!("errors encountered when trying to make test description");
1043+
}
1044+
10091045
// The `should-fail` annotation doesn't apply to pretty tests,
10101046
// since we run the pretty printer across all tests by default.
10111047
// If desired, we could add a `should-fail-pretty` annotation.

0 commit comments

Comments
 (0)