test_cmakeast.py¶
tests/test_cmakeast.py
CMake functions and macros are definitions, and a CMake tree is not a Rust tree.
test_a_cmake_file_that_only_calls_commands_defines_nothing
None test_cmakeast.test_a_cmake_file_that_only_calls_commands_defines_nothing()
A command-only CMake file yields no definitions.
Checks
assert out == {"functions": [], "classes": []}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-012 | measured |
Source · 11 lines
def test_a_cmake_file_that_only_calls_commands_defines_nothing() -> None:
"""The common case — most `CMakeLists.txt` files define no function at all. The file
is still indexed and still searchable; it simply contributes no symbols.
@brief A command-only CMake file yields no definitions. @version 1
"""
out = _harvest(b"project(demo C)\nadd_library(mylib src/a.c)\n")
assert out == {"functions": [], "classes": []}
Activity · 2 steps
test_a_definition_with_no_parameters_reports_empty_parentheses
None test_cmakeast.test_a_definition_with_no_parameters_reports_empty_parentheses()
No parameters is `()`, not a missing signature.
Checks
assert out["functions"][0]["args"] == "()"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-012 | measured |
Source · 7 lines
def test_a_definition_with_no_parameters_reports_empty_parentheses() -> None:
"""@brief No parameters is `()`, not a missing signature. @version 1"""
out = _harvest(b"function(no_args)\nendfunction()\n")
assert out["functions"][0]["args"] == "()"
Activity · 2 steps
test_a_function_and_a_macro_are_both_definitions
None test_cmakeast.test_a_function_and_a_macro_are_both_definitions()
Both definition forms are harvested with their spans.
Checks
assert sorted(by_name) == ["add_firmware", "strict_warnings"]assert by_name["add_firmware"]["line"] == 7assert by_name["add_firmware"]["end"] == 9assert by_name["strict_warnings"]["line"] == 12
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-012 | measured |
Source · 11 lines
def test_a_function_and_a_macro_are_both_definitions() -> None:
"""@brief Both definition forms are harvested with their spans. @version 1"""
out = _harvest(_LISTS)
by_name = {fn["name"]: fn for fn in out["functions"]}
assert sorted(by_name) == ["add_firmware", "strict_warnings"]
assert by_name["add_firmware"]["line"] == 7
assert by_name["add_firmware"]["end"] == 9
assert by_name["strict_warnings"]["line"] == 12
Activity · 6 steps
test_a_macro_is_recorded_as_a_macro_not_a_function
None test_cmakeast.test_a_macro_is_recorded_as_a_macro_not_a_function()
The `kind` field separates macro from function.
Checks
assert kinds == {"add_firmware": "function", "strict_warnings": "macro"}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-012 | measured |
Source · 12 lines
def test_a_macro_is_recorded_as_a_macro_not_a_function() -> None:
"""A `macro` body runs in the CALLER's scope. A reader chasing a variable that leaks
needs that in the answer, so the distinction is a field and not a guess.
@brief The `kind` field separates macro from function. @version 1
"""
out = _harvest(_LISTS)
kinds = {fn["name"]: fn["kind"] for fn in out["functions"]}
assert kinds == {"add_firmware": "function", "strict_warnings": "macro"}
Activity · 3 steps
test_a_rust_tree_yields_no_cmake_definitions
None test_cmakeast.test_a_rust_tree_yields_no_cmake_definitions()
A Rust tree harvests no CMake definitions.
Checks
assert tree.root_node.type == "source_file", "the premise of this test"assert not is_cmake_tree(tree)assert harvest_definitions(tree, src) == {"functions": [], "classes": []}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-012 | measured |
Source · 13 lines
def test_a_rust_tree_yields_no_cmake_definitions() -> None:
"""THE COLLISION, pinned: both grammars root at `source_file`.
@brief A Rust tree harvests no CMake definitions. @version 1
"""
src = b'fn main() { println!("hi"); }\n'
tree = lps.parse_tree("rust", src)
assert tree.root_node.type == "source_file", "the premise of this test"
assert not is_cmake_tree(tree)
assert harvest_definitions(tree, src) == {"functions": [], "classes": []}
Activity · 5 steps
test_the_declared_parameters_are_the_signature
None test_cmakeast.test_the_declared_parameters_are_the_signature()
Parameters are reported.
Checks
assert args["add_firmware"] == "(NAME SOURCES)"assert args["strict_warnings"] == "(TARGET)"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-012 | measured |
Source · 13 lines
def test_the_declared_parameters_are_the_signature() -> None:
"""Unlike shell, CMake declares named parameters, so withholding them would be a gap
in the harvest rather than a fact about the language.
@brief Parameters are reported. @version 1
"""
out = _harvest(_LISTS)
args = {fn["name"]: fn["args"] for fn in out["functions"]}
assert args["add_firmware"] == "(NAME SOURCES)"
assert args["strict_warnings"] == "(TARGET)"
Activity · 4 steps
test_the_hash_block_above_the_definition_is_its_doc
None test_cmakeast.test_the_hash_block_above_the_definition_is_its_doc()
The preceding `#` block documents the definition.
Checks
assert "Register one firmware image and its map file." in fn["doc"]assert "@version 2" in fn["doc"]assert "#" not in fn["doc"]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-012 | measured |
Source · 10 lines
def test_the_hash_block_above_the_definition_is_its_doc() -> None:
"""@brief The preceding `#` block documents the definition. @version 1"""
out = _harvest(_LISTS)
fn = next(f for f in out["functions"] if f["name"] == "add_firmware")
assert "Register one firmware image and its map file." in fn["doc"]
assert "@version 2" in fn["doc"]
assert "#" not in fn["doc"]
Activity · 5 steps
test_the_payload_is_json_serializable
None test_cmakeast.test_the_payload_is_json_serializable()
The payload survives a JSON round trip.
Checks
assert json.loads(json.dumps(out)) == out
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-012 | measured |
Source · 4 lines
def test_the_payload_is_json_serializable() -> None:
"""@brief The payload survives a JSON round trip. @version 1"""
out = _harvest(_LISTS)
assert json.loads(json.dumps(out)) == out1 more lines, not shown