test_macro_query.py

tests/test_macro_query.py

gh#373 — a `#define` is reachable: its expansion, its parameters, its sites.

test_a_bare_lookup_is_unchanged_by_the_macro_kind_fix

None test_macro_query.test_a_bare_lookup_is_unchanged_by_the_macro_kind_fix(Path macro_db)

A BARE lookup is unchanged — still the function, still the disclosure.

tests/test_macro_query.py:447

Checks

  • assert doss is not None
  • assert doss.kind == "function", "a BARE lookup must still resolve to the function"
  • assert "#define" in doss.macro_collision, "and must still disclose the collision"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_a_bare_lookup_is_unchanged_by_the_macro_kind_fix → function_dossier → _dossier_conn → symbol_provenance
REQ-DDB-PIPE-003inferredtest_a_bare_lookup_is_unchanged_by_the_macro_kind_fix → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_harvest_calls → is_python_tree
REQ-DDB-PIPE-011inferredtest_a_bare_lookup_is_unchanged_by_the_macro_kind_fix → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_bare_lookup_is_unchanged_by_the_macro_kind_fix → function_dossier → _dossier_conn → _body_and_external → external_callees → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-001measuredtest_a_bare_lookup_is_unchanged_by_the_macro_kind_fix → function_dossier → connect
REQ-DDB-QUERY-002measuredtest_a_bare_lookup_is_unchanged_by_the_macro_kind_fix → function_dossier → _dossier_conn → unresolved_inbound_for_rowids
REQ-DDB-QUERY-003measuredtest_a_bare_lookup_is_unchanged_by_the_macro_kind_fix → function_dossier → _dossier_conn → function_candidates
REQ-DDB-QUERY-004measuredtest_a_bare_lookup_is_unchanged_by_the_macro_kind_fix → function_dossier
REQ-DDB-QUERY-006measuredtest_a_bare_lookup_is_unchanged_by_the_macro_kind_fix → function_dossier → _dossier_conn → gates_covering
REQ-DDB-QUERY-009measuredtest_a_bare_lookup_is_unchanged_by_the_macro_kind_fix → function_dossier
REQ-DDB-QUERY-010measuredtest_a_bare_lookup_is_unchanged_by_the_macro_kind_fix → function_dossier
REQ-DDB-QUERY-012measuredtest_a_bare_lookup_is_unchanged_by_the_macro_kind_fix → function_dossier → _dossier_conn → _macro_dossier
REQ-DDB-QUERY-013inferredtest_a_bare_lookup_is_unchanged_by_the_macro_kind_fix → function_dossier → _dossier_conn → config_defaults_conn
REQ-DDB-SCHEMA-011measuredtest_a_bare_lookup_is_unchanged_by_the_macro_kind_fix → function_dossier → _dossier_conn → locks_held_for_rowids
Source · 17 lines
def test_a_bare_lookup_is_unchanged_by_the_macro_kind_fix(macro_db: Path) -> None:
    """THE REGRESSION GUARD FOR THE DECISION NOT TAKEN. The tempting fix was to change
    `dossier.py`'s `if not cands` guard so a colliding name preferred the macro. That is the
    re-ranking this repo already tried and WITHDREW — the standing disposition for a bare name is a
    NOTE, not a demotion, because the same rule would fire on `#define isalpha(c)` sitting beside a
    legitimate `int isalpha(int);`.

    So the fix was confined to the builder, and this asserts the bare path still behaves exactly as
    the withdrawn-re-ranking tests above require: the function wins and the collision is disclosed.

    @brief The bare-name path did not move.
    @version 1
    """
    doss = function_dossier(macro_db, "WRAP")
    assert doss is not None
    assert doss.kind == "function", "a BARE lookup must still resolve to the function"
    assert "#define" in doss.macro_collision, "and must still disclose the collision"

1 more lines, not shown

Activity · 4 steps
lines 460–460doss = function_dossier(macro_db, "WRAP")lines 461–461assert doss is not Nonelines 462–462assert doss.kind == "function", "a BARE lookup must still resolve to the function"lines 463–463assert "#define" in doss.macro_collision, "and must still disclose the collision"

test_a_bodiless_colliding_identity_discloses_the_macro_collision

None test_macro_query.test_a_bodiless_colliding_identity_discloses_the_macro_collision(Path macro_db)

A colliding, bodiless identity DISCLOSES that it may be a macro artefact.

tests/test_macro_query.py:244

Checks

  • assert doss is not None
  • assert doss.line_start is None, "the fixture's collision row must have no body extent"
  • assert "#define" in doss.macro_collision
  • assert "macros" in doss.macro_collision, "the note must name the field that answers"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_a_bodiless_colliding_identity_discloses_the_macro_collision → function_dossier → _dossier_conn → symbol_provenance
REQ-DDB-PIPE-003inferredtest_a_bodiless_colliding_identity_discloses_the_macro_collision → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_harvest_calls → is_python_tree
REQ-DDB-PIPE-011inferredtest_a_bodiless_colliding_identity_discloses_the_macro_collision → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_bodiless_colliding_identity_discloses_the_macro_collision → function_dossier → _dossier_conn → _body_and_external → external_callees → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-001measuredtest_a_bodiless_colliding_identity_discloses_the_macro_collision → function_dossier → connect
REQ-DDB-QUERY-002measuredtest_a_bodiless_colliding_identity_discloses_the_macro_collision → function_dossier → _dossier_conn → unresolved_inbound_for_rowids
REQ-DDB-QUERY-003measuredtest_a_bodiless_colliding_identity_discloses_the_macro_collision → function_dossier → _dossier_conn → function_candidates
REQ-DDB-QUERY-004measuredtest_a_bodiless_colliding_identity_discloses_the_macro_collision → function_dossier
REQ-DDB-QUERY-006measuredtest_a_bodiless_colliding_identity_discloses_the_macro_collision → function_dossier → _dossier_conn → gates_covering
REQ-DDB-QUERY-009measuredtest_a_bodiless_colliding_identity_discloses_the_macro_collision → function_dossier
REQ-DDB-QUERY-010measuredtest_a_bodiless_colliding_identity_discloses_the_macro_collision → function_dossier
REQ-DDB-QUERY-012measuredtest_a_bodiless_colliding_identity_discloses_the_macro_collision → function_dossier → _dossier_conn → _macro_dossier
REQ-DDB-QUERY-013inferredtest_a_bodiless_colliding_identity_discloses_the_macro_collision → function_dossier → _dossier_conn → config_defaults_conn
REQ-DDB-SCHEMA-011measuredtest_a_bodiless_colliding_identity_discloses_the_macro_collision → function_dossier → _dossier_conn → locks_held_for_rowids
Source · 16 lines
def test_a_bodiless_colliding_identity_discloses_the_macro_collision(macro_db: Path) -> None:
    """gh#403. `WRAP` resolves to the struct-member stand-in: `kind='function'`, no body
    extent, one of the rows doxygen writes for a macro appearing in a declarator. The
    graded run measured a reader acting on that headline and going to source 8-9 times per
    run, so the payload says so.

    @brief The collision note fires on a bodiless row whose name is a macro.
    @version 1
    """
    doss = function_dossier(macro_db, "WRAP")
    assert doss is not None
    assert doss.line_start is None, "the fixture's collision row must have no body extent"
    assert "#define" in doss.macro_collision
    assert "macros" in doss.macro_collision, "the note must name the field that answers"

Activity · 5 steps
lines 253–253doss = function_dossier(macro_db, "WRAP")lines 254–254assert doss is not Nonelines 255–255assert doss.line_start is None, "the fixture's collision row must have no body extent"lines 256–256assert "#define" in doss.macro_collisionlines 257–257assert "macros" in doss.macro_collision, "the note must name the field that answers"

test_a_declared_undefined_function_is_disclosed_and_still_described

None test_macro_query.test_a_declared_undefined_function_is_disclosed_and_still_described(Path macro_db)

A legitimate bodiless DECLARATION is disclosed, not replaced.

tests/test_macro_query.py:285

Checks

  • assert doss is not None
  • assert doss.macro_collision, "the shape is ambiguous and the payload must say so"
  • assert doss.kind == "function", "the note must not change which subject is described"
  • assert doss.signature == "int PLATFORM_CALL(int)"
  • assert doss.brief == "the platform hook", "the declaration's documentation must survive"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_a_declared_undefined_function_is_disclosed_and_still_described → function_dossier → _dossier_conn → symbol_provenance
REQ-DDB-PIPE-003inferredtest_a_declared_undefined_function_is_disclosed_and_still_described → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_harvest_calls → is_python_tree
REQ-DDB-PIPE-011inferredtest_a_declared_undefined_function_is_disclosed_and_still_described → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_declared_undefined_function_is_disclosed_and_still_described → function_dossier → _dossier_conn → _body_and_external → external_callees → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-001measuredtest_a_declared_undefined_function_is_disclosed_and_still_described → function_dossier → connect
REQ-DDB-QUERY-002measuredtest_a_declared_undefined_function_is_disclosed_and_still_described → function_dossier → _dossier_conn → unresolved_inbound_for_rowids
REQ-DDB-QUERY-003measuredtest_a_declared_undefined_function_is_disclosed_and_still_described → function_dossier → _dossier_conn → function_candidates
REQ-DDB-QUERY-004measuredtest_a_declared_undefined_function_is_disclosed_and_still_described → function_dossier
REQ-DDB-QUERY-006measuredtest_a_declared_undefined_function_is_disclosed_and_still_described → function_dossier → _dossier_conn → gates_covering
REQ-DDB-QUERY-009measuredtest_a_declared_undefined_function_is_disclosed_and_still_described → function_dossier
REQ-DDB-QUERY-010measuredtest_a_declared_undefined_function_is_disclosed_and_still_described → function_dossier
REQ-DDB-QUERY-012measuredtest_a_declared_undefined_function_is_disclosed_and_still_described → function_dossier → _dossier_conn → _macro_dossier
REQ-DDB-QUERY-013inferredtest_a_declared_undefined_function_is_disclosed_and_still_described → function_dossier → _dossier_conn → config_defaults_conn
REQ-DDB-SCHEMA-011measuredtest_a_declared_undefined_function_is_disclosed_and_still_described → function_dossier → _dossier_conn → locks_held_for_rowids
Source · 25 lines
def test_a_declared_undefined_function_is_disclosed_and_still_described(macro_db: Path) -> None:
    """THE ASSERTION THAT MAKES THE DESIGN DECISION AUDITABLE, and it pins a deliberate
    FALSE POSITIVE rather than the absence of one.

    `PLATFORM_CALL` is a macro AND a declared, never-defined function — indistinguishable
    by any structural rule from the doxygen artefact, because `function_candidates` prefers
    definition rows and so the chosen row is bodiless in both cases. A demotion would
    therefore replace this documented declaration with a macro payload, which is why the
    fix is a note.

    So the note DOES fire here, and the payload still describes the DECLARATION — same
    signature, same brief, nothing substituted. That is what makes firing on the legitimate
    case harmless: the reader is told both things are true and chooses.

    @brief A legitimate bodiless declaration keeps its own payload beside the note.
    @version 1
    """
    doss = function_dossier(macro_db, "PLATFORM_CALL")
    assert doss is not None
    assert doss.macro_collision, "the shape is ambiguous and the payload must say so"
    assert doss.kind == "function", "the note must not change which subject is described"
    assert doss.signature == "int PLATFORM_CALL(int)"
    assert doss.brief == "the platform hook", "the declaration's documentation must survive"

Activity · 6 steps
lines 302–302doss = function_dossier(macro_db, "PLATFORM_CALL")lines 303–303assert doss is not Nonelines 304–304assert doss.macro_collision, "the shape is ambiguous and the payload must say so"lines 305–305assert doss.kind == "function", "the note must not change which subject is described"lines 306–306assert doss.signature == "int PLATFORM_CALL(int)"lines 307–307assert doss.brief == "the platform hook", "the declaration's documentation must survive"

test_a_defined_function_sharing_a_macro_name_is_not_flagged

None test_macro_query.test_a_defined_function_sharing_a_macro_name_is_not_flagged(Path macro_db)

A REAL function that shares a macro's name is not disclosed as an artefact.

tests/test_macro_query.py:262

Checks

  • assert doss is not None
  • assert doss.kind == "function"
  • assert doss.line_start == 210, "the definition-preferring pick must be the body row"
  • assert doss.macros, "the macro panel must still report the #define"
  • assert doss.macro_collision == ""

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_a_defined_function_sharing_a_macro_name_is_not_flagged → function_dossier → _dossier_conn → symbol_provenance
REQ-DDB-PIPE-003inferredtest_a_defined_function_sharing_a_macro_name_is_not_flagged → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_harvest_calls → is_python_tree
REQ-DDB-PIPE-011inferredtest_a_defined_function_sharing_a_macro_name_is_not_flagged → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_defined_function_sharing_a_macro_name_is_not_flagged → function_dossier → _dossier_conn → _body_and_external → external_callees → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-001measuredtest_a_defined_function_sharing_a_macro_name_is_not_flagged → function_dossier → connect
REQ-DDB-QUERY-002measuredtest_a_defined_function_sharing_a_macro_name_is_not_flagged → function_dossier → _dossier_conn → unresolved_inbound_for_rowids
REQ-DDB-QUERY-003measuredtest_a_defined_function_sharing_a_macro_name_is_not_flagged → function_dossier → _dossier_conn → function_candidates
REQ-DDB-QUERY-004measuredtest_a_defined_function_sharing_a_macro_name_is_not_flagged → function_dossier
REQ-DDB-QUERY-006measuredtest_a_defined_function_sharing_a_macro_name_is_not_flagged → function_dossier → _dossier_conn → gates_covering
REQ-DDB-QUERY-009measuredtest_a_defined_function_sharing_a_macro_name_is_not_flagged → function_dossier
REQ-DDB-QUERY-010measuredtest_a_defined_function_sharing_a_macro_name_is_not_flagged → function_dossier
REQ-DDB-QUERY-012measuredtest_a_defined_function_sharing_a_macro_name_is_not_flagged → function_dossier → _dossier_conn → _macro_dossier
REQ-DDB-QUERY-013inferredtest_a_defined_function_sharing_a_macro_name_is_not_flagged → function_dossier → _dossier_conn → config_defaults_conn
REQ-DDB-SCHEMA-011measuredtest_a_defined_function_sharing_a_macro_name_is_not_flagged → function_dossier → _dossier_conn → locks_held_for_rowids
Source · 21 lines
def test_a_defined_function_sharing_a_macro_name_is_not_flagged(macro_db: Path) -> None:
    """THE NEGATIVE HALF, AND THE REASON THIS IS A NOTE AND NOT A DEMOTION. `DUAL` is a
    macro and also a function with a body — the C library idiom. `function_candidates`
    prefers definition rows, so the chosen row HAS an extent and the disclosure stays
    silent.

    Without this assertion the note would read as "fires whenever a name is `#define`d",
    which is a claim about ~2,000 mbedtls rows AND about every `#define`d libc wrapper,
    and a reader who saw it on both would learn to ignore it.

    @brief A defined function's dossier carries no collision note.
    @version 1
    """
    doss = function_dossier(macro_db, "DUAL")
    assert doss is not None
    assert doss.kind == "function"
    assert doss.line_start == 210, "the definition-preferring pick must be the body row"
    assert doss.macros, "the macro panel must still report the #define"
    assert doss.macro_collision == ""

Activity · 6 steps
lines 275–275doss = function_dossier(macro_db, "DUAL")lines 276–276assert doss is not Nonelines 277–277assert doss.kind == "function"lines 278–278assert doss.line_start == 210, "the definition-preferring pick must be the body row"lines 279–279assert doss.macros, "the macro panel must still report the #define"lines 280–280assert doss.macro_collision == ""

test_a_macro_only_name_gets_a_dossier

None test_macro_query.test_a_macro_only_name_gets_a_dossier(Path macro_db)

A name that is only a macro gets a dossier instead of nothing.

tests/test_macro_query.py:215

Checks

  • assert doss is not None
  • assert doss.kind == MACRO_KIND
  • assert [m.file for m in doss.macros] == ["library/common.h", "programs/app.c"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_a_macro_only_name_gets_a_dossier → function_dossier → _dossier_conn → symbol_provenance
REQ-DDB-PIPE-003inferredtest_a_macro_only_name_gets_a_dossier → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_harvest_calls → is_python_tree
REQ-DDB-PIPE-011inferredtest_a_macro_only_name_gets_a_dossier → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_macro_only_name_gets_a_dossier → function_dossier → _dossier_conn → _body_and_external → external_callees → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-001measuredtest_a_macro_only_name_gets_a_dossier → function_dossier → connect
REQ-DDB-QUERY-002inferredtest_a_macro_only_name_gets_a_dossier → function_dossier → _dossier_conn → unresolved_inbound_for_rowids
REQ-DDB-QUERY-003measuredtest_a_macro_only_name_gets_a_dossier → function_dossier → _dossier_conn → function_candidates
REQ-DDB-QUERY-004measuredtest_a_macro_only_name_gets_a_dossier → function_dossier
REQ-DDB-QUERY-006measuredtest_a_macro_only_name_gets_a_dossier → function_dossier → _dossier_conn → gates_covering
REQ-DDB-QUERY-009measuredtest_a_macro_only_name_gets_a_dossier → function_dossier
REQ-DDB-QUERY-010measuredtest_a_macro_only_name_gets_a_dossier → function_dossier
REQ-DDB-QUERY-012measuredtest_a_macro_only_name_gets_a_dossier → function_dossier → _dossier_conn → _macro_dossier
REQ-DDB-QUERY-013measuredtest_a_macro_only_name_gets_a_dossier → function_dossier → _dossier_conn → config_defaults_conn
REQ-DDB-SCHEMA-011inferredtest_a_macro_only_name_gets_a_dossier → function_dossier → _dossier_conn → locks_held_for_rowids
Source · 10 lines
def test_a_macro_only_name_gets_a_dossier(macro_db: Path) -> None:
    """@brief `dossier` on a macro-only name returns the macro, not None.
    @version 1
    """
    doss = function_dossier(macro_db, "ALLOW")
    assert doss is not None
    assert doss.kind == MACRO_KIND
    assert [m.file for m in doss.macros] == ["library/common.h", "programs/app.c"]

Activity · 4 steps
lines 219–219doss = function_dossier(macro_db, "ALLOW")lines 220–220assert doss is not Nonelines 221–221assert doss.kind == MACRO_KINDlines 222–222assert [m.file for m in doss.macros] == ["library/common.h", "programs/app.c"]

test_a_macro_panel_rides_a_function_dossier_of_the_same_name

None test_macro_query.test_a_macro_panel_rides_a_function_dossier_of_the_same_name(Path macro_db)

The macro panel rides a dossier whose resolved subject is a function.

tests/test_macro_query.py:227

Checks

  • assert doss is not None
  • assert doss.kind == "function", "the fixture's collision must still resolve to the function"
  • assert [m.expansion for m in doss.macros] == ["hidden_##member"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_a_macro_panel_rides_a_function_dossier_of_the_same_name → function_dossier → _dossier_conn → symbol_provenance
REQ-DDB-PIPE-003inferredtest_a_macro_panel_rides_a_function_dossier_of_the_same_name → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_harvest_calls → is_python_tree
REQ-DDB-PIPE-011inferredtest_a_macro_panel_rides_a_function_dossier_of_the_same_name → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_macro_panel_rides_a_function_dossier_of_the_same_name → function_dossier → _dossier_conn → _body_and_external → external_callees → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-001measuredtest_a_macro_panel_rides_a_function_dossier_of_the_same_name → function_dossier → connect
REQ-DDB-QUERY-002measuredtest_a_macro_panel_rides_a_function_dossier_of_the_same_name → function_dossier → _dossier_conn → unresolved_inbound_for_rowids
REQ-DDB-QUERY-003measuredtest_a_macro_panel_rides_a_function_dossier_of_the_same_name → function_dossier → _dossier_conn → function_candidates
REQ-DDB-QUERY-004measuredtest_a_macro_panel_rides_a_function_dossier_of_the_same_name → function_dossier
REQ-DDB-QUERY-006measuredtest_a_macro_panel_rides_a_function_dossier_of_the_same_name → function_dossier → _dossier_conn → gates_covering
REQ-DDB-QUERY-009measuredtest_a_macro_panel_rides_a_function_dossier_of_the_same_name → function_dossier
REQ-DDB-QUERY-010measuredtest_a_macro_panel_rides_a_function_dossier_of_the_same_name → function_dossier
REQ-DDB-QUERY-012measuredtest_a_macro_panel_rides_a_function_dossier_of_the_same_name → function_dossier → _dossier_conn → _macro_dossier
REQ-DDB-QUERY-013inferredtest_a_macro_panel_rides_a_function_dossier_of_the_same_name → function_dossier → _dossier_conn → config_defaults_conn
REQ-DDB-SCHEMA-011measuredtest_a_macro_panel_rides_a_function_dossier_of_the_same_name → function_dossier → _dossier_conn → locks_held_for_rowids
Source · 15 lines
def test_a_macro_panel_rides_a_function_dossier_of_the_same_name(macro_db: Path) -> None:
    """THE ONE THAT WOULD HAVE SHIPPED BROKEN. `WRAP` resolves to a function row —
    the stand-in for the ~2,000 struct members doxygen names after the macro — so a
    macro lookup gated on "no function of this name" would return nothing here,
    which is precisely the symbol the change exists for.

    @brief A colliding function name does not hide the macro.
    @version 1
    """
    doss = function_dossier(macro_db, "WRAP")
    assert doss is not None
    assert doss.kind == "function", "the fixture's collision must still resolve to the function"
    assert [m.expansion for m in doss.macros] == ["hidden_##member"]

Activity · 4 steps
lines 236–236doss = function_dossier(macro_db, "WRAP")lines 237–237assert doss is not Nonelines 238–238assert doss.kind == "function", "the fixture's collision must still resolve to the function"lines 239–239assert [m.expansion for m in doss.macros] == ["hidden_##member"]

test_a_macro_parameter_is_the_defname_alone

None test_macro_query.test_a_macro_parameter_is_the_defname_alone(Path macro_db)

A parameter name comes from defname and drags no borrowed columns with it.

tests/test_macro_query.py:187

Show on the map →

Called by none

Calls none

Checks

  • assert params == "(member)"
  • assert "int" not in params and "[" not in params

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measured
REQ-DDB-QUERY-001measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-006measured
REQ-DDB-QUERY-012measured
Source · 13 lines
def test_a_macro_parameter_is_the_defname_alone(macro_db: Path) -> None:
    """The negative half. doxygen's `param` de-duplication can staple another
    symbol's `type`/`declname`/`array` onto a macro's parameter row, so a rendered
    parameter list must contain the NAME and nothing that could have been borrowed.

    @brief A macro's parameter list carries no type text.
    @version 1
    """
    params = macro_definitions(macro_db, "WRAP")[0].params
    assert params == "(member)"
    assert "int" not in params and "[" not in params

Activity · 3 steps
lines 195–195params = macro_definitions(macro_db, "WRAP")[0].paramslines 196–196assert params == "(member)"lines 197–197assert "int" not in params and "[" not in params

test_a_macro_reports_its_expansion_parameters_and_site

None test_macro_query.test_a_macro_reports_its_expansion_parameters_and_site(Path macro_db)

A macro's expansion and location are reachable by name.

tests/test_macro_query.py:174

Show on the map →

Called by none

Calls none

Checks

  • assert len(defs) == 1
  • assert defs[0].expansion == "hidden_##member"
  • assert defs[0].params == "(member)"
  • assert (defs[0].file, defs[0].line) == ("include/private_access.h", 15)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measured
REQ-DDB-QUERY-001measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-006measured
REQ-DDB-QUERY-012measured
Source · 11 lines
def test_a_macro_reports_its_expansion_parameters_and_site(macro_db: Path) -> None:
    """@brief The three facts a `#define` has, out of the index.
    @version 1
    """
    defs = macro_definitions(macro_db, "WRAP")
    assert len(defs) == 1
    assert defs[0].expansion == "hidden_##member"
    assert defs[0].params == "(member)"
    assert (defs[0].file, defs[0].line) == ("include/private_access.h", 15)

Activity · 5 steps
lines 178–178defs = macro_definitions(macro_db, "WRAP")lines 179–179assert len(defs) == 1lines 180–180assert defs[0].expansion == "hidden_##member"lines 181–181assert defs[0].params == "(member)"lines 182–182assert (defs[0].file, defs[0].line) == ("include/private_access.h", 15)

test_an_explicit_function_kind_still_returns_the_function

None test_macro_query.test_an_explicit_function_kind_still_returns_the_function(Path macro_db)

An explicit kind="function" on the same name still returns the function.

tests/test_macro_query.py:427

Show on the map →

Called by none

Calls none

Checks

  • assert built is not None and built.kind == "function"
  • assert payload is not None
  • assert payload.kind == "function", f"asking for the function must yield one: {payload.kind!r}"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measured
REQ-DDB-QUERY-001measured
REQ-DDB-QUERY-002measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-004measured
REQ-DDB-QUERY-006measured
REQ-DDB-QUERY-009measured
REQ-DDB-QUERY-010measured
REQ-DDB-QUERY-012measured
REQ-DDB-SCHEMA-011measured
Source · 17 lines
def test_an_explicit_function_kind_still_returns_the_function(macro_db: Path) -> None:
    """THE NEGATIVE HALF, and without it the fix above is indistinguishable from routing every
    colliding name to the macro. `WRAP` is both; asking for the function must still get the
    function, or the kind filter has simply been inverted rather than honoured.

    @brief The other kind is unaffected.
    @version 1
    """
    from clew.query import dossier

    built = dossier(macro_db, "WRAP", kind="function")
    assert built is not None and built.kind == "function"
    payload = built.function
    assert payload is not None
    assert payload.kind == "function", f"asking for the function must yield one: {payload.kind!r}"

Activity · 6 steps
lines 435–435from clew.query import dossierlines 437–437built = dossier(macro_db, "WRAP", kind="function")lines 438–438assert built is not None and built.kind == "function"lines 439–439payload = built.functionlines 440–440assert payload is not Nonelines 441–441assert payload.kind == "function", f"asking for the function must yield one: {payload.kind!r}"

test_an_explicit_macro_kind_selects_the_macro_not_the_field_row

None test_macro_query.test_an_explicit_macro_kind_selects_the_macro_not_the_field_row(Path macro_db)

An explicit kind="macro" selects the MACRO, not the colliding function row.

tests/test_macro_query.py:385

Show on the map →

Called by none

Calls none

Checks

  • assert built is not None, f"kind={spelling!r} must resolve — the name defines a macro"
  • assert built.kind == "macro", (f"kind={spelling!r} must land on the canonical subject kind: {built.kind!r}" )
  • assert payload is not None
  • assert payload.kind == MACRO_KIND, (f"the payload must BE the macro, not a function row relabelled: {payload.kind!r}" )
  • assert [m.expansion for m in payload.macros] == ["hidden_##member"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measured
REQ-DDB-QUERY-001measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-004measured
REQ-DDB-QUERY-006measured
REQ-DDB-QUERY-010measured
REQ-DDB-QUERY-012measured
REQ-DDB-QUERY-013measured
Source · 39 lines
def test_an_explicit_macro_kind_selects_the_macro_not_the_field_row(macro_db: Path) -> None:
    """gh#404 — THE DEFECT A BENCHMARK CELL PAID FOR TWICE. `_chosen_kind` filtered correctly
    (it returned `"macro"`), and then `_BUILDERS["macro"]` threw the answer away by being
    byte-identical to the function builder. Its comment justified that on the premise that
    `_dossier_conn` "already resolves a macro-only name to `_macro_dossier`" — true, and it names
    its own exception: MACRO-ONLY. `dossier.py`'s guard is `if not cands`, so a name that is ALSO a
    function never reached the macro path however explicitly the caller asked.

    Measured on mbedtls: `MBEDTLS_PRIVATE` has 473 `kind='function'` rows and NONE with a body
    extent, so the pick degenerated to lowest rowid — `include/mbedtls/aes.h`, `line_start: null` —
    and the agent read the file instead. `WRAP` is that shape in fixture form.

    THE ENVELOPE AND THE PAYLOAD USED TO DISAGREE: `subject_kind: "macro"` over a payload saying
    `kind: "function"`. Both halves are asserted here, because a label that contradicts its own
    contents is worse than either being wrong alone.

    @brief kind="macro" builds the macro dossier.
    @version 1
    """
    from clew.query import dossier

    ## BOTH SPELLINGS, and the aliased one is what the benchmark cell actually sent: it read
    ## `kind: "macro definition"` off a search row and passed it straight back. Testing only the
    ## canonical `"macro"` would leave the alias mapped but unwired — the exact state
    ## `_BUILDERS["macro"]` was in.
    for spelling in ("macro", MACRO_KIND):
        built = dossier(macro_db, "WRAP", kind=spelling)
        assert built is not None, f"kind={spelling!r} must resolve — the name defines a macro"
        assert built.kind == "macro", (
            f"kind={spelling!r} must land on the canonical subject kind: {built.kind!r}"
        )
        payload = built.function
        assert payload is not None
        assert payload.kind == MACRO_KIND, (
            f"the payload must BE the macro, not a function row relabelled: {payload.kind!r}"
        )
        assert [m.expansion for m in payload.macros] == ["hidden_##member"]

Activity · 9 steps
lines 404–404from clew.query import dossierlines 410–410◇ for spelling in ("macro", MACRO_KIND)lines 411–411built = dossier(macro_db, "WRAP", kind=spelling)lines 412–412assert built is not None, f"kind={spelling!r} must resolve — the name defines a macro"lines 413–415assert built.kind == "macro", ( f"kind={spelling!r} must land on the canonical subject kind: {built.kind!r}" )lines 416–416payload = built.functionlines 417–417assert payload is not Nonelines 418–420assert payload.kind == MACRO_KIND, ( f"the payload must BE the macro, not a function row relabelled: {payload.kind!r}" )lines 421–421assert [m.expansion for m in payload.macros] == ["hidden_##member"]

test_an_unmatched_selector_is_not_answered_with_a_macro

None test_macro_query.test_an_unmatched_selector_is_not_answered_with_a_macro(Path macro_db)

An unmatched qualified selector still returns nothing, not a macro.

tests/test_macro_query.py:312

Checks

  • assert function_dossier(macro_db, "WRAP", qualified="nothing::like::this") is None

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_an_unmatched_selector_is_not_answered_with_a_macro → function_dossier → _dossier_conn → symbol_provenance
REQ-DDB-PIPE-003inferredtest_an_unmatched_selector_is_not_answered_with_a_macro → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_harvest_calls → is_python_tree
REQ-DDB-PIPE-011inferredtest_an_unmatched_selector_is_not_answered_with_a_macro → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_an_unmatched_selector_is_not_answered_with_a_macro → function_dossier → _dossier_conn → _body_and_external → external_callees → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-001measuredtest_an_unmatched_selector_is_not_answered_with_a_macro → function_dossier → connect
REQ-DDB-QUERY-002inferredtest_an_unmatched_selector_is_not_answered_with_a_macro → function_dossier → _dossier_conn → unresolved_inbound_for_rowids
REQ-DDB-QUERY-003measuredtest_an_unmatched_selector_is_not_answered_with_a_macro → function_dossier → _dossier_conn → function_candidates
REQ-DDB-QUERY-004measuredtest_an_unmatched_selector_is_not_answered_with_a_macro → function_dossier
REQ-DDB-QUERY-006measuredtest_an_unmatched_selector_is_not_answered_with_a_macro → function_dossier → _dossier_conn → gates_covering
REQ-DDB-QUERY-009measuredtest_an_unmatched_selector_is_not_answered_with_a_macro → function_dossier
REQ-DDB-QUERY-010measuredtest_an_unmatched_selector_is_not_answered_with_a_macro → function_dossier
REQ-DDB-QUERY-012measuredtest_an_unmatched_selector_is_not_answered_with_a_macro → function_dossier → _dossier_conn → _macro_dossier
REQ-DDB-QUERY-013inferredtest_an_unmatched_selector_is_not_answered_with_a_macro → function_dossier → _dossier_conn → config_defaults_conn
REQ-DDB-SCHEMA-011inferredtest_an_unmatched_selector_is_not_answered_with_a_macro → function_dossier → _dossier_conn → locks_held_for_rowids
Source · 11 lines
def test_an_unmatched_selector_is_not_answered_with_a_macro(macro_db: Path) -> None:
    """A `qualified` argument names ONE function identity. Substituting a macro for
    an identity that does not exist would answer a different question than the one
    asked, and look authoritative doing it.

    @brief A failed disambiguation returns None even when a macro shares the name.
    @version 1
    """
    assert function_dossier(macro_db, "WRAP", qualified="nothing::like::this") is None

Activity · 1 steps
lines 320–320assert function_dossier(macro_db, "WRAP", qualified="nothing::like::this") is None

test_every_definition_site_is_reported

None test_macro_query.test_every_definition_site_is_reported(Path macro_db)

Every definition site of a conditionally redefined macro is reported.

tests/test_macro_query.py:202

Show on the map →

Called by none

Calls none

Checks

  • assert sites == [("library/common.h", 132), ("programs/app.c", 8)]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measured
REQ-DDB-QUERY-001measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-006measured
REQ-DDB-QUERY-012measured
Source · 11 lines
def test_every_definition_site_is_reported(macro_db: Path) -> None:
    """The library-vs-application answer IS the several sites. Collapsing them would
    leave the payload technically correct and useless.

    @brief A macro defined twice reports both sites, file-ordered.
    @version 1
    """
    sites = [(d.file, d.line) for d in macro_definitions(macro_db, "ALLOW")]
    assert sites == [("library/common.h", 132), ("programs/app.c", 8)]

Activity · 2 steps
lines 209–209sites = [(d.file, d.line) for d in macro_definitions(macro_db, "ALLOW")]lines 210–210assert sites == [("library/common.h", 132), ("programs/app.c", 8)]

test_search_finds_a_macro_by_its_expansion

None test_macro_query.test_search_finds_a_macro_by_its_expansion(Path macro_db)

search finds a macro by its EXPANSION.

tests/test_macro_query.py:338

Show on the map →

Called by none

Calls none

Checks

  • assert [h.name for h in hits] == ["WRAP"]
  • assert hits[0].kind == MACRO_KIND
  • assert hits[0].brief == "hidden_##member", "the expansion stands in for an absent brief"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measured
REQ-DDB-QUERY-001measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-007measured
REQ-DDB-QUERY-012measured
Source · 13 lines
def test_search_finds_a_macro_by_its_expansion(macro_db: Path) -> None:
    """The reverse lookup: a reader who meets a generated identifier finds the macro
    that generates it. This is the half a name-only corpus would have missed.

    @brief A macro is findable by the text it expands to.
    @version 1
    """
    hits = search(macro_db, "hidden_##member")
    assert [h.name for h in hits] == ["WRAP"]
    assert hits[0].kind == MACRO_KIND
    assert hits[0].brief == "hidden_##member", "the expansion stands in for an absent brief"

Activity · 4 steps
lines 345–345hits = search(macro_db, "hidden_##member")lines 346–346assert [h.name for h in hits] == ["WRAP"]lines 347–347assert hits[0].kind == MACRO_KINDlines 348–348assert hits[0].brief == "hidden_##member", "the expansion stands in for an absent brief"

test_search_finds_a_macro_by_name

None test_macro_query.test_search_finds_a_macro_by_name(Path macro_db)

search finds a macro by name.

tests/test_macro_query.py:325

Show on the map →

Called by none

Calls none

Checks

  • assert [h.kind for h in hits] == [MACRO_KIND]
  • assert hits[0].name == "ALLOW"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measured
REQ-DDB-QUERY-001measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-007measured
REQ-DDB-QUERY-012measured
Source · 11 lines
def test_search_finds_a_macro_by_name(macro_db: Path) -> None:
    """The measured defect verbatim: this query returned a confident zero.

    @brief The gating macro is findable.
    @version 1
    """
    hits = search(macro_db, "ALLOW")
    assert [h.kind for h in hits] == [MACRO_KIND]
    assert hits[0].name == "ALLOW"

Activity · 3 steps
lines 331–331hits = search(macro_db, "ALLOW")lines 332–332assert [h.kind for h in hits] == [MACRO_KIND]lines 333–333assert hits[0].name == "ALLOW"

test_the_shared_fixture_reaches_an_object_like_macro

None test_macro_query.test_the_shared_fixture_reaches_an_object_like_macro(Path rich_db)

The shared fixture's object-like macros carry the expansions csample writes.

tests/test_macro_query.py:369

Show on the map →

Called by none

Calls none

Checks

  • assert [d.expansion for d in defs] == ["8"]
  • assert [d.params for d in defs] == [""], "an object-like macro has no parameter list"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measured
REQ-DDB-QUERY-001measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-006measured
REQ-DDB-QUERY-012measured
Source · 13 lines
def test_the_shared_fixture_reaches_an_object_like_macro(rich_db: Path) -> None:
    """Runs against the SHARED index rather than the purpose-built one, so the macro
    path is exercised on a database assembled by the real pipeline stages. `8` is the
    literal in `tests/data/csample/src/event_bus/event_bus.c`.

    @brief An object-like macro's expansion survives a full fixture build.
    @version 1
    """
    defs = macro_definitions(rich_db, "EVENT_QUEUE_DEPTH")
    assert [d.expansion for d in defs] == ["8"]
    assert [d.params for d in defs] == [""], "an object-like macro has no parameter list"

Activity · 3 steps
lines 377–377defs = macro_definitions(rich_db, "EVENT_QUEUE_DEPTH")lines 378–378assert [d.expansion for d in defs] == ["8"]lines 379–379assert [d.params for d in defs] == [""], "an object-like macro has no parameter list"

test_the_token_diagnosis_counts_macros

None test_macro_query.test_the_token_diagnosis_counts_macros(Path macro_db)

The zero-result token diagnosis counts the macro corpus too.

tests/test_macro_query.py:353

Checks

  • assert counts["allow"] >= 1
  • assert counts["hidden_##member"] >= 1
  • assert counts["nosuchtoken"] == 0

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_the_token_diagnosis_counts_macros → token_hit_counts → connect
REQ-DDB-QUERY-003measuredtest_the_token_diagnosis_counts_macros → token_hit_counts → _one_token_count → table_exists
REQ-DDB-QUERY-007measuredtest_the_token_diagnosis_counts_macros → token_hit_counts
REQ-DDB-QUERY-012catalog
Source · 14 lines
def test_the_token_diagnosis_counts_macros(macro_db: Path) -> None:
    """gh#31's defect reintroduced through a new corpus: a token that matches ONLY a
    macro must not be named as the token that emptied the query. Asserted on the
    expansion, not just the name, because that is what `search` matches.

    @brief A macro-only token is counted, by name and by expansion.
    @version 1
    """
    counts = token_hit_counts(macro_db, ["allow", "hidden_##member", "nosuchtoken"])
    assert counts["allow"] >= 1
    assert counts["hidden_##member"] >= 1
    assert counts["nosuchtoken"] == 0

Activity · 4 steps
lines 361–361counts = token_hit_counts(macro_db, ["allow", "hidden_##member", "nosuchtoken"])lines 362–362assert counts["allow"] >= 1lines 363–363assert counts["hidden_##member"] >= 1lines 364–364assert counts["nosuchtoken"] == 0