path_coverage 0.5.0 → 0.7.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 (48) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +33 -153
  3. data/lib/path_coverage/call_trace.rb +26 -5
  4. data/lib/path_coverage/calls.rb +24 -0
  5. data/lib/path_coverage/condition.rb +10 -19
  6. data/lib/path_coverage/configuration_limits.rb +1 -1
  7. data/lib/path_coverage/console_summary.rb +13 -13
  8. data/lib/path_coverage/fold_cells.rb +0 -1
  9. data/lib/path_coverage/fold_rows.rb +2 -2
  10. data/lib/path_coverage/gaps.rb +1 -1
  11. data/lib/path_coverage/json_reader.rb +3 -3
  12. data/lib/path_coverage/json_reports.rb +28 -21
  13. data/lib/path_coverage/json_writer.rb +4 -4
  14. data/lib/path_coverage/kernel.rb +41 -20
  15. data/lib/path_coverage/kinds/block.rb +37 -45
  16. data/lib/path_coverage/leaving.rb +14 -6
  17. data/lib/path_coverage/loop_forks.rb +12 -26
  18. data/lib/path_coverage/loop_nodes.rb +41 -5
  19. data/lib/path_coverage/method_loops.rb +57 -13
  20. data/lib/path_coverage/method_statements.rb +25 -12
  21. data/lib/path_coverage/method_ways.rb +49 -21
  22. data/lib/path_coverage/{card_context.rb → paths_context.rb} +16 -16
  23. data/lib/path_coverage/paths_fitting.rb +31 -0
  24. data/lib/path_coverage/paths_forks.rb +72 -0
  25. data/lib/path_coverage/{card_gaps.rb → paths_gaps.rb} +38 -26
  26. data/lib/path_coverage/paths_leaving.rb +40 -0
  27. data/lib/path_coverage/paths_rescues.rb +146 -0
  28. data/lib/path_coverage/{card_scopes.rb → paths_scopes.rb} +6 -6
  29. data/lib/path_coverage/{card_tree.rb → paths_tree.rb} +20 -16
  30. data/lib/path_coverage/{card_way_lists.rb → paths_way_lists.rb} +3 -3
  31. data/lib/path_coverage/paths_ways.rb +193 -0
  32. data/lib/path_coverage/recorder.rb +21 -4
  33. data/lib/path_coverage/recorder_blocks.rb +21 -30
  34. data/lib/path_coverage/render.rb +6 -6
  35. data/lib/path_coverage/rescue_forks.rb +174 -0
  36. data/lib/path_coverage/rewriter.rb +83 -14
  37. data/lib/path_coverage/source_report.rb +4 -4
  38. data/lib/path_coverage/stable_leaves.rb +3 -3
  39. data/lib/path_coverage/statement_arms.rb +23 -9
  40. data/lib/path_coverage/totals.rb +5 -5
  41. data/lib/path_coverage/version.rb +1 -1
  42. data/lib/path_coverage/way_algebras.rb +2 -2
  43. data/lib/path_coverage/ways_report.rb +8 -8
  44. data/lib/path_coverage/ways_totals.rb +7 -7
  45. data/lib/path_coverage/within_methods.rb +62 -62
  46. metadata +12 -8
  47. data/lib/path_coverage/card_forks.rb +0 -44
  48. data/lib/path_coverage/card_ways.rb +0 -196
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dfcf376aea729af49e8d6f48c4c2d73b14c4aeea64cea91ce202849645ad7b38
4
- data.tar.gz: 923eca731e697aacc281f150256279b60c9f1ef9e708fc5a860f2509424f8831
3
+ metadata.gz: 72f61105ee75c749617db00548e9d803bcae76919e51cac6b0a081b93eca54b4
4
+ data.tar.gz: deec7238a3260dceecdb937464246a5b0d7b502c73826a6bde0947a611713b22
5
5
  SHA512:
6
- metadata.gz: ddd032573b9bd84312589e4e34126fee5b5e1aab8041e11c2e15b8ce5ee681e466fc9abc1de2b4ecd6579f9945b61c77cbfce9c551722f9618119854bbc7ead5
7
- data.tar.gz: 312bf6551c5bbec5eb30a35002bb23ef4a87fe45c65833348747ffa75a17f5cb9a1ea2363fe5b77e011e4240fe0aa1c0b389d97b231690be18ac9e8886089437
6
+ metadata.gz: e7b265531ef2dc15e67e3554d0cae1292163dd3874333a10546822bdb62dd06ceea24ecb12bfd62dad4d32d16eb2c9b3329eddfd3d26d8d3b73e96077f81a912
7
+ data.tar.gz: d847e2497b63d34f392cd88d6b538fa3b5fc1ab92796a183e4cae55176c1edb43cf499310c31f1b4a0c8d5fbb75705c89f9153f938828c4ca7b2bd2619447357
data/README.md CHANGED
@@ -9,7 +9,6 @@ coverage.
9
9
 
10
10
  - [Overview](#overview)
11
11
  - [Getting started](#getting-started)
12
- - [Reading the HTML](#reading-the-html)
13
12
  - [Ignoring and treating](#ignoring-and-treating)
14
13
  - [Use when you cannot edit the code!](#use-when-you-cannot-edit-the-code)
15
14
  - [What a run reports](#what-a-run-reports)
@@ -70,123 +69,6 @@ PathCoverage.start do
70
69
  end
71
70
  ```
72
71
 
73
- ## Reading the HTML
74
-
75
- https://path-coverage.github.io/ruby/ shows a demo HTML report
76
- for the mock source tree in `demo/`. `make demo` builds and opens the
77
- same report locally.
78
-
79
- The HTML report, for people, is drawn from the two JSON files, by
80
- [html-reporter](https://github.com/path-coverage/html-reporter).
81
-
82
- ```sh
83
- docker run --rm -v "$PWD/coverage:/paths" ghcr.io/path-coverage/html-reporter /paths
84
- ```
85
-
86
- Clicking a `def` line on a file's HTML page opens that method's
87
- *card* to its left.
88
-
89
- A card has a row for each decision in the method, by `line:col`,
90
- with its counts of paths not taken and taken.
91
-
92
- Clicking a row's `▼` opens it:
93
- - on the left are the decision's parts, one per row: its
94
- operator, eg `&&`, then each operand it tests, nested
95
- operators indented under it.
96
- - on the right is one column for each possible path through it.
97
- - the column's head is `≀0` for a path never taken, and `≀*`
98
- for one taken (hover for its count). Look for zeros!
99
- - the symbols in a column line up with those rows, and
100
- are explained below.
101
-
102
- Hovering over code in the open card's method opens the tree holding
103
- that code, its row lit, or, for a `return` or `raise`, lights its row.
104
- A long piece of code scrolls within its row.
105
-
106
- ### Boolean: `T` `F`
107
-
108
- Many parts of a decision, such as `name.size > 2`, are true or false.
109
-
110
- ![A file's page: line 2, name.size > 2 && name.ascii_only?, its card open to its left](docs/example-outcome.png)
111
-
112
- - `T` the expression was true.
113
- - `F` the expression was false.
114
-
115
- In this example, there was no test which exercised the path where `name.size > 2` was `true`, and
116
- `name.ascii_only?` was `false`.
117
-
118
- ### Unreachable: blank
119
-
120
- Some parts of a decision are not always evaluated.
121
-
122
- ![A file's page: line 2, @x = dee || dum, its card open to its left](docs/example-unreachable.png)
123
-
124
- - "blank" the expression is never evaluated.
125
-
126
- In the second column `dee` was `T`, so because of `||`'s short-circuiting, `dum` is never evaluated.
127
-
128
- ### Taken: `✓`
129
-
130
- A `?:` takes one of its arms.
131
-
132
- ![A file's page: line 2, paid ? 'paid' : 'due', its card open to its left](docs/example-taken.png)
133
-
134
- - `✓` marks the column whose path goes to that arm
135
-
136
- The `paid` row is the `?:`'s predicate, `T` or `F`. Below it is one row
137
- per arm, `? 'paid'` and `: 'due'`. The first column, `paid` false, never
138
- taken, goes to `: 'due'`; the second, `paid` true, to `? 'paid'`.
139
-
140
- An `if`, `unless`, `case` or `||=` shows no arm rows: which arm a path
141
- takes follows from its predicate, and the code in an arm is a row of
142
- its own on the card.
143
-
144
- ### Navigation: `∅` `●`
145
-
146
- `&.` skips the rest of its chain when its receiver is nil.
147
-
148
- ![A file's page: line 2, user&.account&.owner, its card open to its left](docs/example-nil.png)
149
-
150
- - `∅` the receiver was nil, so `&.` skipped the rest of the chain.
151
- - `●` the receiver was not nil, so `&.` made the call.
152
-
153
- In this example, there was no test which exercised the path where
154
- `user` was nil.
155
-
156
- ### Count: `0` `1` `*`
157
-
158
- A block method can call its block on any number of items.
159
-
160
- ![A file's page: line 2, ids.any? { |id| id.odd? }, its card open to its left](docs/example-count.png)
161
-
162
- - `0` the block was called with no items.
163
- - `1` the block was called with one item.
164
- - `*` the block was called with two or more items.
165
-
166
- In this example, there was no test which exercised the path where
167
- the block was called with two or more items and every answer was
168
- `false`.
169
-
170
- ### Both: `TF`
171
-
172
- A block's answers can differ from item to item.
173
-
174
- ![A file's page: line 2, ids.select { |id| id.odd? }, its card open to its left](docs/example-both.png)
175
-
176
- - `T` every answer of the block was true.
177
- - `F` every answer of the block was false.
178
- - `TF` the block's answers were both true and false.
179
-
180
- In this example, there was no test which exercised the path where
181
- the block was called with two or more items and every answer was
182
- `false`.
183
-
184
- ### Lots of paths!
185
-
186
- Ruby code can be very compact so short expressions can generate lots of paths!
187
-
188
- ![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)
189
-
190
72
  ## Ignoring and treating
191
73
 
192
74
  `ignore '&&=', '||='` stops `&&=` and `||=` writes being measured.
@@ -206,7 +88,7 @@ limit a treatment to the files that glob matches.
206
88
  `filter_map`, `partition` or `take_while`, the path that call took
207
89
  often decides whether it kept any items. Paths where `any?` disagrees
208
90
  with that are not listed, eg `ids.select { |i| i.odd? }.any?` true
209
- with `ids` empty.
91
+ with every answer false.
210
92
 
211
93
  A run where a treatment turns out to be wrong is reported:
212
94
 
@@ -420,9 +302,13 @@ among its patterns, is no decision.
420
302
  A call to `any?` `all?` `none?` `find` `detect` `find_index`
421
303
  `take_while` `select` `filter` `reject` `partition` `count` or
422
304
  `filter_map`, with no arguments and a block of one expression, is a decision
423
- named at its method. Its item count is noted from the block's own calls,
424
- so the receiver is never asked its size, which could consume a sequence
425
- that can be read only once.
305
+ named at its method. Its paths are its block's answers: the last one for a
306
+ method that can stop early, eg `any?` true or false, and all true, all
307
+ false or both for one that calls its block with every item, eg `select`.
308
+ A call whose block was never called witnesses no path. How many items the
309
+ block was called with is a loop's question, asked by `loops`, so the
310
+ receiver is never asked its size, which could consume a sequence that can
311
+ be read only once.
426
312
 
427
313
  A `||=` or `&&=` write is a decision, whatever its target: a variable of any
428
314
  kind, a constant, an attribute (`self.size ||= n`) or an index
@@ -473,20 +359,28 @@ cannot be closed is the lesser error than hiding one that can.
473
359
 
474
360
  ### Methods
475
361
 
476
- Each method has a card, named by the `path:line:column` of its `def`,
477
- with a row for each statement that shapes its paths: each decision, and
478
- each `return` or `raise`, which ends a path. Any other statement, eg
362
+ Each method has a flow, named by the `path:line:column` of its `def`,
363
+ with a row for each statement that shapes its paths: each decision, each
364
+ `return` or `raise`, which ends a path, and each `next`, `break` or
365
+ `retry`, which ends a pass of its loop. Any other statement, eg
479
366
  `x = 1`, runs exactly when what holds it does, so is no row. A decision's
480
367
  row counts its paths; a `return` or `raise` row is one path, taken
481
- when it is reached. A method's total adds up its rows. Its title says
482
- how many times it was called, so a method never called is a gap,
483
- even one with no rows. A file's code outside any method gets a card
368
+ when it is reached. A method's total adds up its rows. Its `calls`
369
+ count how many times it was called, so a method never called is a gap,
370
+ even one with no rows. A file's code outside any method gets a flow
484
371
  of its own.
485
372
 
486
- The JSON report's `cards` hold each card's rows, its `ways` and its
373
+ A `begin` or `def` with `rescue` clauses forks its flow: its body
374
+ completes, or one of its rescues runs. A rescue can run after any part
375
+ of its body, as a raise can come from any call, so which exception was
376
+ raised is not tracked. A `rescue` modifier, `x rescue y`, forks the
377
+ same way, with one rescue. With `loops`, each loop forks too, a block
378
+ method's block included: 0 items, or 1+ items, its body walked once.
379
+
380
+ The JSON report's `flows` hold each flow's rows, its `ways` and its
487
381
  `calls`, and its `tree` says how those rows nest.
488
382
 
489
- A method's card counts only the paths its method can take. A
383
+ A method's flow counts only the paths its method can take. A
490
384
  local variable the method never writes, eg a parameter, read as a
491
385
  leaf outside any block, has one outcome all through a call, so
492
386
 
@@ -514,7 +408,9 @@ flip.rb:5:11 path taken that its method rules out: `member` true
514
408
 
515
409
  - `:ways` prints, for each method with a path through it that no run
516
410
  took, the choices a test must make to take each one, every leaf by its
517
- source text; a loop is named by its line and how many items it ran:
411
+ source text; a loop is named by its line and how many items it ran,
412
+ and a rescue by its line and whether its body completed or which
413
+ rescue ran:
518
414
 
519
415
  ```text
520
416
  lib/orders.rb:2 total() has 1 untested path.
@@ -569,7 +465,7 @@ PathCoverage.leave(PathCoverage.enter("k.rb:2:2", 2), PathCoverage.record("k.rb:
569
465
  An `if` decision's leave call wraps its predicate alone, as its path is
570
466
  decided there, so an arm that returns or raises still counts it.
571
467
  Each statement that is no decision gets a reach call before it, counting
572
- its run, for its card's row.
468
+ its run, for its flow's row.
573
469
 
574
470
  A command call such as `ok? id` (after `and`) is not valid as a bare
575
471
  argument, so that leaf alone gets parentheses of its own, and so does a
@@ -598,8 +494,8 @@ Decisions covered now: `&&`, `||`, `and`, `or`, the ternary `?:`,
598
494
  with a subject, and the block methods `any?` `all?` `none?` `find`
599
495
  `detect` `find_index` `take_while` `select` `filter` `reject`
600
496
  `partition` `count` `filter_map`, the writes `||=` and `&&=`, and `&.`
601
- safe-navigation chains. Method paths cover every decision at a method's
602
- top level.
497
+ safe-navigation chains. Method paths cover every decision in a method,
498
+ nested ones included, and its `rescue` clauses and modifiers.
603
499
 
604
500
  Next:
605
501
 
@@ -608,28 +504,21 @@ Next:
608
504
  with blocks of more than one expression
609
505
  - `fetch(k, default)`, `dig`, `Hash#[]` with a default: present vs default
610
506
  - `x || default` in value context: nil vs not nil
611
- - `x rescue y` modifier: raised vs not raised
612
507
  - `case` with no subject, and `case`/`in` patterns
613
508
  - regex matches: nil vs MatchData
614
509
  - `treat 'methods_of', as: :truthy`, so each call to it counts as a
615
510
  leaf that is only truthy, as `Foo.new` is, and a run where it returns
616
511
  nil or false is reported. Later, treatments could come from the
617
512
  project's RBS signatures (`sig/*.rbs`) too.
618
- - exceptions the code itself names: a `begin` or `def` with `rescue`
619
- clauses as a decision, like a `case`, whose paths are no raise and each
620
- clause that rescued, eg `rescue IOError` never taken. Branch coverage
621
- ignores `rescue`, and tests reach these paths with real input. A raise
622
- that nothing names, from any call, stays out, as every leaf would gain
623
- a third outcome that only fault injection could take.
624
513
  - an evaluation that raised part way through a decision, eg
625
514
  `ok?(id) && fetch(id)` where `fetch` raises, reported as a path that
626
515
  raised rather than dropped as unfinished.
627
516
  - complexity maximums, reported and gated, since the possible paths
628
517
  count how much there is to test, not only how much was tested. A
629
518
  file's total measures its size, so each is a maximum over smaller
630
- parts:
631
- - paths in one decision, eg 6 for a `select` block
632
- - paths through one method's decisions, eg 2 top-level ifs give 4
519
+ parts. `max_paths` already gates the paths through one method; still
520
+ to come:
521
+ - paths in one decision, eg 3 for a `select` block
633
522
  - paths within each decision, summed over every decision in one
634
523
  method, nested ones included, eg decisions of 2, 3 and 15 paths
635
524
  sum to 20. Every method has one, and it grows as the method gains
@@ -689,12 +578,3 @@ a copy of `lib/` renamed `PathCoverageSelf` (`test/self_coverage.rb`), so
689
578
  the tests start and restart `PathCoverage` as always. SimpleCov's figures
690
579
  for `lib/` are the same with it as without.
691
580
 
692
- `make demo` (not part of `make all`) runs `demo/run.rb` through
693
- `bin/build_demo.sh`, writing the report to `site/` and opening it. The
694
- Pages workflow (`.github/workflows/pages.yml`) runs the same script on
695
- each push to `main` and publishes `site/`.
696
-
697
- `bin/capture_card_images.sh` runs the examples in `demo/cards/` and
698
- saves this README's screenshots, `docs/example-*.png`, with headless
699
- Chrome. Run it again whenever the card's look changes.
700
-
@@ -13,6 +13,7 @@ module PathCoverage
13
13
  @owners = {}
14
14
  @ways = {}
15
15
  @stack_key = :"path_coverage_calls_#{object_id}"
16
+ @depths_key = :"path_coverage_depths_#{object_id}"
16
17
  end
17
18
 
18
19
  # { unit's name => { way => count } } of every way ended so
@@ -33,15 +34,28 @@ module PathCoverage
33
34
  # reaches its entry.
34
35
  def call
35
36
  stack.push(nil)
37
+ depths.push(nil)
36
38
  end
37
39
 
38
- # Notes the statement named name reached: a method's entry
39
- # starts its call's way, unless no call is under way to take
40
- # it, as when the call began before this trace did; any other
41
- # row is a step of the innermost call of the method holding it.
40
+ # Starts a call of a covered method a retry can restart, its
41
+ # frame at depth. A call at the depth of the call under way is
42
+ # that call restarting, so it starts nothing.
43
+ def restartable_call(depth)
44
+ return if depths.last == depth
45
+
46
+ stack.push(nil)
47
+ depths.push(depth)
48
+ end
49
+
50
+ # Notes the statement named name reached. A method's entry
51
+ # starts its call's way. It does not when no call is under way
52
+ # to take it, as when the call began before this trace did. Nor
53
+ # does it when the call's way has started already, as when a
54
+ # retry runs the body again. Any other row is a step of the
55
+ # innermost call of the method holding it.
42
56
  def reach(name)
43
57
  if @entries.key?(name)
44
- enter(name) unless stack.empty?
58
+ enter(name) unless stack.empty? || stack.last
45
59
  else
46
60
  innermost(@owners[name])&.step([name])
47
61
  end
@@ -61,6 +75,7 @@ module PathCoverage
61
75
 
62
76
  # Ends the innermost call under way, counting its way.
63
77
  def return
78
+ depths.pop
64
79
  stack.pop&.finish
65
80
  end
66
81
 
@@ -79,6 +94,12 @@ module PathCoverage
79
94
  Thread.current[@stack_key] ||= []
80
95
  end
81
96
 
97
+ # The frame depth of each call under way in the current thread,
98
+ # as stack holds them. It is nil for a call no retry restarts.
99
+ def depths
100
+ Thread.current[@depths_key] ||= []
101
+ end
102
+
82
103
  # The Walk of the innermost call under way of the method
83
104
  # whose entry is named entry, else nil.
84
105
  def innermost(entry)
@@ -102,4 +102,28 @@ module PathCoverage
102
102
  def self.pass(name)
103
103
  @recorder.pass(name)
104
104
  end
105
+
106
+ # The call rewritten code makes around the last statement of a
107
+ # body with a rescue. It notes that the fork named name
108
+ # completed, its body running to its end. It returns value
109
+ # unchanged.
110
+ def self.completed(name, value)
111
+ @recorder.completed(name, value)
112
+ end
113
+
114
+ # The call rewritten code makes first in the body of the rescue
115
+ # numbered number of the rescue fork named name. It notes that
116
+ # this rescue ran.
117
+ def self.rescued(name, number)
118
+ @recorder.rescued(name, number)
119
+ end
120
+
121
+ # The call rewritten code makes around the rescue of a rescue
122
+ # modifier, its rescue numbered number of the rescue fork named
123
+ # name. It notes that this rescue ran, and returns value
124
+ # unchanged.
125
+ def self.ran(name, number, value)
126
+ @recorder.rescued(name, number)
127
+ value
128
+ end
105
129
  end
@@ -34,18 +34,14 @@ module PathCoverage
34
34
  any? all? none? find detect find_index take_while
35
35
  ].freeze
36
36
 
37
- # How many items a block method's block was called with, as
38
- # its receiver's leaf outcome: none, one, or two or more.
37
+ # How many passes a loop made in a call, as a step of its
38
+ # way: none, one, or two or more.
39
39
  ITEMS = ['0 items', '1 item', '2+ items'].freeze
40
40
 
41
- # Every path a stop-early block method's call can take: how
42
- # many items its block was called with, and its last answer,
43
- # nil when it was never called.
44
- STOP_EARLY_PATHS = [
45
- [ITEMS[0], nil],
46
- [ITEMS[1], true], [ITEMS[1], false],
47
- [ITEMS[2], true], [ITEMS[2], false]
48
- ].freeze
41
+ # Every path a stop-early block method's call can take: its
42
+ # block's last answer. How many items the block was called
43
+ # with is a loop's question, so the receiver's leaf is nil.
44
+ STOP_EARLY_PATHS = [[nil, true], [nil, false]].freeze
49
45
 
50
46
  # The methods that call their block with every item.
51
47
  EVERY_ITEM = %w[
@@ -55,15 +51,10 @@ module PathCoverage
55
51
  # A block's answers over every item it was called with.
56
52
  ANSWERS = ['all true', 'all false', 'both'].freeze
57
53
 
58
- # Every path an every-item block method's call can take: how
59
- # many items its block was called with, and its answers,
60
- # which can be both only with two or more items.
61
- EVERY_ITEM_PATHS = [
62
- [ITEMS[0], nil],
63
- [ITEMS[1], ANSWERS[0]], [ITEMS[1], ANSWERS[1]],
64
- [ITEMS[2], ANSWERS[0]], [ITEMS[2], ANSWERS[1]],
65
- [ITEMS[2], ANSWERS[2]]
66
- ].freeze
54
+ # Every path an every-item block method's call can take: its
55
+ # block's answers. How many items the block was called with
56
+ # is a loop's question, so the receiver's leaf is nil.
57
+ EVERY_ITEM_PATHS = ANSWERS.map { [nil, _1] }.freeze
67
58
 
68
59
  # The block methods whose value follows from their path alone:
69
60
  # all but find and detect, whose found item may itself be nil.
@@ -1,5 +1,5 @@
1
1
  module PathCoverage
2
- # The settings of a PathCoverage.start block that limit a card's
2
+ # The settings of a PathCoverage.start block that limit a flow's
3
3
  # ways: the most paths a method may have and still be checked,
4
4
  # and whether a loop counts as a decision. It relies on its
5
5
  # includer's ConfigurationError, and sets @max_paths and @loops
@@ -8,37 +8,37 @@ 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 decision_paths and, when cards, { def
11
+ # The summary lines of decision_paths and, when flows, { def
12
12
  # decision => [taken, size] }, are given, as they are when
13
- # methods are measured, of cards; groups is { name =>
13
+ # methods are measured, of flows; groups is { name =>
14
14
  # [glob, ...] }.
15
- def self.lines(decision_paths, cards, groups = {})
15
+ def self.lines(decision_paths, flows, groups = {})
16
16
  if groups.empty?
17
17
  return totals_lines(totals(decision_paths,
18
- cards))
18
+ flows))
19
19
  end
20
20
 
21
- all = group_totals(decision_paths, cards, groups)
21
+ all = group_totals(decision_paths, flows, groups)
22
22
  all.flat_map do |name, totals|
23
23
  ["#{name}:", *totals_lines(totals).map { |line| " #{line}" }]
24
24
  end
25
25
  end
26
26
 
27
27
  # { 'alone' => [taken, possible] } of decision_paths, with
28
- # 'combined' => [taken, possible] of cards when given.
29
- def self.totals(decision_paths, cards)
28
+ # 'combined' => [taken, possible] of flows when given.
29
+ def self.totals(decision_paths, flows)
30
30
  totals = { 'alone' => Totals.alone(decision_paths) }
31
- return totals if cards.nil?
31
+ return totals if flows.nil?
32
32
 
33
- totals.merge('combined' => Totals.combined(cards))
33
+ totals.merge('combined' => Totals.combined(flows))
34
34
  end
35
35
 
36
36
  # { group name => totals } of each group's own decisions and
37
- # cards alone.
38
- def self.group_totals(decision_paths, cards, groups)
37
+ # flows alone.
38
+ def self.group_totals(decision_paths, flows, groups)
39
39
  groups.to_h do |name, globs|
40
- own_cards = cards ? own(cards, globs) : nil
41
- [name, totals(own(decision_paths, globs), own_cards)]
40
+ own_flows = flows ? own(flows, globs) : nil
41
+ [name, totals(own(decision_paths, globs), own_flows)]
42
42
  end
43
43
  end
44
44
 
@@ -13,7 +13,6 @@ module PathCoverage
13
13
  # hovering as not nil or nil.
14
14
  OUTCOMES = {
15
15
  true => ['T'], false => ['F'], nil => [''],
16
- ITEMS[0] => ['0'], ITEMS[1] => ['1'], ITEMS[2] => ['*'],
17
16
  ANSWERS[0] => ['T'], ANSWERS[1] => ['F'], ANSWERS[2] => ['TF'],
18
17
  PRESENCE[0] => ['', 'present', PRESENCE[0]],
19
18
  PRESENCE[1] => ['', 'absent', PRESENCE[1]]
@@ -6,7 +6,7 @@ require_relative 'kinds'
6
6
 
7
7
  module PathCoverage
8
8
  # The tree of a decision, from DecisionTree.of, as its row's
9
- # fold in a card shows it: a grid whose columns are the
9
+ # fold in a flow shows it: a grid whose columns are the
10
10
  # decision's paths, as page data holds its rows, each a kind,
11
11
  # a branch, a label, where its code is and a cell per path.
12
12
  module FoldRows
@@ -81,7 +81,7 @@ module PathCoverage
81
81
  FoldCells.values(arm[:cells], FoldCells::TAKEN)
82
82
  end
83
83
 
84
- # The operands of condition a card's fold shows: a ?:'s arms,
84
+ # The operands of condition a flow's fold shows: a ?:'s arms,
85
85
  # as its arms are part of its one expression; for any other,
86
86
  # eg an if, a ||= or a case, no arm, as which arm a path takes
87
87
  # follows from its leaves, but each arm's body, eg a when's
@@ -32,7 +32,7 @@ module PathCoverage
32
32
  # Example: ["k.rb:5:11 path taken that its method rules out:
33
33
  # `a` true"].
34
34
  # One line per path taken, or return or raise reached, that
35
- # its method rules out, ruled as CardContext.ruled_out gives
35
+ # its method rules out, ruled as PathsContext.ruled_out gives
36
36
  # them, texts being { decision => each leaf's source text }.
37
37
  # Such a line shows a fact derived from the code to be wrong.
38
38
  def self.ruled_by_method(ruled, texts)
@@ -51,9 +51,9 @@ module PathCoverage
51
51
  end
52
52
  end
53
53
 
54
- # True when report, a JSON report, lists its cards' ways: one a
55
- # run wrote, which names the max_paths its cards were listed
56
- # with; not one the :post reporter sent, which has no cards.
54
+ # True when report, a JSON report, lists its flows' ways: one a
55
+ # run wrote, which names the max_paths its flows were listed
56
+ # with; not one the :post reporter sent, which has no flows.
57
57
  def self.listed_ways?(report)
58
58
  report.key?('max_paths')
59
59
  end
@@ -1,6 +1,6 @@
1
1
  require 'fileutils'
2
2
  require 'json'
3
- require_relative 'card_gaps'
3
+ require_relative 'paths_gaps'
4
4
  require_relative 'console_summary'
5
5
  require_relative 'json_writer'
6
6
  require_relative 'paths_report'
@@ -27,26 +27,26 @@ module PathCoverage
27
27
  paths = taken.values_at(:decision_paths, :outside)
28
28
  recorded = Recorded.new(operands, *paths)
29
29
  reached = taken[:reached]
30
- cards = WithinMethods.listed(files, config, recorded,
30
+ flows = WithinMethods.listed(files, config, recorded,
31
31
  [reached, taken[:ways]])
32
32
  tree = WithinMethods.tree(files, config, recorded)
33
- write_json(recorded, files, config, [cards, reached, tree])
34
- write_ways(cards, files, config, tree)
35
- write_source(files, config, recorded.paths, cards)
33
+ write_json(recorded, files, config, [flows, reached, tree])
34
+ write_ways(flows, files, config, tree)
35
+ write_source(files, config, recorded.paths, flows)
36
36
  end
37
37
 
38
38
  # Writes recorded as the JSON report at config's json_path:
39
39
  # its operands, decision paths, paths a treatment rules out,
40
- # totals, cards, each def's card, as WithinMethods.listed
41
- # gives them, tree, how each card's rows nest, the statements
40
+ # totals, flows, each def's flow, as WithinMethods.listed
41
+ # gives them, tree, how each flow's rows nest, the statements
42
42
  # reached, when known, and config's fingerprint and limits.
43
43
  def self.write_json(recorded, files, config, listed)
44
- cards, reached, tree = listed
44
+ flows, reached, tree = listed
45
45
  report = PathsReport.of(recorded.paths, files)
46
46
  totals = totals(recorded.paths, files, config, reached)
47
47
  limits = { 'loops' => config.loops?,
48
48
  'max_paths' => config.path_limit }
49
- parts = { totals:, outside: recorded.outside, cards:, tree:,
49
+ parts = { totals:, outside: recorded.outside, flows:, tree:,
50
50
  fingerprint: config.fingerprint, limits: }
51
51
  parts[:reached] = reached if reached
52
52
  path = config.json_path
@@ -54,12 +54,21 @@ module PathCoverage
54
54
  end
55
55
 
56
56
  # Writes the ways lines, each method's untested paths, as
57
- # CardGaps.lines gives them for cards, beside the JSON report,
57
+ # PathsGaps.lines gives them for flows, beside the JSON report,
58
58
  # at ways_path, so a later check, or the :ways reporter, can
59
- # show them; tree is how each card's rows nest, as
59
+ # show them; tree is how each flow's rows nest, as
60
60
  # WithinMethods.tree gives it.
61
- def self.write_ways(cards, files, config, tree)
62
- parents = tree.flat_map do |path, nested|
61
+ def self.write_ways(flows, files, config, tree)
62
+ texts = PathsReport.texts(files)
63
+ lines = PathsGaps.lines(flows, texts, parents_of(tree))
64
+ File.write(ways_path(config), lines.map { "#{_1}\n" }.join)
65
+ end
66
+
67
+ # { row's decision => its parent's decision } of each row in
68
+ # tree that runs inside another row, as WithinMethods.tree
69
+ # gives it. Each decision is named path:line:column.
70
+ def self.parents_of(tree)
71
+ tree.flat_map do |path, nested|
63
72
  nested.values.flat_map do |rows|
64
73
  rows.filter_map do |at, place|
65
74
  next unless place['parent']
@@ -68,8 +77,6 @@ module PathCoverage
68
77
  end
69
78
  end
70
79
  end.to_h
71
- lines = CardGaps.lines(cards, PathsReport.texts(files), parents)
72
- File.write(ways_path(config), lines.map { "#{_1}\n" }.join)
73
80
  end
74
81
 
75
82
  # Where the ways lines go, beside the JSON report.
@@ -78,9 +85,9 @@ module PathCoverage
78
85
  end
79
86
 
80
87
  # Writes the source report beside the JSON report, from
81
- # files, decision_paths and cards, as write has them.
82
- def self.write_source(files, config, decision_paths, cards)
83
- source = SourceReport.of(files, config, decision_paths, cards)
88
+ # files, decision_paths and flows, as write has them.
89
+ def self.write_source(files, config, decision_paths, flows)
90
+ source = SourceReport.of(files, config, decision_paths, flows)
84
91
  path = config.json_path.sub(/\.json\z/, '.source.json')
85
92
  File.write(path, JSON.generate(source))
86
93
  end
@@ -89,13 +96,13 @@ module PathCoverage
89
96
  # within each decision, and within each method; with groups
90
97
  # configured, each group's own too, under groups.
91
98
  def self.totals(decision_paths, files, config, reached)
92
- cards = WithinMethods.cards(files, config, decision_paths,
99
+ flows = WithinMethods.flows(files, config, decision_paths,
93
100
  reached)
94
- totals = ConsoleSummary.totals(decision_paths, cards)
101
+ totals = ConsoleSummary.totals(decision_paths, flows)
95
102
  groups = config.groups
96
103
  return totals if groups.empty?
97
104
 
98
- own = ConsoleSummary.group_totals(decision_paths, cards, groups)
105
+ own = ConsoleSummary.group_totals(decision_paths, flows, groups)
99
106
  totals.merge('groups' => own)
100
107
  end
101
108
  end