mirror of
https://github.com/unclebob/mutator.git
synced 2026-11-26 18:58:50 +00:00
Kill the Clojure site survivors instead of leaving them.
A reader quote is a quoting_lit, so '(+ 1 0) was not covered by the (quote ...) test. The skip returned True there and the mutant survived. A + inside a vector is not a call, a symbol True is not a boolean, and the anchor of a Clojure site is its own line. _clojure_text repeated its type check with a child-count clause, and _is_head's final return never ran because the symbol is a child of its list. Both are gone. Proved by the Clojure site tests. mutator on src/mutator/sites.py then scored 66 killed, 0 survived, 0 uncovered. The suite passes (119 tests, and the SwiftPM run is skipped because swift is not installed). Co-authored-by: Robert C. Martin <[email protected]>
This commit is contained in:
co-authored by
Robert C. Martin
parent
b494411b07
commit
8118590503
@@ -124,7 +124,7 @@ _CLOJURE_HEAD = {
|
|||||||
|
|
||||||
class RawSite:
|
class RawSite:
|
||||||
def __init__(
|
def __init__(
|
||||||
self, line: int, start: int, end: int, original: str, mutant: str, category: str, anchor_line: int = 0
|
self, line: int, start: int, end: int, original: str, mutant: str, category: str, anchor_line: int
|
||||||
):
|
):
|
||||||
self.line = line
|
self.line = line
|
||||||
# The line its statement starts on. LCOV marks only that line of a multi-line statement.
|
# The line its statement starts on. LCOV marks only that line of a multi-line statement.
|
||||||
@@ -248,10 +248,10 @@ def _is_head(node) -> bool:
|
|||||||
parent = node.parent
|
parent = node.parent
|
||||||
if parent is None or parent.type != "list_lit":
|
if parent is None or parent.type != "list_lit":
|
||||||
return False
|
return False
|
||||||
|
# The symbol is one of these children, so this loop returns.
|
||||||
for child in parent.children:
|
for child in parent.children:
|
||||||
if child.type == "sym_lit":
|
if child.type == "sym_lit":
|
||||||
return child.id == node.id
|
return child.id == node.id
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def _clojure_skipped(node, data: bytes) -> bool:
|
def _clojure_skipped(node, data: bytes) -> bool:
|
||||||
@@ -268,7 +268,7 @@ def _clojure_skipped(node, data: bytes) -> bool:
|
|||||||
|
|
||||||
|
|
||||||
def _clojure_text(node, data: bytes) -> str:
|
def _clojure_text(node, data: bytes) -> str:
|
||||||
if node.child_count == 0 or node.type in {"sym_lit", "bool_lit", "num_lit"}:
|
if node.type in {"sym_lit", "bool_lit", "num_lit"}:
|
||||||
return _text(data, node)
|
return _text(data, node)
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ def test_clojure_rules_follow_clj_mutate_and_mark_private_defns(tmp_path):
|
|||||||
assert ("defn/place", "1", "0") in described
|
assert ("defn/place", "1", "0") in described
|
||||||
assert ("defn-/hide", "false", "true") in described
|
assert ("defn-/hide", "false", "true") in described
|
||||||
assert {site.namespace for site in sites} == {"demo.core"}
|
assert {site.namespace for site in sites} == {"demo.core"}
|
||||||
|
plus = [site for site in sites if site.original == "+"]
|
||||||
|
assert [site.anchor_line for site in plus] == [4]
|
||||||
functions = project_functions(source, tmp_path / "src/demo/core.clj", tmp_path)
|
functions = project_functions(source, tmp_path / "src/demo/core.clj", tmp_path)
|
||||||
assert form_id("hide", True) == "defn-/hide"
|
assert form_id("hide", True) == "defn-/hide"
|
||||||
assert is_private("clojure", "hide", source, 6, 7)
|
assert is_private("clojure", "hide", source, 6, 7)
|
||||||
@@ -40,12 +42,25 @@ def test_clojure_ignores_strings_comments_and_quotes(tmp_path):
|
|||||||
(defn place []
|
(defn place []
|
||||||
(comment (+ 1 0))
|
(comment (+ 1 0))
|
||||||
(quote (+ 1 0))
|
(quote (+ 1 0))
|
||||||
|
'(+ 1 0)
|
||||||
(str "true + 1"))
|
(str "true + 1"))
|
||||||
"""
|
"""
|
||||||
sites = _sites(tmp_path, "src/demo/core.clj", source)
|
sites = _sites(tmp_path, "src/demo/core.clj", source)
|
||||||
assert sites == []
|
assert sites == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_a_clojure_vector_and_a_capitalized_symbol_are_not_calls(tmp_path):
|
||||||
|
source = """(defn place []
|
||||||
|
[+ 1]
|
||||||
|
True)
|
||||||
|
"""
|
||||||
|
sites = _sites(tmp_path, "src/demo/core.clj", source)
|
||||||
|
described = {(site.original, site.mutant) for site in sites}
|
||||||
|
assert ("+", "-") not in described
|
||||||
|
assert ("True", "False") not in described
|
||||||
|
assert ("1", "0") in described
|
||||||
|
|
||||||
|
|
||||||
def test_java_rules_follow_mutate4java(tmp_path):
|
def test_java_rules_follow_mutate4java(tmp_path):
|
||||||
source = """package demo;
|
source = """package demo;
|
||||||
class Board {
|
class Board {
|
||||||
|
|||||||
Reference in New Issue
Block a user