path_coverage 0.4.0 → 0.5.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 (102) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +286 -199
  3. data/exe/path_coverage_report +4 -0
  4. data/lib/path_coverage/call_trace.rb +88 -0
  5. data/lib/path_coverage/calls.rb +49 -43
  6. data/lib/path_coverage/card_context.rb +104 -0
  7. data/lib/path_coverage/card_forks.rb +44 -0
  8. data/lib/path_coverage/card_gaps.rb +125 -0
  9. data/lib/path_coverage/card_scopes.rb +37 -0
  10. data/lib/path_coverage/card_tree.rb +79 -66
  11. data/lib/path_coverage/card_way_lists.rb +72 -0
  12. data/lib/path_coverage/card_ways.rb +123 -67
  13. data/lib/path_coverage/{html_syntax.rb → code_tokens.rb} +35 -33
  14. data/lib/path_coverage/condition.rb +14 -14
  15. data/lib/path_coverage/configuration.rb +7 -4
  16. data/lib/path_coverage/configuration_limits.rb +52 -0
  17. data/lib/path_coverage/configuration_paths.rb +7 -7
  18. data/lib/path_coverage/console_summary.rb +24 -22
  19. data/lib/path_coverage/{site.rb → decision.rb} +2 -2
  20. data/lib/path_coverage/decision_locations.rb +76 -0
  21. data/lib/path_coverage/{site_paths.rb → decision_paths.rb} +13 -11
  22. data/lib/path_coverage/{site_tree.rb → decision_tree.rb} +25 -16
  23. data/lib/path_coverage/fold_branches.rb +18 -0
  24. data/lib/path_coverage/fold_cells.rb +42 -0
  25. data/lib/path_coverage/{html_tree.rb → fold_rows.rb} +42 -71
  26. data/lib/path_coverage/gaps.rb +33 -15
  27. data/lib/path_coverage/json_reader.rb +54 -19
  28. data/lib/path_coverage/json_reports.rb +102 -0
  29. data/lib/path_coverage/json_writer.rb +27 -12
  30. data/lib/path_coverage/kernel.rb +56 -58
  31. data/lib/path_coverage/kinds/base.rb +16 -16
  32. data/lib/path_coverage/kinds/block.rb +16 -15
  33. data/lib/path_coverage/kinds/case.rb +14 -12
  34. data/lib/path_coverage/kinds/chain.rb +40 -11
  35. data/lib/path_coverage/kinds/choice.rb +4 -3
  36. data/lib/path_coverage/kinds/contains.rb +40 -32
  37. data/lib/path_coverage/kinds/safe.rb +38 -26
  38. data/lib/path_coverage/kinds/write.rb +6 -6
  39. data/lib/path_coverage/kinds.rb +2 -2
  40. data/lib/path_coverage/leaving.rb +44 -0
  41. data/lib/path_coverage/loop_forks.rb +57 -0
  42. data/lib/path_coverage/loop_nodes.rb +55 -0
  43. data/lib/path_coverage/manifest.rb +92 -58
  44. data/lib/path_coverage/manifest_blocks.rb +5 -26
  45. data/lib/path_coverage/manifest_case.rb +2 -2
  46. data/lib/path_coverage/manifest_chains.rb +8 -8
  47. data/lib/path_coverage/manifest_choices.rb +23 -20
  48. data/lib/path_coverage/manifest_disabled.rb +97 -0
  49. data/lib/path_coverage/manifest_folding.rb +43 -40
  50. data/lib/path_coverage/manifest_ignoring.rb +6 -6
  51. data/lib/path_coverage/manifest_writes.rb +11 -10
  52. data/lib/path_coverage/measured_by.rb +20 -0
  53. data/lib/path_coverage/merge.rb +7 -7
  54. data/lib/path_coverage/method_loops.rb +128 -0
  55. data/lib/path_coverage/method_statements.rb +130 -127
  56. data/lib/path_coverage/method_ways.rb +142 -0
  57. data/lib/path_coverage/paths_report.rb +16 -16
  58. data/lib/path_coverage/recorder.rb +57 -36
  59. data/lib/path_coverage/recorder_blocks.rb +17 -17
  60. data/lib/path_coverage/recorder_cases.rb +12 -11
  61. data/lib/path_coverage/recorder_chains.rb +12 -12
  62. data/lib/path_coverage/recorder_writes.rb +9 -9
  63. data/lib/path_coverage/render.rb +58 -51
  64. data/lib/path_coverage/result.rb +32 -31
  65. data/lib/path_coverage/rewriter.rb +39 -27
  66. data/lib/path_coverage/rewriter_nested.rb +13 -13
  67. data/lib/path_coverage/runs_report.rb +84 -0
  68. data/lib/path_coverage/source_lines.rb +16 -16
  69. data/lib/path_coverage/source_report.rb +100 -0
  70. data/lib/path_coverage/stable_leaves.rb +162 -0
  71. data/lib/path_coverage/statement_arms.rb +31 -30
  72. data/lib/path_coverage/summary.rb +4 -62
  73. data/lib/path_coverage/totals.rb +10 -8
  74. data/lib/path_coverage/version.rb +1 -1
  75. data/lib/path_coverage/walk.rb +106 -0
  76. data/lib/path_coverage/way_algebras.rb +127 -0
  77. data/lib/path_coverage/ways_report.rb +91 -0
  78. data/lib/path_coverage/ways_totals.rb +46 -0
  79. data/lib/path_coverage/within_methods.rb +135 -80
  80. metadata +33 -28
  81. data/lib/path_coverage/card.rb +0 -14
  82. data/lib/path_coverage/html/file.html +0 -33
  83. data/lib/path_coverage/html/index.html +0 -29
  84. data/lib/path_coverage/html/settings.js +0 -50
  85. data/lib/path_coverage/html/side.js +0 -599
  86. data/lib/path_coverage/html/sort.js +0 -34
  87. data/lib/path_coverage/html/style.css +0 -484
  88. data/lib/path_coverage/html/tabs.js +0 -15
  89. data/lib/path_coverage/html/theme.js +0 -27
  90. data/lib/path_coverage/html_branch.rb +0 -30
  91. data/lib/path_coverage/html_cards.rb +0 -88
  92. data/lib/path_coverage/html_cells.rb +0 -71
  93. data/lib/path_coverage/html_file.rb +0 -123
  94. data/lib/path_coverage/html_index.rb +0 -128
  95. data/lib/path_coverage/html_index_head.rb +0 -29
  96. data/lib/path_coverage/html_labels.rb +0 -16
  97. data/lib/path_coverage/html_methods.rb +0 -66
  98. data/lib/path_coverage/html_nav.rb +0 -67
  99. data/lib/path_coverage/html_report.rb +0 -131
  100. data/lib/path_coverage/html_statements.rb +0 -186
  101. data/lib/path_coverage/html_tabs.rb +0 -26
  102. data/lib/path_coverage/html_template.rb +0 -26
@@ -1,186 +0,0 @@
1
- require 'cgi/escape'
2
- require_relative 'html_syntax'
3
- require_relative 'method_statements'
4
-
5
- module PathCoverage
6
- # One method's card in method mode, hidden in its file's page
7
- # until side.js moves it into the rail: a title row of the
8
- # method's name, its complexity, its size and the paths
9
- # taken, a row titling the columns, then a row per statement,
10
- # as MethodStatements gives them.
11
- module HtmlStatements
12
- # Example: ship, an if then a value, gives its title row,
13
- # the column titles, then an if row and a value row.
14
- # The card at site drawn from card, as the JSON report lists
15
- # it, as WithinMethods.card gives it: its name, its last line,
16
- # the ways through it and its rows. tree, when given, gives a
17
- # row's site's tree rows, folded under its row.
18
- def self.card(site, card, &)
19
- first, column = site.split(':').last(2)
20
- rows = card['rows']
21
- attrs = [
22
- %(id="paths-#{first}" data-first="#{first}"),
23
- %(data-col="#{column}" data-last="#{card['last']}"),
24
- %(data-status="#{status(card)}" hidden="hidden")
25
- ].join(' ')
26
- head = title_row(first, card, rows) + columns_row
27
- %(<div class="#{GRID}" #{attrs}>) +
28
- %(#{head}#{body(rows, &)}</div>)
29
- end
30
-
31
- # The classes of every card.
32
- GRID = 'pathgrid statements'.freeze
33
-
34
- # Example: FEE = (a ? 1 : 0) + (b ? 2 : 0) on line 1, scope
35
- # file, gives a card titled file, a ?: row each.
36
- # The card of the sites at the top level whose lines start at
37
- # site, drawn from card as card draws a def's, its name its
38
- # scope, eg file or its module, as a method's card is named
39
- # by its method, its last its lines' last; and marked
40
- # top-level, as it is no method's: a class no other part of
41
- # the page has, so no style of another's, eg the header's top
42
- # line's display, shows it when it is hidden.
43
- def self.top_card(site, card, &)
44
- card(site, card, &)
45
- .sub(%(class="#{GRID}"), %(class="#{GRID} top-level"))
46
- end
47
-
48
- # Each row's, a site's with the rows tree gives for that site,
49
- # headed as its row is, folded under it; rows as the JSON
50
- # report lists a card's.
51
- def self.body(rows, &tree)
52
- rows.map do |row|
53
- site = row['site']
54
- folded = tree&.call(site, row['top']) if site
55
- row_of(row, folds: !folded.nil?) + fold(site, folded)
56
- end.join
57
- end
58
-
59
- # card's status: covered when every row's taken is known and
60
- # is all of its paths, and its method was called, if it is a
61
- # method's; gaps otherwise, as a row not known may have one,
62
- # and a method never called, even of no rows, ran none of its
63
- # code.
64
- def self.status(card)
65
- rows = card['rows']
66
- done = rows.all? { |row| row['taken'] == row['paths'] } &&
67
- card['calls'] != 0
68
- done ? 'covered' : 'gaps'
69
- end
70
-
71
- # The row level with the def: card's name and how many times
72
- # it was called, *its ways, then how many of its rows' paths
73
- # were not taken, those of rows not known among them, and how
74
- # many were.
75
- def self.title_row(first, card, rows)
76
- seen = rows.map { _1['taken'] }.compact.sum
77
- paths = rows.map { _1['paths'] }
78
- cells = [
79
- "*#{card['ways']}",
80
- (MethodStatements.size(paths) - seen).to_s, seen.to_s
81
- ]
82
- attrs = %(class="prow calls" data-line="#{first}")
83
- row(attrs, title_label(card), cells)
84
- end
85
-
86
- # The label of card's title row: its name, escaped, then how
87
- # many times its method was called.
88
- def self.title_label(card)
89
- CGI.escapeHTML(card['name'].to_s) + call_count(card['calls'])
90
- end
91
-
92
- # Example: 3 as <span class="call-count">&times;3</span>.
93
- # How many times a method was called, after its name, a gap,
94
- # never, for 0; none for a top card, or when not known.
95
- def self.call_count(calls)
96
- return '' if calls.nil?
97
-
98
- css = calls.zero? ? 'call-count never' : 'call-count'
99
- %(<span class="#{css}">&times;#{calls}</span>)
100
- end
101
-
102
- # The row naming the not taken and taken columns.
103
- def self.columns_row
104
- cells = ['', 'not taken', 'taken']
105
- row('class="prow columns"', 'line:col', cells)
106
- end
107
-
108
- # One statement's row, as the JSON report lists it: its
109
- # line:column, its at, its top, how many of its paths were
110
- # not taken, and how many were, ? for both when not known. A
111
- # site's row is marked as one, so a click on it can open its
112
- # tree; when it folds a tree, its arrow, left of its
113
- # line:column, shows whether the fold is open.
114
- def self.row_of(row, folds: false)
115
- count = row['taken']
116
- counts = count ? [row['paths'] - count, count] : %w[? ?]
117
- cells = [top(row['top']), *counts.map(&:to_s)]
118
- css = row['site'] ? 'prow site' : 'prow'
119
- at = row['at']
120
- attrs = %(class="#{css}" data-line="#{Integer(at[/\d+/])}")
121
- lead = folds ? arrow(at) : ''
122
- row(attrs, at, cells, lead)
123
- end
124
-
125
- # Example: if, a site's top, as <span class="k">if</span>.
126
- # A row's top, text, coloured as the code pane colours the
127
- # code it quotes, eg if and return as keywords, as
128
- # HtmlSyntax.label colours it.
129
- def self.top(text)
130
- HtmlSyntax.label(text)
131
- end
132
-
133
- # The arrow left of the line:column at of a row, its glyph,
134
- # as style.css draws it, pointing down while its fold is shut
135
- # and up while it is open.
136
- def self.arrow(at)
137
- [
138
- '<button type="button" class="fold-arrow"',
139
- ' aria-expanded="false"',
140
- %( aria-label="Paths of #{at}"></button>)
141
- ].join
142
- end
143
-
144
- # Example: 19:04, a statement on line 19 at column 4.
145
- # statement's line:column, the column two digits so they
146
- # line up.
147
- def self.label(statement)
148
- format('%<line>d:%<column>02d',
149
- line: statement.line, column: statement.column)
150
- end
151
-
152
- # The fold under the row of site, hidden until the row is
153
- # clicked: tree, site's rows as its tree draws them. Empty
154
- # for a row with no tree.
155
- def self.fold(site, tree)
156
- return '' unless tree
157
-
158
- [
159
- %(<div class="fold" data-site="#{site}"),
160
- ' hidden="hidden"><div class="site" data-site="">',
161
- tree, '</div></div>'
162
- ].join
163
- end
164
-
165
- # The class each of a row's cells adds after pcell: none for
166
- # its top, then those colouring not taken and taken.
167
- CELLS = ['', ' not-taken', ' was-taken'].freeze
168
-
169
- # The class marking a not taken cell of 0, no gap, coloured
170
- # blue as taken is; none for any other cell, as a count of
171
- # paths not taken, or one not known, ?, is a gap.
172
- def self.none(cell, css)
173
- css == ' not-taken' && cell == '0' ? ' none' : ''
174
- end
175
-
176
- # A row div with attrs, lead, then its label, then a span
177
- # per cell.
178
- def self.row(attrs, label, cells, lead = '')
179
- spans = cells.zip(CELLS).map do |cell, css|
180
- %(<span class="pcell#{css}#{none(cell, css)}">#{cell}</span>)
181
- end
182
- %(<div #{attrs}>#{lead}<span class="plabel">#{label}</span>) +
183
- %(#{spans.join}</div>)
184
- end
185
- end
186
- end
@@ -1,26 +0,0 @@
1
- require 'cgi/escape'
2
-
3
- module PathCoverage
4
- # The index page's tab bar, one tab per table: All files,
5
- # then each group.
6
- module HtmlTabs
7
- # The tab bar of names, the first tab selected, each tab
8
- # controlling the table of the same index.
9
- def self.bar(names)
10
- tabs = names.each_with_index.map { |name, i| tab(name, i) }
11
- nav = %(<nav class="tabs" role="tablist" aria-label="Groups">)
12
- "#{nav}#{tabs.join}</nav>"
13
- end
14
-
15
- # The index-th tab, named name.
16
- def self.tab(name, index)
17
- selected = index.zero?
18
- [
19
- %(<button type="button" role="tab"),
20
- %( aria-selected="#{selected}"),
21
- %( aria-controls="files-#{index}">),
22
- CGI.escapeHTML(name), '</button>'
23
- ].join
24
- end
25
- end
26
- end
@@ -1,26 +0,0 @@
1
- module PathCoverage
2
- # The HTML report's page templates, styles and scripts, kept
3
- # as files beside this one, and the filling of their slots.
4
- module HtmlTemplate
5
- DIR = File.join(__dir__, 'html')
6
-
7
- # The text of one of the report's template, style or script
8
- # files.
9
- def self.asset(name)
10
- File.read(File.join(DIR, name))
11
- end
12
-
13
- # The page template named name, its {{style}} the report's
14
- # style sheet, and each other {{name}} values[name].
15
- def self.page(name, values)
16
- fill(asset(name), values.merge('style' => asset('style.css')))
17
- end
18
-
19
- # template with each {{name}} replaced by values[name].
20
- def self.fill(template, values)
21
- template.gsub(/\{\{(\w+)\}\}/) do
22
- values.fetch(Regexp.last_match(1))
23
- end
24
- end
25
- end
26
- end