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.
Checks
assert doss is not Noneassert 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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_a_bare_lookup_is_unchanged_by_the_macro_kind_fix → function_dossier → _dossier_conn → symbol_provenance |
| REQ-DDB-PIPE-003 | inferred | test_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-011 | inferred | test_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-012 | inferred | test_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-001 | measured | test_a_bare_lookup_is_unchanged_by_the_macro_kind_fix → function_dossier → connect |
| REQ-DDB-QUERY-002 | measured | test_a_bare_lookup_is_unchanged_by_the_macro_kind_fix → function_dossier → _dossier_conn → unresolved_inbound_for_rowids |
| REQ-DDB-QUERY-003 | measured | test_a_bare_lookup_is_unchanged_by_the_macro_kind_fix → function_dossier → _dossier_conn → function_candidates |
| REQ-DDB-QUERY-004 | measured | test_a_bare_lookup_is_unchanged_by_the_macro_kind_fix → function_dossier |
| REQ-DDB-QUERY-006 | measured | test_a_bare_lookup_is_unchanged_by_the_macro_kind_fix → function_dossier → _dossier_conn → gates_covering |
| REQ-DDB-QUERY-009 | measured | test_a_bare_lookup_is_unchanged_by_the_macro_kind_fix → function_dossier |
| REQ-DDB-QUERY-010 | measured | test_a_bare_lookup_is_unchanged_by_the_macro_kind_fix → function_dossier |
| REQ-DDB-QUERY-012 | measured | test_a_bare_lookup_is_unchanged_by_the_macro_kind_fix → function_dossier → _dossier_conn → _macro_dossier |
| REQ-DDB-QUERY-013 | inferred | test_a_bare_lookup_is_unchanged_by_the_macro_kind_fix → function_dossier → _dossier_conn → config_defaults_conn |
| REQ-DDB-SCHEMA-011 | measured | test_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
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.
Checks
assert doss is not Noneassert doss.line_start is None, "the fixture's collision row must have no body extent"assert "#define" in doss.macro_collisionassert "macros" in doss.macro_collision, "the note must name the field that answers"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_a_bodiless_colliding_identity_discloses_the_macro_collision → function_dossier → _dossier_conn → symbol_provenance |
| REQ-DDB-PIPE-003 | inferred | test_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-011 | inferred | test_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-012 | inferred | test_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-001 | measured | test_a_bodiless_colliding_identity_discloses_the_macro_collision → function_dossier → connect |
| REQ-DDB-QUERY-002 | measured | test_a_bodiless_colliding_identity_discloses_the_macro_collision → function_dossier → _dossier_conn → unresolved_inbound_for_rowids |
| REQ-DDB-QUERY-003 | measured | test_a_bodiless_colliding_identity_discloses_the_macro_collision → function_dossier → _dossier_conn → function_candidates |
| REQ-DDB-QUERY-004 | measured | test_a_bodiless_colliding_identity_discloses_the_macro_collision → function_dossier |
| REQ-DDB-QUERY-006 | measured | test_a_bodiless_colliding_identity_discloses_the_macro_collision → function_dossier → _dossier_conn → gates_covering |
| REQ-DDB-QUERY-009 | measured | test_a_bodiless_colliding_identity_discloses_the_macro_collision → function_dossier |
| REQ-DDB-QUERY-010 | measured | test_a_bodiless_colliding_identity_discloses_the_macro_collision → function_dossier |
| REQ-DDB-QUERY-012 | measured | test_a_bodiless_colliding_identity_discloses_the_macro_collision → function_dossier → _dossier_conn → _macro_dossier |
| REQ-DDB-QUERY-013 | inferred | test_a_bodiless_colliding_identity_discloses_the_macro_collision → function_dossier → _dossier_conn → config_defaults_conn |
| REQ-DDB-SCHEMA-011 | measured | test_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
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.
Checks
assert doss is not Noneassert 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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_a_declared_undefined_function_is_disclosed_and_still_described → function_dossier → _dossier_conn → symbol_provenance |
| REQ-DDB-PIPE-003 | inferred | test_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-011 | inferred | test_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-012 | inferred | test_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-001 | measured | test_a_declared_undefined_function_is_disclosed_and_still_described → function_dossier → connect |
| REQ-DDB-QUERY-002 | measured | test_a_declared_undefined_function_is_disclosed_and_still_described → function_dossier → _dossier_conn → unresolved_inbound_for_rowids |
| REQ-DDB-QUERY-003 | measured | test_a_declared_undefined_function_is_disclosed_and_still_described → function_dossier → _dossier_conn → function_candidates |
| REQ-DDB-QUERY-004 | measured | test_a_declared_undefined_function_is_disclosed_and_still_described → function_dossier |
| REQ-DDB-QUERY-006 | measured | test_a_declared_undefined_function_is_disclosed_and_still_described → function_dossier → _dossier_conn → gates_covering |
| REQ-DDB-QUERY-009 | measured | test_a_declared_undefined_function_is_disclosed_and_still_described → function_dossier |
| REQ-DDB-QUERY-010 | measured | test_a_declared_undefined_function_is_disclosed_and_still_described → function_dossier |
| REQ-DDB-QUERY-012 | measured | test_a_declared_undefined_function_is_disclosed_and_still_described → function_dossier → _dossier_conn → _macro_dossier |
| REQ-DDB-QUERY-013 | inferred | test_a_declared_undefined_function_is_disclosed_and_still_described → function_dossier → _dossier_conn → config_defaults_conn |
| REQ-DDB-SCHEMA-011 | measured | test_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
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.
Checks
assert doss is not Noneassert 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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_a_defined_function_sharing_a_macro_name_is_not_flagged → function_dossier → _dossier_conn → symbol_provenance |
| REQ-DDB-PIPE-003 | inferred | test_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-011 | inferred | test_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-012 | inferred | test_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-001 | measured | test_a_defined_function_sharing_a_macro_name_is_not_flagged → function_dossier → connect |
| REQ-DDB-QUERY-002 | measured | test_a_defined_function_sharing_a_macro_name_is_not_flagged → function_dossier → _dossier_conn → unresolved_inbound_for_rowids |
| REQ-DDB-QUERY-003 | measured | test_a_defined_function_sharing_a_macro_name_is_not_flagged → function_dossier → _dossier_conn → function_candidates |
| REQ-DDB-QUERY-004 | measured | test_a_defined_function_sharing_a_macro_name_is_not_flagged → function_dossier |
| REQ-DDB-QUERY-006 | measured | test_a_defined_function_sharing_a_macro_name_is_not_flagged → function_dossier → _dossier_conn → gates_covering |
| REQ-DDB-QUERY-009 | measured | test_a_defined_function_sharing_a_macro_name_is_not_flagged → function_dossier |
| REQ-DDB-QUERY-010 | measured | test_a_defined_function_sharing_a_macro_name_is_not_flagged → function_dossier |
| REQ-DDB-QUERY-012 | measured | test_a_defined_function_sharing_a_macro_name_is_not_flagged → function_dossier → _dossier_conn → _macro_dossier |
| REQ-DDB-QUERY-013 | inferred | test_a_defined_function_sharing_a_macro_name_is_not_flagged → function_dossier → _dossier_conn → config_defaults_conn |
| REQ-DDB-SCHEMA-011 | measured | test_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
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.
Checks
assert doss is not Noneassert doss.kind == MACRO_KINDassert [m.file for m in doss.macros] == ["library/common.h", "programs/app.c"]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_a_macro_only_name_gets_a_dossier → function_dossier → _dossier_conn → symbol_provenance |
| REQ-DDB-PIPE-003 | inferred | test_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-011 | inferred | test_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-012 | inferred | test_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-001 | measured | test_a_macro_only_name_gets_a_dossier → function_dossier → connect |
| REQ-DDB-QUERY-002 | inferred | test_a_macro_only_name_gets_a_dossier → function_dossier → _dossier_conn → unresolved_inbound_for_rowids |
| REQ-DDB-QUERY-003 | measured | test_a_macro_only_name_gets_a_dossier → function_dossier → _dossier_conn → function_candidates |
| REQ-DDB-QUERY-004 | measured | test_a_macro_only_name_gets_a_dossier → function_dossier |
| REQ-DDB-QUERY-006 | measured | test_a_macro_only_name_gets_a_dossier → function_dossier → _dossier_conn → gates_covering |
| REQ-DDB-QUERY-009 | measured | test_a_macro_only_name_gets_a_dossier → function_dossier |
| REQ-DDB-QUERY-010 | measured | test_a_macro_only_name_gets_a_dossier → function_dossier |
| REQ-DDB-QUERY-012 | measured | test_a_macro_only_name_gets_a_dossier → function_dossier → _dossier_conn → _macro_dossier |
| REQ-DDB-QUERY-013 | measured | test_a_macro_only_name_gets_a_dossier → function_dossier → _dossier_conn → config_defaults_conn |
| REQ-DDB-SCHEMA-011 | inferred | test_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
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.
Checks
assert doss is not Noneassert 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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_a_macro_panel_rides_a_function_dossier_of_the_same_name → function_dossier → _dossier_conn → symbol_provenance |
| REQ-DDB-PIPE-003 | inferred | test_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-011 | inferred | test_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-012 | inferred | test_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-001 | measured | test_a_macro_panel_rides_a_function_dossier_of_the_same_name → function_dossier → connect |
| REQ-DDB-QUERY-002 | measured | test_a_macro_panel_rides_a_function_dossier_of_the_same_name → function_dossier → _dossier_conn → unresolved_inbound_for_rowids |
| REQ-DDB-QUERY-003 | measured | test_a_macro_panel_rides_a_function_dossier_of_the_same_name → function_dossier → _dossier_conn → function_candidates |
| REQ-DDB-QUERY-004 | measured | test_a_macro_panel_rides_a_function_dossier_of_the_same_name → function_dossier |
| REQ-DDB-QUERY-006 | measured | test_a_macro_panel_rides_a_function_dossier_of_the_same_name → function_dossier → _dossier_conn → gates_covering |
| REQ-DDB-QUERY-009 | measured | test_a_macro_panel_rides_a_function_dossier_of_the_same_name → function_dossier |
| REQ-DDB-QUERY-010 | measured | test_a_macro_panel_rides_a_function_dossier_of_the_same_name → function_dossier |
| REQ-DDB-QUERY-012 | measured | test_a_macro_panel_rides_a_function_dossier_of_the_same_name → function_dossier → _dossier_conn → _macro_dossier |
| REQ-DDB-QUERY-013 | inferred | test_a_macro_panel_rides_a_function_dossier_of_the_same_name → function_dossier → _dossier_conn → config_defaults_conn |
| REQ-DDB-SCHEMA-011 | measured | test_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
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.
Checks
assert params == "(member)"assert "int" not in params and "[" not in params
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | |
| REQ-DDB-QUERY-001 | measured | |
| REQ-DDB-QUERY-003 | measured | |
| REQ-DDB-QUERY-006 | measured | |
| REQ-DDB-QUERY-012 | measured |
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
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.
Checks
assert len(defs) == 1assert 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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | |
| REQ-DDB-QUERY-001 | measured | |
| REQ-DDB-QUERY-003 | measured | |
| REQ-DDB-QUERY-006 | measured | |
| REQ-DDB-QUERY-012 | measured |
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
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.
Checks
assert built is not None and built.kind == "function"assert payload is not Noneassert payload.kind == "function", f"asking for the function must yield one: {payload.kind!r}"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | |
| REQ-DDB-QUERY-001 | measured | |
| REQ-DDB-QUERY-002 | measured | |
| REQ-DDB-QUERY-003 | measured | |
| REQ-DDB-QUERY-004 | measured | |
| REQ-DDB-QUERY-006 | measured | |
| REQ-DDB-QUERY-009 | measured | |
| REQ-DDB-QUERY-010 | measured | |
| REQ-DDB-QUERY-012 | measured | |
| REQ-DDB-SCHEMA-011 | measured |
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
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.
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 Noneassert 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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | |
| REQ-DDB-QUERY-001 | measured | |
| REQ-DDB-QUERY-003 | measured | |
| REQ-DDB-QUERY-004 | measured | |
| REQ-DDB-QUERY-006 | measured | |
| REQ-DDB-QUERY-010 | measured | |
| REQ-DDB-QUERY-012 | measured | |
| REQ-DDB-QUERY-013 | measured |
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
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.
Checks
assert function_dossier(macro_db, "WRAP", qualified="nothing::like::this") is None
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_an_unmatched_selector_is_not_answered_with_a_macro → function_dossier → _dossier_conn → symbol_provenance |
| REQ-DDB-PIPE-003 | inferred | test_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-011 | inferred | test_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-012 | inferred | test_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-001 | measured | test_an_unmatched_selector_is_not_answered_with_a_macro → function_dossier → connect |
| REQ-DDB-QUERY-002 | inferred | test_an_unmatched_selector_is_not_answered_with_a_macro → function_dossier → _dossier_conn → unresolved_inbound_for_rowids |
| REQ-DDB-QUERY-003 | measured | test_an_unmatched_selector_is_not_answered_with_a_macro → function_dossier → _dossier_conn → function_candidates |
| REQ-DDB-QUERY-004 | measured | test_an_unmatched_selector_is_not_answered_with_a_macro → function_dossier |
| REQ-DDB-QUERY-006 | measured | test_an_unmatched_selector_is_not_answered_with_a_macro → function_dossier → _dossier_conn → gates_covering |
| REQ-DDB-QUERY-009 | measured | test_an_unmatched_selector_is_not_answered_with_a_macro → function_dossier |
| REQ-DDB-QUERY-010 | measured | test_an_unmatched_selector_is_not_answered_with_a_macro → function_dossier |
| REQ-DDB-QUERY-012 | measured | test_an_unmatched_selector_is_not_answered_with_a_macro → function_dossier → _dossier_conn → _macro_dossier |
| REQ-DDB-QUERY-013 | inferred | test_an_unmatched_selector_is_not_answered_with_a_macro → function_dossier → _dossier_conn → config_defaults_conn |
| REQ-DDB-SCHEMA-011 | inferred | test_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
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.
Checks
assert sites == [("library/common.h", 132), ("programs/app.c", 8)]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | |
| REQ-DDB-QUERY-001 | measured | |
| REQ-DDB-QUERY-003 | measured | |
| REQ-DDB-QUERY-006 | measured | |
| REQ-DDB-QUERY-012 | measured |
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
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.
Checks
assert [h.name for h in hits] == ["WRAP"]assert hits[0].kind == MACRO_KINDassert hits[0].brief == "hidden_##member", "the expansion stands in for an absent brief"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | |
| REQ-DDB-QUERY-001 | measured | |
| REQ-DDB-QUERY-003 | measured | |
| REQ-DDB-QUERY-007 | measured | |
| REQ-DDB-QUERY-012 | measured |
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
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.
Checks
assert [h.kind for h in hits] == [MACRO_KIND]assert hits[0].name == "ALLOW"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | |
| REQ-DDB-QUERY-001 | measured | |
| REQ-DDB-QUERY-003 | measured | |
| REQ-DDB-QUERY-007 | measured | |
| REQ-DDB-QUERY-012 | measured |
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
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.
Checks
assert counts["allow"] >= 1assert counts["hidden_##member"] >= 1assert counts["nosuchtoken"] == 0
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_the_token_diagnosis_counts_macros → token_hit_counts → connect |
| REQ-DDB-QUERY-003 | measured | test_the_token_diagnosis_counts_macros → token_hit_counts → _one_token_count → table_exists |
| REQ-DDB-QUERY-007 | measured | test_the_token_diagnosis_counts_macros → token_hit_counts |
| REQ-DDB-QUERY-012 | catalog |
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