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.

tests/test_cmakeast.py:128

Show on the map →

Called by none

Calls _harvest

Checks

  • assert out == {"functions": [], "classes": []}

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-012measured
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
lines 134–134out = _harvest(b"project(demo C)\nadd_library(mylib src/a.c)\n")lines 136–136assert out == {"functions": [], "classes": []}

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.

tests/test_cmakeast.py:98

Show on the map →

Called by none

Calls _harvest

Checks

  • assert out["functions"][0]["args"] == "()"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-012measured
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
lines 100–100out = _harvest(b"function(no_args)\nendfunction()\n")lines 102–102assert out["functions"][0]["args"] == "()"

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.

tests/test_cmakeast.py:62

Show on the map →

Called by none

Calls _harvest

Checks

  • 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

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-012measured
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
lines 64–64out = _harvest(_LISTS)lines 66–66by_name = {fn["name"]: fn for fn in out["functions"]}lines 67–67assert sorted(by_name) == ["add_firmware", "strict_warnings"]lines 68–68assert by_name["add_firmware"]["line"] == 7lines 69–69assert by_name["add_firmware"]["end"] == 9lines 70–70assert by_name["strict_warnings"]["line"] == 12

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.

tests/test_cmakeast.py:73

Show on the map →

Called by none

Calls _harvest

Checks

  • assert kinds == {"add_firmware": "function", "strict_warnings": "macro"}

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-012measured
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
lines 79–79out = _harvest(_LISTS)lines 81–81kinds = {fn["name"]: fn["kind"] for fn in out["functions"]}lines 82–82assert kinds == {"add_firmware": "function", "strict_warnings": "macro"}

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.

tests/test_cmakeast.py:115

Show on the map →

Called by none

Calls is_cmake_tree

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

requirementlinkedpath to the implementer
REQ-DDB-PIPE-012measured
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
lines 120–120src = b'fn main() { println!("hi"); }\n'lines 121–121tree = lps.parse_tree("rust", src)lines 123–123assert tree.root_node.type == "source_file", "the premise of this test"lines 124–124assert not is_cmake_tree(tree)lines 125–125assert harvest_definitions(tree, src) == {"functions": [], "classes": []}

test_the_declared_parameters_are_the_signature

None test_cmakeast.test_the_declared_parameters_are_the_signature()

Parameters are reported.

tests/test_cmakeast.py:85

Show on the map →

Called by none

Calls _harvest

Checks

  • assert args["add_firmware"] == "(NAME SOURCES)"
  • assert args["strict_warnings"] == "(TARGET)"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-012measured
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
lines 91–91out = _harvest(_LISTS)lines 93–93args = {fn["name"]: fn["args"] for fn in out["functions"]}lines 94–94assert args["add_firmware"] == "(NAME SOURCES)"lines 95–95assert args["strict_warnings"] == "(TARGET)"

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.

tests/test_cmakeast.py:105

Show on the map →

Called by none

Calls _harvest

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

requirementlinkedpath to the implementer
REQ-DDB-PIPE-012measured
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
lines 107–107out = _harvest(_LISTS)lines 109–109fn = next(f for f in out["functions"] if f["name"] == "add_firmware")lines 110–110assert "Register one firmware image and its map file." in fn["doc"]lines 111–111assert "@version 2" in fn["doc"]lines 112–112assert "#" not in fn["doc"]

test_the_payload_is_json_serializable

None test_cmakeast.test_the_payload_is_json_serializable()

The payload survives a JSON round trip.

tests/test_cmakeast.py:139

Show on the map →

Called by none

Calls _harvest

Checks

  • assert json.loads(json.dumps(out)) == out

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-012measured
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)) == out

1 more lines, not shown

Activity · 2 steps
lines 141–141out = _harvest(_LISTS)lines 142–142assert json.loads(json.dumps(out)) == out