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.
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-012 | measured |
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
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.
Checks
assert out["functions"][0]["doc"] == ""
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-012 | measured |
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
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.
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-012 | measured |
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
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.
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-012 | measured |
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
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.
Checks
assert sorted(by_name) == ["deploy", "rollback"]assert by_name["deploy"]["line"] == 6assert by_name["deploy"]["end"] == 9assert by_name["rollback"]["line"] == 12
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-012 | measured |
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
test_shell_defines_no_classes
None test_shast.test_shell_defines_no_classes()
The classes list is present and empty.
Checks
assert _harvest(_SCRIPT)["classes"] == []
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-012 | measured |
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
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.
Checks
assert json.loads(json.dumps(out)) == out
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-012 | measured |
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)) == out1 more lines, not shown