Skip to content

Commit 7f12d21

Browse files
committed
ignore some unsupported directives in checks
1 parent 4db5b3e commit 7f12d21

File tree

3 files changed

+114
-78
lines changed

3 files changed

+114
-78
lines changed

src/tools/test_common/src/directives.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ macro_rules! name_val_or_name_directive {
363363
// Macros are in the form (name, compiletest_name, ui_test_name).
364364
// If ui_test_name does not exist, ui_test does not support that directive.
365365
// ========================================================================
366-
name_value_directive!(ErrorPatternDirective, "error-in-other-file", "error-pattern");
366+
name_value_directive!(ErrorPatternDirective, "error-pattern", "error-in-other-file");
367367
name_value_directive!(CompileFlagsDirective, "compile-flags", "compile-flags");
368368
name_value_directive!(RunFlagsDirective, "run-flags"); // UNUSED IN UI TESTS
369369
name_value_directive!(PrettyModeDirective, "pretty-mode"); // UNUSED IN UI TESTS

src/tools/tidy/src/ui_tests.rs

+64-57
Original file line numberDiff line numberDiff line change
@@ -192,18 +192,21 @@ fn check_ui_test_headers(bad: &mut bool, file_path: &Path, mode: HeaderCheckMode
192192
}
193193
}
194194

195+
fn emit_error(file_path: &Path, action: &HeaderAction) {
196+
tidy_error!(
197+
&mut false,
198+
"invalid test header\n {}:{}\n {}",
199+
file_path.display(),
200+
action.line_num(),
201+
action.error_message()
202+
);
203+
}
195204
/// Emits errors for the header lines specified. Returns whether any errors were emitted
196205
fn emit_header_errors(file_path: &Path, bad_lines: Vec<HeaderAction>) -> bool {
197206
let mut bad = false;
198207
for action in bad_lines {
199-
let err = action.error_message();
200-
tidy_error!(
201-
&mut bad,
202-
"invalid test header\n {}:{}\n {}",
203-
file_path.display(),
204-
action.line_num(),
205-
err
206-
);
208+
emit_error(file_path, &action);
209+
bad = true;
207210
}
208211
bad
209212
}
@@ -212,61 +215,65 @@ fn fix_header_errors(file_path: &Path, bad_lines: Vec<HeaderAction>) -> io::Resu
212215
// Process each header error into a replacement for a line.
213216
let line_replacements = bad_lines
214217
.into_iter()
215-
.map(|header_action| {
216-
(
217-
header_action.line_num(),
218-
match header_action.action() {
219-
LineAction::UseUiTestComment => {
220-
replace_compiletest_comment(header_action.line()).unwrap()
221-
}
222-
LineAction::MigrateToUiTest { compiletest_name, ui_test_name } => {
223-
// Replace comment type first, then the name range specified.
224-
let mut new_line =
225-
replace_compiletest_comment(header_action.line()).unwrap();
226-
// This is always a directive that contains the compiletest name.
227-
let name_start = new_line.find(compiletest_name.as_str()).unwrap();
228-
new_line.replace_range(
229-
name_start..(name_start + compiletest_name.len()),
230-
ui_test_name.as_str(),
231-
);
232-
new_line
233-
}
234-
LineAction::UseUITestName { compiletest_name, ui_test_name } => {
235-
// This is always a directive that contains the compiletest name.
236-
let name_start =
237-
header_action.line().find(compiletest_name.as_str()).unwrap();
238-
let mut new_line = header_action.line().to_string();
239-
new_line.replace_range(
240-
name_start..(name_start + compiletest_name.len()),
241-
ui_test_name.as_str(),
242-
);
243-
new_line
244-
}
245-
LineAction::Error { message } => todo!(),
246-
},
247-
)
218+
.filter_map(|header_action| {
219+
match header_action.action() {
220+
LineAction::UseUiTestComment => Some((
221+
header_action.line_num(),
222+
replace_compiletest_comment(header_action.line()).unwrap(),
223+
)),
224+
LineAction::MigrateToUiTest { compiletest_name, ui_test_name } => {
225+
// Replace comment type first, then the name range specified.
226+
let mut new_line = replace_compiletest_comment(header_action.line()).unwrap();
227+
// This is always a directive that contains the compiletest name.
228+
let name_start = new_line.find(compiletest_name.as_str()).unwrap();
229+
new_line.replace_range(
230+
name_start..(name_start + compiletest_name.len()),
231+
ui_test_name.as_str(),
232+
);
233+
Some((header_action.line_num(), new_line))
234+
}
235+
LineAction::UseUITestName { compiletest_name, ui_test_name } => {
236+
// This is always a directive that contains the compiletest name.
237+
let name_start = header_action.line().find(compiletest_name.as_str()).unwrap();
238+
let mut new_line = header_action.line().to_string();
239+
new_line.replace_range(
240+
name_start..(name_start + compiletest_name.len()),
241+
ui_test_name.as_str(),
242+
);
243+
Some((header_action.line_num(), new_line))
244+
}
245+
LineAction::Error { .. } => {
246+
emit_error(file_path, &header_action);
247+
// No line to replace
248+
None
249+
}
250+
}
248251
})
249252
.collect::<HashMap<_, _>>();
250253

251-
let file_contents = fs::read_to_string(file_path)?;
254+
if line_replacements.len() > 0 {
255+
let file_contents = fs::read_to_string(file_path)?;
252256

253-
// Replace each line in the contents of the file that there is an entry for.
254-
let replaced_contents = file_contents
255-
// split_inclusive here because we want each line to still have its newline to be
256-
// joined. The line replacements also keep their newline.
257-
.split_inclusive('\n')
258-
.enumerate()
259-
.map(|(line_num_zero_idx, line)| {
260-
// enumerate is 0-indexed, but the entries for line numbers are 1-indexed.
261-
line_replacements.get(&(line_num_zero_idx + 1)).map(|s| s.as_str()).unwrap_or(line)
262-
})
263-
.collect::<String>();
264-
// dbg!(&replaced_contents);
257+
// Replace each line in the contents of the file that there is an entry for.
258+
let replaced_contents = file_contents
259+
// split_inclusive here because we want each line to still have its newline to be
260+
// joined. The line replacements also keep their newline.
261+
.split_inclusive('\n')
262+
.enumerate()
263+
.map(|(line_num_zero_idx, line)| {
264+
// enumerate is 0-indexed, but the entries for line numbers are 1-indexed.
265+
line_replacements.get(&(line_num_zero_idx + 1)).map(|s| s.as_str()).unwrap_or(line)
266+
})
267+
.collect::<String>();
268+
// dbg!(&replaced_contents);
265269

266-
println!("Writing fixed file {}", file_path.display());
270+
println!("Writing fixed file {}", file_path.display());
267271

268-
// Return whether the file was successfully written.
269-
fs::write(file_path, replaced_contents)
272+
// Return whether the file was successfully written.
273+
fs::write(file_path, replaced_contents)
274+
} else {
275+
Ok(())
276+
}
270277
}
271278

272279
/// Replace the comment portion of a compiletest style header with a ui_test style comment.

src/tools/tidy/src/ui_tests/ui_test_headers.rs

+49-20
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,29 @@ pub(super) fn check_file_headers(file_path: &Path) -> Result<(), HeaderError> {
4040
DirectiveMatchResult::UseUiTestComment => {
4141
errors.push(HeaderAction {
4242
line_num,
43-
line: comment.full_line().to_string(),
43+
line: comment.full_line().to_owned(),
4444
action: LineAction::UseUiTestComment,
4545
});
4646
break;
4747
}
4848
DirectiveMatchResult::MigrateToUiTest => {
4949
errors.push(HeaderAction {
5050
line_num,
51-
line: comment.full_line().to_string(),
51+
line: comment.full_line().to_owned(),
5252
action: LineAction::MigrateToUiTest {
53-
compiletest_name: directive.compiletest_name().to_string(),
54-
ui_test_name: directive.ui_test_name().unwrap().to_string(),
53+
compiletest_name: directive.compiletest_name().to_owned(),
54+
ui_test_name: directive.ui_test_name().unwrap().to_owned(),
5555
},
5656
});
5757
break;
5858
}
5959
DirectiveMatchResult::UseUITestName => {
6060
errors.push(HeaderAction {
6161
line_num,
62-
line: comment.full_line().to_string(),
62+
line: comment.full_line().to_owned(),
6363
action: LineAction::UseUITestName {
64-
compiletest_name: directive.compiletest_name().to_string(),
65-
ui_test_name: directive.ui_test_name().unwrap().to_string(),
64+
compiletest_name: directive.compiletest_name().to_owned(),
65+
ui_test_name: directive.ui_test_name().unwrap().to_owned(),
6666
},
6767
});
6868
break;
@@ -75,24 +75,29 @@ pub(super) fn check_file_headers(file_path: &Path) -> Result<(), HeaderError> {
7575
Err(ConditionError::ConvertToUiTest { compiletest_name, ui_test_name }) => {
7676
errors.push(HeaderAction {
7777
line_num,
78-
line: comment.full_line().to_string(),
78+
line: comment.full_line().to_owned(),
7979
action: LineAction::MigrateToUiTest { compiletest_name, ui_test_name },
8080
})
8181
}
8282
Err(ConditionError::UiTestUnknownTarget { target_substr }) => {
8383
errors.push(HeaderAction {
8484
line_num,
85-
line: comment.full_line().to_string(),
85+
line: comment.full_line().to_owned(),
8686
action: LineAction::Error {
8787
message: format!("invalid target substring: {}", target_substr),
8888
},
8989
})
9090
}
9191
Err(ConditionError::UseUiTestComment) => errors.push(HeaderAction {
9292
line_num,
93-
line: comment.full_line().to_string(),
93+
line: comment.full_line().to_owned(),
9494
action: LineAction::UseUiTestComment,
9595
}),
96+
Err(ConditionError::UnknownCondition { name }) => errors.push(HeaderAction {
97+
line_num,
98+
line: comment.full_line().to_owned(),
99+
action: LineAction::Error { message: format!("unknown condition {}", name) },
100+
}),
96101
}
97102
});
98103

@@ -182,6 +187,8 @@ enum ConditionError {
182187
ConvertToUiTest { compiletest_name: String, ui_test_name: String },
183188
/// The target substring in the comment is not known.
184189
UiTestUnknownTarget { target_substr: String },
190+
/// The comment looked like a condition, but was not known.
191+
UnknownCondition { name: String },
185192
}
186193

187194
/// Checks that a test comment uses the ui_test style only or ignore directives, and that
@@ -213,19 +220,16 @@ fn check_condition(comment: &TestComment<'_>) -> Result<(), ConditionError> {
213220
// wasm32-bare is an alias for wasm32-unknown-unknown
214221
Err(ConditionError::ConvertToUiTest {
215222
compiletest_name: String::from("wasm32-bare"),
216-
ui_test_name: String::from("wasm32-unknown-unknown"),
223+
ui_test_name: String::from("target-wasm32-unknown-unknown"),
217224
})
218-
} else if condition.starts_with("tidy-")
219-
|| ["stable", "beta", "nightly", "stage1", "cross-compile", "remote"]
220-
.contains(&condition)
221-
{
222-
// Ignore tidy directives, and a few other unknown comment types
223-
// FIXME (ui_test): make ui_test know about all of these
225+
} else if condition.starts_with("tidy-") {
226+
// Ignore tidy directives
224227
Ok(())
225-
} else {
226-
// Unknown only/ignore directive, or the target is not known, do nothing.
227-
eprintln!("unknown comment: {:#?}", comment);
228+
} else if UNSUPPORTED_CONDITIONS.contains(&condition) {
228229
Ok(())
230+
} else {
231+
// Unknown only/ignore directive, or the target is not known.
232+
Err(ConditionError::UnknownCondition { name: condition.to_owned() })
229233
}
230234
}
231235

@@ -321,6 +325,30 @@ impl From<io::Error> for HeaderError {
321325
}
322326
}
323327

328+
/// Directives that ui_test does not yet support. Used for emitting a warning instead of an error
329+
/// in tidy.
330+
// FIXME (ui_test): This should ideally be empty/removed by supporting everything.
331+
const UNSUPPORTED_CONDITIONS: &[&str] = [
332+
"stable",
333+
"beta",
334+
"nightly",
335+
"stage1",
336+
"remote",
337+
"cross-compile",
338+
"debug", // When building with debug assertions enabled. Primarily used for codegen tests.
339+
// `ignore-pass` is sorta like ui_test's `check-pass` but not really, compiletest instead
340+
// Falls back to a pass-mode which can be set by headers.
341+
"pass",
342+
"endian-big",
343+
"compare-mode-polonius",
344+
"compare-mode-next-solver",
345+
"compare-mode-next-solver-coherence",
346+
"compare-mode-split-dwarf",
347+
"compare-mode-split-dwarf-single",
348+
"llvm-version",
349+
]
350+
.as_slice();
351+
324352
// All components of target triples (including the whole triple) that were known by compiletest
325353
// at the time of writing (2023-08-13). This list is used to guide migration to ui_test style
326354
// only/ignore directives, since ui_test only knows how to do substring matches on target triples
@@ -556,6 +584,7 @@ const KNOWN_TARGET_COMPONENTS: &[&str] = [
556584
"tvos",
557585
"uefi",
558586
"unknown",
587+
"uwp",
559588
"vita",
560589
"vxworks",
561590
"wasi",

0 commit comments

Comments
 (0)