test_ifdef_and_ifndef_are_normalised_to_opposite_polarities¶
Tests › tests/test_binding_edges.py
What this test is for
Why it exists
`#ifdef X` and `#ifndef X` are the SAME tree-sitter node type (`preproc_ifdef`) and differ only in the directive token, so the polarity has to be read off that token. Getting it backwards selects the wrong implementation while still emitting exactly one confident edge — the most dangerous possible outcome, because it looks like the fix working.
Given
source = """\ int impl_a(int *m) { return *m; } int impl_b(int *m) { return -1; } #ifdef PICK_A int (*mutex_lock)(int *) = impl_a; #endif #ifndef PICK_A int (*mutex_lock)(int *) = impl_b; #endif void critical(void) { mutex_lock(0); } """funcs = [(1, "impl_a", 1, 1), (2, "impl_b", 2, 2), (3, "critical", 9, 9)]
2 more
on = _c_edges_with_config(tmp_path / "on", source, funcs, ["PICK_A"])off = _c_edges_with_config(tmp_path / "off", source, funcs, ["OTHER"])
When
- —
Then
- ✓ on contains ("critical", "impl_a", "fnptr", "resolved")
- ✓ [e for e in on if e[1] == "impl_b"] is false
- ✓ off contains ("critical", "impl_b", "fnptr", "resolved")
- ✓ [e for e in off if e[1] == "impl_a"] is false
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.
clew — `main` (clew/cli.py) · 7 of 400 steps
… 70 earlier steps
… 313 later steps
tests/test_binding_edges.py:408 · its file's page
What it checks (4)
assert ("critical", "impl_a", "fnptr", "resolved") in onobserves_c_edges_with_configviaonassert not [e for e in on if e[1] == "impl_b"], "#ifndef PICK_A is dead when PICK_A is set"observes_c_edges_with_configviaonassert ("critical", "impl_b", "fnptr", "resolved") in offobserves_c_edges_with_configviaoffassert not [e for e in off if e[1] == "impl_a"], "#ifdef PICK_A is dead when PICK_A is unset"observes_c_edges_with_configviaoff
Where the product reaches it
No product flow reaches this code: no product entry point's flow calls any of the functions this test calls.
Call flow
test_ifdef_and_ifndef_are_normalised_to_opposite_polarities→_c_edges_with_configWhat 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 8 requirements
Its run touches their code; that is reach, not proof.
- REQ-DDB-CONFIG-004 measured
- REQ-DDB-PIPE-003 measured
- REQ-DDB-PIPE-011 measured
- REQ-DDB-PIPE-012 inferred
- REQ-DDB-SCHEMA-003 measured
- REQ-DDB-SCHEMA-007 measured
- REQ-DDB-SCHEMA-012 measured
- REQ-DDB-WIKI-054 inferred