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
@@ -9,23 +9,91 @@ module PathCoverage
9
9
  module Rewriter
10
10
  # Returns source with each operand in decisions wrapped in a
11
11
  # record call, each decision as a whole in a leave call that
12
- # enters it first, and each statement in reaches, { name =>
13
- # offset }, after a reach call that counts its runs. Only
14
- # text is inserted, never a newline, so backtrace line
15
- # numbers still match the file on disk.
16
- def self.rewrite(source, decisions, reaches = {}, passes = {})
12
+ # enters it first, then the inserts of marks, as mark_inserts
13
+ # gives them. Only text is inserted, never a newline, so
14
+ # backtrace line numbers still match the file on disk.
15
+ def self.rewrite(source, decisions, marks = {})
17
16
  inserts = decisions.flat_map do |decision, condition|
18
17
  decision_inserts(decision, condition)
19
18
  end
20
- apply(source.dup, inserts + reach_inserts(reaches) +
21
- pass_inserts(passes))
19
+ apply(source.dup, inserts + mark_inserts(marks))
22
20
  end
23
21
 
22
+ # The inserts of marks, a hash. Each key is optional, and a
23
+ # missing key marks nothing. reaches is { name => offset }:
24
+ # each statement there gets a reach call before it, counting
25
+ # its runs. passes is { name => offset }: each loop body there
26
+ # gets a pass call first. entries is { name => offset }: each
27
+ # method's entry is reached there, outermost, before any
28
+ # statement's reach at the same place. completions is { rescue
29
+ # fork's name => where }: each body completing is noted there.
30
+ # rescues is { [fork's name, number] => offset }: each rescue
31
+ # running is noted there. values is { fork's name => byte
32
+ # range }: each rescue modifier's rescue running is noted
33
+ # there.
34
+ def self.mark_inserts(marks)
35
+ reach_inserts(marks.fetch(:reaches, {})) +
36
+ pass_inserts(marks.fetch(:passes, {})) +
37
+ reach_inserts(marks.fetch(:entries, {}), :entry) +
38
+ completed_inserts(marks.fetch(:completions, {})) +
39
+ rescued_inserts(marks.fetch(:rescues, {})) +
40
+ ran_inserts(marks.fetch(:values, {}))
41
+ end
42
+
43
+ # Example: { "k.rb:3:18" => 25...26 } wraps bytes 25...26.
44
+ # The inserts that wrap the rescue of each rescue modifier in
45
+ # values, { fork's name => its byte range }, in a ran call. The
46
+ # call keeps the rescue's value, and notes that its rescue 1
47
+ # ran.
48
+ def self.ran_inserts(values)
49
+ values.flat_map do |name, range|
50
+ rank = [range.size, LAYERS.index(:completed)]
51
+ call = "PathCoverage.ran(#{name.inspect}, 1, ("
52
+ [[range.begin, call, rank], [range.end, '))', rank, :close]]
53
+ end
54
+ end
55
+
56
+ # Example: { ["k.rb:4:2", 1] => 52 } puts a rescued call at 52.
57
+ # The inserts that put a rescued call after the header of each
58
+ # rescue in rescues, { [fork's name, its number] => offset }.
59
+ # The call is a statement of its own, the first its rescue
60
+ # runs.
61
+ def self.rescued_inserts(rescues)
62
+ rank = [Float::INFINITY, LAYERS.index(:reach)]
63
+ rescues.map do |(name, number), at|
64
+ call = "; PathCoverage.rescued(#{name.inspect}, #{number})"
65
+ [at, call, rank]
66
+ end
67
+ end
68
+
69
+ # Example: { "k.rb:4:2" => 30...43 } wraps bytes 30...43.
70
+ # The inserts that note each body of completions completing.
71
+ # completions is { rescue fork's name => where }. A byte range
72
+ # is a last statement, wrapped in a completed call that keeps
73
+ # its value, inside any reach before it. A byte offset is an
74
+ # empty body. It gets a completed call of nil, a statement of
75
+ # its own, because the body's value is nil either way.
76
+ def self.completed_inserts(completions)
77
+ completions.flat_map do |name, at|
78
+ call = "PathCoverage.completed(#{name.inspect}, "
79
+ next [[at, "#{call}nil); ", own_rank]] unless at.is_a?(Range)
80
+
81
+ rank = [at.size, LAYERS.index(:completed)]
82
+ [[at.begin, "#{call}(", rank], [at.end, '))', rank, :close]]
83
+ end
84
+ end
85
+
86
+ # The rank of a completed call that is a statement of its own,
87
+ # for an empty body. It is inside any reach at the same place.
88
+ def self.own_rank = [Float::INFINITY, LAYERS.index(:completed)]
89
+
24
90
  # Example: { "k.rb:4:16" => 60 } puts a pass call at 60.
25
91
  # The inserts that put a pass call, a statement of its own,
26
- # first in each loop body in passes, { name => offset }.
92
+ # first in each loop body in passes, { name => offset }. It
93
+ # comes before the reach of a row at the same place, so the
94
+ # row is a step of the pass.
27
95
  def self.pass_inserts(passes)
28
- rank = [Float::INFINITY, LAYERS.index(:reach)]
96
+ rank = [Float::INFINITY, LAYERS.index(:pass)]
29
97
  passes.map do |name, at|
30
98
  [at, "PathCoverage.pass(#{name.inspect}); ", rank]
31
99
  end
@@ -34,11 +102,11 @@ module PathCoverage
34
102
  # Example: { "k.rb:2:2" => 18 } puts a reach call at 18.
35
103
  # The inserts that put a reach call, a statement of its
36
104
  # own, before each statement in reaches, outside all else
37
- # there. A statement reached by
105
+ # there, in layer. A statement reached by
38
106
  # its byte range, eg an endless def's body, is wrapped in
39
107
  # parentheses with its call, being one expression.
40
- def self.reach_inserts(reaches)
41
- rank = [Float::INFINITY, LAYERS.index(:reach)]
108
+ def self.reach_inserts(reaches, layer = :reach)
109
+ rank = [Float::INFINITY, LAYERS.index(layer)]
42
110
  reaches.flat_map do |name, at|
43
111
  call = "PathCoverage.reach(#{name.inspect}); "
44
112
  next [[at, call, rank]] unless at.is_a?(Range)
@@ -98,8 +166,9 @@ module PathCoverage
98
166
  # The layers of inserts, innermost first, that break a tie
99
167
  # between inserts wrapping the same range: a leaf's call, a
100
168
  # nested kind's call around its whole, eg end_items, a decision's
101
- # leave, and a statement's reach.
102
- LAYERS = %i[leaf kind decision reach].freeze
169
+ # leave, a rescue body's last statement's completed, a
170
+ # statement's reach, a loop's pass, and a method's entry.
171
+ LAYERS = %i[leaf kind decision completed reach pass entry].freeze
103
172
 
104
173
  # The two inserts that wrap the code at range in call. Their
105
174
  # order, [size, rank], nests them among inserts at the same
@@ -14,18 +14,18 @@ module PathCoverage
14
14
  SCHEMA = 1
15
15
 
16
16
  # The URL of the schema the source report follows.
17
- SCHEMA_URL = 'https://path-coverage.github.io/schemas/v1/' \
17
+ SCHEMA_URL = 'https://path-coverage.github.io/schemas/v2/' \
18
18
  'path_coverage.source.schema.json'.freeze
19
19
 
20
20
  # The source report of a run, headed by its schema's URL and
21
21
  # version: config's ignored operators, the
22
22
  # covered files of each of config's groups, each top of the
23
- # rows of cards, { def decision => card }, coloured, and each of
23
+ # rows of flows, { def decision => flow }, coloured, and each of
24
24
  # files', { full path => {source:, decisions:} }, lines and
25
25
  # decisions, each decision's paths as decision_paths has
26
26
  # them, its fold headed by its row's top.
27
- def self.of(files, config, decision_paths, cards)
28
- rows = cards.values.flat_map { _1['rows'] }
27
+ def self.of(files, config, decision_paths, flows)
28
+ rows = flows.values.flat_map { _1['rows'] }
29
29
  tops = rows.to_h { [_1['decision'], _1['top']] }
30
30
  shown = files.to_h do |full_path, parsed|
31
31
  [config.relative(full_path),
@@ -2,7 +2,7 @@ require 'prism'
2
2
  require_relative 'condition'
3
3
 
4
4
  module PathCoverage
5
- # The leaves of a card whose outcomes cannot differ within one
5
+ # The leaves of a flow whose outcomes cannot differ within one
6
6
  # call: each a read of a local variable that its method never
7
7
  # writes, eg a parameter, where the leaf's outcome is the
8
8
  # variable's truthiness. Every such read in a call has the same
@@ -25,10 +25,10 @@ module PathCoverage
25
25
  # Example: { 32...33 => :a, 54...55 => :a } for def f(a),
26
26
  # return 0 if a, then a ? 1 : 2.
27
27
  # { leaf byte range => local name } for each truthy leaf of
28
- # the decisions of rows, a card's in source, decisions being
28
+ # the decisions of rows, a flow's in source, decisions being
29
29
  # { decision => Condition }, that reads, outside any block, a
30
30
  # local its def never writes, for each name two or more such
31
- # leaves read; none for a card in no def, or one whose def
31
+ # leaves read; none for a flow in no def, or one whose def
32
32
  # calls any of REWRITERS.
33
33
  def self.of(source, decisions, rows)
34
34
  conditions = decisions.values_at(*rows.map(&:decision).compact)
@@ -1,7 +1,7 @@
1
1
  module PathCoverage
2
- # The lists of statements a method's card has rows for: a def's
2
+ # The lists of statements a method's flow has rows for: a def's
3
3
  # body, the arms of each decision in it whose arms are statements,
4
- # and the body of each block in it, as the card lays them out
4
+ # and the body of each block in it, as the flow lays them out
5
5
  # flat. It relies on its includer's rows_in, decision? and
6
6
  # decision_name.
7
7
  module StatementArms
@@ -9,7 +9,7 @@ module PathCoverage
9
9
  # block's, a lambda's and a begin's statements are rows of
10
10
  # their own, after the statement holding them, and a def's
11
11
  # body runs only when it is called, its decisions rows of its own
12
- # card.
12
+ # flow.
13
13
  UNSEEN = %i[block_node begin_node def_node lambda_node].freeze
14
14
 
15
15
  # Example: if/else for if a then 1 else 2 end.
@@ -23,11 +23,13 @@ module PathCoverage
23
23
  clause&.type == :else_node ? "#{operator}/else" : operator
24
24
  end
25
25
 
26
- # The tops of statements that end a path, leaving the method.
27
- LEAVING = %w[return raise].freeze
26
+ # The tops of statements that end a path. A return or a raise
27
+ # leaves the method. A next, a break or a retry leaves its pass
28
+ # or its loop.
29
+ LEAVING = %w[return raise next break retry].freeze
28
30
 
29
31
  # True for a row that shapes its method's paths: a decision, or a
30
- # return or a raise, which ends a path. Any other, eg x = 1,
32
+ # statement in LEAVING, which ends a path. Any other, eg x = 1,
31
33
  # runs exactly where what holds it does, so is no row.
32
34
  def shapes?(node)
33
35
  decision?(node) || LEAVING.include?(top_of(node))
@@ -40,11 +42,23 @@ module PathCoverage
40
42
  body = node.body
41
43
  return node.end_keyword_loc.start_offset if body.nil?
42
44
 
43
- loc = body.location
45
+ loc = entered(body).location
44
46
  start = loc.start_offset
45
47
  node.equal_loc ? start...loc.end_offset : start
46
48
  end
47
49
 
50
+ # The node where body, a def's, is entered on every call.
51
+ # Usually that is body itself. A body with a rescue or an
52
+ # ensure has a begin that starts at the def. Its statements
53
+ # are entered instead. With no statements, its first rescue
54
+ # is, or else its ensure.
55
+ def entered(body)
56
+ return body unless body.type == :begin_node
57
+
58
+ [body.statements, body.rescue_clause, body.ensure_clause]
59
+ .compact.first
60
+ end
61
+
48
62
  # Example: return a ? 1 : 2 if x gives the ?:.
49
63
  # The decisions inside decision that are decisions of their
50
64
  # own, in the order they are written: in its leaves, eg a
@@ -54,7 +68,7 @@ module PathCoverage
54
68
  # where a decision does, eg a ?:'s predicate, names that
55
69
  # decision: each is kept once, and decision itself not at
56
70
  # all. None for a top that is no decision, eg a def inside a
57
- # def, whose decisions are on its own card.
71
+ # def, whose decisions are on its own flow.
58
72
  def inner_decisions(decision)
59
73
  return [] unless decision?(decision)
60
74
 
@@ -87,7 +101,7 @@ module PathCoverage
87
101
  # The body of each block and lambda in node, run 0 or more
88
102
  # times, and each begin: none inside an arm of statements or
89
103
  # another body, whose rows are their own, nor in a def, whose
90
- # rows are its own card's.
104
+ # rows are its own flow's.
91
105
  def bodies_in(node)
92
106
  case node.type
93
107
  when :def_node then []
@@ -12,12 +12,12 @@ module PathCoverage
12
12
  [every.count { |each| each[:count].positive? }, every.size]
13
13
  end
14
14
 
15
- # Example: cards [4, 6] and [17, 21] give [21, 27].
16
- # Paths combined through each method: cards is { def decision =>
17
- # [taken, size] }, each method's card's paths taken of its
15
+ # Example: flows [4, 6] and [17, 21] give [21, 27].
16
+ # Paths combined through each method: flows is { def decision =>
17
+ # [taken, size] }, each method's flow's paths taken of its
18
18
  # size, its rows' paths added up.
19
- def self.combined(cards)
20
- cards.values.reduce([0, 0]) do |(taken, possible), (more, of)|
19
+ def self.combined(flows)
20
+ flows.values.reduce([0, 0]) do |(taken, possible), (more, of)|
21
21
  [taken + more, possible + of]
22
22
  end
23
23
  end
@@ -1,3 +1,3 @@
1
1
  module PathCoverage
2
- VERSION = '0.5.0'.freeze
2
+ VERSION = '0.7.0'.freeze
3
3
  end
@@ -1,5 +1,5 @@
1
1
  module PathCoverage
2
- # The algebras CardWays can fold a card's ways in, each giving
2
+ # The algebras PathsWays can fold a flow's ways in, each giving
3
3
  # no ways, the one way through no rows, the one way taking a
4
4
  # labelled path, and ways added and joined one after another.
5
5
  # A way's label at a row is [row key, path index].
@@ -38,7 +38,7 @@ module PathCoverage
38
38
  def self.plus(ways, more) = ways | more
39
39
 
40
40
  # The labels of each way of ways going on to each of more:
41
- # every one of either, as CardWays never joins no ways.
41
+ # every one of either, as PathsWays never joins no ways.
42
42
  def self.times(ways, more) = ways | more
43
43
  end
44
44
 
@@ -1,7 +1,7 @@
1
1
  require 'json'
2
2
 
3
3
  module PathCoverage
4
- # A method card's taken ways, and its loops' passes, as the JSON
4
+ # A method flow's taken ways, and its loops' passes, as the JSON
5
5
  # report lists them: each way the steps one call, or one pass,
6
6
  # took, in order, a decision's {"at", "path"}, a loop's {"at",
7
7
  # "path", "passes"}, its path how many passes it made, or any
@@ -36,15 +36,15 @@ module PathCoverage
36
36
  end
37
37
 
38
38
  # { method's entry, or loop's name => { way => count } } of a
39
- # JSON report's cards, as a CallTrace counts them: each card
40
- # listing its calls' ways and its loops' passes; a top card
39
+ # JSON report's flows, as a CallTrace counts them: each flow
40
+ # listing its calls' ways and its loops' passes; a top flow
41
41
  # lists neither, as no call runs it.
42
42
  def self.ways(report)
43
- report['cards'].each_with_object({}) do |(entry, card), found|
44
- next unless card.key?('taken')
43
+ report['flows'].each_with_object({}) do |(entry, flow), found|
44
+ next unless flow.key?('taken')
45
45
 
46
- found[entry] = read(entry, card['taken'])
47
- card['passes'].each do |at, passes|
46
+ found[entry] = read(entry, flow['taken'])
47
+ flow['passes'].each do |at, passes|
48
48
  loop = named(entry, at)
49
49
  found[loop] = read(loop, passes)
50
50
  end
@@ -82,7 +82,7 @@ module PathCoverage
82
82
  end
83
83
 
84
84
  # The line:column of the row or loop named name, the column two
85
- # digits, as a card's rows have it: "k.rb:4:6" gives "4:06".
85
+ # digits, as a flow's rows have it: "k.rb:4:6" gives "4:06".
86
86
  def self.at(name)
87
87
  line, column = name.split(':').last(2)
88
88
  format('%<line>s:%<column>02d', line:, column: Integer(column))
@@ -11,8 +11,8 @@ module PathCoverage
11
11
  # impossible, or more paths than its max_paths.
12
12
  def self.failed?(report)
13
13
  listed, over = methods(report)
14
- untaken = listed.sum do |card|
15
- card['gaps'].size + card['impossible_taken'].size
14
+ untaken = listed.sum do |flow|
15
+ flow['gaps'].size + flow['impossible_taken'].size
16
16
  end
17
17
  !over.empty? || untaken.positive?
18
18
  end
@@ -30,15 +30,15 @@ module PathCoverage
30
30
  "Functions over --max-paths=#{limit}: #{over.size}"]
31
31
  end
32
32
 
33
- # [listed, over] of report's method cards: those listing their
33
+ # [listed, over] of report's method flows: those listing their
34
34
  # ways, and those with more paths than its max_paths, which
35
- # list none. A top card, run by no call, has no taken ways, so
35
+ # list none. A top flow, run by no call, has no taken ways, so
36
36
  # is in neither.
37
37
  def self.methods(report)
38
- found = report['cards'].values.group_by do |card|
39
- next :top unless card.key?('taken')
38
+ found = report['flows'].values.group_by do |flow|
39
+ next :top unless flow.key?('taken')
40
40
 
41
- card.key?('covered') ? :listed : :over
41
+ flow.key?('covered') ? :listed : :over
42
42
  end
43
43
  [found.fetch(:listed, []), found.fetch(:over, [])]
44
44
  end
@@ -1,8 +1,8 @@
1
- require_relative 'card_context'
2
- require_relative 'card_scopes'
3
- require_relative 'card_tree'
4
- require_relative 'card_way_lists'
5
- require_relative 'card_ways'
1
+ require_relative 'paths_context'
2
+ require_relative 'paths_scopes'
3
+ require_relative 'paths_tree'
4
+ require_relative 'paths_way_lists'
5
+ require_relative 'paths_ways'
6
6
  require_relative 'loop_forks'
7
7
  require_relative 'method_loops'
8
8
  require_relative 'method_statements'
@@ -12,38 +12,29 @@ require_relative 'source_lines'
12
12
  module PathCoverage
13
13
  # What is measured within each method of a covered file.
14
14
  module WithinMethods
15
- # Where each statement of the covered file at path, parsed
16
- # as Manifest.parse gives it, that is no decision is reached,
17
- # as MethodStatements.reaches gives them.
18
- def self.reaches(path, parsed, config)
19
- source, decisions = parsed.values_at(:source, :decisions)
20
- relative = config.relative(path)
21
- MethodStatements.reaches(source, relative, decisions)
22
- end
23
-
24
15
  # Example: { "k.rb:0:0" => [1, 2], "k.rb:1:0" => [2, 4] }.
25
- # Each def's card total, [taken, size], in every file in
16
+ # Each def's flow total, [taken, size], in every file in
26
17
  # files, { full path => {source:, decisions:} }, from paths, as
27
18
  # Result#paths gives them, and reached, as Recorder#reached
28
- # does; and each file's top level's, its decisions on no card,
19
+ # does; and each file's top level's, its decisions on no flow,
29
20
  # named for line 0, which no def is on.
30
- def self.cards(files, config, paths, reached)
21
+ def self.flows(files, config, paths, reached)
31
22
  files.map do |full_path, parsed|
32
23
  path = config.relative(full_path)
33
24
  source, decisions = parsed.values_at(:source, :decisions)
34
25
  args = [source, path, paths]
35
26
  top = MethodStatements.top_level(*args, decisions)
36
- CardContext.totals(*args, reached, decisions)
37
- .merge("#{path}:0:0" => top)
27
+ PathsContext.totals(*args, reached, decisions)
28
+ .merge("#{path}:0:0" => top)
38
29
  end.reduce({}, :merge)
39
30
  end
40
31
 
41
32
  # Example: { "k.rb:1:0" => { "name" => "ship", "first" => 1,
42
33
  # "last" => 3, "rows" => [{ "at" => "2:04", ... }] } }.
43
- # Each card in every file in files, a def's and a top card's,
34
+ # Each flow in every file in files, a def's and a top flow's,
44
35
  # as its page draws it, for the JSON report, so a reader
45
- # finds a card's gap without the page; result a Result;
46
- # counted [reached, ways], reached as cards takes it, ways as
36
+ # finds a flow's gap without the page; result a Result;
37
+ # counted [reached, ways], reached as flows takes it, ways as
47
38
  # a CallTrace counts them, nil when not known.
48
39
  def self.listed(files, config, result, counted)
49
40
  files.map do |full_path, parsed|
@@ -57,10 +48,10 @@ module PathCoverage
57
48
 
58
49
  # Example: { "k.rb" => { "1:0" => { "2:2" => { "parent" =>
59
50
  # nil, "in" => nil, "on" => nil } } } }.
60
- # How the rows of each card nest, in every file in files: by
61
- # the file's path, then its card's line:column, a def's card
62
- # and each top card, as listed names them, then each row's,
63
- # as CardTree places them; result a Result.
51
+ # How the rows of each flow nest, in every file in files: by
52
+ # the file's path, then its flow's line:column, a def's flow
53
+ # and each top flow, as listed names them, then each row's,
54
+ # as PathsTree places them; result a Result.
64
55
  def self.tree(files, config, result)
65
56
  files.to_h do |full_path, parsed|
66
57
  path = config.relative(full_path)
@@ -68,42 +59,42 @@ module PathCoverage
68
59
  end
69
60
  end
70
61
 
71
- # How the rows of each card of the file at path nest, parsed
62
+ # How the rows of each flow of the file at path nest, parsed
72
63
  # as Manifest.parse gives it, as tree gives them.
73
64
  def self.tree_in(path, parsed, result)
74
65
  source, decisions = parsed.values_at(:source, :decisions)
75
- cards = CardTree.of(source, path, decisions).to_a +
66
+ flows = PathsTree.of(source, path, decisions).to_a +
76
67
  tree_tops(path, parsed, result)
77
- cards.to_h do |decision, rows|
68
+ flows.to_h do |decision, rows|
78
69
  [decision.split(':').last(2) * ':', rows]
79
70
  end
80
71
  end
81
72
 
82
- # [[card decision, its rows' places]] for each top card of the
73
+ # [[flow decision, its rows' places]] for each top flow of the
83
74
  # file at path, as listed_tops names them.
84
75
  def self.tree_tops(path, parsed, result)
85
76
  source, decisions = parsed.values_at(:source, :decisions)
86
77
  lines = SourceLines.of(source, decisions, result.operands)
87
78
  spans(path, parsed, lines).map do |span, rows|
88
- nested = CardTree.nested(source, decisions, rows)
79
+ nested = PathsTree.nested(source, decisions, rows)
89
80
  ["#{path}:#{span.begin}:0", nested]
90
81
  end
91
82
  end
92
83
 
93
- # The top cards of the file at path, as its page draws them:
84
+ # The top flows of the file at path, as its page draws them:
94
85
  # each under the decision of its first line's start, named for
95
86
  # its scope, as listed gives them; operands and decision_paths
96
87
  # as Result gives them.
97
88
  def self.listed_tops(path, parsed, (operands, decision_paths))
98
89
  source, decisions = parsed.values_at(:source, :decisions)
99
90
  lines = SourceLines.of(source, decisions, operands)
100
- scopes = CardScopes.of(source)
91
+ scopes = PathsScopes.of(source)
101
92
  spans(path, parsed, lines).to_h do |span, rows|
102
93
  decision = "#{path}:#{span.begin}:0"
103
94
  taken = rows.zip(MethodStatements.taken(rows, decision_paths))
104
- ways = CardWays.card(source, decisions, rows)
95
+ ways = PathsWays.flow(source, decisions, rows)
105
96
  named = [scopes[span.begin], span.end, ways, nil]
106
- [decision, card(decision, named, taken)]
97
+ [decision, flow(decision, named, taken)]
107
98
  end
108
99
  end
109
100
 
@@ -116,10 +107,10 @@ module PathCoverage
116
107
  rows.group_by { lines[_1.line - 1][:span] }
117
108
  end
118
109
 
119
- # The cards of the file at path, parsed as Manifest.parse
110
+ # The flows of the file at path, parsed as Manifest.parse
120
111
  # gives it, as listed gives them, each listing its ways too
121
112
  # when counted's ways are known, counted being [reached, ways,
122
- # limit, loops], limit the most ways a card lists, loops
113
+ # limit, loops], limit the most ways a flow lists, loops
123
114
  # whether each loop is a fork.
124
115
  def self.listed_in(path, parsed, paths, (reached, *counted))
125
116
  source, decisions = parsed.values_at(:source, :decisions)
@@ -129,72 +120,81 @@ module PathCoverage
129
120
  MethodStatements.of(source, path, decisions).to_h do |key, rows|
130
121
  count = lister.count(key, rows)
131
122
  named = [*titles[key], count, reached&.fetch(key, 0)]
132
- shown = method_card(key, rows, named, context)
123
+ shown = method_flow(key, rows, named, context)
133
124
  [key, shown.merge(lister.lists(key, rows, count))]
134
125
  end
135
126
  end
136
127
 
137
- # The card of the def at key, its rows, named as card takes
128
+ # The flow of the def at key, its rows, named as flow takes
138
129
  # named; context is [source, decisions, paths, reached], as
139
130
  # listed_in has them.
140
- def self.method_card(key, rows, named, context)
131
+ def self.method_flow(key, rows, named, context)
141
132
  source, decisions, paths, reached = context
142
- shown = CardContext.rows(source, decisions, rows, paths,
143
- reached)
144
- card(key, named, shown)
133
+ shown = PathsContext.rows(source, decisions, rows, paths,
134
+ reached)
135
+ flow(key, named, shown)
145
136
  end
146
137
 
147
138
  # { def decision => [its name, its last line] } for each def in
148
- # source, at path, as its card is titled.
139
+ # source, at path, as its flow is titled.
149
140
  def self.titles(source, path, decisions)
150
141
  names = MethodStatements.names(source, path, decisions)
151
142
  lasts = MethodStatements.lasts(source, path, decisions)
152
143
  names.to_h { |key, name| [key, [name, lasts[key]]] }
153
144
  end
154
145
 
155
- # The way lists of each card of a file, as CardWayLists gives
146
+ # The way lists of each flow of a file, as PathsWayLists gives
156
147
  # them.
157
148
  class WayLister
158
149
  # The lister of the file at path, source, its decisions as
159
150
  # Manifest.parse gives them; counted [ways, limit]: ways as a
160
151
  # CallTrace counts them, nil when not known, and limit the
161
- # most ways a card lists.
152
+ # most ways a flow lists.
162
153
  def initialize(source, path, decisions, (ways, limit, loops))
163
154
  @source = source
164
155
  @decisions = decisions
165
156
  @ways = ways
166
157
  @limit = limit
167
158
  @loops = MethodLoops.of(source, path, decisions)
168
- @forks = LoopForks.of(source, path, decisions)
159
+ @forks = LoopForks.of(source, path)
160
+ @rescues = RescueForks.of(source, path)
169
161
  @forking = loops
170
162
  end
171
163
 
172
- # How many ways go through the card of the def at key, its
173
- # rows, each loop a fork when loops are.
164
+ # How many ways go through the flow of the def at key, its
165
+ # rows. Each loop is a scope, and a fork when loops are. Its
166
+ # rescue is a fork.
174
167
  def count(key, rows)
175
- CardWays.card(@source, @decisions, rows,
176
- WayAlgebras::Counted, [true, forked(key)])
168
+ PathsWays.flow(@source, @decisions, rows,
169
+ WayAlgebras::Counted, [true, *scopes(key)])
177
170
  end
178
171
 
179
- # The way lists of the card of the def at key, its rows, with
172
+ # The way lists of the flow of the def at key, its rows, with
180
173
  # count ways through it: none when the ways are not known;
181
174
  # those its calls took and its loops' passes; and, when count
182
175
  # is no more than the limit, its covered, gaps and impossible.
183
176
  def lists(key, rows, count)
184
177
  return {} if @ways.nil?
185
178
 
186
- walked = CardWayLists.walked(key, @ways, loops(key))
179
+ walked = PathsWayLists.walked(key, @ways, loops(key))
187
180
  return walked if count > @limit
188
181
 
189
- forked = forked(key)
190
- split = MethodWays.split_card(@source, @decisions, rows,
191
- forked)
192
- checked = [split, forked.keys]
193
- walked.merge(CardWayLists.checked(key, @ways, checked))
182
+ split = MethodWays.split_flow(@source, @decisions, rows,
183
+ scopes(key))
184
+ checked = [split, forked(key).keys]
185
+ walked.merge(PathsWayLists.checked(key, @ways, checked))
194
186
  end
195
187
 
196
188
  private
197
189
 
190
+ # [forks, rescues, forking] of the def at key, as
191
+ # MethodWays.split_flow takes them. forks is each of its
192
+ # loops, as LoopForks gives them. rescues is its rescue
193
+ # forks. forking says whether its loops fork.
194
+ def scopes(key)
195
+ [@forks.fetch(key), @rescues.fetch(key), @forking]
196
+ end
197
+
198
198
  # The names of the loops of the def at key: those holding a
199
199
  # row, and those that fork.
200
200
  def loops(key)
@@ -208,19 +208,19 @@ module PathCoverage
208
208
  end
209
209
  end
210
210
 
211
- # The card of the def at decision, named name, ending on line
211
+ # The flow of the def at decision, named name, ending on line
212
212
  # last, with ways through it, as ways folds them, and calls,
213
- # how many times it was called, nil for a top card, which is no
213
+ # how many times it was called, nil for a top flow, which is no
214
214
  # method's, or when not known: its first line, from decision, and
215
215
  # a row for each [statement, taken] of rows.
216
- def self.card(decision, (name, last, ways, calls), rows)
216
+ def self.flow(decision, (name, last, ways, calls), rows)
217
217
  first = Integer(decision.split(':')[-2])
218
218
  listed = rows.map { |statement, count| row(statement, count) }
219
219
  { 'name' => name, 'first' => first, 'last' => last,
220
220
  'ways' => ways, 'calls' => calls, 'rows' => listed }
221
221
  end
222
222
 
223
- # A card's row: statement's line:column, as its page labels
223
+ # A flow's row: statement's line:column, as its page labels
224
224
  # it, its top, its paths, count, how many were taken, and
225
225
  # its decision, nil for a statement that is no decision.
226
226
  def self.row(statement, count)