LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
test: scan source directories recursively
aiongg567e7f11262e
diff --git a/apps/lightcraft/src/dialog_filter.rs b/apps/lightcraft/src/dialog_filter.rsindex 87760f799..27c3fd704 100644--- a/apps/lightcraft/src/dialog_filter.rs+++ b/apps/lightcraft/src/dialog_filter.rs@@ -133,13 +133,23 @@ mod tests {}}- /// Every dialog filter goes through the helper: `main.rs` must not call rfd's own+ /// Every dialog filter goes through the helper: no source file in `src/` calls rfd's own/// `add_filter`.#[test]fn no_dialog_bypasses_the_helper() {- for (file, src) in [("main.rs", include_str!("main.rs")), ("control_server.rs", include_str!("control_server.rs"))] {- assert!(!src.contains(".add_filter("), "{file} calls rfd's add_filter; use add_filter_nocase");+ let mut dirs = vec![std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("src")];+ let mut helper_used = false;+ while let Some(dir) = dirs.pop() {+ for path in std::fs::read_dir(&dir).unwrap().map(|entry| entry.unwrap().path()) {+ if path.is_dir() {+ dirs.push(path);+ } else if path.extension().is_some_and(|ext| ext == "rs") && !path.ends_with("dialog_filter.rs") {+ let src = std::fs::read_to_string(&path).unwrap();+ assert!(!src.contains(".add_filter("), "{} calls rfd's add_filter; use add_filter_nocase", path.display());+ helper_used |= src.contains(".add_filter_nocase(");+ }+ }}- assert!(include_str!("main.rs").contains(".add_filter_nocase("));+ assert!(helper_used);}}diff --git a/xtask/src/parity.rs b/xtask/src/parity.rsindex dcc940b92..538d93973 100644--- a/xtask/src/parity.rs+++ b/xtask/src/parity.rs@@ -153,6 +153,30 @@ pub fn ui_command_ids(menus_rs: &str) -> Vec<String> {ids}+/// The source of the UI menu module: `menus.rs` and every `.rs` file under `menus/`, so the+/// tables are found in whichever file of the module holds them.+pub fn menu_sources(ui_src: &Path) -> Result<String, String> {+ let mut text = std::fs::read_to_string(ui_src.join("menus.rs")).map_err(|e| format!("menus.rs: {e}"))?;+ let mut dirs = vec![ui_src.join("menus")];+ let mut files = Vec::new();+ while let Some(dir) = dirs.pop() {+ let Ok(entries) = std::fs::read_dir(&dir) else { continue };+ for path in entries.flatten().map(|e| e.path()) {+ if path.is_dir() {+ dirs.push(path);+ } else if path.extension().is_some_and(|ext| ext == "rs") {+ files.push(path);+ }+ }+ }+ files.sort();+ for path in files {+ text.push('\n');+ text.push_str(&std::fs::read_to_string(&path).map_err(|e| format!("{}: {e}", path.display()))?);+ }+ Ok(text)+}+fn known(set: &BTreeSet<String>, id: &str) -> bool {match id.strip_suffix('*') {Some(prefix) => set.iter().any(|s| s.starts_with(prefix)),@@ -314,7 +338,7 @@ pub fn run(root: &Path, write: bool) -> Result<(), String> {let path = root.join(DOC);let md = std::fs::read_to_string(&path).map_err(|e| format!("{}: {e}", path.display()))?;let doc = parse(&md);- let menus = std::fs::read_to_string(root.join("crates/ui-egui/src/menus.rs")).map_err(|e| format!("menus.rs: {e}"))?;+ let menus = menu_sources(&root.join("crates/ui-egui/src"))?;let mut commands = registry("commands")?;commands.extend(ui_command_ids(&menus));let controls = registry("controls")?;@@ -510,8 +534,8 @@ old/// The real menu tables: both are found, so every language command is a known id.#[test]fn reads_the_language_commands_from_menus_rs() {- let menus = include_str!("../../crates/ui-egui/src/menus.rs");- let ids = ui_command_ids(menus);+ let ui_src = Path::new(env!("CARGO_MANIFEST_DIR")).join("../crates/ui-egui/src");+ let ids = ui_command_ids(&menu_sources(&ui_src).unwrap());for id in ["view.detail", "app.language.english", "app.language.japanese", "app.language.simplifiedChinese", "app.language.portuguese"] {assert!(ids.iter().any(|known| known == id), "{id} not found");}