Skip to content

Commit f9cc011

Browse files
committed
Tidy up tidy error codes check
1 parent e5e5fcb commit f9cc011

File tree

1 file changed

+11
-26
lines changed

1 file changed

+11
-26
lines changed

src/tools/tidy/src/error_codes_check.rs

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,6 @@ fn check_if_error_code_is_test_in_explanation(f: &str, err_code: &str) -> bool {
8080
ignore_found
8181
}
8282

83-
macro_rules! some_or_continue {
84-
($e:expr) => {
85-
match $e {
86-
Some(e) => e,
87-
None => continue,
88-
}
89-
};
90-
}
91-
9283
fn extract_error_codes(
9384
f: &str,
9485
error_codes: &mut HashMap<String, ErrorCodeStatus>,
@@ -122,10 +113,16 @@ fn extract_error_codes(
122113
Some((file_name, _)) => file_name,
123114
},
124115
};
125-
let path = some_or_continue!(path.parent())
116+
117+
let Some(parent) = path.parent() else {
118+
continue;
119+
};
120+
121+
let path = parent
126122
.join(md_file_name)
127123
.canonicalize()
128124
.expect("failed to canonicalize error explanation file path");
125+
129126
match read_to_string(&path) {
130127
Ok(content) => {
131128
let has_test = check_if_error_code_is_test_in_explanation(&content, &err_code);
@@ -215,8 +212,6 @@ pub fn check(paths: &[&Path], bad: &mut bool) {
215212
// * #[error = "E0111"]
216213
let regex = Regex::new(r#"[(,"\s](E\d{4})[,)"]"#).unwrap();
217214

218-
println!("Checking which error codes lack tests...");
219-
220215
for path in paths {
221216
walk(path, &mut filter_dirs, &mut |entry, contents| {
222217
let file_name = entry.file_name();
@@ -245,20 +240,15 @@ pub fn check(paths: &[&Path], bad: &mut bool) {
245240
});
246241
}
247242
if found_explanations == 0 {
248-
eprintln!("No error code explanation was tested!");
249-
*bad = true;
243+
tidy_error!(bad, "No error code explanation was tested!");
250244
}
251245
if found_tests == 0 {
252-
eprintln!("No error code was found in compilation errors!");
253-
*bad = true;
246+
tidy_error!(bad, "No error code was found in compilation errors!");
254247
}
255248
if explanations.is_empty() {
256-
eprintln!("No error code explanation was found!");
257-
*bad = true;
249+
tidy_error!(bad, "No error code explanation was found!");
258250
}
259251
if errors.is_empty() {
260-
println!("Found {} error codes", error_codes.len());
261-
262252
for (err_code, error_status) in &error_codes {
263253
if !error_status.has_test && !EXEMPTED_FROM_TEST.contains(&err_code.as_str()) {
264254
errors.push(format!("Error code {err_code} needs to have at least one UI test!"));
@@ -310,11 +300,6 @@ pub fn check(paths: &[&Path], bad: &mut bool) {
310300
}
311301
errors.sort();
312302
for err in &errors {
313-
eprintln!("{err}");
314-
}
315-
println!("Found {} error(s) in error codes", errors.len());
316-
if !errors.is_empty() {
317-
*bad = true;
303+
tidy_error!(bad, "{err}");
318304
}
319-
println!("Done!");
320305
}

0 commit comments

Comments
 (0)