test_ast_includes.py¶
tests/test_ast_includes.py
Every `#include` is recorded from the parse, resolved to an indexed file where one matches (T3; 2.0.0).
test_specs_resolve_beside_the_includer_then_by_unique_suffix
None test_ast_includes.test_specs_resolve_beside_the_includer_then_by_unique_suffix(Path tmp_path)
Same directory first; else the unique indexed suffix; ambiguous or absent → NULL.
Checks
assert import_ast_includes(db, tmp_path / "repo") == 4assert rows == [
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-010 | measured | test_specs_resolve_beside_the_includer_then_by_unique_suffix → import_ast_includes |
| REQ-DDB-PIPE-003 | measured | test_specs_resolve_beside_the_includer_then_by_unique_suffix → import_ast_includes → run_harvest |
| REQ-DDB-PIPE-011 | measured | test_specs_resolve_beside_the_includer_then_by_unique_suffix → import_ast_includes → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_specs_resolve_beside_the_includer_then_by_unique_suffix → import_ast_includes → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language |
Source · 30 lines
def test_specs_resolve_beside_the_includer_then_by_unique_suffix(tmp_path: Path) -> None:
"""@brief Same directory first; else the unique indexed suffix; ambiguous or absent → NULL."""
from clew.ast_includes import import_ast_includes
db = _index(
tmp_path,
{
"library/aes.c": '#include "common.h"\n#include "mbedtls/aes.h"\n#include "dup.h"\n#include <stdio.h>\n',
"library/common.h": "",
"include/mbedtls/aes.h": "",
"a/dup.h": "",
"b/dup.h": "",
},
)
assert import_ast_includes(db, tmp_path / "repo") == 4
rows = (
sqlite3.connect(db)
.execute(
"SELECT i.spec, d.name FROM ast_includes i LEFT JOIN path d ON d.rowid = i.dst_id ORDER BY i.line"
)
.fetchall()
)
assert rows == [
("common.h", "library/common.h"),
("mbedtls/aes.h", "include/mbedtls/aes.h"),
("dup.h", None),
("stdio.h", None),
]
Activity · 5 steps
test_the_harvest_reads_quoted_system_and_nested_includes
None test_ast_includes.test_the_harvest_reads_quoted_system_and_nested_includes()
Quoted, angle-bracket and conditional includes; a macro include is skipped.
Checks
assert sorted(rows) == [["a/b.h", 1, 1], ["c.h", 1, 4], ["stdio.h", 0, 2]]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-010 | measured | test_the_harvest_reads_quoted_system_and_nested_includes → includes_harvester |
Source · 11 lines
def test_the_harvest_reads_quoted_system_and_nested_includes() -> None:
"""@brief Quoted, angle-bracket and conditional includes; a macro include is skipped."""
from clew.ast_includes import includes_harvester
src = (
b'#include "a/b.h"\n#include <stdio.h>\n#if X\n# include "c.h"\n#endif\n#include MACRO_H\n'
)
rows = includes_harvester().harvest(Parser("c").parse(src), src)
assert sorted(rows) == [["a/b.h", 1, 1], ["c.h", 1, 4], ["stdio.h", 0, 2]]
Activity · 4 steps
test_the_table_exists_when_nothing_includes_anything
None test_ast_includes.test_the_table_exists_when_nothing_includes_anything(Path tmp_path)
Empty, not absent.
Checks
assert import_ast_includes(db, tmp_path / "repo") == 0assert sqlite3.connect(db).execute("SELECT COUNT(*) FROM ast_includes").fetchone() == (0,)
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-010 | measured | test_the_table_exists_when_nothing_includes_anything → import_ast_includes |
| REQ-DDB-PIPE-003 | measured | test_the_table_exists_when_nothing_includes_anything → import_ast_includes → run_harvest |
| REQ-DDB-PIPE-011 | measured | test_the_table_exists_when_nothing_includes_anything → import_ast_includes → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_the_table_exists_when_nothing_includes_anything → import_ast_includes → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language |
Source · 7 lines
def test_the_table_exists_when_nothing_includes_anything(tmp_path: Path) -> None:
"""@brief Empty, not absent."""
from clew.ast_includes import import_ast_includes
db = _index(tmp_path, {"main.py": "print(1)\n"})
assert import_ast_includes(db, tmp_path / "repo") == 0
assert sqlite3.connect(db).execute("SELECT COUNT(*) FROM ast_includes").fetchone() == (0,)1 more lines, not shown