path_coverage 0.7.1 → 0.8.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 (64) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +45 -19
  3. data/lib/path_coverage/call_trace.rb +1 -1
  4. data/lib/path_coverage/calls.rb +35 -8
  5. data/lib/path_coverage/condition.rb +35 -9
  6. data/lib/path_coverage/current_test.rb +28 -0
  7. data/lib/path_coverage/decision.rb +7 -0
  8. data/lib/path_coverage/decision_sites.rb +40 -0
  9. data/lib/path_coverage/decision_tree.rb +11 -21
  10. data/lib/path_coverage/evaluated.rb +23 -0
  11. data/lib/path_coverage/fold_rows.rb +7 -8
  12. data/lib/path_coverage/gaps.rb +4 -4
  13. data/lib/path_coverage/json_reader.rb +22 -17
  14. data/lib/path_coverage/json_reports.rb +5 -3
  15. data/lib/path_coverage/json_writer.rb +12 -8
  16. data/lib/path_coverage/kernel.rb +11 -3
  17. data/lib/path_coverage/kinds/base.rb +9 -0
  18. data/lib/path_coverage/kinds/block.rb +7 -1
  19. data/lib/path_coverage/kinds/case.rb +63 -20
  20. data/lib/path_coverage/kinds/chain.rb +13 -3
  21. data/lib/path_coverage/kinds/choice.rb +5 -0
  22. data/lib/path_coverage/kinds/contains.rb +6 -0
  23. data/lib/path_coverage/kinds/safe.rb +3 -3
  24. data/lib/path_coverage/kinds/write.rb +3 -3
  25. data/lib/path_coverage/kinds.rb +14 -0
  26. data/lib/path_coverage/loop_nodes.rb +15 -10
  27. data/lib/path_coverage/manifest.rb +61 -35
  28. data/lib/path_coverage/manifest_case.rb +43 -26
  29. data/lib/path_coverage/manifest_folding.rb +20 -0
  30. data/lib/path_coverage/merge.rb +8 -8
  31. data/lib/path_coverage/method_statements.rb +41 -61
  32. data/lib/path_coverage/minitest.rb +7 -0
  33. data/lib/path_coverage/minitest_tests.rb +25 -0
  34. data/lib/path_coverage/paths_context.rb +2 -2
  35. data/lib/path_coverage/paths_forks.rb +6 -3
  36. data/lib/path_coverage/paths_leaving.rb +3 -1
  37. data/lib/path_coverage/paths_regions.rb +78 -0
  38. data/lib/path_coverage/paths_rescues.rb +5 -2
  39. data/lib/path_coverage/paths_scopes.rb +2 -1
  40. data/lib/path_coverage/paths_tree.rb +10 -68
  41. data/lib/path_coverage/paths_way_lists.rb +11 -10
  42. data/lib/path_coverage/recorder.rb +28 -47
  43. data/lib/path_coverage/recorder_blocks.rb +3 -3
  44. data/lib/path_coverage/recorder_cases.rb +70 -17
  45. data/lib/path_coverage/recorder_chains.rb +2 -2
  46. data/lib/path_coverage/render.rb +7 -3
  47. data/lib/path_coverage/report_tallies.rb +79 -0
  48. data/lib/path_coverage/report_text.rb +23 -0
  49. data/lib/path_coverage/rescue_forks.rb +3 -0
  50. data/lib/path_coverage/result.rb +17 -16
  51. data/lib/path_coverage/rewriter.rb +42 -114
  52. data/lib/path_coverage/rewriter_marks.rb +108 -0
  53. data/lib/path_coverage/source_report.rb +5 -6
  54. data/lib/path_coverage/stable_leaves.rb +6 -26
  55. data/lib/path_coverage/statement_arms.rb +23 -25
  56. data/lib/path_coverage/statement_tops.rb +53 -0
  57. data/lib/path_coverage/tally.rb +129 -0
  58. data/lib/path_coverage/testing.rb +13 -0
  59. data/lib/path_coverage/totals.rb +3 -3
  60. data/lib/path_coverage/version.rb +1 -1
  61. data/lib/path_coverage/walk.rb +4 -3
  62. data/lib/path_coverage/ways_report.rb +11 -10
  63. data/lib/path_coverage/within_methods.rb +12 -3
  64. metadata +13 -1
@@ -0,0 +1,13 @@
1
+ require_relative 'current_test'
2
+
3
+ # The part of path coverage's API that names the test under way,
4
+ # so the JSON report tells which tests take which paths.
5
+ module PathCoverage
6
+ # Counts everything measured from now on, in this thread and any
7
+ # thread it starts, under test, a test's id, or Tally::NO_TEST as
8
+ # a test ends: for a test framework with no hook here, eg in an
9
+ # RSpec around hook; Minitest's is path_coverage/minitest.
10
+ def self.testing(test)
11
+ CurrentTest.testing(test)
12
+ end
13
+ end
@@ -5,11 +5,11 @@ module PathCoverage
5
5
  module Totals
6
6
  # Paths alone, each decision's counted on its own:
7
7
  # decision_paths, as Result#paths gives them, lists every
8
- # possible path of each decision with its count; one with a
9
- # count above zero was taken.
8
+ # possible path of each decision with its Tally; one some test
9
+ # took was taken.
10
10
  def self.alone(decision_paths)
11
11
  every = decision_paths.values.flatten
12
- [every.count { |each| each[:count].positive? }, every.size]
12
+ [every.count { |each| !each[:tests].empty? }, every.size]
13
13
  end
14
14
 
15
15
  # Example: flows [4, 6] and [17, 21] give [21, 27].
@@ -1,3 +1,3 @@
1
1
  module PathCoverage
2
- VERSION = '0.7.1'.freeze
2
+ VERSION = '0.8.0'.freeze
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require_relative 'condition'
2
+ require_relative 'current_test'
2
3
 
3
4
  module PathCoverage
4
5
  # The way one call is taking through its method, kept as a stack
@@ -95,11 +96,11 @@ module PathCoverage
95
96
  @units.last.steps << [ended.name, [items], ended.seen]
96
97
  end
97
98
 
98
- # Counts unit's steps as one more taking of its way, noting it
99
- # among the ways seen.
99
+ # Counts unit's steps as one more taking of its way, under the
100
+ # test under way, noting it among the ways seen.
100
101
  def count(unit)
101
102
  way = unit.steps.dup.freeze
102
- (@ways[unit.name] ||= Hash.new(0))[way] += 1
103
+ (@ways[unit.name] ||= Tally.per_key)[way].add(CurrentTest.id)
103
104
  unit.seen << way
104
105
  end
105
106
  end
@@ -5,14 +5,14 @@ module PathCoverage
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
8
- # other row's {"at"}, with how many took it.
8
+ # other row's {"at"}, with the Tally of the tests that took it.
9
9
  module WaysReport
10
- # [{ "way" => [step, ...], "count" => n }] of walked, { way =>
11
- # n }, one unit's ways as a CallTrace counts them, in the order
12
- # first taken.
10
+ # [{ "way" => [step, ...], "tests" => Tally }] of walked, { way
11
+ # => Tally }, one unit's ways as a CallTrace counts them, in the
12
+ # order first taken.
13
13
  def self.taken(walked)
14
- walked.map do |each, count|
15
- { 'way' => way(each), 'count' => count }
14
+ walked.map do |each, tests|
15
+ { 'way' => way(each), 'tests' => tests }
16
16
  end
17
17
  end
18
18
 
@@ -35,8 +35,9 @@ module PathCoverage
35
35
  listed.merge('passes' => passes)
36
36
  end
37
37
 
38
- # { method's entry, or loop's name => { way => count } } of a
39
- # JSON report's flows, as a CallTrace counts them: each flow
38
+ # { method's entry, or loop's name => { way => Tally } } of a
39
+ # JSON report's flows, its tallies read as JsonReader.load reads
40
+ # them, as a CallTrace counts them: each flow
40
41
  # listing its calls' ways and its loops' passes; a top flow
41
42
  # lists neither, as no call runs it.
42
43
  def self.ways(report)
@@ -51,11 +52,11 @@ module PathCoverage
51
52
  end
52
53
  end
53
54
 
54
- # { way => count } of listed, the unit named unit's ways as
55
+ # { way => Tally } of listed, the unit named unit's ways as
55
56
  # taken lists them.
56
57
  def self.read(unit, listed)
57
58
  listed.to_h do |each|
58
- [each['way'].map { unlisted(unit, _1) }, each['count']]
59
+ [each['way'].map { unlisted(unit, _1) }, each['tests']]
59
60
  end
60
61
  end
61
62
 
@@ -7,6 +7,7 @@ require_relative 'method_loops'
7
7
  require_relative 'method_statements'
8
8
  require_relative 'method_ways'
9
9
  require_relative 'source_lines'
10
+ require_relative 'tally'
10
11
 
11
12
  module PathCoverage
12
13
  # What is measured within each method of a covered file.
@@ -120,12 +121,19 @@ module PathCoverage
120
121
  context = [source, decisions, [paths, reached], lister]
121
122
  MethodStatements.of(source, path, decisions).to_h do |key, rows|
122
123
  count = lister.count(key, rows)
123
- named = [*titles[key], count, reached&.fetch(key, 0)]
124
+ named = [*titles[key], count, calls_of(reached, key)]
124
125
  shown = method_flow(key, rows, named, context)
125
126
  [key, shown.merge(lister.lists(key, rows, count))]
126
127
  end
127
128
  end
128
129
 
130
+ # The Tally of the calls of the def at key, its entry's reaches
131
+ # in reached, empty for one never called; nil when reached is
132
+ # nil, not known.
133
+ def self.calls_of(reached, key)
134
+ reached&.fetch(key) { Tally.new }
135
+ end
136
+
129
137
  # The flow of the def at key, its rows, named as flow takes
130
138
  # named; context is [source, decisions, recorded, lister], as
131
139
  # listed_in has them, recorded as PathsContext takes it, and
@@ -211,8 +219,9 @@ module PathCoverage
211
219
 
212
220
  # The flow of the def at decision, named name, ending on line
213
221
  # last, with ways through it, as ways folds them, and calls,
214
- # how many times it was called, nil for a top flow, which is no
215
- # method's, or when not known: its first line, from decision, and
222
+ # the Tally of the tests that called it, nil for a top flow,
223
+ # which is no method's, or when not known: its first line, from
224
+ # decision, and
216
225
  # a row for each [statement, taken] of rows.
217
226
  def self.flow(decision, (name, last, ways, calls), rows)
218
227
  first = Integer(decision.split(':')[-2])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: path_coverage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Jagger
@@ -46,10 +46,13 @@ files:
46
46
  - lib/path_coverage/configuration_limits.rb
47
47
  - lib/path_coverage/configuration_paths.rb
48
48
  - lib/path_coverage/console_summary.rb
49
+ - lib/path_coverage/current_test.rb
49
50
  - lib/path_coverage/decision.rb
50
51
  - lib/path_coverage/decision_locations.rb
51
52
  - lib/path_coverage/decision_paths.rb
53
+ - lib/path_coverage/decision_sites.rb
52
54
  - lib/path_coverage/decision_tree.rb
55
+ - lib/path_coverage/evaluated.rb
53
56
  - lib/path_coverage/fold_branches.rb
54
57
  - lib/path_coverage/fold_cells.rb
55
58
  - lib/path_coverage/fold_rows.rb
@@ -84,11 +87,14 @@ files:
84
87
  - lib/path_coverage/method_loops.rb
85
88
  - lib/path_coverage/method_statements.rb
86
89
  - lib/path_coverage/method_ways.rb
90
+ - lib/path_coverage/minitest.rb
91
+ - lib/path_coverage/minitest_tests.rb
87
92
  - lib/path_coverage/paths_context.rb
88
93
  - lib/path_coverage/paths_fitting.rb
89
94
  - lib/path_coverage/paths_forks.rb
90
95
  - lib/path_coverage/paths_gaps.rb
91
96
  - lib/path_coverage/paths_leaving.rb
97
+ - lib/path_coverage/paths_regions.rb
92
98
  - lib/path_coverage/paths_report.rb
93
99
  - lib/path_coverage/paths_rescues.rb
94
100
  - lib/path_coverage/paths_scopes.rb
@@ -102,16 +108,22 @@ files:
102
108
  - lib/path_coverage/recorder_chains.rb
103
109
  - lib/path_coverage/recorder_writes.rb
104
110
  - lib/path_coverage/render.rb
111
+ - lib/path_coverage/report_tallies.rb
112
+ - lib/path_coverage/report_text.rb
105
113
  - lib/path_coverage/rescue_forks.rb
106
114
  - lib/path_coverage/result.rb
107
115
  - lib/path_coverage/rewriter.rb
116
+ - lib/path_coverage/rewriter_marks.rb
108
117
  - lib/path_coverage/rewriter_nested.rb
109
118
  - lib/path_coverage/runs_report.rb
110
119
  - lib/path_coverage/source_lines.rb
111
120
  - lib/path_coverage/source_report.rb
112
121
  - lib/path_coverage/stable_leaves.rb
113
122
  - lib/path_coverage/statement_arms.rb
123
+ - lib/path_coverage/statement_tops.rb
114
124
  - lib/path_coverage/summary.rb
125
+ - lib/path_coverage/tally.rb
126
+ - lib/path_coverage/testing.rb
115
127
  - lib/path_coverage/totals.rb
116
128
  - lib/path_coverage/version.rb
117
129
  - lib/path_coverage/walk.rb