test_macro_recovery.py¶
tests/test_macro_recovery.py
gh#403 — the `#define` branch doxygen's preprocessor cannot reach.
test_a_macro_only_dossier_carries_the_first_sites_gates
None test_macro_recovery.test_a_macro_only_dossier_carries_the_first_sites_gates(Path taken_branch_index, Path repo)
A function_dossier has ONE `file` and ONE `line_start`, so its `gated_by` can describe one position — and it must be the position it reports. `_macro_dossier` takes its identity from the first site and COPIES that site's gates rather than recomputing them, so the two cannot drift apart.
tests/test_macro_recovery.py:325
Checks
assert doss is not Noneassert doss.kind == MACRO_KINDassert doss.line_start == GATED_LINEassert {(g.macro, g.form) for g in doss.gated_by} == {assert sorted(m.line for m in doss.macros) == [GATED_LINE, ELSE_LINE]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-004 | measured | test_a_macro_only_dossier_carries_the_first_sites_gates → import_kconfig_gates → declared_macro_names → bare_macro_names |
| REQ-DDB-INDEX-004 | measured | test_a_macro_only_dossier_carries_the_first_sites_gates → recover_ast_symbols |
| REQ-DDB-PIPE-003 | measured | test_a_macro_only_dossier_carries_the_first_sites_gates → import_kconfig_gates → run_harvest |
| REQ-DDB-PIPE-007 | measured | test_a_macro_only_dossier_carries_the_first_sites_gates → import_kconfig_gates |
| REQ-DDB-PIPE-011 | measured | test_a_macro_only_dossier_carries_the_first_sites_gates → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_a_macro_only_dossier_carries_the_first_sites_gates → import_kconfig_gates → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language |
| REQ-DDB-QUERY-001 | measured | test_a_macro_only_dossier_carries_the_first_sites_gates → function_dossier → connect |
| REQ-DDB-QUERY-002 | inferred | test_a_macro_only_dossier_carries_the_first_sites_gates → function_dossier → _dossier_conn → unresolved_inbound_for_rowids |
| REQ-DDB-QUERY-003 | measured | test_a_macro_only_dossier_carries_the_first_sites_gates → function_dossier → _dossier_conn → function_candidates |
| REQ-DDB-QUERY-004 | measured | test_a_macro_only_dossier_carries_the_first_sites_gates → function_dossier |
| REQ-DDB-QUERY-006 | measured | test_a_macro_only_dossier_carries_the_first_sites_gates → function_dossier → _dossier_conn → gates_covering |
| REQ-DDB-QUERY-009 | measured | test_a_macro_only_dossier_carries_the_first_sites_gates → function_dossier |
| REQ-DDB-QUERY-010 | measured | test_a_macro_only_dossier_carries_the_first_sites_gates → function_dossier |
| REQ-DDB-QUERY-012 | measured | test_a_macro_only_dossier_carries_the_first_sites_gates → function_dossier → _dossier_conn → _macro_dossier |
| REQ-DDB-QUERY-013 | measured | test_a_macro_only_dossier_carries_the_first_sites_gates → function_dossier → _dossier_conn → config_defaults_conn |
| REQ-DDB-SCHEMA-011 | inferred | test_a_macro_only_dossier_carries_the_first_sites_gates → function_dossier → _dossier_conn → locks_held_for_rowids |
| REQ-DDB-SCHEMA-012 | measured | |
| REQ-DDB-SCHEMA-013 | measured | test_a_macro_only_dossier_carries_the_first_sites_gates → import_kconfig_gates → ensure_kconfig_gates_table |
| REQ-DDB-WIKI-054 | inferred | test_a_macro_only_dossier_carries_the_first_sites_gates → recover_ast_symbols → _recover_into → all |
Source · 27 lines
def test_a_macro_only_dossier_carries_the_first_sites_gates(
taken_branch_index: Path, repo: Path
) -> None:
"""A function_dossier has ONE `file` and ONE `line_start`, so its `gated_by` can describe one
position — and it must be the position it reports. `_macro_dossier` takes its identity
from the first site and COPIES that site's gates rather than recomputing them, so the
two cannot drift apart.
`PRIVATE` resolves to no function in this fixture, so this is the macro-SUBJECT path.
The per-site lists on `macros` stay the complete answer; this pins that the
function_dossier-level field means the same thing here as it does on a function."""
recover_ast_symbols(taken_branch_index, repo, None)
import_kconfig_gates(taken_branch_index, repo)
doss = function_dossier(taken_branch_index, "PRIVATE")
assert doss is not None
assert doss.kind == MACRO_KIND
assert doss.line_start == GATED_LINE
assert {(g.macro, g.form) for g in doss.gated_by} == {
("ALLOW_PRIVATE_ACCESS", KCONFIG_GATE_IFNDEF)
}, (
"the function_dossier's gates must describe the line the function_dossier reports, not both branches"
)
## And the panel still carries both, which is the field a reader is pointed at.
assert sorted(m.line for m in doss.macros) == [GATED_LINE, ELSE_LINE]
Activity · 8 steps
test_a_template_argument_macro_use_is_recovered_into_referenced_by
None test_macro_recovery.test_a_template_argument_macro_use_is_recovered_into_referenced_by(Path tmp_path)
A macro used as a non-type template argument must appear in referenced_by .
tests/test_macro_recovery.py:375
Checks
assert result.returncode == 0, (f"the build failed, so the recovery cannot be under test:\n{result.stderr[-2000:]}" )assert macro, "precondition: the macro must be indexed at all"assert expected <= referenced, (f"macro uses missing from referenced_by: {sorted(expected - referenced)}. " f"`bold_table` is gh#9's reported shape; the others are the measured control set." )
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 · 106 lines
def test_a_template_argument_macro_use_is_recovered_into_referenced_by(tmp_path: Path) -> None:
"""gh#9. `referenced_by` answers "I am about to change this constant — what else is baked
against it", and it was answering INCOMPLETELY: doxygen's xref pass does not record a macro
used as a NON-TYPE TEMPLATE ARGUMENT.
MEASURED, six uses of one macro each inside a documented body, before the fix:
int n = MACRO; xref emitted
int buf[MACRO]; xref emitted
static const int k = MACRO; xref emitted
std::array<Row, MACRO> kRows{}; NO XREF
std::array<int, MACRO> a{}; NO XREF
Box<int, MACRO> b{}; NO XREF (user template)
So the discriminator is template-argument POSITION — not "inside a body", which was the
reporter's first reading, and not `std::array` specifically, since a user-defined template
misses too.
A PARTIAL LIST IS WORSE THAN AN EMPTY ONE. The existing disclosure covers empty — on mbedtls
871 of 2,504 macros have any inbound reference — and says nothing about present-and-short,
which reads as complete. The reporter found two of three sites and would have learned about
the third from a compiler error.
ALL SIX ARE ASSERTED, and that is what makes this test worth having: the first fix recovered
five and missed `bold_table`, the exact reported shape, because its `reference_declarator`
defeated the shared declarator walk. Any single-case assertion would have passed.
@brief Every measured macro use reaches `referenced_by`.
@return None.
@version 1
"""
import subprocess
import sys
from clew.query import macro_definitions
root = tmp_path / "repo"
(root / "src").mkdir(parents=True)
(root / "src" / "m.h").write_text(
"#pragma once\n/** @brief Face count. */\n#define FACE_COUNT 20\n", encoding="utf-8"
)
(root / "src" / "m.cpp").write_text(
'#include "m.h"\n#include <array>\n'
"template <typename T, int N> struct Box { T v[N]; };\n"
"struct Row { int a; };\n"
"/** @brief return-type AND body use. */\n"
"const std::array<Row, FACE_COUNT>& bold_table() {\n"
" static const std::array<Row, FACE_COUNT> kRows{};\n return kRows;\n}\n"
"/** @brief plain statement. */\nint plain_use() { int n = FACE_COUNT; return n; }\n"
"/** @brief C array size. */\nint array_size_use() { int b[FACE_COUNT]; return b[0]; }\n"
"/** @brief static scalar. */\n"
"int static_scalar() { static const int k = FACE_COUNT; return k; }\n"
"/** @brief std::array, no static. */\n"
"int std_array_plain() { std::array<int, FACE_COUNT> a{}; return a[0]; }\n"
"/** @brief user template. */\n"
"int user_template_use() { Box<int, FACE_COUNT> b{}; return b.v[0]; }\n",
encoding="utf-8",
)
subprocess.run(["git", "init", "-q", str(root)], check=True)
subprocess.run(["git", "-C", str(root), "add", "-A"], check=True)
subprocess.run(
[
"git",
"-C",
str(root),
"-c",
"user.email=t@t",
"-c",
"user.name=t",
"commit",
"-qm",
"init",
],
check=True,
)
db = tmp_path / "out.db"
## `sys.executable`, NEVER a bare "python". CI runs pytest from the venv while bare
## `python` resolves to the hosted-tool interpreter, which has no `clew` installed — so this
## passed locally (the venv is on this shell's PATH) and failed on all three CI versions.
## The house rule against bare interpreter invocations exists for exactly this.
result = subprocess.run(
[sys.executable, "-m", "clew", "--repo-root", str(root), "--output", str(db)],
capture_output=True,
text=True,
)
assert result.returncode == 0, (
f"the build failed, so the recovery cannot be under test:\n{result.stderr[-2000:]}"
)
macro = macro_definitions(db, "FACE_COUNT")
assert macro, "precondition: the macro must be indexed at all"
referenced = set(macro[0].referenced_by)
expected = {
"plain_use",
"array_size_use",
"static_scalar",
"bold_table",
"std_array_plain",
"user_template_use",
}
assert expected <= referenced, (
f"macro uses missing from referenced_by: {sorted(expected - referenced)}. "
f"`bold_table` is gh#9's reported shape; the others are the measured control set."
)1 more lines, not shown
Activity · 18 steps
test_each_definition_site_reports_its_own_gate_polarity
None test_macro_recovery.test_each_definition_site_reports_its_own_gate_polarity(Path taken_branch_index, Path repo)
"WHICH CONSUMER GETS WHICH" IS A QUESTION ABOUT A GATE, and this is the assertion the graded question actually needs. Two rows with two different expansions read as a contradiction until something says which branch each sits in.
tests/test_macro_recovery.py:288
Checks
assert import_kconfig_gates(taken_branch_index, repo) > 0assert ("ALLOW_PRIVATE_ACCESS", KCONFIG_GATE_IFNDEF) in gatedassert ("ALLOW_PRIVATE_ACCESS", KCONFIG_GATE_IFDEF) not in gated, ("the private_ spelling is what a unit that has NOT defined the symbol gets" )assert ("ALLOW_PRIVATE_ACCESS", KCONFIG_GATE_IFDEF) in otherwiseassert ("ALLOW_PRIVATE_ACCESS", KCONFIG_GATE_IFNDEF) not in otherwise, ("the bare spelling is what a unit that HAS defined the symbol gets" )assert sites[GATED_LINE].gates_unplaceable == 0assert sites[ELSE_LINE].gates_unplaceable == 0
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-004 | measured | test_each_definition_site_reports_its_own_gate_polarity → import_kconfig_gates → declared_macro_names → bare_macro_names |
| REQ-DDB-INDEX-004 | measured | test_each_definition_site_reports_its_own_gate_polarity → recover_ast_symbols |
| REQ-DDB-PIPE-003 | measured | test_each_definition_site_reports_its_own_gate_polarity → import_kconfig_gates → run_harvest |
| REQ-DDB-PIPE-007 | measured | test_each_definition_site_reports_its_own_gate_polarity → import_kconfig_gates |
| REQ-DDB-PIPE-011 | measured | test_each_definition_site_reports_its_own_gate_polarity → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_each_definition_site_reports_its_own_gate_polarity → import_kconfig_gates → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language |
| REQ-DDB-QUERY-001 | measured | |
| REQ-DDB-QUERY-003 | measured | |
| REQ-DDB-QUERY-006 | measured | |
| REQ-DDB-QUERY-012 | measured | |
| REQ-DDB-SCHEMA-012 | measured | |
| REQ-DDB-SCHEMA-013 | measured | test_each_definition_site_reports_its_own_gate_polarity → import_kconfig_gates → ensure_kconfig_gates_table |
| REQ-DDB-WIKI-054 | inferred | test_each_definition_site_reports_its_own_gate_polarity → recover_ast_symbols → _recover_into → all |
Source · 37 lines
def test_each_definition_site_reports_its_own_gate_polarity(
taken_branch_index: Path, repo: Path
) -> None:
""" "WHICH CONSUMER GETS WHICH" IS A QUESTION ABOUT A GATE, and this is the assertion
the graded question actually needs. Two rows with two different expansions read as a
contradiction until something says which branch each sits in.
EVERY CLAIM IS TWO-SIDED. An implementation that attached every gate in the file to
every line would satisfy the positive halves of both assertions below and would answer
the question backwards half the time, so each site is asserted to report its own form
AND to NOT report the other's.
Both stages run for real against the same file, which is the coupling no hand-written
database can test: `ast_symbols` decides line 17 from `node.start_point` and
`kconfig_gates` decides the `#else` extent from its own walk, and the answer is only
right if those two agree."""
recover_ast_symbols(taken_branch_index, repo, None)
assert import_kconfig_gates(taken_branch_index, repo) > 0
sites = {m.line: m for m in macro_definitions(taken_branch_index, "PRIVATE")}
gated = {(g.macro, g.form) for g in sites[GATED_LINE].gated_by}
otherwise = {(g.macro, g.form) for g in sites[ELSE_LINE].gated_by}
assert ("ALLOW_PRIVATE_ACCESS", KCONFIG_GATE_IFNDEF) in gated
assert ("ALLOW_PRIVATE_ACCESS", KCONFIG_GATE_IFDEF) not in gated, (
"the private_ spelling is what a unit that has NOT defined the symbol gets"
)
assert ("ALLOW_PRIVATE_ACCESS", KCONFIG_GATE_IFDEF) in otherwise
assert ("ALLOW_PRIVATE_ACCESS", KCONFIG_GATE_IFNDEF) not in otherwise, (
"the bare spelling is what a unit that HAS defined the symbol gets"
)
## Zero is a measurement here: every gate in this file had a recorded extent, so an
## empty `gated_by` on some other site would mean ungated rather than unknown.
assert sites[GATED_LINE].gates_unplaceable == 0
assert sites[ELSE_LINE].gates_unplaceable == 0
Activity · 11 steps
test_recovery_is_idempotent_for_macros
None test_macro_recovery.test_recovery_is_idempotent_for_macros(Path taken_branch_index, Path repo)
A `(file, name, line)` key is finer than the variable rule's `(file, name)`, and a finer key has more ways to miss: read back the wrong column, or compare a tree-sitter line against a `bodystart`, and every macro is re-inserted on every build. Only a second pass returning zero new rows catches it.
tests/test_macro_recovery.py:271
Checks
assert _macro_rows(taken_branch_index, SYMBOL_SOURCE_AST) == after_firstassert _macro_rows(taken_branch_index, SYMBOL_SOURCE_DOXYGEN) == 1
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_recovery_is_idempotent_for_macros → recover_ast_symbols |
| REQ-DDB-PIPE-003 | measured | test_recovery_is_idempotent_for_macros → recover_ast_symbols → _recover_into → function_definition_harvester |
| REQ-DDB-PIPE-011 | measured | test_recovery_is_idempotent_for_macros → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_recovery_is_idempotent_for_macros → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language |
| REQ-DDB-WIKI-054 | inferred | test_recovery_is_idempotent_for_macros → recover_ast_symbols → _recover_into → all |
Source · 17 lines
def test_recovery_is_idempotent_for_macros(taken_branch_index: Path, repo: Path) -> None:
"""A `(file, name, line)` key is finer than the variable rule's `(file, name)`, and a
finer key has more ways to miss: read back the wrong column, or compare a tree-sitter
line against a `bodystart`, and every macro is re-inserted on every build. Only a
second pass returning zero new rows catches it."""
recover_ast_symbols(taken_branch_index, repo, None)
after_first = _macro_rows(taken_branch_index, SYMBOL_SOURCE_AST)
recover_ast_symbols(taken_branch_index, repo, None)
assert _macro_rows(taken_branch_index, SYMBOL_SOURCE_AST) == after_first
assert _macro_rows(taken_branch_index, SYMBOL_SOURCE_DOXYGEN) == 1
# ─── part 3: which branch — two-sided, per site ──────────────────────────────
Activity · 5 steps
test_the_else_branch_is_recovered_and_doxygens_own_row_is_untouched
None test_macro_recovery.test_the_else_branch_is_recovered_and_doxygens_own_row_is_untouched(Path taken_branch_index, Path repo)
THE DEDUP CONTROL, and the assertion that matters is the FIRST one: doxygen's own macro row count must not move. Measured the same way on the real target across this change — 2,504 either side — because that holds whatever the dedup rule does, where an assertion about the rule only holds if the rule is the one being read.
tests/test_macro_recovery.py:238
Checks
assert _macro_rows(taken_branch_index, SYMBOL_SOURCE_DOXYGEN) == 1assert _macro_rows(taken_branch_index, SYMBOL_SOURCE_DOXYGEN) == 1, ("recovery must not add, replace or relabel a row doxygen emitted" )assert _macro_rows(taken_branch_index, SYMBOL_SOURCE_AST) == 1assert sorted(sites) == [GATED_LINE, ELSE_LINE]assert sites[GATED_LINE].expansion == "private_##member"assert sites[ELSE_LINE].expansion == "member"assert sites[GATED_LINE].provenance is Noneassert sites[ELSE_LINE].provenance == SYMBOL_SOURCE_ASTassert sites[ELSE_LINE].params == "(member)"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_the_else_branch_is_recovered_and_doxygens_own_row_is_untouched → recover_ast_symbols |
| REQ-DDB-PIPE-003 | measured | test_the_else_branch_is_recovered_and_doxygens_own_row_is_untouched → recover_ast_symbols → _recover_into → function_definition_harvester |
| REQ-DDB-PIPE-011 | measured | test_the_else_branch_is_recovered_and_doxygens_own_row_is_untouched → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_the_else_branch_is_recovered_and_doxygens_own_row_is_untouched → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language |
| REQ-DDB-QUERY-001 | measured | |
| REQ-DDB-QUERY-003 | measured | |
| REQ-DDB-QUERY-006 | measured | |
| REQ-DDB-QUERY-012 | measured | |
| REQ-DDB-WIKI-054 | inferred | test_the_else_branch_is_recovered_and_doxygens_own_row_is_untouched → recover_ast_symbols → _recover_into → all |
Source · 33 lines
def test_the_else_branch_is_recovered_and_doxygens_own_row_is_untouched(
taken_branch_index: Path, repo: Path
) -> None:
"""THE DEDUP CONTROL, and the assertion that matters is the FIRST one: doxygen's own
macro row count must not move. Measured the same way on the real target across this
change — 2,504 either side — because that holds whatever the dedup rule does, where an
assertion about the rule only holds if the rule is the one being read."""
assert _macro_rows(taken_branch_index, SYMBOL_SOURCE_DOXYGEN) == 1
recover_ast_symbols(taken_branch_index, repo, None)
assert _macro_rows(taken_branch_index, SYMBOL_SOURCE_DOXYGEN) == 1, (
"recovery must not add, replace or relabel a row doxygen emitted"
)
## Exactly ONE recovered row for this name: the `#else` branch. A `(file, name)` key
## would give zero (doxygen already has the name in this file) and no key at all would
## give two.
assert _macro_rows(taken_branch_index, SYMBOL_SOURCE_AST) == 1
sites = {m.line: m for m in macro_definitions(taken_branch_index, "PRIVATE")}
assert sorted(sites) == [GATED_LINE, ELSE_LINE]
assert sites[GATED_LINE].expansion == "private_##member"
assert sites[ELSE_LINE].expansion == "member"
## Provenance separates the two halves of the answer. The `#else` spelling is not
## something doxygen declined to document — it is something doxygen could not see.
assert sites[GATED_LINE].provenance is None
assert sites[ELSE_LINE].provenance == SYMBOL_SOURCE_AST
## The recovered site carries its parameters, which means the `param` /
## `memberdef_param` write happened. Without it the site reads as object-like and the
## two rows of one macro would differ by who recovered them.
assert sites[ELSE_LINE].params == "(member)"
Activity · 11 steps
test_the_harvest_reads_both_branches_of_a_conditional_define
None test_macro_recovery.test_the_harvest_reads_both_branches_of_a_conditional_define(Path repo)
The parser has no preprocessor, so BOTH `#define`s are ordinary nodes to it. This is the premise of the whole change and it is asserted before anything is stored: if the walk saw one, no dedup rule downstream could recover the other.
tests/test_macro_recovery.py:210
Checks
assert parsed is not Noneassert macros[("PRIVATE", GATED_LINE)].expansion == "private_##member"assert macros[("PRIVATE", ELSE_LINE)].expansion == "member"assert macros[("PRIVATE", GATED_LINE)].params == ("member",)assert macros[("PRIVATE", ELSE_LINE)].params == ("member",)assert macros[("MBEDTLS_PRIVATE_ACCESS_H", 8)].expansion == ""assert macros[("MBEDTLS_PRIVATE_ACCESS_H", 8)].params == ()
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | test_the_harvest_reads_both_branches_of_a_conditional_define → harvest_macro_definitions |
| REQ-DDB-PIPE-011 | measured | test_the_harvest_reads_both_branches_of_a_conditional_define → _ast_parse_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_the_harvest_reads_both_branches_of_a_conditional_define → _ast_parse_one_file → _ts_language_for → _grammar_available → has_language |
Source · 28 lines
def test_the_harvest_reads_both_branches_of_a_conditional_define(repo: Path) -> None:
"""The parser has no preprocessor, so BOTH `#define`s are ordinary nodes to it. This
is the premise of the whole change and it is asserted before anything is stored: if
the walk saw one, no dedup rule downstream could recover the other."""
parsed = _ast_parse_one_file(HEADER, repo / HEADER, {})
assert parsed is not None
tree, src = parsed
macros = {(m.name, m.line): m for m in harvest_macro_definitions(tree, src)}
assert macros[("PRIVATE", GATED_LINE)].expansion == "private_##member"
assert macros[("PRIVATE", ELSE_LINE)].expansion == "member"
## The parameter list, on BOTH sites. A function-like macro is a
## `preproc_function_def` with a `parameters` field; a walk that accepted only
## `preproc_def` would report every object-like `#define` in the repo and miss the one
## symbol this exists for, and a `preproc_params` read that took every child would
## return the parentheses as parameters.
assert macros[("PRIVATE", GATED_LINE)].params == ("member",)
assert macros[("PRIVATE", ELSE_LINE)].params == ("member",)
## The include guard is an OBJECT-like define with no value, and it is recovered
## rather than special-cased — recognising the idiom would be one more heuristic on a
## walk whose whole value is that a `#define` is unambiguous.
assert macros[("MBEDTLS_PRIVATE_ACCESS_H", 8)].expansion == ""
assert macros[("MBEDTLS_PRIVATE_ACCESS_H", 8)].params == ()
# ─── part 2: the row doxygen already has is not duplicated ───────────────────
Activity · 10 steps
test_the_include_guard_is_not_reported_as_a_configuration_gate
None test_macro_recovery.test_the_include_guard_is_not_reported_as_a_configuration_gate(Path taken_branch_index, Path repo)
THE NEGATIVE HALF, and it is what stops the polarity answer above from being luck. The fixture's outer `#ifndef MBEDTLS_PRIVATE_ACCESS_H` spans BOTH `#define`s, so a gate harvest that recorded include guards would attach it to every site — every macro in every header would come back "gated", and the one gate that means something would sit in a list beside a guard that means nothing.
tests/test_macro_recovery.py:352
Checks
assert "MBEDTLS_PRIVATE_ACCESS_H" not in {g.macro for g in site.gated_by}, (f"site at line {line} reports the include guard as a configuration gate" )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-004 | measured | test_the_include_guard_is_not_reported_as_a_configuration_gate → import_kconfig_gates → declared_macro_names → bare_macro_names |
| REQ-DDB-INDEX-004 | measured | test_the_include_guard_is_not_reported_as_a_configuration_gate → recover_ast_symbols |
| REQ-DDB-PIPE-003 | measured | test_the_include_guard_is_not_reported_as_a_configuration_gate → import_kconfig_gates → run_harvest |
| REQ-DDB-PIPE-007 | measured | test_the_include_guard_is_not_reported_as_a_configuration_gate → import_kconfig_gates |
| REQ-DDB-PIPE-011 | measured | test_the_include_guard_is_not_reported_as_a_configuration_gate → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_the_include_guard_is_not_reported_as_a_configuration_gate → import_kconfig_gates → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language |
| REQ-DDB-QUERY-001 | measured | |
| REQ-DDB-QUERY-003 | measured | |
| REQ-DDB-QUERY-006 | measured | |
| REQ-DDB-QUERY-012 | measured | |
| REQ-DDB-SCHEMA-012 | measured | |
| REQ-DDB-SCHEMA-013 | measured | test_the_include_guard_is_not_reported_as_a_configuration_gate → import_kconfig_gates → ensure_kconfig_gates_table |
| REQ-DDB-WIKI-054 | inferred | test_the_include_guard_is_not_reported_as_a_configuration_gate → recover_ast_symbols → _recover_into → all |
Source · 18 lines
def test_the_include_guard_is_not_reported_as_a_configuration_gate(
taken_branch_index: Path, repo: Path
) -> None:
"""THE NEGATIVE HALF, and it is what stops the polarity answer above from being luck.
The fixture's outer `#ifndef MBEDTLS_PRIVATE_ACCESS_H` spans BOTH `#define`s, so a
gate harvest that recorded include guards would attach it to every site — every macro
in every header would come back "gated", and the one gate that means something would
sit in a list beside a guard that means nothing."""
recover_ast_symbols(taken_branch_index, repo, None)
import_kconfig_gates(taken_branch_index, repo)
sites = {m.line: m for m in macro_definitions(taken_branch_index, "PRIVATE")}
for line, site in sites.items():
assert "MBEDTLS_PRIVATE_ACCESS_H" not in {g.macro for g in site.gated_by}, (
f"site at line {line} reports the include guard as a configuration gate"
)