* Whether a caller is test code, for one blast-radius section. A Rust unit * test is told by its file's source (an inline `#[cfg(test)]` module, or the * parent's `#[cfg(test)] mod tests;`), so each file is read once.
(cg: CodeGraph)
| 4184 | * parent's `#[cfg(test)] mod tests;`), so each file is read once. |
| 4185 | */ |
| 4186 | private testCodeReading(cg: CodeGraph): (node: Node) => boolean { |
| 4187 | const root = cg.getProjectRoot(); |
| 4188 | const sources = new Map<string, string | undefined>(); |
| 4189 | const readSource: SourceReader = (filePath) => { |
| 4190 | if (!sources.has(filePath)) { |
| 4191 | let text: string | undefined; |
| 4192 | try { |
| 4193 | const abs = validatePathWithinRoot(root, filePath); |
| 4194 | text = abs === null ? undefined : readFileSync(abs, 'utf-8'); |
| 4195 | } catch { /* unreadable → not known to be test code */ } |
| 4196 | sources.set(filePath, text); |
| 4197 | } |
| 4198 | return sources.get(filePath); |
| 4199 | }; |
| 4200 | const verdicts = new Map<string, boolean>(); |
| 4201 | return (node) => { |
| 4202 | let v = verdicts.get(node.id); |
| 4203 | if (v === undefined) verdicts.set(node.id, (v = isTestCode(node, readSource))); |
| 4204 | return v; |
| 4205 | }; |
| 4206 | } |
| 4207 | |
| 4208 | /** |
| 4209 | * Compact "blast radius" for the entry symbols of an explore result: who |
no test coverage detected