path_coverage 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +315 -107
- data/lib/path_coverage/calls.rb +55 -23
- data/lib/path_coverage/card.rb +14 -0
- data/lib/path_coverage/condition.rb +33 -3
- data/lib/path_coverage/configuration.rb +43 -22
- data/lib/path_coverage/configuration_paths.rb +58 -0
- data/lib/path_coverage/console_summary.rb +75 -0
- data/lib/path_coverage/gaps.rb +32 -13
- data/lib/path_coverage/html/file.html +5 -5
- data/lib/path_coverage/html/index.html +6 -18
- data/lib/path_coverage/html/settings.js +50 -0
- data/lib/path_coverage/html/side.js +341 -413
- data/lib/path_coverage/html/sort.js +24 -21
- data/lib/path_coverage/html/style.css +339 -207
- data/lib/path_coverage/html/tabs.js +15 -0
- data/lib/path_coverage/html/theme.js +27 -0
- data/lib/path_coverage/html_branch.rb +30 -0
- data/lib/path_coverage/html_cards.rb +111 -0
- data/lib/path_coverage/html_cells.rb +66 -0
- data/lib/path_coverage/html_file.rb +82 -68
- data/lib/path_coverage/html_index.rb +95 -41
- data/lib/path_coverage/html_index_head.rb +29 -0
- data/lib/path_coverage/html_labels.rb +23 -0
- data/lib/path_coverage/html_methods.rb +66 -0
- data/lib/path_coverage/html_nav.rb +50 -50
- data/lib/path_coverage/html_report.rb +69 -56
- data/lib/path_coverage/html_statements.rb +166 -0
- data/lib/path_coverage/html_syntax.rb +156 -0
- data/lib/path_coverage/html_tabs.rb +26 -0
- data/lib/path_coverage/html_template.rb +6 -0
- data/lib/path_coverage/html_tree.rb +59 -74
- data/lib/path_coverage/json_reader.rb +101 -0
- data/lib/path_coverage/json_writer.rb +52 -7
- data/lib/path_coverage/kernel.rb +55 -53
- data/lib/path_coverage/kinds/base.rb +71 -0
- data/lib/path_coverage/kinds/block.rb +137 -0
- data/lib/path_coverage/kinds/case.rb +92 -0
- data/lib/path_coverage/kinds/chain.rb +45 -0
- data/lib/path_coverage/kinds/choice.rb +68 -0
- data/lib/path_coverage/kinds/contains.rb +113 -0
- data/lib/path_coverage/kinds/safe.rb +153 -0
- data/lib/path_coverage/kinds/write.rb +54 -0
- data/lib/path_coverage/kinds.rb +37 -0
- data/lib/path_coverage/manifest.rb +60 -20
- data/lib/path_coverage/manifest_blocks.rb +48 -10
- data/lib/path_coverage/manifest_case.rb +2 -3
- data/lib/path_coverage/manifest_chains.rb +76 -0
- data/lib/path_coverage/manifest_choices.rb +32 -18
- data/lib/path_coverage/manifest_folding.rb +91 -0
- data/lib/path_coverage/manifest_ignoring.rb +35 -0
- data/lib/path_coverage/manifest_writes.rb +67 -0
- data/lib/path_coverage/merge.rb +19 -3
- data/lib/path_coverage/method_statements.rb +300 -0
- data/lib/path_coverage/post.rb +8 -8
- data/lib/path_coverage/recorder.rb +20 -79
- data/lib/path_coverage/recorder_blocks.rb +68 -0
- data/lib/path_coverage/recorder_cases.rb +23 -0
- data/lib/path_coverage/recorder_chains.rb +40 -0
- data/lib/path_coverage/recorder_writes.rb +26 -0
- data/lib/path_coverage/render.rb +56 -47
- data/lib/path_coverage/result.rb +19 -0
- data/lib/path_coverage/rewriter.rb +69 -107
- data/lib/path_coverage/rewriter_nested.rb +62 -0
- data/lib/path_coverage/site_paths.rb +9 -58
- data/lib/path_coverage/site_tree.rb +21 -57
- data/lib/path_coverage/statement_arms.rb +161 -0
- data/lib/path_coverage/summary.rb +41 -17
- data/lib/path_coverage/totals.rb +6 -12
- data/lib/path_coverage/version.rb +1 -1
- data/lib/path_coverage/within_methods.rb +92 -0
- metadata +40 -11
- data/lib/path_coverage/html/toggle.js +0 -12
- data/lib/path_coverage/html_paths.rb +0 -138
- data/lib/path_coverage/path_gaps.rb +0 -41
- data/lib/path_coverage/path_manifest.rb +0 -110
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fa9b979dc64b90e8ab047df2074c999067a5992bf62067c1e2975921a95a635b
|
|
4
|
+
data.tar.gz: 540e4226258cdcff171e560defc1ade28089a9901c2ed0578758cbc0e56484ba
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 822d8277455c05c7ac74af3e9e97625bca3884aa1f6d54fdaf625e112d28b210a929d8ade9c4941b9635f403daf2d1a87a1232741cf36d715dbfa568e36d39fc
|
|
7
|
+
data.tar.gz: e0ca639c839185f833e1e99bc5b12ea1f7e6d45b8281d5a43764135c37c975509463fd7a342f0a8ec7e3b9d3fe4a3eeab041c9c8bdc47e2195f6df34b467618c
|
data/README.md
CHANGED
|
@@ -7,58 +7,138 @@
|
|
|
7
7
|
Path coverage for Ruby, to run alongside SimpleCov's line and branch
|
|
8
8
|
coverage.
|
|
9
9
|
|
|
10
|
-
Gem: https://rubygems.org/gems/path_coverage (which shows the latest
|
|
11
|
-
version).
|
|
12
|
-
|
|
13
10
|
Status: sites cover `&&`, `||`, `and`, `or`, the ternary `?:`,
|
|
14
11
|
`if`/`elsif`/`else` and `unless` (modifiers included), `case`/`when`
|
|
15
12
|
with a subject, and the block methods `any?` `all?` `none?` `find`
|
|
16
13
|
`detect` `find_index` `take_while` `select` `filter` `reject`
|
|
17
|
-
`partition` `count` `filter_map
|
|
14
|
+
`partition` `count` `filter_map`, the writes `||=` and `&&=`, and `&.`
|
|
15
|
+
safe-navigation chains. Method paths cover every site at a method's
|
|
16
|
+
top level.
|
|
18
17
|
More decisions hidden inside calls come next (see Roadmap).
|
|
19
18
|
|
|
20
19
|
Demo: https://cyber-dojo.github.io/path_coverage/ shows the HTML report
|
|
21
20
|
for the mock source tree in `demo/`. `make demo` builds and opens the
|
|
22
21
|
same report locally.
|
|
23
22
|
|
|
24
|
-
|
|
23
|
+
## Overview
|
|
24
|
+
|
|
25
|
+
A *site* is one decision in your code: an `&&`, `||`, `if`,
|
|
26
|
+
`case`, `&.` chain, `||=`, or a block method such as `any?`.
|
|
27
|
+
Each way it can go is a *path*. For example
|
|
25
28
|
|
|
26
29
|
```ruby
|
|
27
|
-
|
|
28
|
-
total = 100
|
|
29
|
-
if user.member? && order.paid?
|
|
30
|
-
total -= 5
|
|
31
|
-
end
|
|
32
|
-
if order.big?
|
|
33
|
-
total -= 10
|
|
34
|
-
end
|
|
35
|
-
total
|
|
36
|
-
end
|
|
30
|
+
name.size > 2 && name.ascii_only?
|
|
37
31
|
```
|
|
38
32
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
path
|
|
33
|
+
has three paths: true then true, true then false, and false
|
|
34
|
+
alone, as `&&` then skips its right side.
|
|
35
|
+
|
|
36
|
+
Line and branch coverage can be 100% while a path was never
|
|
37
|
+
taken. path_coverage counts how often each path was taken:
|
|
38
|
+
within each site, and within each method, through its sites.
|
|
39
|
+
|
|
40
|
+
As the run exits it writes its report:
|
|
41
|
+
- `path_coverage.json`, for AIs and other tools.
|
|
42
|
+
- `index.html`, with a page per file, for people.
|
|
43
|
+
|
|
44
|
+
## Reading the HTML
|
|
45
|
+
|
|
46
|
+
Clicking a `def` line on a file's HTML page opens that method's
|
|
47
|
+
*card* to its left. One card is always open.
|
|
48
|
+
|
|
49
|
+
A card has a row for each site in the method, by `line:col`,
|
|
50
|
+
with its counts of paths not taken and taken.
|
|
51
|
+
|
|
52
|
+
Clicking a row's `▼` opens it:
|
|
53
|
+
- on the left is the site's code, as a tree.
|
|
54
|
+
- on the right is one column for each possible path through it.
|
|
55
|
+
- the column's head is `≀0` for a path never taken, and `≀*`
|
|
56
|
+
for one taken (hover for its count). Look for zeros!
|
|
57
|
+
- the symbols in a column line up with the tree's rows, and
|
|
58
|
+
are explained below.
|
|
59
|
+
|
|
60
|
+
### Boolean: `T` `F`
|
|
61
|
+
|
|
62
|
+
Many parts of a site, such as `name.size > 2`, are true or false.
|
|
63
|
+
|
|
64
|
+

|
|
65
|
+
|
|
66
|
+
- `T` the expression was true.
|
|
67
|
+
- `F` the expression was false.
|
|
68
|
+
|
|
69
|
+
In this example, there was no test which exercised the path where `name.size > 2` was `true`, and
|
|
70
|
+
`name.ascii_only?` was `false`.
|
|
71
|
+
|
|
72
|
+
### Unreachable: blank
|
|
73
|
+
|
|
74
|
+
Some parts of a site are not always evaluated.
|
|
75
|
+
|
|
76
|
+

|
|
77
|
+
|
|
78
|
+
- "blank" the expression is never evaluated.
|
|
79
|
+
|
|
80
|
+
In the second column `dee` was `T`, so because of `||`'s short-circuiting, `dum` is never evaluated.
|
|
43
81
|
|
|
44
|
-
|
|
82
|
+
### Taken: `✓`
|
|
45
83
|
|
|
46
|
-
|
|
47
|
-
paid, not a member. A member who has not paid may never have been
|
|
48
|
-
tried.
|
|
84
|
+
An `if` takes one of its arms.
|
|
49
85
|
|
|
50
|
-

|
|
86
|
+

|
|
52
87
|
|
|
53
|
-
|
|
88
|
+
- `✓` marks the column whose path took that "arm"
|
|
54
89
|
|
|
55
|
-
The
|
|
56
|
-
|
|
90
|
+
The `paid` row is the `if`'s predicate, `T` or `F`. Below it is one row
|
|
91
|
+
per arm, named `then` and `else`. The first column, `paid` false, took `else`; the
|
|
92
|
+
second, `paid` true, took `then`.
|
|
57
93
|
|
|
58
|
-
|
|
59
|
-
headed by its count, true then false at 0 and selected](docs/method.png)
|
|
94
|
+
### Navigation: `∅` `●`
|
|
60
95
|
|
|
61
|
-
|
|
96
|
+
`&.` skips the rest of its chain when its receiver is nil.
|
|
97
|
+
|
|
98
|
+

|
|
99
|
+
|
|
100
|
+
- `∅` the receiver was nil, so `&.` skipped the rest of the chain.
|
|
101
|
+
- `●` the receiver was not nil, so `&.` made the call.
|
|
102
|
+
|
|
103
|
+
In this example, there was no test which exercised the path where
|
|
104
|
+
`user` was nil.
|
|
105
|
+
|
|
106
|
+
### Count: `0` `1` `*`
|
|
107
|
+
|
|
108
|
+
A block method can call its block on any number of items.
|
|
109
|
+
|
|
110
|
+

|
|
111
|
+
|
|
112
|
+
- `0` the block was called with no items.
|
|
113
|
+
- `1` the block was called with one item.
|
|
114
|
+
- `*` the block was called with two or more items.
|
|
115
|
+
|
|
116
|
+
In this example, there was no test which exercised the path where
|
|
117
|
+
the block was called with two or more items and every answer was
|
|
118
|
+
`false`.
|
|
119
|
+
|
|
120
|
+
### Both: `TF`
|
|
121
|
+
|
|
122
|
+
A block's answers can differ from item to item.
|
|
123
|
+
|
|
124
|
+

|
|
125
|
+
|
|
126
|
+
- `T` every answer of the block was true.
|
|
127
|
+
- `F` every answer of the block was false.
|
|
128
|
+
- `TF` the block's answers were both true and false.
|
|
129
|
+
|
|
130
|
+
In this example, there was no test which exercised the path where
|
|
131
|
+
the block was called with two or more items and every answer was
|
|
132
|
+
`false`.
|
|
133
|
+
|
|
134
|
+
### Lots of paths!
|
|
135
|
+
|
|
136
|
+
Ruby code can be very compact so short expressions can generate lots of paths!
|
|
137
|
+
|
|
138
|
+

|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
## Getting started
|
|
62
142
|
|
|
63
143
|
```ruby
|
|
64
144
|
# test coverage config, before any application code is required
|
|
@@ -70,14 +150,20 @@ end
|
|
|
70
150
|
PathCoverage.start do
|
|
71
151
|
root APP_DIR # cover globs and site names are relative to it
|
|
72
152
|
cover 'source/**/*.rb' # each matching file is instrumented as it loads
|
|
153
|
+
cover 'test/**/*.rb' # more than one cover glob may be given
|
|
154
|
+
skip 'source/vendor/**/*.rb' # except these, though a cover glob matches them
|
|
73
155
|
coverage_dir '/tmp/coverage' # where path_coverage.json is written
|
|
74
|
-
|
|
75
|
-
|
|
156
|
+
report :gaps, :html # the reporters run at exit (default :gaps);
|
|
157
|
+
# also :summary and :post
|
|
158
|
+
group 'code', 'source/**/*.rb' # each group a tab of its own on index.html
|
|
159
|
+
group 'test', 'test/**/*.rb'
|
|
160
|
+
ignore '&&=' # operators whose sites are not measured
|
|
161
|
+
treat 'name', as: :present # a call to name is never nil
|
|
162
|
+
treat 'any?', as: :nonempty # any? is true when its receiver has items
|
|
76
163
|
end
|
|
77
164
|
```
|
|
78
165
|
|
|
79
|
-
|
|
80
|
-
of the ones there are. Calling `start` again replaces the configuration.
|
|
166
|
+
## Use when you cannot edit the code!
|
|
81
167
|
|
|
82
168
|
A run whose code cannot be changed, such as a script in a `docker build`
|
|
83
169
|
step, can be covered from its environment alone:
|
|
@@ -86,6 +172,7 @@ step, can be covered from its environment alone:
|
|
|
86
172
|
RUBYOPT=-rpath_coverage/auto
|
|
87
173
|
PATH_COVERAGE_ROOT=/app # root
|
|
88
174
|
PATH_COVERAGE_COVER=src/**/*.rb,lib/*.rb # cover, comma-separated
|
|
175
|
+
PATH_COVERAGE_SKIP=src/vendor/**/*.rb # skip, comma-separated, optional
|
|
89
176
|
PATH_COVERAGE_DIR=/tmp/paths # coverage_dir
|
|
90
177
|
PATH_COVERAGE_COLLECTOR=http://host.docker.internal:4570/runs
|
|
91
178
|
```
|
|
@@ -122,27 +209,33 @@ As the process exits:
|
|
|
122
209
|
|
|
123
210
|
- `path_coverage.json` is always written to `coverage_dir`: every site
|
|
124
211
|
of every covered file, with each operand's true and false counts under
|
|
125
|
-
`sites`,
|
|
126
|
-
|
|
212
|
+
`sites`, each site's paths under `paths`, each method's card under
|
|
213
|
+
`cards`, the statements reached under `reached`, and the paths taken
|
|
214
|
+
of all possible under `totals`, as [taken, possible]: `decisions`,
|
|
215
|
+
`methods`, and, with groups, each group's
|
|
216
|
+
own under `groups`, eg `"groups": {"code": {"decisions": [481, 567]}}`.
|
|
217
|
+
It also names the kinds of site measured under `kinds`, any `ignored`
|
|
218
|
+
operators and `treats`, and any paths taken that a treatment rules
|
|
219
|
+
out under `outside`.
|
|
220
|
+
It is the base the other reporters read, so they can also be run
|
|
221
|
+
later, in another process, from
|
|
127
222
|
it alone: `PathCoverage::Render.from_json(config)`, where `config` is a
|
|
128
223
|
`PathCoverage::Configuration` built from the same settings block.
|
|
129
224
|
Given several runs' reports, `Render.from_json(config, paths)` adds
|
|
130
225
|
their counts together first, so the report shows only the gaps that
|
|
131
|
-
every run left.
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
226
|
+
every run left. A report whose kinds, `ignored` or `treats` differ
|
|
227
|
+
from `config`'s is refused, as its sites list their paths
|
|
228
|
+
differently.
|
|
229
|
+
- `:gaps` prints one line per site path never taken, in manifest
|
|
230
|
+
order, naming the outcome of each leaf on it:
|
|
135
231
|
|
|
136
232
|
```text
|
|
137
233
|
source/kata.rb:3:23 path never taken: `ok?(id)` true, `new?(id)` false
|
|
138
234
|
source/kata.rb:4:24 never reached
|
|
139
|
-
source/fee.rb:2:2 fee path never taken: line 4 true, line 7 false
|
|
140
235
|
```
|
|
141
236
|
|
|
142
237
|
### Decisions
|
|
143
238
|
|
|
144
|
-
Measured always, as `:decisions`: the paths within each decision.
|
|
145
|
-
|
|
146
239
|
A site is named by the `path:line:column` where it starts, the path
|
|
147
240
|
relative to `root`. A site in a covered file the run never loaded is
|
|
148
241
|
still reported, as `never reached`.
|
|
@@ -168,17 +261,8 @@ should read the JSON, whose `paths` give each site's leaves as
|
|
|
168
261
|
```
|
|
169
262
|
|
|
170
263
|
A site is an outermost condition. Its leaves are numbered left to right
|
|
171
|
-
across the whole of it, nested conditions included
|
|
172
|
-
|
|
173
|
-
```ruby
|
|
174
|
-
ok?(id) && new?(id) && id.size == 6 # one && site, leaves 0 1 2
|
|
175
|
-
ok?(id) && (new?(id) || id.size == 6) # an || nested in an && site, 0 1 2
|
|
176
|
-
ok?(id) && new?(id) || id.size == 6 # an && nested in an || site, 0 1 2
|
|
177
|
-
ids.map { |k| k && k.ok? } && ok?(id) # two sites: the block's is its own
|
|
178
|
-
ok?(id) ? :ok : :no # a ?: site, its predicate leaf 0
|
|
179
|
-
ok?(id) && new?(id) ? :ok : :no # an && nested in a ?: site, 0 1
|
|
180
|
-
ok?(id) ? new?(id) && id.size == 6 : :no # one ?: site, its then arm 1 2
|
|
181
|
-
```
|
|
264
|
+
across the whole of it, nested conditions included. A condition inside a
|
|
265
|
+
block is a site of its own.
|
|
182
266
|
|
|
183
267
|
A ternary is a site even when its predicate is a single leaf. An arm
|
|
184
268
|
holding a condition of `&&`, `||`, `and`, `or` or `?:` is part of the
|
|
@@ -201,16 +285,31 @@ whose `===` calls the pattern's `===` once, exactly as the `case` would,
|
|
|
201
285
|
and notes whether it matched. A `case` with no subject, or with a splat
|
|
202
286
|
among its patterns, is no site.
|
|
203
287
|
|
|
204
|
-
A call to
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
288
|
+
A call to `any?` `all?` `none?` `find` `detect` `find_index`
|
|
289
|
+
`take_while` `select` `filter` `reject` `partition` `count` or
|
|
290
|
+
`filter_map`, with no arguments and a block of one expression, is a site
|
|
291
|
+
named at its method. Its item count is noted from the block's own calls,
|
|
292
|
+
so the receiver is never asked its size, which could consume a sequence
|
|
293
|
+
that can be read only once.
|
|
294
|
+
|
|
295
|
+
A `||=` or `&&=` write is a site, whatever its target: a variable of any
|
|
296
|
+
kind, a constant, an attribute (`self.size ||= n`) or an index
|
|
297
|
+
(`store[key] ||= key.upcase`). Its one leaf is its target, and its right
|
|
298
|
+
side is an arm, run when the target is false for `||=`, true for `&&=`,
|
|
299
|
+
as an `unless` or an `if` runs its arm. The target is never read again,
|
|
300
|
+
since reading `store[key]` could call a method twice: its outcome follows
|
|
301
|
+
from whether the right side ran. So `@clock ||= Clock.now` called only
|
|
302
|
+
once, as a fresh object, leaves the path with `@clock` true a gap.
|
|
303
|
+
|
|
304
|
+
A `&.` chain is a site, named where it starts. Its leaves are the
|
|
305
|
+
receivers of its `&.` calls. `false` counts as not nil, as `&.` calls on
|
|
306
|
+
it.
|
|
307
|
+
|
|
308
|
+
A chain inside a condition, eg `ok?(id) && user&.admin?` or
|
|
309
|
+
`if user&.admin?`, folds into its site, as one expression: its value is
|
|
310
|
+
one more leaf, true or false, reached when every receiver is not nil. A
|
|
311
|
+
write through `&.`, eg `box&.size ||= 3`, is no site, as a nil `box`
|
|
312
|
+
skips it whole and its target is never looked at.
|
|
214
313
|
|
|
215
314
|
A chain of one operator is flat; a change of operator, by precedence or by
|
|
216
315
|
parentheses, nests. Parentheses are not part of the tree, since they decide
|
|
@@ -228,46 +327,74 @@ constants, since one can hold nil or false (`VERBOSE = false`). `nil` and
|
|
|
228
327
|
@clock = options[:clock] || MonotonicClock.new # leaf 1: never evaluated, or no gap
|
|
229
328
|
```
|
|
230
329
|
|
|
330
|
+
Any other leaf, a call among them, is taken to have either outcome, as its
|
|
331
|
+
form alone cannot say which it returns. So a call that never returns nil
|
|
332
|
+
or false still leaves a path needing it falsy, which no test can take:
|
|
333
|
+
|
|
334
|
+
```ruby
|
|
335
|
+
methods: paths && methods_of(path, methods, paths) # [true, false] impossible
|
|
336
|
+
methods: paths ? methods_of(path, methods, paths) : nil # the same, no such path
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
Written as a choice, the same code has no such path. Reporting a gap that
|
|
340
|
+
cannot be closed is the lesser error than hiding one that can.
|
|
341
|
+
|
|
231
342
|
### Methods
|
|
232
343
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
344
|
+
Each method has a card, named by the `path:line:column` of its `def`,
|
|
345
|
+
with a row per top-level statement. A row that is a site counts its
|
|
346
|
+
paths; any other row is one path, taken when the statement is reached.
|
|
347
|
+
A method's total adds up its rows. A file's code outside any method
|
|
348
|
+
gets a card of its own.
|
|
349
|
+
|
|
350
|
+
The JSON report's `cards` hold each card's rows:
|
|
351
|
+
|
|
352
|
+
```json
|
|
353
|
+
"cards": {
|
|
354
|
+
"label.rb:1:0": {
|
|
355
|
+
"name": "label", "first": 1, "last": 7,
|
|
356
|
+
"rows": [
|
|
357
|
+
{ "at": "2:02", "top": "if", "paths": 2, "taken": 1, "site": "label.rb:2:2" },
|
|
358
|
+
{ "at": "3:04", "top": "value", "paths": 1, "taken": 1, "site": null },
|
|
359
|
+
{ "at": "5:04", "top": "value", "paths": 1, "taken": 0, "site": null }
|
|
360
|
+
]
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
```
|
|
241
364
|
|
|
242
365
|
### Reporters
|
|
243
366
|
|
|
244
|
-
- `:html` writes `index.html` to `coverage_dir`:
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
source. On a line holding a site the line number is a button (blue
|
|
251
|
-
and outlined when every outcome was seen, solid orange when any is
|
|
252
|
-
missing) that opens a grid of the site's paths, on the left. Its rows
|
|
253
|
-
are the site's tree: its operators, nested as Ruby groups them, a
|
|
254
|
-
ternary's arms marked `?` and `:`, an `if`'s named `then` and `else`,
|
|
255
|
-
and its leaves. Its columns are the site's paths, never taken first,
|
|
256
|
-
each headed by its count, orange when zero; a leaf shows its outcome on
|
|
257
|
-
each path, T or F, blank where the path never reached it, and a plain
|
|
258
|
-
arm a dot on each path that took it. A site written over several lines
|
|
259
|
-
has one button over all of its line numbers. Grids with gaps start
|
|
260
|
-
open. A header that stays at the top of the page lists every site as a
|
|
261
|
-
link to its line, covered sites first, then those with gaps, and arrows
|
|
262
|
-
beside each site with gaps jump to the previous and next one, wrapping
|
|
263
|
-
round at either end. Measuring paths, each method's grid of its
|
|
264
|
-
decisions' paths opens on the right.
|
|
367
|
+
- `:html` writes `index.html` to `coverage_dir`: a sortable row per
|
|
368
|
+
covered file, with its sites and its paths taken of all possible
|
|
369
|
+
within each method (eg `9 / 28 32%`, or `-` for a file with no
|
|
370
|
+
method of two or more decisions), and a Total row. Each file name
|
|
371
|
+
opens `files/<path>.html`, the file's source with its cards, as
|
|
372
|
+
Reading the HTML shows.
|
|
265
373
|
- `:post` sends the JSON report, as an HTTP POST, to the url set by
|
|
266
374
|
`collector 'http://...'`. It is for a run whose own files are thrown
|
|
267
375
|
away, such as a failing `docker build` step. It prints nothing, never
|
|
268
376
|
goes through an `http_proxy`, and gives up in silence on a collector
|
|
269
377
|
that cannot be reached or does not answer within a second, so the
|
|
270
378
|
run's output and exit status are unchanged.
|
|
379
|
+
- `:summary` prints each total as SimpleCov prints its line and branch
|
|
380
|
+
coverage:
|
|
381
|
+
|
|
382
|
+
```text
|
|
383
|
+
Path coverage within decisions: 527 / 631 (83.52%)
|
|
384
|
+
Path coverage within methods: 44 / 52 (84.62%)
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
With groups, each group is a heading, its own totals indented under it,
|
|
388
|
+
and there is no total over every group.
|
|
389
|
+
|
|
390
|
+
```text
|
|
391
|
+
code:
|
|
392
|
+
Path coverage within decisions: 481 / 567 (84.83%)
|
|
393
|
+
Path coverage within methods: 41 / 49 (83.67%)
|
|
394
|
+
test:
|
|
395
|
+
Path coverage within decisions: 65 / 84 (77.38%)
|
|
396
|
+
Path coverage within methods: 3 / 3 (100.00%)
|
|
397
|
+
```
|
|
271
398
|
|
|
272
399
|
## How it works
|
|
273
400
|
|
|
@@ -286,9 +413,8 @@ PathCoverage.leave(PathCoverage.enter("k.rb:2:2", 2), PathCoverage.record("k.rb:
|
|
|
286
413
|
|
|
287
414
|
An `if` site's leave call wraps its predicate alone, as its path is
|
|
288
415
|
decided there, so an arm that returns or raises still counts it.
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
calls.
|
|
416
|
+
Each statement that is no site gets a reach call before it, counting
|
|
417
|
+
its run, for its card's row.
|
|
292
418
|
|
|
293
419
|
A command call such as `ok? id` (after `and`) is not valid as a bare
|
|
294
420
|
argument, so that leaf alone gets parentheses of its own, and so does a
|
|
@@ -310,19 +436,65 @@ rewrite happens in memory; no file on disk changes.
|
|
|
310
436
|
At exit the manifests parsed during the run are reused; only covered files
|
|
311
437
|
the run never loaded are read and parsed then.
|
|
312
438
|
|
|
439
|
+
## Ignoring and treating
|
|
440
|
+
|
|
441
|
+
`ignore '&&=', '||='` stops `&&=` and `||=` writes being measured.
|
|
442
|
+
A site inside such a write is still measured, eg the `a && b` in
|
|
443
|
+
`@m ||= a && b`. Ignoring `&&` does not ignore `and`, nor does ignoring
|
|
444
|
+
`||` ignore `or`. The summary and `index.html` list what is ignored.
|
|
445
|
+
|
|
446
|
+
`treat` tells path_coverage what you know about a method, so paths that
|
|
447
|
+
cannot happen are not listed as gaps. Add `in: 'source/models/**'` to
|
|
448
|
+
limit a treatment to the files that glob matches.
|
|
449
|
+
|
|
450
|
+
- `treat 'name', as: :present`: a call to `name` is never nil, so
|
|
451
|
+
`user.name&.size` has no path with `user.name` nil.
|
|
452
|
+
- `treat 'any?', as: :nonempty`: `x.any?` is true exactly when `x` has
|
|
453
|
+
items. When `x` is a call to `select`, `reject`, `filter`,
|
|
454
|
+
`filter_map`, `partition` or `take_while`, the path that call took
|
|
455
|
+
often decides whether it kept any items. Paths where `any?` disagrees
|
|
456
|
+
with that are not listed, eg `ids.select { |i| i.odd? }.any?` true
|
|
457
|
+
with `ids` empty.
|
|
458
|
+
|
|
459
|
+
A run where a treatment turns out to be wrong is reported:
|
|
460
|
+
|
|
461
|
+
```text
|
|
462
|
+
source/user.rb:4:9 path taken that a treatment rules out: `user.name` nil
|
|
463
|
+
```
|
|
464
|
+
|
|
313
465
|
## Roadmap
|
|
314
466
|
|
|
315
467
|
- decisions hidden inside calls, each with its own outcome classes:
|
|
316
468
|
- `one?`, whose last answer does not decide it, and block methods
|
|
317
469
|
with blocks of more than one expression
|
|
318
470
|
- `fetch(k, default)`, `dig`, `Hash#[]` with a default: present vs default
|
|
319
|
-
- `x || default` in value context
|
|
320
|
-
- `||=` and `&&=`, on variables, attributes and index targets: the
|
|
321
|
-
right side evaluated vs skipped, counted without evaluating the
|
|
322
|
-
target twice
|
|
471
|
+
- `x || default` in value context: nil vs not nil
|
|
323
472
|
- `x rescue y` modifier: raised vs not raised
|
|
324
473
|
- `case` with no subject, and `case`/`in` patterns
|
|
325
474
|
- regex matches: nil vs MatchData
|
|
475
|
+
- `treat 'methods_of', as: :truthy`, so each call to it counts as a
|
|
476
|
+
leaf that is only truthy, as `Foo.new` is, and a run where it returns
|
|
477
|
+
nil or false is reported. Later, treatments could come from the
|
|
478
|
+
project's RBS signatures (`sig/*.rbs`) too.
|
|
479
|
+
- exceptions the code itself names: a `begin` or `def` with `rescue`
|
|
480
|
+
clauses as a site, like a `case`, whose paths are no raise and each
|
|
481
|
+
clause that rescued, eg `rescue IOError` never taken. Branch coverage
|
|
482
|
+
ignores `rescue`, and tests reach these paths with real input. A raise
|
|
483
|
+
that nothing names, from any call, stays out, as every leaf would gain
|
|
484
|
+
a third outcome that only fault injection could take.
|
|
485
|
+
- an evaluation that raised part way through a site, eg
|
|
486
|
+
`ok?(id) && fetch(id)` where `fetch` raises, reported as a path that
|
|
487
|
+
raised rather than dropped as unfinished.
|
|
488
|
+
- complexity maximums, reported and gated, since the possible paths
|
|
489
|
+
count how much there is to test, not only how much was tested. A
|
|
490
|
+
file's total measures its size, so each is a maximum over smaller
|
|
491
|
+
parts:
|
|
492
|
+
- paths in one decision, eg 6 for a `select` block
|
|
493
|
+
- paths through one method's decisions, eg 2 top-level ifs give 4
|
|
494
|
+
- paths within each decision, summed over every decision in one
|
|
495
|
+
method, nested ones included, eg decisions of 2, 3 and 15 paths
|
|
496
|
+
sum to 20. Every method has one, and it grows as the method gains
|
|
497
|
+
conditions, where the paths through a method multiply.
|
|
326
498
|
|
|
327
499
|
## Constraints
|
|
328
500
|
|
|
@@ -336,18 +508,54 @@ the run never loaded are read and parsed then.
|
|
|
336
508
|
`make all` runs, in a Docker image built from the repo's `Dockerfile`:
|
|
337
509
|
|
|
338
510
|
- `make lint`: rubocop over `lib/`, `test/` and `bin/` alike
|
|
339
|
-
- `make test`: the tests,
|
|
340
|
-
|
|
341
|
-
|
|
511
|
+
- `make test`: the tests, with path_coverage measuring its own `lib/` and
|
|
512
|
+
`test/`, then a check that SimpleCov's report has zero missed lines and
|
|
513
|
+
branches in both the code and the tests, and that every path within the
|
|
514
|
+
tests' methods was taken, within the bounds in
|
|
515
|
+
`test/coverage_metrics_params.json` (a path bound is eg
|
|
516
|
+
`test.paths.methods.missed`, and a missing path report denies it)
|
|
342
517
|
(`make test tids='6D1K'` runs only matching tests, and skips the check)
|
|
343
518
|
- `make test_check`: shunit2 tests showing that a breached bound fails the
|
|
344
519
|
check with a non-zero exit
|
|
345
520
|
|
|
521
|
+
Each run prints its seed; `SEED=n make test` replays that run's order of
|
|
522
|
+
files and tests. When the coverage check fails, it names each line and
|
|
523
|
+
branch missed.
|
|
524
|
+
|
|
525
|
+
A run ends with each group, code and test, as a heading over its four
|
|
526
|
+
figures, SimpleCov's and path_coverage's together, then where each report
|
|
527
|
+
is, each with a code and a test tab, then the check's verdict:
|
|
528
|
+
|
|
529
|
+
```text
|
|
530
|
+
code:
|
|
531
|
+
Line coverage: 1270 / 1270 (100.00%)
|
|
532
|
+
Branch coverage: 321 / 321 (100.00%)
|
|
533
|
+
Path coverage within decisions: 481 / 567 (84.83%)
|
|
534
|
+
Path coverage within methods: 41 / 49 (83.67%)
|
|
535
|
+
test:
|
|
536
|
+
Line coverage: 2250 / 2250 (100.00%)
|
|
537
|
+
Branch coverage: 43 / 43 (100.00%)
|
|
538
|
+
Path coverage within decisions: 65 / 84 (77.38%)
|
|
539
|
+
Path coverage within methods: 3 / 3 (100.00%)
|
|
540
|
+
SimpleCov report: .../reports/index.html
|
|
541
|
+
PathCov report: .../reports/paths/index.html
|
|
542
|
+
coverage: ALLOWED
|
|
543
|
+
```
|
|
544
|
+
|
|
545
|
+
`bin/check_coverage_metrics.rb` prints the groups, reading SimpleCov's
|
|
546
|
+
figures from `reports/coverage_metrics.json` and path_coverage's from the
|
|
547
|
+
`totals` in `reports/paths/path_coverage.json`; SimpleCov's own console
|
|
548
|
+
lines, totals over every group, are silenced. The tool measuring paths is
|
|
549
|
+
a copy of `lib/` renamed `PathCoverageSelf` (`test/self_coverage.rb`), so
|
|
550
|
+
the tests start and restart `PathCoverage` as always. SimpleCov's figures
|
|
551
|
+
for `lib/` are the same with it as without.
|
|
552
|
+
|
|
346
553
|
`make demo` (not part of `make all`) runs `demo/run.rb` through
|
|
347
554
|
`bin/build_demo.sh`, writing the report to `site/` and opening it. The
|
|
348
555
|
Pages workflow (`.github/workflows/pages.yml`) runs the same script on
|
|
349
556
|
each push to `main` and publishes `site/`.
|
|
350
557
|
|
|
351
|
-
`bin/
|
|
352
|
-
|
|
353
|
-
|
|
558
|
+
`bin/capture_card_images.sh` runs the examples in `demo/cards/` and
|
|
559
|
+
saves this README's screenshots, `docs/example-*.png`, with headless
|
|
560
|
+
Chrome. Run it again whenever the card's look changes.
|
|
561
|
+
|