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.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +112 -113
  3. data/lib/path_coverage/calls.rb +4 -11
  4. data/lib/path_coverage/card.rb +14 -0
  5. data/lib/path_coverage/condition.rb +8 -1
  6. data/lib/path_coverage/configuration.rb +1 -17
  7. data/lib/path_coverage/configuration_paths.rb +4 -2
  8. data/lib/path_coverage/console_summary.rb +15 -17
  9. data/lib/path_coverage/gaps.rb +12 -9
  10. data/lib/path_coverage/html/file.html +5 -5
  11. data/lib/path_coverage/html/index.html +3 -1
  12. data/lib/path_coverage/html/settings.js +50 -0
  13. data/lib/path_coverage/html/side.js +341 -432
  14. data/lib/path_coverage/html/style.css +330 -225
  15. data/lib/path_coverage/html/theme.js +27 -0
  16. data/lib/path_coverage/html_branch.rb +30 -0
  17. data/lib/path_coverage/html_cards.rb +111 -0
  18. data/lib/path_coverage/html_cells.rb +66 -0
  19. data/lib/path_coverage/html_file.rb +82 -68
  20. data/lib/path_coverage/html_index.rb +28 -29
  21. data/lib/path_coverage/html_index_head.rb +10 -30
  22. data/lib/path_coverage/html_labels.rb +23 -0
  23. data/lib/path_coverage/html_methods.rb +66 -0
  24. data/lib/path_coverage/html_nav.rb +50 -50
  25. data/lib/path_coverage/html_report.rb +45 -49
  26. data/lib/path_coverage/html_statements.rb +166 -0
  27. data/lib/path_coverage/html_syntax.rb +156 -0
  28. data/lib/path_coverage/html_template.rb +6 -0
  29. data/lib/path_coverage/html_tree.rb +36 -72
  30. data/lib/path_coverage/json_reader.rb +21 -14
  31. data/lib/path_coverage/json_writer.rb +26 -13
  32. data/lib/path_coverage/kernel.rb +29 -49
  33. data/lib/path_coverage/kinds/block.rb +2 -1
  34. data/lib/path_coverage/kinds/case.rb +7 -4
  35. data/lib/path_coverage/kinds/contains.rb +6 -4
  36. data/lib/path_coverage/kinds/safe.rb +5 -3
  37. data/lib/path_coverage/manifest.rb +2 -1
  38. data/lib/path_coverage/manifest_blocks.rb +3 -4
  39. data/lib/path_coverage/manifest_case.rb +2 -3
  40. data/lib/path_coverage/manifest_choices.rb +4 -3
  41. data/lib/path_coverage/manifest_folding.rb +1 -1
  42. data/lib/path_coverage/merge.rb +3 -3
  43. data/lib/path_coverage/method_statements.rb +300 -0
  44. data/lib/path_coverage/recorder.rb +12 -31
  45. data/lib/path_coverage/render.rb +19 -22
  46. data/lib/path_coverage/rewriter.rb +36 -55
  47. data/lib/path_coverage/site_tree.rb +9 -0
  48. data/lib/path_coverage/statement_arms.rb +161 -0
  49. data/lib/path_coverage/summary.rb +11 -15
  50. data/lib/path_coverage/totals.rb +6 -12
  51. data/lib/path_coverage/version.rb +1 -1
  52. data/lib/path_coverage/within_methods.rb +92 -0
  53. metadata +16 -11
  54. data/lib/path_coverage/html/toggle.js +0 -12
  55. data/lib/path_coverage/html_paths.rb +0 -138
  56. data/lib/path_coverage/path_gaps.rb +0 -41
  57. data/lib/path_coverage/path_manifest.rb +0 -110
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c68ba875b18ba000eb6be70f5c7bcb294ab4d50915868b913825c3f53bc60a93
4
- data.tar.gz: 2beaba1e32cd4110ff9d04d3ab06e8c689395748566502a092175d8a339c9a5d
3
+ metadata.gz: fa9b979dc64b90e8ab047df2074c999067a5992bf62067c1e2975921a95a635b
4
+ data.tar.gz: 540e4226258cdcff171e560defc1ade28089a9901c2ed0578758cbc0e56484ba
5
5
  SHA512:
6
- metadata.gz: 6539c5ce97bd892ee616d0b1f780c79f18624381a404d3e6d2c60f6245957243b5ac7c395e130496fbbb2ba0ac6d69b4e9daf8e4fd235cb124d184aa3f8e5ad2
7
- data.tar.gz: f72f62b796ad07d0290f56a88bc920ef1088b81abc04c6667ae1ee612e97499cc2f40ca6689acb1e8df35ebff607b463e8ec5ef271de11227bcf01017e98bb42
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 `if` decisions.
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
- ## Getting started
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
- # test coverage config, before any application code is required
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 number on a file's HTML page opens that line's popout.
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
- Each popout has two sections:
54
- - on the left is a hierarchical representation of the code fragment.
55
- - on the right is one column for each possible path through that fragment.
56
- - at the top of the column is the count of that path. Look for zeros!
57
- - the symbols in the column align with their fragment and are explained below.
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
- ![A file's page: line 2, name.size > 2 && name.ascii_only?, its button pressed, its popout open beside it](docs/example-outcome.png)
62
+ Many parts of a site, such as `name.size > 2`, are true or false.
63
+
64
+ ![A file's page: line 2, name.size > 2 && name.ascii_only?, its card open to its left](docs/example-outcome.png)
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
- ![A file's page: line 2, @x = dee || dum, its button pressed, its popout open beside it](docs/example-unreachable.png)
76
+ ![A file's page: line 2, @x = dee || dum, its card open to its left](docs/example-unreachable.png)
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
- ![A file's page: line 2, if paid, its button pressed, its popout open beside it](docs/example-taken.png)
84
+ An `if` takes one of its arms.
85
+
86
+ ![A file's page: line 2, if paid, its card open to its left](docs/example-taken.png)
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
- ![A file's page: line 2, user&.account&.owner, its button pressed, its popout open beside it](docs/example-nil.png)
96
+ `&.` skips the rest of its chain when its receiver is nil.
97
+
98
+ ![A file's page: line 2, user&.account&.owner, its card open to its left](docs/example-nil.png)
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
- ![A file's page: line 2, ids.any? { |id| id.odd? }, its button pressed, its popout open beside it](docs/example-count.png)
108
+ A block method can call its block on any number of items.
109
+
110
+ ![A file's page: line 2, ids.any? { |id| id.odd? }, its card open to its left](docs/example-count.png)
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
- ![A file's page: line 2, ids.select { |id| id.odd? }, its button pressed, its popout open beside it](docs/example-both.png)
122
+ A block's answers can differ from item to item.
123
+
124
+ ![A file's page: line 2, ids.select { |id| id.odd? }, its card open to its left](docs/example-both.png)
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
- ![A file's page: line 2, if user&.admin? && ids.select { |id| id.odd? }.any?, its button pressed, its popout open beside it](docs/example-overview.png)
138
+ ![A file's page: line 2, if user&.admin? && ids.select { |id| id.odd? }.any?, its card open to its left](docs/example-overview.png)
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 paths taken
175
- under `method_paths` when `:methods` is measured, and the paths taken
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` when `:methods` is measured, and, with groups, each group's
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 order: a
192
- site's naming the outcome of each leaf on it, a method's the outcome
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
- With `measure :decisions, :methods`, each method with two or more
312
- decisions also counts each call's path through them: the outcome of each
313
- decision it reached, in order. A method is named by the `path:line:column`
314
- of its `def`, then its name. Each decision is one outcome on the path,
315
- however many leaves its predicate has; those are its site's to show. So a
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 `method_paths` lists each method's paths taken, with
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
- "method_paths": {
327
- "source/fee.rb:2:2": [
328
- { "path": [true, false], "count": 1 }
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`: the covered files with
336
- their sites and their paths taken of all possible, within each decision
337
- and, when `:methods` is measured, within each method (eg
338
- `9 / 28 (32%)`, or `-` for a file with no method of two or more
339
- decisions), each column sortable, and a Total row for every file
340
- together. Each file name opens `files/<path>.html`, the file's
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, the methods line only when `:methods` is measured:
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
- Measuring paths, each method starts a path at its entry, and each
400
- decision's predicate is wrapped in a decide call too, outside its site's
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
- Coverage report: .../reports/index.html
525
- Path coverage report: .../reports/paths/index.html
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/capture_readme_images.sh` rebuilds the demo and saves this README's
543
- two screenshots, `docs/decision.png` and `docs/method.png`, from it with
544
- headless Chrome. Run it again whenever the report's look changes.
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
- ![The first if's grid: a column per way it can go, each headed by
554
- its count, the member who has not paid at 0](docs/decision.png)
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
- ![fee's grid: a column per way its two ifs can go together, each
562
- headed by its count, true then false at 0 and selected](docs/method.png)
@@ -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 as a call reaches its
95
- # method's first decision; returns the call's new path.
96
- def self.path(site, size)
97
- @recorder.path(site, size)
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.body&.leaves || []
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 measure report root
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
- all = { 'ignored' => @ignored, 'treats' => @treats }
53
- all.reject { |_, setting| setting.empty? }
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 paths are given,
12
- # as they are when methods are measured, of methods; groups
13
- # is { name => [glob, ...] }.
14
- def self.lines(site_paths, methods, paths, groups = {})
15
- if groups.empty?
16
- return totals_lines(totals(site_paths, methods, paths))
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, methods, paths, groups)
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 methods when paths are
27
- # given.
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 paths.nil?
28
+ return totals if cards.nil?
31
29
 
32
- totals.merge('methods' => Totals.methods(methods, paths))
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
- # methods alone.
37
- def self.group_totals(site_paths, methods, paths, groups)
34
+ # cards alone.
35
+ def self.group_totals(site_paths, cards, groups)
38
36
  groups.to_h do |name, globs|
39
- own_sites = own(site_paths, globs)
40
- [name, totals(own_sites, own(methods, globs), paths)]
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
 
@@ -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
- if counts.all? { |each| never_ran?(each) }
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).filter_map do |outcome, text|
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.select { |each| each[:count].zero? }.map do |each|
44
- "#{site} path never taken: #{steps(each[:path], texts)}"
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="back"><a data-index="" href="{{index}}">Path coverage</a></p>
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
- {{listing}}
20
+ <div class="rail">
21
+ {{rail}}
22
22
  </div>
23
- <div class="pathgrids" hidden="hidden">
24
- {{grids}}
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
- <h1>Path coverage</h1>
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}}