Skip to content

VectorCraft: An open-source, vector art tool written by scratch in pure Rust

test: scan source directories recursively

aiongg777a764a0e01
diff --git a/crates/eps/src/import/tests_generators.rs b/crates/eps/src/import/tests_generators.rs
index 892bcf417..2fe6ba324 100644
--- a/crates/eps/src/import/tests_generators.rs
+++ b/crates/eps/src/import/tests_generators.rs
@@ -768,17 +768,24 @@ fn errors_say_what_the_postscript_error_means() {
fn every_postscript_error_the_reader_raises_has_a_meaning() {
let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("src").join("import");
let mut raised = std::collections::BTreeSet::new();
- for entry in std::fs::read_dir(&dir).unwrap() {
- let path = entry.unwrap().path();
- let name = path.file_name().and_then(|n| n.to_str()).unwrap_or_default();
- if !name.ends_with(".rs") || name.starts_with("tests") {
- continue;
- }
- let text = std::fs::read_to_string(&path).unwrap();
- for marker in ["Ps(\"", "ps_err(\""] {
- for (at, _) in text.match_indices(marker) {
- let rest = &text[at + marker.len()..];
- raised.insert(rest[..rest.find('"').unwrap()].to_string());
+ let mut stack = vec![dir];
+ while let Some(d) = stack.pop() {
+ for entry in std::fs::read_dir(&d).unwrap() {
+ let path = entry.unwrap().path();
+ let name = path.file_name().and_then(|n| n.to_str()).unwrap_or_default();
+ if path.is_dir() {
+ stack.push(path);
+ continue;
+ }
+ if !name.ends_with(".rs") || name.starts_with("tests") {
+ continue;
+ }
+ let text = std::fs::read_to_string(&path).unwrap();
+ for marker in ["Ps(\"", "ps_err(\""] {
+ for (at, _) in text.match_indices(marker) {
+ let rest = &text[at + marker.len()..];
+ raised.insert(rest[..rest.find('"').unwrap()].to_string());
+ }
}
}
}
diff --git a/crates/ui-egui/src/i18n/tests.rs b/crates/ui-egui/src/i18n/tests.rs
index d383eaa01..22ade9b79 100644
--- a/crates/ui-egui/src/i18n/tests.rs
+++ b/crates/ui-egui/src/i18n/tests.rs
@@ -491,7 +491,9 @@ pub fn tl_literals() -> std::collections::BTreeSet<String> {
let path = entry.path();
let name = path.file_name().and_then(|n| n.to_str()).unwrap_or("");
if path.is_dir() {
- stack.push(path);
+ if name != "tests" {
+ stack.push(path);
+ }
} else if name.ends_with(".rs") && name != "lib.rs" && !name.starts_with("tests") {
let text = std::fs::read_to_string(&path).unwrap_or_default();
let code = text.split("#[cfg(test)]").next().unwrap_or("");
diff --git a/crates/ui-egui/src/tests_picks.rs b/crates/ui-egui/src/tests_picks.rs
index 686fddd18..609f38bd5 100644
--- a/crates/ui-egui/src/tests_picks.rs
+++ b/crates/ui-egui/src/tests_picks.rs
@@ -991,7 +991,9 @@ fn only_picks_shows_the_hosts_dialogs() {
let path = entry.path();
let name = path.file_name().and_then(|n| n.to_str()).unwrap_or("").to_string();
if path.is_dir() {
- stack.push(path);
+ if name != "tests" {
+ stack.push(path);
+ }
} else if name.ends_with(".rs") && !name.starts_with("tests") && name != "picks.rs" {
let key = path.strip_prefix(&dir).unwrap().to_string_lossy().replace('\\', "/");
scanned.insert(key, without_tests(&code_only(&std::fs::read_to_string(&path).unwrap())));