diff --git a/examples/src/lib.rs b/examples/src/lib.rs index e3f9f9aac..a7a757db0 100644 --- a/examples/src/lib.rs +++ b/examples/src/lib.rs @@ -137,37 +137,35 @@ mod test { let allowed_dirs = ["experimental", "testing"]; let root_dirs_with_exceptions = ["general", "supplementary", "restriction"]; - for entry in WalkDir::new("examples") { - if let Ok(entry) = entry { - let path = entry.path(); - let normalized_path = path.strip_prefix("examples").unwrap_or(path); + for entry in WalkDir::new("examples").into_iter().flatten() { + let path = entry.path(); + let normalized_path = path.strip_prefix("examples").unwrap_or(path); - if let Some(file_name) = normalized_path.file_name().and_then(OsStr::to_str) { - if forbidden_files_general.contains(&file_name) { - panic!( - "Forbidden file `.gitignore` found in examples directory: {:?}", - normalized_path - ); - } + if let Some(file_name) = normalized_path.file_name().and_then(OsStr::to_str) { + if forbidden_files_general.contains(&file_name) { + panic!( + "Forbidden file `.gitignore` found in examples directory: {}", + normalized_path.display() + ); + } - if forbidden_files_specific.contains(&file_name) { - let is_in_allowed_directory = allowed_dirs - .iter() - .any(|&allowed| normalized_path.starts_with(allowed)); + if forbidden_files_specific.contains(&file_name) { + let is_in_allowed_directory = allowed_dirs + .iter() + .any(|&allowed| normalized_path.starts_with(allowed)); - let is_in_root_of_exception_dirs = - root_dirs_with_exceptions.iter().any(|&exception| { - normalized_path.starts_with(exception) - && normalized_path.components().count() == 2 - }); + let is_in_root_of_exception_dirs = + root_dirs_with_exceptions.iter().any(|&exception| { + normalized_path.starts_with(exception) + && normalized_path.components().count() == 2 + }); - if !is_in_allowed_directory && !is_in_root_of_exception_dirs { - panic!( - "Forbidden file {:?} found in non-allowed directory: {:?}", - file_name, normalized_path - ); - } - } + assert!( + !(is_in_allowed_directory || is_in_root_of_exception_dirs), + "Forbidden file {} found in non-allowed directory: {}", + file_name, + normalized_path.display() + ); } } }