test_a_template_argument_macro_use_is_recovered_into_referenced_by¶
Tests › tests/test_macro_recovery.py
What this test is for
Why it exists
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.
Given
root = tmp_path / "repo"(root / "src").mkdir(parents=True)
10 more
(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"result = subprocess.run( [sys.executable, "-m", "clew", "--repo-root", str(root), "--output", str(db)], capture_output=True, text=True, )macro = macro_definitions(db, "FACE_COUNT")referenced = set(macro[0].referenced_by)expected = { "plain_use", "array_size_use", "static_scalar", "bold_table", "std_array_plain", "user_template_use", }
When
- —
Then
- ✓ result.returncode equals 0
- ✓ macro holds
- ✓ expected is at most referenced
What it exercises
The parts of the system's flows this test ran, measured by per-test coverage: lit steps ran in this test, dimmed ones did not, and ▶ marks where the test called in. Each title opens the whole flow with these steps lit.
Look up one name: everything the index holds about it · 21 of 226 steps
… 17 earlier steps
… 33 steps between
… 143 later steps
2 more
- clew — `main` (clew/cli.py) · 6 of 400 steps
- `main` (scripts/export_parity.py) · 6 of 203 steps
tests/test_macro_recovery.py:375 · its file's page
What it checks (3)
assert result.returncode == 0, ( f"the build failed, so the recovery cannot be under test:\n{result.stderr[-2000:]}" )not attributedassert macro, "precondition: the macro must be indexed at all"not attributedassert 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." )not attributed
What it reaches
Each row runs from this test, through the calls it makes, to the code a requirement names. If that code breaks, the test's checks are what should catch it. Reaching is not proving: a check only proves what it observes. No mutation records were given, so these rows say what the test REACHES.
Also reaches 5 requirements
Its run touches their code; that is reach, not proof.
- 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