(projectRoot: string)
| 42 | * tools both read through this, so the two never disagree on what a test is. |
| 43 | */ |
| 44 | export function testCodeReading(projectRoot: string): (node: Node) => boolean { |
| 45 | const sources = new Map<string, string | undefined>(); |
| 46 | const readSource: SourceReader = (filePath) => { |
| 47 | if (!sources.has(filePath)) { |
| 48 | let text: string | undefined; |
| 49 | try { |
| 50 | const abs = validatePathWithinRoot(projectRoot, filePath); |
| 51 | text = abs === null ? undefined : readFileSync(abs, 'utf-8'); |
| 52 | } catch { /* unreadable → not known to be test code */ } |
| 53 | sources.set(filePath, text); |
| 54 | } |
| 55 | return sources.get(filePath); |
| 56 | }; |
| 57 | const verdicts = new Map<string, boolean>(); |
| 58 | return (node) => { |
| 59 | let v = verdicts.get(node.id); |
| 60 | if (v === undefined) verdicts.set(node.id, (v = isTestCode(node, readSource))); |
| 61 | return v; |
| 62 | }; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * `filePath` (project-relative) is a Rust module file its parent declares |
no test coverage detected