From fa31c7d49e7456b57bc32de118e72e0d7045ef6e Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Sat, 2 Aug 2025 16:16:41 +0800 Subject: [PATCH] Pull out recursive ui test check into its own function --- src/tools/tidy/src/ui_tests.rs | 65 +++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/src/tools/tidy/src/ui_tests.rs b/src/tools/tidy/src/ui_tests.rs index 6c83764cc194..b968ea5f2d89 100644 --- a/src/tools/tidy/src/ui_tests.rs +++ b/src/tools/tidy/src/ui_tests.rs @@ -40,34 +40,7 @@ pub fn check(root_path: &Path, bless: bool, bad: &mut bool) { ); } - let mut remaining_issue_names: BTreeSet<&str> = allowed_issue_names.clone(); - - let (ui, ui_fulldeps) = (path.join("ui"), path.join("ui-fulldeps")); - let paths = [ui.as_path(), ui_fulldeps.as_path()]; - crate::walk::walk_no_read(&paths, |_, _| false, &mut |entry| { - let file_path = entry.path(); - if let Some(ext) = file_path.extension().and_then(OsStr::to_str) { - check_unexpected_extension(bad, file_path, ext); - - // NB: We do not use file_stem() as some file names have multiple `.`s and we - // must strip all of them. - let testname = - file_path.file_name().unwrap().to_str().unwrap().split_once('.').unwrap().0; - if ext == "stderr" || ext == "stdout" || ext == "fixed" { - check_stray_output_snapshot(bad, file_path, testname); - check_empty_output_snapshot(bad, file_path); - } - - deny_new_nondescriptive_test_names( - bad, - path, - &mut remaining_issue_names, - file_path, - testname, - ext, - ); - } - }); + let remaining_issue_names = recursively_check_ui_tests(bad, path, &allowed_issue_names); // if there are any file names remaining, they were moved on the fs. // our data must remain up to date, so it must be removed from issues.txt @@ -98,6 +71,42 @@ pub fn check(root_path: &Path, bless: bool, bad: &mut bool) { } } +fn recursively_check_ui_tests<'issues>( + bad: &mut bool, + path: &Path, + allowed_issue_names: &'issues BTreeSet<&'issues str>, +) -> BTreeSet<&'issues str> { + let mut remaining_issue_names: BTreeSet<&str> = allowed_issue_names.clone(); + + let (ui, ui_fulldeps) = (path.join("ui"), path.join("ui-fulldeps")); + let paths = [ui.as_path(), ui_fulldeps.as_path()]; + crate::walk::walk_no_read(&paths, |_, _| false, &mut |entry| { + let file_path = entry.path(); + if let Some(ext) = file_path.extension().and_then(OsStr::to_str) { + check_unexpected_extension(bad, file_path, ext); + + // NB: We do not use file_stem() as some file names have multiple `.`s and we + // must strip all of them. + let testname = + file_path.file_name().unwrap().to_str().unwrap().split_once('.').unwrap().0; + if ext == "stderr" || ext == "stdout" || ext == "fixed" { + check_stray_output_snapshot(bad, file_path, testname); + check_empty_output_snapshot(bad, file_path); + } + + deny_new_nondescriptive_test_names( + bad, + path, + &mut remaining_issue_names, + file_path, + testname, + ext, + ); + } + }); + remaining_issue_names +} + fn check_unexpected_extension(bad: &mut bool, file_path: &Path, ext: &str) { const EXPECTED_TEST_FILE_EXTENSIONS: &[&str] = &[ "rs", // test source files