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.

tests/test_ast_includes.py:56

Show on the map →

Called by none

Calls _index, import_ast_includes

Checks

  • assert import_ast_includes(db, tmp_path / "repo") == 4
  • assert rows == [

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-010measuredtest_specs_resolve_beside_the_includer_then_by_unique_suffix → import_ast_includes
REQ-DDB-PIPE-003measuredtest_specs_resolve_beside_the_includer_then_by_unique_suffix → import_ast_includes → run_harvest
REQ-DDB-PIPE-011measuredtest_specs_resolve_beside_the_includer_then_by_unique_suffix → import_ast_includes → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_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
lines 58–58from clew.ast_includes import import_ast_includeslines 60–69db = _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": "", }, )lines 70–70assert import_ast_includes(db, tmp_path / "repo") == 4lines 71–77rows = ( 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() )lines 78–83assert rows == [ ("common.h", "library/common.h"), ("mbedtls/aes.h", "include/mbedtls/aes.h"), ("dup.h", None), ("stdio.h", None), ]

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.

tests/test_ast_includes.py:26

Checks

  • assert sorted(rows) == [["a/b.h", 1, 1], ["c.h", 1, 4], ["stdio.h", 0, 2]]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-010measuredtest_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
lines 28–28from clew.ast_includes import includes_harvesterlines 30–32src = ( b'#include "a/b.h"\n#include <stdio.h>\n#if X\n# include "c.h"\n#endif\n#include MACRO_H\n' )lines 33–33rows = includes_harvester().harvest(Parser("c").parse(src), src)lines 34–34assert sorted(rows) == [["a/b.h", 1, 1], ["c.h", 1, 4], ["stdio.h", 0, 2]]

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.

tests/test_ast_includes.py:86

Show on the map →

Called by none

Calls _index, import_ast_includes

Checks

  • assert import_ast_includes(db, tmp_path / "repo") == 0
  • assert sqlite3.connect(db).execute("SELECT COUNT(*) FROM ast_includes").fetchone() == (0,)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-010measuredtest_the_table_exists_when_nothing_includes_anything → import_ast_includes
REQ-DDB-PIPE-003measuredtest_the_table_exists_when_nothing_includes_anything → import_ast_includes → run_harvest
REQ-DDB-PIPE-011measuredtest_the_table_exists_when_nothing_includes_anything → import_ast_includes → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_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

Activity · 4 steps
lines 88–88from clew.ast_includes import import_ast_includeslines 90–90db = _index(tmp_path, {"main.py": "print(1)\n"})lines 91–91assert import_ast_includes(db, tmp_path / "repo") == 0lines 92–92assert sqlite3.connect(db).execute("SELECT COUNT(*) FROM ast_includes").fetchone() == (0,)