test_bare_call_one_function.py

tests/test_bare_call_one_function.py

A bare call to a function the index holds twice — its prototype and its definition.

test_a_bare_call_reaches_a_RECOVERED_definition

None test_bare_call_one_function.test_a_bare_call_reaches_a_RECOVERED_definition(Path tmp_path)

THE REPORTED SHAPE. doxygen saw the prototype and not the definition, so the only definition row is the one `recover_ast_symbols` wrote, spelled the way the source spells it. The call is to the one function both rows describe, and it must land on the row with the body.

tests/test_bare_call_one_function.py:148

Show on the map →

Called by none

Calls _build, _edges_to, build_call_edges, import_ast_call_edges, recover_ast_symbols

Checks

  • assert recover_ast_symbols(db, repo) >= 1, "premise: the guarded definition is recovered"
  • assert _edges_to(db, "lib_fn") == [("use_it", recovered, SOURCE_AST)]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_a_bare_call_reaches_a_RECOVERED_definition → recover_ast_symbols
REQ-DDB-PIPE-003measuredtest_a_bare_call_reaches_a_RECOVERED_definition → build_call_edges
REQ-DDB-PIPE-011measuredtest_a_bare_call_reaches_a_RECOVERED_definition → import_ast_call_edges → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_bare_call_reaches_a_RECOVERED_definition → import_ast_call_edges → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_a_bare_call_reaches_a_RECOVERED_definition → recover_ast_symbols → _recover_into → all
Source · 17 lines
def test_a_bare_call_reaches_a_RECOVERED_definition(tmp_path: Path) -> None:
    """THE REPORTED SHAPE. doxygen saw the prototype and not the definition, so the only
    definition row is the one `recover_ast_symbols` wrote, spelled the way the source spells it.
    The call is to the one function both rows describe, and it must land on the row with the
    body."""
    repo, db = _build(tmp_path, _GUARDED_SOURCE, [_PROTOTYPE, _USE_IT])
    assert recover_ast_symbols(db, repo) >= 1, "premise: the guarded definition is recovered"
    build_call_edges(db)
    import_ast_call_edges(db, repo)
    conn = sqlite3.connect(str(db))
    recovered = conn.execute(
        "SELECT rowid FROM memberdef WHERE name = 'lib_fn' AND dg_source = 'ast'"
    ).fetchone()[0]
    conn.close()
    assert _edges_to(db, "lib_fn") == [("use_it", recovered, SOURCE_AST)]

Activity · 8 steps
lines 153–153repo, db = _build(tmp_path, _GUARDED_SOURCE, [_PROTOTYPE, _USE_IT])lines 154–154assert recover_ast_symbols(db, repo) >= 1, "premise: the guarded definition is recovered"lines 155–155build_call_edges(db)lines 156–156import_ast_call_edges(db, repo)lines 157–157conn = sqlite3.connect(str(db))lines 158–160recovered = conn.execute( "SELECT rowid FROM memberdef WHERE name = 'lib_fn' AND dg_source = 'ast'" ).fetchone()[0]lines 161–161conn.close()lines 162–162assert _edges_to(db, "lib_fn") == [("use_it", recovered, SOURCE_AST)]

test_a_bare_call_reaches_a_pair_doxygen_wrote_both_halves_of

None test_bare_call_one_function.test_a_bare_call_reaches_a_pair_doxygen_wrote_both_halves_of(Path tmp_path)

THE OTHER SHAPE. doxygen copies the definition's body range onto the header row, so both rows carry one body and one identity. The edge goes to the definition — the row whose own file holds the body.

tests/test_bare_call_one_function.py:165

Show on the map →

Called by none

Calls _build, _edges_to, build_call_edges, import_ast_call_edges

Checks

  • assert _edges_to(db, "lib_fn") == [("use_it", 11, SOURCE_AST)]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-003measuredtest_a_bare_call_reaches_a_pair_doxygen_wrote_both_halves_of → build_call_edges
REQ-DDB-PIPE-011measuredtest_a_bare_call_reaches_a_pair_doxygen_wrote_both_halves_of → import_ast_call_edges → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_bare_call_reaches_a_pair_doxygen_wrote_both_halves_of → import_ast_call_edges → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_a_bare_call_reaches_a_pair_doxygen_wrote_both_halves_of → import_ast_call_edges → _fold_all_files → _fold_call_payload → _ast_record_call_edge → _narrow_by_receiver → _one_class → all
Source · 12 lines
def test_a_bare_call_reaches_a_pair_doxygen_wrote_both_halves_of(tmp_path: Path) -> None:
    """THE OTHER SHAPE. doxygen copies the definition's body range onto the header row, so both
    rows carry one body and one identity. The edge goes to the definition — the row whose own
    file holds the body."""
    definition = (11, "lib_fn", "int lib_fn", "(int a, char *b)", 2, 5, _C, _C)
    header = (10, "lib_fn", "int lib_fn", "(int a, char *b)", 2, 5, _C, _H)
    repo, db = _build(tmp_path, _PLAIN_SOURCE, [header, definition, _USE_IT])
    build_call_edges(db)
    import_ast_call_edges(db, repo)
    assert _edges_to(db, "lib_fn") == [("use_it", 11, SOURCE_AST)]

Activity · 6 steps
lines 169–169definition = (11, "lib_fn", "int lib_fn", "(int a, char *b)", 2, 5, _C, _C)lines 170–170header = (10, "lib_fn", "int lib_fn", "(int a, char *b)", 2, 5, _C, _H)lines 171–171repo, db = _build(tmp_path, _PLAIN_SOURCE, [header, definition, _USE_IT])lines 172–172build_call_edges(db)lines 173–173import_ast_call_edges(db, repo)lines 174–174assert _edges_to(db, "lib_fn") == [("use_it", 11, SOURCE_AST)]

test_a_member_call_is_not_resolved_by_the_pair_alone

None test_bare_call_one_function.test_a_member_call_is_not_resolved_by_the_pair_alone()

THE CONTROL on the source. `obj.lib_fn()` names a function of that name and says nothing about the receiver; the unverified-receiver refusal holds whether the name has one row or a decl/def pair.

tests/test_bare_call_one_function.py:251

Show on the map →

Called by none

Calls _ast_record_call_edge, _one_function_targets

Checks

  • assert targets == {(10, 11): 11}, "premise: the pair is one function"
  • assert resolved == []

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-WIKI-054inferredtest_a_member_call_is_not_resolved_by_the_pair_alone → _ast_record_call_edge → _narrow_by_receiver → _one_class → all
Source · 14 lines
def test_a_member_call_is_not_resolved_by_the_pair_alone() -> None:
    """THE CONTROL on the source. `obj.lib_fn()` names a function of that name and says nothing
    about the receiver; the unverified-receiver refusal holds whether the name has one row or a
    decl/def pair."""
    identity = ("lib_fn", "lib_fn", "(inta,char*b)")
    targets = _one_function_targets(
        {"lib_fn": [10, 11]}, {10: identity, 11: identity}, {11: (2, 2)}, homes={11}
    )
    assert targets == {(10, 11): 11}, "premise: the pair is one function"
    resolved: list[tuple[int, int, str]] = []
    _ast_record_call_edge(
        1, "lib_fn", {"lib_fn": [10, 11]}, resolved, [], SOURCE_AST_MEMBER, one_function=targets
    )
    assert resolved == []

1 more lines, not shown

Activity · 6 steps
lines 255–255identity = ("lib_fn", "lib_fn", "(inta,char*b)")lines 256–258targets = _one_function_targets( {"lib_fn": [10, 11]}, {10: identity, 11: identity}, {11: (2, 2)}, homes={11} )lines 259–259assert targets == {(10, 11): 11}, "premise: the pair is one function"lines 260–260resolved: list[tuple[int, int, str]] = []lines 261–263_ast_record_call_edge( 1, "lib_fn", {"lib_fn": [10, 11]}, resolved, [], SOURCE_AST_MEMBER, one_function=targets )lines 264–264assert resolved == []

test_two_bodies_with_one_signature_are_still_refused

None test_bare_call_one_function.test_two_bodies_with_one_signature_are_still_refused()

THE CONTROL on the resolution. Two `static int helper(void)` definitions in two files share an identity and are still two functions; a name cannot say which one a call meant, so the call is refused exactly as before (gh#347) and the refusal is recorded.

tests/test_bare_call_one_function.py:224

Show on the map →

Called by none

Calls _ast_record_call_edge, _one_function_targets

Checks

  • assert targets == {}, "two bodies are two functions"
  • assert resolved == [] and unresolved == [[30, 31]]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-WIKI-054inferredtest_two_bodies_with_one_signature_are_still_refused → _ast_record_call_edge → _narrow_by_receiver → _one_class → all
Source · 27 lines
def test_two_bodies_with_one_signature_are_still_refused() -> None:
    """THE CONTROL on the resolution. Two `static int helper(void)` definitions in two files
    share an identity and are still two functions; a name cannot say which one a call meant, so
    the call is refused exactly as before (gh#347) and the refusal is recorded."""
    identity = ("helper", "helper", "(void)")
    targets = _one_function_targets(
        {"helper": [30, 31]},
        {30: identity, 31: identity},
        {30: (1, 10), 31: (2, 10)},
        homes={30, 31},
    )
    assert targets == {}, "two bodies are two functions"
    resolved: list[tuple[int, int, str]] = []
    unresolved: list[list[int]] = []
    _ast_record_call_edge(
        1,
        "helper",
        {"helper": [30, 31]},
        resolved,
        [],
        SOURCE_AST,
        unresolved=unresolved,
        one_function=targets,
    )
    assert resolved == [] and unresolved == [[30, 31]]

Activity · 7 steps
lines 228–228identity = ("helper", "helper", "(void)")lines 229–234targets = _one_function_targets( {"helper": [30, 31]}, {30: identity, 31: identity}, {30: (1, 10), 31: (2, 10)}, homes={30, 31}, )lines 235–235assert targets == {}, "two bodies are two functions"lines 236–236resolved: list[tuple[int, int, str]] = []lines 237–237unresolved: list[list[int]] = []lines 238–247_ast_record_call_edge( 1, "helper", {"helper": [30, 31]}, resolved, [], SOURCE_AST, unresolved=unresolved, one_function=targets, )lines 248–248assert resolved == [] and unresolved == [[30, 31]]