STRA-338: the bring-up print gate treats the children of test-only files as test-only (split modules)

This commit is contained in:
Pavlo Ratushnyi
2026-11-06 14:45:45 +01:00
parent 5aec574627
commit cae9e1ebc1
@@ -90,9 +90,37 @@ fn test_only(files: &[PathBuf]) -> Vec<PathBuf> {
}
}
}
descend(&mut gated);
gated
}
/// The children of a test-only file are test-only too: every `mod name;` it declares (split modules, `#[path]` ones included).
fn descend(gated: &mut Vec<PathBuf>) {
let mut next = 0;
while next < gated.len() {
let file = gated[next].clone();
next += 1;
let Ok(text) = fs::read_to_string(&file) else { continue };
let Some(dir) = file.parent() else { continue };
let own = file.file_stem().map(|stem| dir.join(stem)).unwrap_or_default();
let lines: Vec<&str> = text.lines().collect();
for (index, line) in lines.iter().enumerate() {
let trimmed = line.trim_start();
let declared = trimmed.strip_prefix("pub(crate) mod ").or_else(|| trimmed.strip_prefix("pub(super) mod ")).or_else(|| trimmed.strip_prefix("pub mod ")).or_else(|| trimmed.strip_prefix("mod "));
let Some(name) = declared.and_then(|rest| rest.strip_suffix(';')) else { continue };
let mut candidates = vec![own.join(format!("{name}.rs")), own.join(name).join("mod.rs"), dir.join(format!("{name}.rs"))];
if let Some(path) = lines[..index].iter().rev().take(3).find_map(|l| l.trim().strip_prefix("#[path = \"").and_then(|r| r.split('"').next())) {
candidates.push(dir.join(path));
}
for candidate in candidates {
if candidate.is_file() && !gated.contains(&candidate) {
gated.push(candidate);
}
}
}
}
}
/// The first string literal of the macro call starting at `at` in `lines`, or `None`.
fn first_literal(lines: &[&str], at: usize, column: usize) -> Option<String> {
let mut text = String::from(&lines[at][column..]);