path_coverage 0.3.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 (103) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +316 -177
  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 +199 -0
  11. data/lib/path_coverage/card_way_lists.rb +72 -0
  12. data/lib/path_coverage/card_ways.rb +196 -0
  13. data/lib/path_coverage/{html_syntax.rb → code_tokens.rb} +38 -25
  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} +18 -8
  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/fold_rows.rb +140 -0
  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 +31 -16
  30. data/lib/path_coverage/kernel.rb +56 -57
  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 -17
  34. data/lib/path_coverage/kinds/chain.rb +40 -11
  35. data/lib/path_coverage/kinds/choice.rb +7 -10
  36. data/lib/path_coverage/kinds/contains.rb +43 -33
  37. data/lib/path_coverage/kinds/safe.rb +44 -46
  38. data/lib/path_coverage/kinds/write.rb +6 -12
  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 +94 -59
  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 +52 -29
  48. data/lib/path_coverage/manifest_disabled.rb +97 -0
  49. data/lib/path_coverage/manifest_folding.rb +66 -26
  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 +147 -139
  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 +61 -27
  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 +184 -44
  80. metadata +36 -29
  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 -470
  86. data/lib/path_coverage/html/sort.js +0 -34
  87. data/lib/path_coverage/html/style.css +0 -470
  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 -111
  92. data/lib/path_coverage/html_cells.rb +0 -66
  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 -23
  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 -166
  101. data/lib/path_coverage/html_tabs.rb +0 -26
  102. data/lib/path_coverage/html_template.rb +0 -26
  103. data/lib/path_coverage/html_tree.rb +0 -131
@@ -1,166 +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 of the def named name at site, its rows' taken as
15
- # MethodStatements.taken gives them, last its def's last
16
- # line. tree, when given, gives a row's site's tree rows,
17
- # folded under its row.
18
- def self.card(site, name, rows, taken, last, &)
19
- first, column = site.split(':').last(2)
20
- attrs = [
21
- %(id="paths-#{first}" data-first="#{first}"),
22
- %(data-col="#{column}" data-last="#{last}"),
23
- %(data-status="#{status(rows, taken)}" hidden="hidden")
24
- ].join(' ')
25
- head = title_row(first, name, rows, taken) + columns_row
26
- %(<div class="#{GRID}" #{attrs}>) +
27
- %(#{head}#{body(rows, taken, &)}</div>)
28
- end
29
-
30
- # The classes of every card.
31
- GRID = 'pathgrid statements'.freeze
32
-
33
- # Example: FEE = (a ? 1 : 0) + (b ? 2 : 0) on line 1, scope
34
- # file, gives a card titled file, a ?: row each.
35
- # The card of the sites at the top level whose lines start at
36
- # site, as card gives it, last its lines' last; titled by
37
- # scope, eg file or its module, as a method's card is by its
38
- # method, and marked top-level, as it is no method's: a class
39
- # no other part of the page has, so no style of another's, eg
40
- # the header's top line's display, shows it when it is
41
- # hidden.
42
- def self.top_card(site, scope, rows, taken, last, &)
43
- card(site, scope, rows, taken, last, &)
44
- .sub(%(class="#{GRID}"), %(class="#{GRID} top-level"))
45
- end
46
-
47
- # Each statement's row, a site's with the rows tree gives
48
- # for that site folded under it.
49
- def self.body(rows, taken, &tree)
50
- rows.zip(taken).map do |row, count|
51
- site = row.site
52
- folded = tree&.call(site) if site
53
- row_of(row, count, folds: !folded.nil?) + fold(row, folded)
54
- end.join
55
- end
56
-
57
- # covered when every row's taken is known and is all of its
58
- # paths; gaps otherwise, as a row not known may have one.
59
- def self.status(rows, taken)
60
- done = rows.zip(taken).all? { |row, count| count == row.paths }
61
- done ? 'covered' : 'gaps'
62
- end
63
-
64
- # The row level with the def: its name, *complexity, then
65
- # how many of its paths were not taken, those of rows not
66
- # known among them, and how many were.
67
- def self.title_row(first, name, rows, taken)
68
- seen = taken.compact.sum
69
- cells = [
70
- "*#{MethodStatements.complexity(rows)}",
71
- (MethodStatements.size(rows) - seen).to_s, seen.to_s
72
- ]
73
- attrs = %(class="prow calls" data-line="#{first}")
74
- row(attrs, CGI.escapeHTML(name.to_s), cells)
75
- end
76
-
77
- # The row naming the not taken and taken columns.
78
- def self.columns_row
79
- cells = ['', 'not taken', 'taken']
80
- row('class="prow columns"', 'line:col', cells)
81
- end
82
-
83
- # One statement's row: its line:column, the column two
84
- # digits so they line up, its top, how many of its paths
85
- # were not taken, and how many were, ? for both when not
86
- # known. A site's row is marked as one, so a click on it can
87
- # open its tree; when it folds a tree, its arrow, left of its
88
- # line:column, shows whether the fold is open.
89
- def self.row_of(statement, count, folds: false)
90
- counts = count ? [statement.paths - count, count] : %w[? ?]
91
- cells = [top(statement), *counts.map(&:to_s)]
92
- css = statement.site ? 'prow site' : 'prow'
93
- attrs = %(class="#{css}" data-line="#{statement.line}")
94
- lead = folds ? arrow(statement) : ''
95
- row(attrs, label(statement), cells, lead)
96
- end
97
-
98
- # Example: if, a site's top, as <span class="k">if</span>.
99
- # statement's top, coloured as the code pane colours the
100
- # code it quotes, eg if, def and return as keywords; but
101
- # value and (), which name kinds of statement and quote no
102
- # code, escaped and plain.
103
- def self.top(statement)
104
- text = statement.top
105
- return CGI.escapeHTML(text) if KINDS.include?(text)
106
-
107
- HtmlSyntax.fragment(text)
108
- end
109
-
110
- # The tops that name a kind of statement, quoting no code.
111
- KINDS = %w[value ()].freeze
112
-
113
- # The arrow left of a row's line:column, its glyph, as
114
- # style.css draws it, pointing down while its fold is shut
115
- # and up while it is open.
116
- def self.arrow(statement)
117
- [
118
- '<button type="button" class="fold-arrow"',
119
- ' aria-expanded="false"',
120
- %( aria-label="Paths of #{label(statement)}"></button>)
121
- ].join
122
- end
123
-
124
- # Example: 19:04, a statement on line 19 at column 4.
125
- # statement's line:column, the column two digits so they
126
- # line up.
127
- def self.label(statement)
128
- format('%<line>d:%<column>02d',
129
- line: statement.line, column: statement.column)
130
- end
131
-
132
- # The fold under statement's row, hidden until the row is
133
- # clicked: tree, its site's rows as its tree draws them.
134
- # Empty for a row with no tree.
135
- def self.fold(statement, tree)
136
- return '' unless tree
137
-
138
- [
139
- %(<div class="fold" data-site="#{statement.site}"),
140
- ' hidden="hidden"><div class="site" data-site="">',
141
- tree, '</div></div>'
142
- ].join
143
- end
144
-
145
- # The class each of a row's cells adds after pcell: none for
146
- # its top, then those colouring not taken and taken.
147
- CELLS = ['', ' not-taken', ' was-taken'].freeze
148
-
149
- # The class marking a not taken cell of 0, no gap, coloured
150
- # blue as taken is; none for any other cell, as a count of
151
- # paths not taken, or one not known, ?, is a gap.
152
- def self.none(cell, css)
153
- css == ' not-taken' && cell == '0' ? ' none' : ''
154
- end
155
-
156
- # A row div with attrs, lead, then its label, then a span
157
- # per cell.
158
- def self.row(attrs, label, cells, lead = '')
159
- spans = cells.zip(CELLS).map do |cell, css|
160
- %(<span class="pcell#{css}#{none(cell, css)}">#{cell}</span>)
161
- end
162
- %(<div #{attrs}>#{lead}<span class="plabel">#{label}</span>) +
163
- %(#{spans.join}</div>)
164
- end
165
- end
166
- 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
@@ -1,131 +0,0 @@
1
- require 'cgi/escape'
2
- require_relative 'condition'
3
- require_relative 'html_branch'
4
- require_relative 'html_cells'
5
- require_relative 'html_labels'
6
- require_relative 'html_syntax'
7
- require_relative 'kinds'
8
-
9
- module PathCoverage
10
- # The tree of a site, from SiteTree.of, as its row's fold in a
11
- # card shows it: a grid whose columns are the site's paths.
12
- module HtmlTree
13
- # A site's row, naming its operator and each path's count,
14
- # then the rows of its operands.
15
- def self.site_rows(site)
16
- counts = HtmlCells.counts(site[:counts])
17
- [row(at(site), operator(site), counts), *operand_rows(site, '')]
18
- end
19
-
20
- # SPIKE: the data-at attribute of a node located in its
21
- # source, '' for one that is not.
22
- def self.at(node)
23
- node[:at] ? %( data-at="#{node[:at].join(',')}") : ''
24
- end
25
-
26
- # The rows of a condition's operands, each branching from
27
- # its operator after indent; a nested condition's operands,
28
- # and those of an arm's condition, follow its own row,
29
- # indented under its branch. A leaf with sites inside it
30
- # branches as those sites, then the leaf, in the order they
31
- # run.
32
- def self.operand_rows(condition, indent)
33
- own = Kinds.of(condition[:operator]).rows(condition, indent)
34
- return own if own
35
-
36
- operands = unfolded(condition[:operands])
37
- last = operands.size - 1
38
- operands.each_with_index.flat_map do |operand, i|
39
- tip = i == last
40
- branch = indent + (tip ? HtmlBranch::ELL : HtmlBranch::TEE)
41
- under = indent + (tip ? HtmlBranch::GAP : HtmlBranch::BAR)
42
- node_rows(operand, branch, under, condition[:operator])
43
- end
44
- end
45
-
46
- # The rows of one operand of a condition whose operator is
47
- # choice, branching after branch, any operands of its own
48
- # indented to under.
49
- def self.node_rows(operand, branch, under, choice)
50
- if operand.key?(:arm)
51
- return arm_rows(operand, branch, under, choice)
52
- end
53
- return [operand_row(operand, branch)] unless operand[:operator]
54
-
55
- [subtree_row(operand, branch), *operand_rows(operand, under)]
56
- end
57
-
58
- # An arm's row: a ternary's, ? for then and : for else, an
59
- # arm holding a condition showing the condition's operator
60
- # and value, its operands below, a plain arm its text; an
61
- # if's named then or else, as its text is statements; its then
62
- # label marked as a name, as no then is written in its code,
63
- # where its else is. A plain arm marks the paths taking it.
64
- def self.arm_rows(arm, branch, under, choice)
65
- body = arm[:body]
66
- values = arm_cells(arm, body)
67
- named = STATEMENT_CHOICES.include?(choice) && arm[:arm] == :then
68
- text = HtmlLabels.arm(arm, choice, named)
69
- flag = named ? ' data-named=""' : ''
70
- lead = HtmlBranch.cell(branch) +
71
- %(<span class="arm" data-label=""#{flag}>#{text}</span>)
72
- row = row(%( data-arm=""#{at(arm)}), lead, values)
73
- body ? [row, *operand_rows(body, under)] : [row]
74
- end
75
-
76
- # The cells of arm's row: its body's values, when its body is
77
- # a condition; else a tick on each path that took it.
78
- def self.arm_cells(arm, body)
79
- return HtmlCells.of(body[:cells]) if body
80
-
81
- HtmlCells.of(arm[:cells], HtmlCells::TAKEN)
82
- end
83
-
84
- # operands with each node standing for the nodes its kind
85
- # unfolds it into, eg a leaf with sites inside it for those
86
- # sites, then the leaf; a leaf or an arm for itself.
87
- def self.unfolded(operands)
88
- operands.flat_map do |operand|
89
- operator = operand[:operator]
90
- operator ? Kinds.of(operator).unfold(operand) : [operand]
91
- end
92
- end
93
-
94
- # A nested condition's row: its branch, its operator, and
95
- # its value on each path.
96
- def self.subtree_row(condition, branch)
97
- lead = HtmlBranch.cell(branch) + operator(condition)
98
- attrs = %( data-subtree=""#{at(condition)})
99
- row(attrs, lead, HtmlCells.of(condition[:cells]))
100
- end
101
-
102
- # A row of the grid, with attrs, lead's cells naming it,
103
- # then values, its cells for each path.
104
- def self.row(attrs, lead, values)
105
- %(<div class="row"#{attrs}>#{lead}#{values}</div>)
106
- end
107
-
108
- # The cell naming a condition's operator, or its label when
109
- # it has one, eg select { for a site inside a leaf, coloured
110
- # as the code it is part of.
111
- def self.operator(condition)
112
- label = condition.fetch(:label) { condition[:operator] }
113
- name = HtmlSyntax.fragment(label)
114
- %(<span class="operator" data-operator="">#{name}</span>)
115
- end
116
-
117
- # One operand's row: its branch, text, coloured as the code it
118
- # is, and its outcome on each path.
119
- # An operand that is only called, eg owner at the end of
120
- # user&.account&.owner, has a tick on each path that called
121
- # it instead.
122
- def self.operand_row(operand, branch)
123
- text = HtmlSyntax.fragment(operand[:text].to_s)
124
- lead = HtmlBranch.cell(branch) +
125
- %(<span class="text" data-text="">#{text}</span>)
126
- attrs = %( data-operand=""#{at(operand)})
127
- names = operand[:called] ? HtmlCells::TAKEN : HtmlCells::OUTCOMES
128
- row(attrs, lead, HtmlCells.of(operand[:cells], names))
129
- end
130
- end
131
- end