You need to sign in or sign up before continuing.
path_coverage 0.2.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 +112 -113
- data/lib/path_coverage/calls.rb +4 -11
- data/lib/path_coverage/card.rb +14 -0
- data/lib/path_coverage/condition.rb +8 -1
- data/lib/path_coverage/configuration.rb +1 -17
- data/lib/path_coverage/configuration_paths.rb +4 -2
- data/lib/path_coverage/console_summary.rb +15 -17
- data/lib/path_coverage/gaps.rb +12 -9
- data/lib/path_coverage/html/file.html +5 -5
- data/lib/path_coverage/html/index.html +3 -1
- data/lib/path_coverage/html/settings.js +50 -0
- data/lib/path_coverage/html/side.js +341 -432
- data/lib/path_coverage/html/style.css +330 -225
- 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 +28 -29
- data/lib/path_coverage/html_index_head.rb +10 -30
- 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 +45 -49
- data/lib/path_coverage/html_statements.rb +166 -0
- data/lib/path_coverage/html_syntax.rb +156 -0
- data/lib/path_coverage/html_template.rb +6 -0
- data/lib/path_coverage/html_tree.rb +36 -72
- data/lib/path_coverage/json_reader.rb +21 -14
- data/lib/path_coverage/json_writer.rb +26 -13
- data/lib/path_coverage/kernel.rb +29 -49
- data/lib/path_coverage/kinds/block.rb +2 -1
- data/lib/path_coverage/kinds/case.rb +7 -4
- data/lib/path_coverage/kinds/contains.rb +6 -4
- data/lib/path_coverage/kinds/safe.rb +5 -3
- data/lib/path_coverage/manifest.rb +2 -1
- data/lib/path_coverage/manifest_blocks.rb +3 -4
- data/lib/path_coverage/manifest_case.rb +2 -3
- data/lib/path_coverage/manifest_choices.rb +4 -3
- data/lib/path_coverage/manifest_folding.rb +1 -1
- data/lib/path_coverage/merge.rb +3 -3
- data/lib/path_coverage/method_statements.rb +300 -0
- data/lib/path_coverage/recorder.rb +12 -31
- data/lib/path_coverage/render.rb +19 -22
- data/lib/path_coverage/rewriter.rb +36 -55
- data/lib/path_coverage/site_tree.rb +9 -0
- data/lib/path_coverage/statement_arms.rb +161 -0
- data/lib/path_coverage/summary.rb +11 -15
- 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 +16 -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
|
@@ -12,71 +12,78 @@ Status: sites cover `&&`, `||`, `and`, `or`, the ternary `?:`,
|
|
|
12
12
|
with a subject, and the block methods `any?` `all?` `none?` `find`
|
|
13
13
|
`detect` `find_index` `take_while` `select` `filter` `reject`
|
|
14
14
|
`partition` `count` `filter_map`, the writes `||=` and `&&=`, and `&.`
|
|
15
|
-
safe-navigation chains. Method paths cover
|
|
15
|
+
safe-navigation chains. Method paths cover every site at a method's
|
|
16
|
+
top level.
|
|
16
17
|
More decisions hidden inside calls come next (see Roadmap).
|
|
17
18
|
|
|
18
19
|
Demo: https://cyber-dojo.github.io/path_coverage/ shows the HTML report
|
|
19
20
|
for the mock source tree in `demo/`. `make demo` builds and opens the
|
|
20
21
|
same report locally.
|
|
21
22
|
|
|
22
|
-
##
|
|
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
|
|
23
28
|
|
|
24
29
|
```ruby
|
|
25
|
-
|
|
26
|
-
require 'simplecov'
|
|
27
|
-
require 'path_coverage'
|
|
28
|
-
SimpleCov.start do
|
|
29
|
-
# ...
|
|
30
|
-
end
|
|
31
|
-
PathCoverage.start do
|
|
32
|
-
root APP_DIR # cover globs and site names are relative to it
|
|
33
|
-
cover 'source/**/*.rb' # each matching file is instrumented as it loads
|
|
34
|
-
cover 'test/**/*.rb' # more than one cover glob may be given
|
|
35
|
-
skip 'source/vendor/**/*.rb' # except these, though a cover glob matches them
|
|
36
|
-
coverage_dir '/tmp/coverage' # where path_coverage.json is written
|
|
37
|
-
measure :decisions, :methods # :decisions alone unless :methods is named
|
|
38
|
-
report :gaps, :html # the reporters run at exit (default :gaps);
|
|
39
|
-
# also :summary and :post
|
|
40
|
-
group 'code', 'source/**/*.rb' # each group a tab of its own on index.html
|
|
41
|
-
group 'test', 'test/**/*.rb'
|
|
42
|
-
ignore '&&=' # operators whose sites are not measured
|
|
43
|
-
treat 'name', as: :present # a call to name is never nil
|
|
44
|
-
treat 'any?', as: :nonempty # any? is true when its receiver has items
|
|
45
|
-
end
|
|
30
|
+
name.size > 2 && name.ascii_only?
|
|
46
31
|
```
|
|
47
32
|
|
|
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.
|
|
48
43
|
|
|
49
44
|
## Reading the HTML
|
|
50
45
|
|
|
51
|
-
Clicking a line
|
|
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.
|
|
52
51
|
|
|
53
|
-
|
|
54
|
-
- on the left is
|
|
55
|
-
- on the right is one column for each possible path through
|
|
56
|
-
-
|
|
57
|
-
|
|
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.
|
|
58
59
|
|
|
59
|
-
### Boolean: `T` `F`
|
|
60
|
+
### Boolean: `T` `F`
|
|
60
61
|
|
|
61
|
-
|
|
62
|
+
Many parts of a site, such as `name.size > 2`, are true or false.
|
|
63
|
+
|
|
64
|
+

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

|
|
72
77
|
|
|
73
|
-
- "blank" the expression is never evaluated.
|
|
78
|
+
- "blank" the expression is never evaluated.
|
|
74
79
|
|
|
75
80
|
In the second column `dee` was `T`, so because of `||`'s short-circuiting, `dum` is never evaluated.
|
|
76
81
|
|
|
77
82
|
### Taken: `✓`
|
|
78
83
|
|
|
79
|
-
|
|
84
|
+
An `if` takes one of its arms.
|
|
85
|
+
|
|
86
|
+

|
|
80
87
|
|
|
81
88
|
- `✓` marks the column whose path took that "arm"
|
|
82
89
|
|
|
@@ -86,7 +93,9 @@ second, `paid` true, took `then`.
|
|
|
86
93
|
|
|
87
94
|
### Navigation: `∅` `●`
|
|
88
95
|
|
|
89
|
-
|
|
96
|
+
`&.` skips the rest of its chain when its receiver is nil.
|
|
97
|
+
|
|
98
|
+

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

|
|
100
111
|
|
|
101
112
|
- `0` the block was called with no items.
|
|
102
113
|
- `1` the block was called with one item.
|
|
@@ -108,7 +119,9 @@ the block was called with two or more items and every answer was
|
|
|
108
119
|
|
|
109
120
|
### Both: `TF`
|
|
110
121
|
|
|
111
|
-
|
|
122
|
+
A block's answers can differ from item to item.
|
|
123
|
+
|
|
124
|
+

|
|
112
125
|
|
|
113
126
|
- `T` every answer of the block was true.
|
|
114
127
|
- `F` every answer of the block was false.
|
|
@@ -122,9 +135,34 @@ the block was called with two or more items and every answer was
|
|
|
122
135
|
|
|
123
136
|
Ruby code can be very compact so short expressions can generate lots of paths!
|
|
124
137
|
|
|
125
|
-

|
|
126
139
|
|
|
127
140
|
|
|
141
|
+
## Getting started
|
|
142
|
+
|
|
143
|
+
```ruby
|
|
144
|
+
# test coverage config, before any application code is required
|
|
145
|
+
require 'simplecov'
|
|
146
|
+
require 'path_coverage'
|
|
147
|
+
SimpleCov.start do
|
|
148
|
+
# ...
|
|
149
|
+
end
|
|
150
|
+
PathCoverage.start do
|
|
151
|
+
root APP_DIR # cover globs and site names are relative to it
|
|
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
|
|
155
|
+
coverage_dir '/tmp/coverage' # where path_coverage.json is written
|
|
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
|
|
163
|
+
end
|
|
164
|
+
```
|
|
165
|
+
|
|
128
166
|
## Use when you cannot edit the code!
|
|
129
167
|
|
|
130
168
|
A run whose code cannot be changed, such as a script in a `docker build`
|
|
@@ -171,10 +209,10 @@ As the process exits:
|
|
|
171
209
|
|
|
172
210
|
- `path_coverage.json` is always written to `coverage_dir`: every site
|
|
173
211
|
of every covered file, with each operand's true and false counts under
|
|
174
|
-
`sites`, each site's paths under `paths`, each method's
|
|
175
|
-
|
|
212
|
+
`sites`, each site's paths under `paths`, each method's card under
|
|
213
|
+
`cards`, the statements reached under `reached`, and the paths taken
|
|
176
214
|
of all possible under `totals`, as [taken, possible]: `decisions`,
|
|
177
|
-
`methods
|
|
215
|
+
`methods`, and, with groups, each group's
|
|
178
216
|
own under `groups`, eg `"groups": {"code": {"decisions": [481, 567]}}`.
|
|
179
217
|
It also names the kinds of site measured under `kinds`, any `ignored`
|
|
180
218
|
operators and `treats`, and any paths taken that a treatment rules
|
|
@@ -188,21 +226,16 @@ As the process exits:
|
|
|
188
226
|
every run left. A report whose kinds, `ignored` or `treats` differ
|
|
189
227
|
from `config`'s is refused, as its sites list their paths
|
|
190
228
|
differently.
|
|
191
|
-
- `:gaps` prints one line per path never taken, in manifest
|
|
192
|
-
|
|
193
|
-
of each decision on it, by line:
|
|
229
|
+
- `:gaps` prints one line per site path never taken, in manifest
|
|
230
|
+
order, naming the outcome of each leaf on it:
|
|
194
231
|
|
|
195
232
|
```text
|
|
196
233
|
source/kata.rb:3:23 path never taken: `ok?(id)` true, `new?(id)` false
|
|
197
234
|
source/kata.rb:4:24 never reached
|
|
198
|
-
source/fee.rb:2:2 fee path never taken: line 4 true, line 7 false
|
|
199
235
|
```
|
|
200
236
|
|
|
201
237
|
### Decisions
|
|
202
238
|
|
|
203
|
-
The paths within each decision are always measured, whatever `measure`
|
|
204
|
-
names.
|
|
205
|
-
|
|
206
239
|
A site is named by the `path:line:column` where it starts, the path
|
|
207
240
|
relative to `root`. A site in a covered file the run never loaded is
|
|
208
241
|
still reported, as `never reached`.
|
|
@@ -308,51 +341,35 @@ cannot be closed is the lesser error than hiding one that can.
|
|
|
308
341
|
|
|
309
342
|
### Methods
|
|
310
343
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
site's columns stay its own leaves' combinations, and a method's its own
|
|
317
|
-
decisions', rather than multiplying together. A decision whose arm always
|
|
318
|
-
leaves the method ends the path there.
|
|
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.
|
|
319
349
|
|
|
320
|
-
The JSON report's `
|
|
321
|
-
their counts, so a later render, or several runs' reports merged, still
|
|
322
|
-
shows them. A report with none, eg from a run that did not measure
|
|
323
|
-
`:methods`, renders as no method path taken:
|
|
350
|
+
The JSON report's `cards` hold each card's rows:
|
|
324
351
|
|
|
325
352
|
```json
|
|
326
|
-
"
|
|
327
|
-
"
|
|
328
|
-
|
|
329
|
-
|
|
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
|
+
}
|
|
330
362
|
}
|
|
331
363
|
```
|
|
332
364
|
|
|
333
365
|
### Reporters
|
|
334
366
|
|
|
335
|
-
- `:html` writes `index.html` to `coverage_dir`:
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
source. On a line holding a site the line number is a button (blue
|
|
342
|
-
and outlined when every outcome was seen, solid orange when any is
|
|
343
|
-
missing) that opens a grid of the site's paths, on the left. Its rows
|
|
344
|
-
are the site's tree: its operators, nested as Ruby groups them, a
|
|
345
|
-
ternary's arms marked `?` and `:`, an `if`'s named `then` and `else`,
|
|
346
|
-
and its leaves. Its columns are the site's paths, never taken first,
|
|
347
|
-
each headed by its count, orange when zero; a leaf shows its outcome on
|
|
348
|
-
each path, T or F, blank where the path never reached it, and a plain
|
|
349
|
-
arm a dot on each path that took it. A site written over several lines
|
|
350
|
-
has one button over all of its line numbers. Grids with gaps start
|
|
351
|
-
open. A header that stays at the top of the page lists every site as a
|
|
352
|
-
link to its line, covered sites first, then those with gaps, and arrows
|
|
353
|
-
beside each site with gaps jump to the previous and next one, wrapping
|
|
354
|
-
round at either end. Measuring paths, each method's grid of its
|
|
355
|
-
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.
|
|
356
373
|
- `:post` sends the JSON report, as an HTTP POST, to the url set by
|
|
357
374
|
`collector 'http://...'`. It is for a run whose own files are thrown
|
|
358
375
|
away, such as a failing `docker build` step. It prints nothing, never
|
|
@@ -360,7 +377,7 @@ shows them. A report with none, eg from a run that did not measure
|
|
|
360
377
|
that cannot be reached or does not answer within a second, so the
|
|
361
378
|
run's output and exit status are unchanged.
|
|
362
379
|
- `:summary` prints each total as SimpleCov prints its line and branch
|
|
363
|
-
coverage
|
|
380
|
+
coverage:
|
|
364
381
|
|
|
365
382
|
```text
|
|
366
383
|
Path coverage within decisions: 527 / 631 (83.52%)
|
|
@@ -396,9 +413,8 @@ PathCoverage.leave(PathCoverage.enter("k.rb:2:2", 2), PathCoverage.record("k.rb:
|
|
|
396
413
|
|
|
397
414
|
An `if` site's leave call wraps its predicate alone, as its path is
|
|
398
415
|
decided there, so an arm that returns or raises still counts it.
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
calls.
|
|
416
|
+
Each statement that is no site gets a reach call before it, counting
|
|
417
|
+
its run, for its card's row.
|
|
402
418
|
|
|
403
419
|
A command call such as `ok? id` (after `and`) is not valid as a bare
|
|
404
420
|
argument, so that leaf alone gets parentheses of its own, and so does a
|
|
@@ -521,8 +537,8 @@ test:
|
|
|
521
537
|
Branch coverage: 43 / 43 (100.00%)
|
|
522
538
|
Path coverage within decisions: 65 / 84 (77.38%)
|
|
523
539
|
Path coverage within methods: 3 / 3 (100.00%)
|
|
524
|
-
|
|
525
|
-
|
|
540
|
+
SimpleCov report: .../reports/index.html
|
|
541
|
+
PathCov report: .../reports/paths/index.html
|
|
526
542
|
coverage: ALLOWED
|
|
527
543
|
```
|
|
528
544
|
|
|
@@ -539,24 +555,7 @@ for `lib/` are the same with it as without.
|
|
|
539
555
|
Pages workflow (`.github/workflows/pages.yml`) runs the same script on
|
|
540
556
|
each push to `main` and publishes `site/`.
|
|
541
557
|
|
|
542
|
-
`bin/
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
## Within each decision
|
|
548
|
-
|
|
549
|
-
The first `if` can go three ways: member and paid, member and not
|
|
550
|
-
paid, not a member. A member who has not paid may never have been
|
|
551
|
-
tried.
|
|
552
|
-
|
|
553
|
-

|
|
555
|
-
|
|
556
|
-
## Within each method
|
|
557
|
-
|
|
558
|
-
The two `if`s can go four ways together. A paying member with a small
|
|
559
|
-
order may never have been tried.
|
|
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.
|
|
560
561
|
|
|
561
|
-

|
data/lib/path_coverage/calls.rb
CHANGED
|
@@ -91,16 +91,9 @@ module PathCoverage
|
|
|
91
91
|
@recorder.chained(site, index, first, value)
|
|
92
92
|
end
|
|
93
93
|
|
|
94
|
-
# The call rewritten code makes
|
|
95
|
-
#
|
|
96
|
-
def self.
|
|
97
|
-
@recorder.
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
# The call rewritten code makes around each decision's
|
|
101
|
-
# predicate, with exits for one whose arm leaves the method;
|
|
102
|
-
# returns value unchanged.
|
|
103
|
-
def self.decide(path, index, value, exits = nil)
|
|
104
|
-
@recorder.decide(path, index, value, exits)
|
|
94
|
+
# The call rewritten code makes before each statement that is
|
|
95
|
+
# no site, counting its run.
|
|
96
|
+
def self.reach(name)
|
|
97
|
+
@recorder.reach(name)
|
|
105
98
|
end
|
|
106
99
|
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module PathCoverage
|
|
2
|
+
# One card of a file's page, as the page lays out the code
|
|
3
|
+
# around it: its first and last lines, its def's column, its
|
|
4
|
+
# status, gaps or covered, whether it is a top card, of sites
|
|
5
|
+
# outside every def, how many sites a top card holds, its
|
|
6
|
+
# button showing that count, nil for a method's, and its HTML.
|
|
7
|
+
Card = Data.define(:first, :last, :column, :status, :top, :sites,
|
|
8
|
+
:html) do
|
|
9
|
+
# True when line is one of the card's lines.
|
|
10
|
+
def holds?(line)
|
|
11
|
+
(first..last).cover?(line)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -110,10 +110,17 @@ module PathCoverage
|
|
|
110
110
|
operands.flat_map do |operand|
|
|
111
111
|
case operand
|
|
112
112
|
when Condition then operand.leaves
|
|
113
|
-
when Arm then operand
|
|
113
|
+
when Arm then arm_leaves(operand)
|
|
114
114
|
else [operand]
|
|
115
115
|
end
|
|
116
116
|
end
|
|
117
117
|
end
|
|
118
|
+
|
|
119
|
+
# The leaves of arm's body, none for an arm whose body is no
|
|
120
|
+
# condition.
|
|
121
|
+
def arm_leaves(arm)
|
|
122
|
+
body = arm.body
|
|
123
|
+
body ? body.leaves : []
|
|
124
|
+
end
|
|
118
125
|
end
|
|
119
126
|
end
|
|
@@ -10,11 +10,10 @@ module PathCoverage
|
|
|
10
10
|
|
|
11
11
|
GLOB_FLAGS = File::FNM_PATHNAME | File::FNM_EXTGLOB
|
|
12
12
|
SETTINGS = %w[
|
|
13
|
-
collector cover coverage_dir group ignore
|
|
13
|
+
collector cover coverage_dir group ignore report root
|
|
14
14
|
skip treat
|
|
15
15
|
].freeze
|
|
16
16
|
REPORTERS = %w[gaps html post summary].freeze
|
|
17
|
-
MEASURES = %w[decisions methods].freeze
|
|
18
17
|
|
|
19
18
|
# Evaluates the settings block against a new configuration.
|
|
20
19
|
def initialize(&)
|
|
@@ -22,7 +21,6 @@ module PathCoverage
|
|
|
22
21
|
@skips = []
|
|
23
22
|
@groups = {}
|
|
24
23
|
@reporters = [:gaps]
|
|
25
|
-
@measures = [:decisions]
|
|
26
24
|
@ignored = []
|
|
27
25
|
@treats = []
|
|
28
26
|
instance_eval(&)
|
|
@@ -31,20 +29,6 @@ module PathCoverage
|
|
|
31
29
|
# The reporters chosen with report, :gaps when none were.
|
|
32
30
|
attr_reader :reporters
|
|
33
31
|
|
|
34
|
-
# What is measured, chosen with measure.
|
|
35
|
-
# :decisions, the paths within each decision, when nothing
|
|
36
|
-
# was chosen.
|
|
37
|
-
attr_reader :measures
|
|
38
|
-
|
|
39
|
-
# Chooses what is measured.
|
|
40
|
-
# Eg measure :decisions, :methods also measures the paths
|
|
41
|
-
# within each method, through its decisions.
|
|
42
|
-
# Refuses a name there is no measure for.
|
|
43
|
-
def measure(*names)
|
|
44
|
-
check('measure', names, MEASURES)
|
|
45
|
-
@measures = names.map(&:to_sym)
|
|
46
|
-
end
|
|
47
|
-
|
|
48
32
|
# The dir the reports are written to.
|
|
49
33
|
def output_dir
|
|
50
34
|
@coverage_dir
|
|
@@ -49,8 +49,10 @@ module PathCoverage
|
|
|
49
49
|
# each only when set: runs whose fingerprints differ list
|
|
50
50
|
# their sites' paths differently.
|
|
51
51
|
def fingerprint
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
print = {}
|
|
53
|
+
print['ignored'] = @ignored unless @ignored.empty?
|
|
54
|
+
print['treats'] = @treats unless @treats.empty?
|
|
55
|
+
print
|
|
54
56
|
end
|
|
55
57
|
end
|
|
56
58
|
end
|
|
@@ -8,36 +8,34 @@ module PathCoverage
|
|
|
8
8
|
# groups configured each group is a heading, its own totals
|
|
9
9
|
# indented under it, and there is no total over every group.
|
|
10
10
|
module ConsoleSummary
|
|
11
|
-
# The summary lines of site_paths and, when
|
|
12
|
-
#
|
|
13
|
-
# is { name =>
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
end
|
|
11
|
+
# The summary lines of site_paths and, when cards, { def
|
|
12
|
+
# site => [taken, size] }, are given, as they are when
|
|
13
|
+
# methods are measured, of cards; groups is { name =>
|
|
14
|
+
# [glob, ...] }.
|
|
15
|
+
def self.lines(site_paths, cards, groups = {})
|
|
16
|
+
return totals_lines(totals(site_paths, cards)) if groups.empty?
|
|
18
17
|
|
|
19
|
-
all = group_totals(site_paths,
|
|
18
|
+
all = group_totals(site_paths, cards, groups)
|
|
20
19
|
all.flat_map do |name, totals|
|
|
21
20
|
["#{name}:", *totals_lines(totals).map { |line| " #{line}" }]
|
|
22
21
|
end
|
|
23
22
|
end
|
|
24
23
|
|
|
25
24
|
# { 'decisions' => [taken, possible] } of site_paths, with
|
|
26
|
-
# 'methods' => [taken, possible] of
|
|
27
|
-
|
|
28
|
-
def self.totals(site_paths, methods, paths)
|
|
25
|
+
# 'methods' => [taken, possible] of cards when given.
|
|
26
|
+
def self.totals(site_paths, cards)
|
|
29
27
|
totals = { 'decisions' => Totals.decisions(site_paths) }
|
|
30
|
-
return totals if
|
|
28
|
+
return totals if cards.nil?
|
|
31
29
|
|
|
32
|
-
totals.merge('methods' => Totals.methods(
|
|
30
|
+
totals.merge('methods' => Totals.methods(cards))
|
|
33
31
|
end
|
|
34
32
|
|
|
35
33
|
# { group name => totals } of each group's own sites and
|
|
36
|
-
#
|
|
37
|
-
def self.group_totals(site_paths,
|
|
34
|
+
# cards alone.
|
|
35
|
+
def self.group_totals(site_paths, cards, groups)
|
|
38
36
|
groups.to_h do |name, globs|
|
|
39
|
-
|
|
40
|
-
[name, totals(
|
|
37
|
+
own_cards = cards ? own(cards, globs) : nil
|
|
38
|
+
[name, totals(own(site_paths, globs), own_cards)]
|
|
41
39
|
end
|
|
42
40
|
end
|
|
43
41
|
|
data/lib/path_coverage/gaps.rb
CHANGED
|
@@ -6,12 +6,11 @@ module PathCoverage
|
|
|
6
6
|
module Gaps
|
|
7
7
|
# The gap lines of operands, paths and outside, as Result
|
|
8
8
|
# gives them, in manifest order; texts is { site => each
|
|
9
|
-
# leaf's source text }.
|
|
9
|
+
# leaf's source text }. A site's first leaf runs before any
|
|
10
|
+
# other, so a site whose first never ran was never reached.
|
|
10
11
|
def self.lines(operands, paths: {}, texts: {}, outside: {})
|
|
11
12
|
operands.flat_map do |site, counts|
|
|
12
|
-
|
|
13
|
-
next ["#{site} never reached"]
|
|
14
|
-
end
|
|
13
|
+
next ["#{site} never reached"] if never_ran?(counts.first)
|
|
15
14
|
|
|
16
15
|
path_gaps(site, paths.fetch(site, []), texts[site]) +
|
|
17
16
|
ruled_out(site, outside.fetch(site, {}), texts[site])
|
|
@@ -29,10 +28,11 @@ module PathCoverage
|
|
|
29
28
|
end
|
|
30
29
|
|
|
31
30
|
# The outcome of each leaf path reaches, each named by its
|
|
32
|
-
# text, eg "`u.name` nil".
|
|
31
|
+
# text, eg "`u.name` nil". A path's first leaf always has an
|
|
32
|
+
# outcome, so it always has a step.
|
|
33
33
|
def self.steps(path, texts)
|
|
34
|
-
path.zip(texts).
|
|
35
|
-
"#{code(text)} #{outcome}" unless outcome.nil?
|
|
34
|
+
path.zip(texts).each_with_object([]) do |(outcome, text), all|
|
|
35
|
+
all << "#{code(text)} #{outcome}" unless outcome.nil?
|
|
36
36
|
end.join(', ')
|
|
37
37
|
end
|
|
38
38
|
|
|
@@ -40,8 +40,11 @@ module PathCoverage
|
|
|
40
40
|
# them, naming the outcome of each leaf the path reaches,
|
|
41
41
|
# texts being each leaf's source text.
|
|
42
42
|
def self.path_gaps(site, paths, texts)
|
|
43
|
-
paths.
|
|
44
|
-
|
|
43
|
+
paths.each_with_object([]) do |each, lines|
|
|
44
|
+
next unless each[:count].zero?
|
|
45
|
+
|
|
46
|
+
named = steps(each[:path], texts)
|
|
47
|
+
lines << "#{site} path never taken: #{named}"
|
|
45
48
|
end
|
|
46
49
|
end
|
|
47
50
|
|
|
@@ -13,15 +13,15 @@
|
|
|
13
13
|
<body>
|
|
14
14
|
<main class="page">
|
|
15
15
|
<header class="head" data-head="">
|
|
16
|
-
<p class="
|
|
17
|
-
<h1 class="path">{{path}}</h1>
|
|
16
|
+
<div class="top"><p class="title"><a data-index="" href="{{index}}">Path coverage</a></p><h1 class="path"><a data-row="" href="{{index}}#row-{{path}}">{{path}}</a></h1><button type="button" class="theme" aria-label="Light or dark"></button></div>
|
|
18
17
|
{{jumps}}
|
|
19
18
|
</header>
|
|
20
19
|
<div class="box">
|
|
21
|
-
|
|
20
|
+
<div class="rail">
|
|
21
|
+
{{rail}}
|
|
22
22
|
</div>
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
{{listing}}
|
|
24
|
+
<div class="divider" role="separator" aria-orientation="vertical" title="Drag to share the width between paths and code"></div>
|
|
25
25
|
</div>
|
|
26
26
|
</main>
|
|
27
27
|
<script>
|
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
</head>
|
|
13
13
|
<body>
|
|
14
14
|
<main class="page">
|
|
15
|
-
<
|
|
15
|
+
<header class="head" data-head="">
|
|
16
|
+
<div class="top"><h1 class="title">Path coverage</h1><button type="button" class="theme" aria-label="Light or dark"></button></div>
|
|
17
|
+
</header>
|
|
16
18
|
{{tabs}}
|
|
17
19
|
<div class="box">
|
|
18
20
|
{{tables}}
|