Test coverage for Clojure: the project's Lazytest run under ClojureStorm and Clofidence.
ClojureStorm is a Clojure compiler that reports each expression it runs, and
Clofidence records those reports. A coverage run adds both to the project's own
test command through one extra deps.edn alias, :vis-coverage. A Lazytest hook
in that alias writes the recorded forms as EDN, because the test JVM has no JSON
library. This process then turns them into the vis-coverage/1 JSON report that
graphify crap reads:
{"format": "vis-coverage/1", "tool": "clofidence", "prefixes": [...],
"forms": [{"file": "app/core.clj", "ns": "app.core", "line": 3,
"kind": "defn", "hittable": 12, "hit": 9,
"children": {"4": [5, 5]}}]}
file is classpath-relative. hittable counts the expressions the compiler
instrumented in the top-level form, and hit the ones that ran. children
gives the same counts for each direct element of the form, keyed by its index,
so a tool can score each method of a defrecord or an extend-type.
Each form also has branches, [measured ran] over the branches of its if,
when, cond, cond-> and case forms, and gaps. A gap is the outermost
code that never ran inside code that did: {"line", "end_line", "kind", "detail"}, where kind is branch or expression.
Test coverage for Clojure: the project's Lazytest run under ClojureStorm and
Clofidence.
ClojureStorm is a Clojure compiler that reports each expression it runs, and
Clofidence records those reports. A coverage run adds both to the project's own
test command through one extra deps.edn alias, `:vis-coverage`. A Lazytest hook
in that alias writes the recorded forms as EDN, because the test JVM has no JSON
library. This process then turns them into the `vis-coverage/1` JSON report that
`graphify crap` reads:
{"format": "vis-coverage/1", "tool": "clofidence", "prefixes": [...],
"forms": [{"file": "app/core.clj", "ns": "app.core", "line": 3,
"kind": "defn", "hittable": 12, "hit": 9,
"children": {"4": [5, 5]}}]}
`file` is classpath-relative. `hittable` counts the expressions the compiler
instrumented in the top-level form, and `hit` the ones that ran. `children`
gives the same counts for each direct element of the form, keyed by its index,
so a tool can score each method of a `defrecord` or an `extend-type`.
Each form also has `branches`, `[measured ran]` over the branches of its `if`,
`when`, `cond`, `cond->` and `case` forms, and `gaps`. A gap is the outermost
code that never ran inside code that did: `{"line", "end_line", "kind",
"detail"}`, where `kind` is `branch` or `expression`.(alias-edn prefixes)The -Sdeps value that adds the :vis-coverage alias.
The `-Sdeps` value that adds the `:vis-coverage` alias.
(branch-label head size idx)The branch that the element at idx is in a call of head with size
elements: then, else, body, clause, step or default. Nil for other elements.
The branch that the element at `idx` is in a call of `head` with `size` elements: then, else, body, clause, step or default. Nil for other elements.
(branches {:keys [coords hits nodes]})The branches of one recorded form that the compiler measured, and the ones that ran. A branch counts when it holds an instrumented expression, and it ran when one of them ran. A branch that is only a constant has no expression to measure.
The branches of one recorded form that the compiler measured, and the ones that ran. A branch counts when it holds an instrumented expression, and it ran when one of them ran. A branch that is only a constant has no expression to measure.
The Clofidence release that records the coverage.
The Clofidence release that records the coverage.
(default-prefixes root)The namespace prefixes to instrument: for each top-level segment of the project's source namespaces, the prefix that its namespaces share.
The namespace prefixes to instrument: for each top-level segment of the project's source namespaces, the prefix that its namespaces share.
(finish! root prefixes)Turn the recorded forms into the report and summarize it. An error names a
run that recorded nothing.
Turn the recorded forms into the report and summarize it. An `error` names a run that recorded nothing.
Where the hook writes the recorded forms, under the project root.
Where the hook writes the recorded forms, under the project root.
(gaps {:keys [coords hits nodes line]})The code of one recorded form that never ran: each expression that did not run inside one that did, so each gap names the outermost code that the tests missed.
The code of one recorded form that never ran: each expression that did not run inside one that did, so each gap names the outermost code that the tests missed.
The source path that holds the hook namespace, under the project root.
The source path that holds the hook namespace, under the project root.
The Lazytest hook that records coverage.
The Lazytest hook that records coverage.
(instrument-command cmd prefixes)cmd, a clojure ... -M:aliases args... vector, run under the coverage alias
with the hook. Nil when cmd has no -M alias argument.
`cmd`, a `clojure ... -M:aliases args...` vector, run under the coverage alias with the hook. Nil when `cmd` has no `-M` alias argument.
(prepare! root)Write the hook namespace and remove the forms of an earlier run.
Write the hook namespace and remove the forms of an earlier run.
(report forms prefixes)The vis-coverage/1 report of the recorded forms that [[measured?]] keeps.
The `vis-coverage/1` report of the recorded `forms` that [[measured?]] keeps.
The vis-coverage/1 report, under the project root.
The `vis-coverage/1` report, under the project root.
The ClojureStorm compiler release, a drop-in replacement for org.clojure/clojure.
The ClojureStorm compiler release, a drop-in replacement for org.clojure/clojure.
(summary root report)Covered and measured expressions, branches and gaps of each file in report.
Covered and measured expressions, branches and gaps of each file in `report`.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |