test_shast.py

tests/test_shast.py

Shell functions are definitions, and a shell tree is not a JavaScript tree.

test_a_c_tree_yields_no_shell_definitions

None test_shast.test_a_c_tree_yields_no_shell_definitions()

A C tree harvests no shell functions.

tests/test_shast.py:129

Show on the map →

Called by none

Calls is_sh_tree

Checks

  • assert "function_definition" in set(tree.kinds), "the premise of this test"
  • assert not is_sh_tree(tree)
  • assert harvest_definitions(tree, src) == {"functions": [], "classes": []}

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-012measured
Source · 14 lines
def test_a_c_tree_yields_no_shell_definitions() -> None:
    """C spells its definition `function_definition` too — the same node name — and is
    separated only by the absence of a `word` name field.

    @brief A C tree harvests no shell functions. @version 1
    """
    src = b"int main(void) { return 0; }\n"
    tree = lps.parse_tree("c", src)

    assert "function_definition" in set(tree.kinds), "the premise of this test"
    assert not is_sh_tree(tree)
    assert harvest_definitions(tree, src) == {"functions": [], "classes": []}

Activity · 5 steps
lines 135–135src = b"int main(void) { return 0; }\n"lines 136–136tree = lps.parse_tree("c", src)lines 138–138assert "function_definition" in set(tree.kinds), "the premise of this test"lines 139–139assert not is_sh_tree(tree)lines 140–140assert harvest_definitions(tree, src) == {"functions": [], "classes": []}

test_a_comment_block_separated_by_a_blank_line_is_not_the_doc

None test_shast.test_a_comment_block_separated_by_a_blank_line_is_not_the_doc()

A detached comment belongs to nothing.

tests/test_shast.py:99

Show on the map →

Called by none

Calls _harvest

Checks

  • assert out["functions"][0]["doc"] == ""

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-012measured
Source · 7 lines
def test_a_comment_block_separated_by_a_blank_line_is_not_the_doc() -> None:
    """@brief A detached comment belongs to nothing. @version 1"""
    out = _harvest(b"# Unrelated note.\n\nfoo() {\n  :\n}\n")

    assert out["functions"][0]["doc"] == ""

Activity · 2 steps
lines 101–101out = _harvest(b"# Unrelated note.\n\nfoo() {\n :\n}\n")lines 103–103assert out["functions"][0]["doc"] == ""

test_a_hash_comment_block_above_the_function_is_its_doc

None test_shast.test_a_hash_comment_block_above_the_function_is_its_doc()

The preceding `#` block becomes the function's doc.

tests/test_shast.py:83

Show on the map →

Called by none

Calls _harvest

Checks

  • assert "Deploy the built artefact to one target." in deploy["doc"]
  • assert "@version 3" in deploy["doc"]
  • assert "#" not in deploy["doc"], "comment markers must be stripped, not served"
  • assert "Undo the last deploy." in rollback["doc"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-012measured
Source · 16 lines
def test_a_hash_comment_block_above_the_function_is_its_doc() -> None:
    """Shell has no doxygen comment, so the convention IS the `#` block immediately above,
    and the tags inside it are kept as literal text the way doxygen keeps an unknown tag.

    @brief The preceding `#` block becomes the function's doc. @version 1
    """
    out = _harvest(_SCRIPT)

    deploy = next(fn for fn in out["functions"] if fn["name"] == "deploy")
    assert "Deploy the built artefact to one target." in deploy["doc"]
    assert "@version 3" in deploy["doc"]
    assert "#" not in deploy["doc"], "comment markers must be stripped, not served"
    rollback = next(fn for fn in out["functions"] if fn["name"] == "rollback")
    assert "Undo the last deploy." in rollback["doc"]

Activity · 7 steps
lines 89–89out = _harvest(_SCRIPT)lines 91–91deploy = next(fn for fn in out["functions"] if fn["name"] == "deploy")lines 92–92assert "Deploy the built artefact to one target." in deploy["doc"]lines 93–93assert "@version 3" in deploy["doc"]lines 94–94assert "#" not in deploy["doc"], "comment markers must be stripped, not served"lines 95–95rollback = next(fn for fn in out["functions"] if fn["name"] == "rollback")lines 96–96assert "Undo the last deploy." in rollback["doc"]

test_a_javascript_tree_yields_no_shell_definitions

None test_shast.test_a_javascript_tree_yields_no_shell_definitions()

A JS tree harvests no shell functions.

tests/test_shast.py:115

Show on the map →

Called by none

Calls is_sh_tree

Checks

  • assert tree.root_node.type == "program", "the premise of this test"
  • assert not is_sh_tree(tree)
  • assert harvest_definitions(tree, src) == {"functions": [], "classes": []}

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-012measured
Source · 14 lines
def test_a_javascript_tree_yields_no_shell_definitions() -> None:
    """THE COLLISION, pinned. Both trees are rooted at `program`, so this harvester is
    offered JS trees by the shared parse and must return nothing for them.

    @brief A JS tree harvests no shell functions. @version 1
    """
    src = b"function foo(a) { return a; }\nconst bar = () => 1;\n"
    tree = lps.parse_tree("javascript", src)

    assert tree.root_node.type == "program", "the premise of this test"
    assert not is_sh_tree(tree)
    assert harvest_definitions(tree, src) == {"functions": [], "classes": []}

Activity · 5 steps
lines 121–121src = b"function foo(a) { return a; }\nconst bar = () => 1;\n"lines 122–122tree = lps.parse_tree("javascript", src)lines 124–124assert tree.root_node.type == "program", "the premise of this test"lines 125–125assert not is_sh_tree(tree)lines 126–126assert harvest_definitions(tree, src) == {"functions": [], "classes": []}

test_both_spellings_of_a_shell_function_are_definitions

None test_shast.test_both_spellings_of_a_shell_function_are_definitions()

Both function forms are harvested, with their line spans.

tests/test_shast.py:69

Show on the map →

Called by none

Calls _harvest

Checks

  • assert sorted(by_name) == ["deploy", "rollback"]
  • assert by_name["deploy"]["line"] == 6
  • assert by_name["deploy"]["end"] == 9
  • assert by_name["rollback"]["line"] == 12

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-012measured
Source · 14 lines
def test_both_spellings_of_a_shell_function_are_definitions() -> None:
    """`name()` and `function name` are the two forms POSIX sh and bash accept.

    @brief Both function forms are harvested, with their line spans. @version 1
    """
    out = _harvest(_SCRIPT)

    by_name = {fn["name"]: fn for fn in out["functions"]}
    assert sorted(by_name) == ["deploy", "rollback"]
    assert by_name["deploy"]["line"] == 6
    assert by_name["deploy"]["end"] == 9
    assert by_name["rollback"]["line"] == 12

Activity · 6 steps
lines 74–74out = _harvest(_SCRIPT)lines 76–76by_name = {fn["name"]: fn for fn in out["functions"]}lines 77–77assert sorted(by_name) == ["deploy", "rollback"]lines 78–78assert by_name["deploy"]["line"] == 6lines 79–79assert by_name["deploy"]["end"] == 9lines 80–80assert by_name["rollback"]["line"] == 12

test_shell_defines_no_classes

None test_shast.test_shell_defines_no_classes()

The classes list is present and empty.

tests/test_shast.py:106

Show on the map →

Called by none

Calls _harvest

Checks

  • assert _harvest(_SCRIPT)["classes"] == []

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-012measured
Source · 9 lines
def test_shell_defines_no_classes() -> None:
    """The payload shape is shared with JS/TS, which has classes; shell has none, so the
    key must be present and empty rather than absent.

    @brief The classes list is present and empty. @version 1
    """
    assert _harvest(_SCRIPT)["classes"] == []

Activity · 1 steps
lines 112–112assert _harvest(_SCRIPT)["classes"] == []

test_the_payload_is_json_serializable_and_rowid_free

None test_shast.test_the_payload_is_json_serializable_and_rowid_free()

The payload survives a JSON round trip.

tests/test_shast.py:143

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 · 10 lines
def test_the_payload_is_json_serializable_and_rowid_free() -> None:
    """Every harvest payload is cached as JSON, so a node object anywhere in it is a bug
    that only shows up on the second build.

    @brief The payload survives a JSON round trip. @version 1
    """
    import json

    out = _harvest(_SCRIPT)
    assert json.loads(json.dumps(out)) == out

1 more lines, not shown

Activity · 3 steps
lines 149–149import jsonlines 151–151out = _harvest(_SCRIPT)lines 152–152assert json.loads(json.dumps(out)) == out