test_a_template_argument_macro_use_is_recovered_into_referenced_by

Tests › tests/test_macro_recovery.py

passed Passed in the packaged run.

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

  1. root = tmp_path / "repo"
  2. (root / "src").mkdir(parents=True)
10 more
  1. (root / "src" / "m.h").write_text( "#pragma once\n/** @brief Face count. */\n#define FACE_COUNT 20\n", encoding="utf-8" )
  2. (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", )
  3. subprocess.run(["git", "init", "-q", str(root)], check=True)
  4. subprocess.run(["git", "-C", str(root), "add", "-A"], check=True)
  5. subprocess.run( [ "git", "-C", str(root), "-c", "user.email=t@t", "-c", "user.name=t", "commit", "-qm", "init", ], check=True, )
  6. db = tmp_path / "out.db"
  7. result = subprocess.run( [sys.executable, "-m", "clew", "--repo-root", str(root), "--output", str(db)], capture_output=True, text=True, )
  8. macro = macro_definitions(db, "FACE_COUNT")
  9. referenced = set(macro[0].referenced_by)
  10. expected = { "plain_use", "array_size_use", "static_scalar", "bold_table", "std_array_plain", "user_template_use", }
→

When

  1. —
→

Then

  1. ✓ result.returncode equals 0
  2. ✓ macro holds
  3. ✓ 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

callercallercallercallerclew/query/_common.pyclew/query/_common.pyclew/query/_common.pyclew/query/_common.pyclew/query/recovery.pyclew/query/recovery.pyclew/query/recovery.pyclew/query/recovery.pydossier18. _documentation_mentions → table_exists18table_exists19. _documentation_mentions → has_columns19has_columns20. has_columns → table_exists20table_exists21–22. _hint_from → _name_exists21_name_exists +1 more

… 33 steps between

callercallercallercallercallerclew/query/payload.pyclew/query/payload.pyclew/query/payload.pyclew/query/payload.pyclew/query/payload.pyclew/query/_common.pyclew/query/_common.pyclew/query/_common.pyclew/query/_common.pyclew/query/_common.pyother filesother filesother filesother filesother filesloop (line 515)looploop (line 660)looploop ×2 (line 288)loop ×2dossier56. _flatten_subject → _gate_definitions56_gate_definitions57. _gate_definitions → macro_definitions57macro_definitions58. macro_definitions → connect58connect▶ test enters59. macro_definitions → macro_definitions_conn59macro_definitions_conn60. macro_definitions_conn → has_columns60has_columns61–62. macro_definitions_conn → _macro_def61_macro_def +1 more63. gates_covering → table_exists63table_exists64. gates_covering → has_columns64has_columns65. gates_covering → _gate_columns65_gate_columns66–67. _gate_columns → has_columns66has_columns ×268. gates_covering → _with_defaults68_with_defaults69. _with_defaults → table_exists69table_exists70. _with_defaults → _defaults_for_macros70_defaults_for_macros71. _with_defaults → decided_default71decided_default72. decided_default → is_shipped_config72is_shipped_config73. _with_defaults → _in_default_build73_in_default_build74. _macro_def → _macro_params74_macro_params75. _macro_params → table_exists75table_exists76. _macro_def → strip_xml76strip_xml77. _macro_def → _referenced_by77_referenced_by78. _referenced_by → table_exists78table_exists79. _macro_def → symbol_provenance79symbol_provenance80–81. symbol_provenance → records_provenance80records_provenance +1 more82. _gate_definitions → _gate_definition_gaps82_gate_definition_gaps83. _flatten_subject → _empty_callers_note83_empty_callers_note

… 143 later steps

2 more

tests/test_macro_recovery.py:375 · its file's page

What it checks (3)

  1. assert result.returncode == 0, ( f"the build failed, so the recovery cannot be under test:\n{result.stderr[-2000:]}" ) not attributed
  2. assert macro, "precondition: the macro must be indexed at all" not attributed
  3. 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." ) 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.