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.
- checksums.yaml +4 -4
- data/README.md +286 -199
- data/exe/path_coverage_report +4 -0
- data/lib/path_coverage/call_trace.rb +88 -0
- data/lib/path_coverage/calls.rb +49 -43
- data/lib/path_coverage/card_context.rb +104 -0
- data/lib/path_coverage/card_forks.rb +44 -0
- data/lib/path_coverage/card_gaps.rb +125 -0
- data/lib/path_coverage/card_scopes.rb +37 -0
- data/lib/path_coverage/card_tree.rb +79 -66
- data/lib/path_coverage/card_way_lists.rb +72 -0
- data/lib/path_coverage/card_ways.rb +123 -67
- data/lib/path_coverage/{html_syntax.rb → code_tokens.rb} +35 -33
- data/lib/path_coverage/condition.rb +14 -14
- data/lib/path_coverage/configuration.rb +7 -4
- data/lib/path_coverage/configuration_limits.rb +52 -0
- data/lib/path_coverage/configuration_paths.rb +7 -7
- data/lib/path_coverage/console_summary.rb +24 -22
- data/lib/path_coverage/{site.rb → decision.rb} +2 -2
- data/lib/path_coverage/decision_locations.rb +76 -0
- data/lib/path_coverage/{site_paths.rb → decision_paths.rb} +13 -11
- data/lib/path_coverage/{site_tree.rb → decision_tree.rb} +25 -16
- data/lib/path_coverage/fold_branches.rb +18 -0
- data/lib/path_coverage/fold_cells.rb +42 -0
- data/lib/path_coverage/{html_tree.rb → fold_rows.rb} +42 -71
- data/lib/path_coverage/gaps.rb +33 -15
- data/lib/path_coverage/json_reader.rb +54 -19
- data/lib/path_coverage/json_reports.rb +102 -0
- data/lib/path_coverage/json_writer.rb +27 -12
- data/lib/path_coverage/kernel.rb +56 -58
- data/lib/path_coverage/kinds/base.rb +16 -16
- data/lib/path_coverage/kinds/block.rb +16 -15
- data/lib/path_coverage/kinds/case.rb +14 -12
- data/lib/path_coverage/kinds/chain.rb +40 -11
- data/lib/path_coverage/kinds/choice.rb +4 -3
- data/lib/path_coverage/kinds/contains.rb +40 -32
- data/lib/path_coverage/kinds/safe.rb +38 -26
- data/lib/path_coverage/kinds/write.rb +6 -6
- data/lib/path_coverage/kinds.rb +2 -2
- data/lib/path_coverage/leaving.rb +44 -0
- data/lib/path_coverage/loop_forks.rb +57 -0
- data/lib/path_coverage/loop_nodes.rb +55 -0
- data/lib/path_coverage/manifest.rb +92 -58
- data/lib/path_coverage/manifest_blocks.rb +5 -26
- data/lib/path_coverage/manifest_case.rb +2 -2
- data/lib/path_coverage/manifest_chains.rb +8 -8
- data/lib/path_coverage/manifest_choices.rb +23 -20
- data/lib/path_coverage/manifest_disabled.rb +97 -0
- data/lib/path_coverage/manifest_folding.rb +43 -40
- data/lib/path_coverage/manifest_ignoring.rb +6 -6
- data/lib/path_coverage/manifest_writes.rb +11 -10
- data/lib/path_coverage/measured_by.rb +20 -0
- data/lib/path_coverage/merge.rb +7 -7
- data/lib/path_coverage/method_loops.rb +128 -0
- data/lib/path_coverage/method_statements.rb +130 -127
- data/lib/path_coverage/method_ways.rb +142 -0
- data/lib/path_coverage/paths_report.rb +16 -16
- data/lib/path_coverage/recorder.rb +57 -36
- data/lib/path_coverage/recorder_blocks.rb +17 -17
- data/lib/path_coverage/recorder_cases.rb +12 -11
- data/lib/path_coverage/recorder_chains.rb +12 -12
- data/lib/path_coverage/recorder_writes.rb +9 -9
- data/lib/path_coverage/render.rb +58 -51
- data/lib/path_coverage/result.rb +32 -31
- data/lib/path_coverage/rewriter.rb +39 -27
- data/lib/path_coverage/rewriter_nested.rb +13 -13
- data/lib/path_coverage/runs_report.rb +84 -0
- data/lib/path_coverage/source_lines.rb +16 -16
- data/lib/path_coverage/source_report.rb +100 -0
- data/lib/path_coverage/stable_leaves.rb +162 -0
- data/lib/path_coverage/statement_arms.rb +31 -30
- data/lib/path_coverage/summary.rb +4 -62
- data/lib/path_coverage/totals.rb +10 -8
- data/lib/path_coverage/version.rb +1 -1
- data/lib/path_coverage/walk.rb +106 -0
- data/lib/path_coverage/way_algebras.rb +127 -0
- data/lib/path_coverage/ways_report.rb +91 -0
- data/lib/path_coverage/ways_totals.rb +46 -0
- data/lib/path_coverage/within_methods.rb +135 -80
- metadata +33 -28
- data/lib/path_coverage/card.rb +0 -14
- data/lib/path_coverage/html/file.html +0 -33
- data/lib/path_coverage/html/index.html +0 -29
- data/lib/path_coverage/html/settings.js +0 -50
- data/lib/path_coverage/html/side.js +0 -599
- data/lib/path_coverage/html/sort.js +0 -34
- data/lib/path_coverage/html/style.css +0 -484
- data/lib/path_coverage/html/tabs.js +0 -15
- data/lib/path_coverage/html/theme.js +0 -27
- data/lib/path_coverage/html_branch.rb +0 -30
- data/lib/path_coverage/html_cards.rb +0 -88
- data/lib/path_coverage/html_cells.rb +0 -71
- data/lib/path_coverage/html_file.rb +0 -123
- data/lib/path_coverage/html_index.rb +0 -128
- data/lib/path_coverage/html_index_head.rb +0 -29
- data/lib/path_coverage/html_labels.rb +0 -16
- data/lib/path_coverage/html_methods.rb +0 -66
- data/lib/path_coverage/html_nav.rb +0 -67
- data/lib/path_coverage/html_report.rb +0 -131
- data/lib/path_coverage/html_statements.rb +0 -186
- data/lib/path_coverage/html_tabs.rb +0 -26
- data/lib/path_coverage/html_template.rb +0 -26
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
require_relative 'kinds'
|
|
2
|
-
|
|
3
|
-
module PathCoverage
|
|
4
|
-
# The cells of a row of a site's tree on a file's page, one per
|
|
5
|
-
# path. A cell says what its path did: its text a letter, eg T
|
|
6
|
-
# or F, or empty with a mark CSS draws, eg a tick; with text to
|
|
7
|
-
# show on hover when its mark alone may not say enough.
|
|
8
|
-
module HtmlCells
|
|
9
|
-
# [text, mark, hover] of a leaf's or a condition's cell, by
|
|
10
|
-
# the value it took on the path: a letter for each value
|
|
11
|
-
# but a &. receiver's, which is a mark, present or absent,
|
|
12
|
-
# hovering as not nil or nil.
|
|
13
|
-
OUTCOMES = {
|
|
14
|
-
true => ['T'], false => ['F'], nil => [''],
|
|
15
|
-
ITEMS[0] => ['0'], ITEMS[1] => ['1'], ITEMS[2] => ['*'],
|
|
16
|
-
ANSWERS[0] => ['T'], ANSWERS[1] => ['F'], ANSWERS[2] => ['TF'],
|
|
17
|
-
PRESENCE[0] => ['', 'present', PRESENCE[0]],
|
|
18
|
-
PRESENCE[1] => ['', 'absent', PRESENCE[1]]
|
|
19
|
-
}.freeze
|
|
20
|
-
|
|
21
|
-
# [text, mark] of a ternary's arm's cell: taken on a path
|
|
22
|
-
# that took it, else blank.
|
|
23
|
-
TAKEN = { true => ['', 'taken'], false => [''] }.freeze
|
|
24
|
-
|
|
25
|
-
# [text, mark] of the cell of an arm that returns or raises:
|
|
26
|
-
# leaves on a path that took it, so left the method there,
|
|
27
|
-
# else blank.
|
|
28
|
-
LEAVES = { true => ['', 'leaves'], false => [''] }.freeze
|
|
29
|
-
|
|
30
|
-
# The cells of values, each named as names gives it.
|
|
31
|
-
def self.of(values, names = OUTCOMES)
|
|
32
|
-
values.map { |value| cell(*names[value]) }.join
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
# One cell: text, and its mark and its hover, when it has
|
|
36
|
-
# them.
|
|
37
|
-
def self.cell(text, mark = nil, hover = nil)
|
|
38
|
-
attrs = +'class="cell" data-cell=""'
|
|
39
|
-
attrs << %( data-mark="#{mark}") if mark
|
|
40
|
-
attrs << %( data-hover="#{hover}") if hover
|
|
41
|
-
%(<span #{attrs}>#{text}</span>)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
# Example: counts 0, 2 and 1284 give 0, * and *.
|
|
45
|
-
# One cell per path: 0 for a path never taken, marked as a
|
|
46
|
-
# gap, * for one taken any number of times, as whether it
|
|
47
|
-
# was taken is what counts; how many times shows on hover,
|
|
48
|
-
# so a count in the thousands never widens the cell.
|
|
49
|
-
def self.counts(counts)
|
|
50
|
-
counts.map do |count|
|
|
51
|
-
css, mark = MARKS[count.zero?]
|
|
52
|
-
hover = times(count)
|
|
53
|
-
%(<span class="#{css}" data-count="" data-hover="#{hover}">) +
|
|
54
|
-
%(#{mark}</span>)
|
|
55
|
-
end.join
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
# [class, mark] of a path's count cell, by whether its count
|
|
59
|
-
# is zero.
|
|
60
|
-
MARKS = { true => ['count never', '0'],
|
|
61
|
-
false => ['count', '*'] }.freeze
|
|
62
|
-
|
|
63
|
-
# Example: 1 gives 1 time, 1284 gives 1,284 times.
|
|
64
|
-
# How many times a path was taken, as its mark's hover reads
|
|
65
|
-
# it, its thousands apart, so a big count still reads.
|
|
66
|
-
def self.times(count)
|
|
67
|
-
digits = count.to_s.reverse.scan(/\d{1,3}/).join(',').reverse
|
|
68
|
-
"#{digits} #{count == 1 ? 'time' : 'times'}"
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
require 'cgi/escape'
|
|
2
|
-
require_relative 'card'
|
|
3
|
-
require_relative 'html_methods'
|
|
4
|
-
require_relative 'html_nav'
|
|
5
|
-
require_relative 'html_syntax'
|
|
6
|
-
require_relative 'html_template'
|
|
7
|
-
|
|
8
|
-
module PathCoverage
|
|
9
|
-
# One covered file's HTML page: its source beside the rail of
|
|
10
|
-
# its cards, as Card gives them, one open at a time. A method's
|
|
11
|
-
# def number opens its card; a site outside every method has
|
|
12
|
-
# one button over its lines' numbers that opens their top card.
|
|
13
|
-
module HtmlFile
|
|
14
|
-
# The whole page for the file at path (relative to root),
|
|
15
|
-
# written at files/<path>.html, so it links back to the
|
|
16
|
-
# index one folder up for each folder in that.
|
|
17
|
-
def self.page(path, lines, cards = [])
|
|
18
|
-
HtmlTemplate.page(
|
|
19
|
-
'file.html',
|
|
20
|
-
'path' => CGI.escapeHTML(path),
|
|
21
|
-
'index' => "#{'../' * (path.count('/') + 1)}index.html",
|
|
22
|
-
'script' => script,
|
|
23
|
-
'rail' => cards.map(&:html).join("\n"),
|
|
24
|
-
'jumps' => HtmlNav.jumps(cards),
|
|
25
|
-
'listing' => listing(lines, cards)
|
|
26
|
-
)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
# The page's script: its rail's behaviour, then its settings
|
|
30
|
-
# and its theme button.
|
|
31
|
-
def self.script
|
|
32
|
-
%w[side.js settings.js theme.js].map do |name|
|
|
33
|
-
HtmlTemplate.asset(name)
|
|
34
|
-
end.join
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
# The source listing of lines, as SourceLines.of gives them,
|
|
38
|
-
# marked with the methods of cards: a row per line, but one
|
|
39
|
-
# row over all the lines of a site outside every method.
|
|
40
|
-
def self.listing(lines, cards = [])
|
|
41
|
-
methods = HtmlMethods.of(cards)
|
|
42
|
-
tops = cards.select(&:top).to_h { |card| [card.first, card] }
|
|
43
|
-
rows = lines.chunk { |line| row_key(line, methods) }
|
|
44
|
-
body = rows.map do |key, row|
|
|
45
|
-
next line(row[0], cards, methods) unless key.is_a?(Range)
|
|
46
|
-
|
|
47
|
-
loose_block(row, cards, tops[key.begin])
|
|
48
|
-
end
|
|
49
|
-
%(<div class="code">\n#{body.join("\n")}\n</div>)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
# The span of line's site when it is outside every method, so
|
|
53
|
-
# its lines share one row; else line's own number.
|
|
54
|
-
def self.row_key(line, methods)
|
|
55
|
-
span = line[:span]
|
|
56
|
-
loose = span && HtmlMethods.loose?(methods, span.begin)
|
|
57
|
-
loose ? span : line[:number]
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
# A line of its own, after its gutter, folded when it is in a
|
|
61
|
-
# method's body.
|
|
62
|
-
def self.line(line, cards, methods)
|
|
63
|
-
number = line[:number]
|
|
64
|
-
cell = HtmlNav.cell([number], cards)
|
|
65
|
-
folded = HtmlMethods.folded?(methods, number)
|
|
66
|
-
css = folded ? 'line method-folded' : 'line'
|
|
67
|
-
parts = number(number, methods) + code(line, methods)
|
|
68
|
-
%(<div class="#{css}">#{cell}#{parts}</div>)
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
# The lines of a site outside every method after their gutter:
|
|
72
|
-
# one button over all their numbers, opening their top card,
|
|
73
|
-
# top, and how many sites it opens when that is two or more,
|
|
74
|
-
# beside their code.
|
|
75
|
-
def self.loose_block(lines, cards, top)
|
|
76
|
-
numbers = lines.map { |line| line[:number] }
|
|
77
|
-
cell = HtmlNav.cell(numbers, cards)
|
|
78
|
-
spans = numbers.map { |number| number(number, []) }.join
|
|
79
|
-
button = button(lines[0], top, site_count(top) + spans)
|
|
80
|
-
srcs = lines.map { |line| code(line, []) }.join
|
|
81
|
-
%(<div class="block">#{cell}#{button}) +
|
|
82
|
-
%(<div class="srcs">#{srcs}</div></div>)
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
# The count of a top card's sites, shown only for two or more.
|
|
86
|
-
def self.site_count(top)
|
|
87
|
-
sites = top ? top.sites : 0
|
|
88
|
-
return '' if sites < 2
|
|
89
|
-
|
|
90
|
-
%(<span class="site-count" data-site-count="">#{sites}</span>)
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
# The button over a loose site's numbers, wearing its top
|
|
94
|
-
# card's status, else its first line's, closed until its card
|
|
95
|
-
# opens.
|
|
96
|
-
def self.button(first, top, numbers)
|
|
97
|
-
status = top ? top.status : first[:status]
|
|
98
|
-
[
|
|
99
|
-
%(<button type="button" class="lnum loose"),
|
|
100
|
-
%( data-status="#{status}" aria-expanded="false"),
|
|
101
|
-
%( aria-controls="paths-#{first[:number]}">),
|
|
102
|
-
numbers, '</button>'
|
|
103
|
-
].join
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
# One line's number, the target of a link to #L<number>; a
|
|
107
|
-
# def's marked to open its method's card.
|
|
108
|
-
def self.number(number, methods)
|
|
109
|
-
css = HtmlMethods.number_attributes(methods, number)
|
|
110
|
-
attributes = %(#{css} id="L#{number}" data-line="#{number}")
|
|
111
|
-
%(<span #{attributes}>#{number}</span>)
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
# One line's code, escaped, each of its tokens, if any, in a
|
|
115
|
-
# span of its colour's class, marked with its methods.
|
|
116
|
-
def self.code(line, methods)
|
|
117
|
-
number, plain = line.values_at(:number, :text)
|
|
118
|
-
text = HtmlSyntax.html(plain, line.fetch(:tokens, []))
|
|
119
|
-
css = HtmlMethods.src_attributes(methods, number, plain)
|
|
120
|
-
%(<span #{css} data-src="">#{text}</span>)
|
|
121
|
-
end
|
|
122
|
-
end
|
|
123
|
-
end
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
require 'cgi/escape'
|
|
2
|
-
require_relative 'html_index_head'
|
|
3
|
-
require_relative 'html_tabs'
|
|
4
|
-
require_relative 'html_template'
|
|
5
|
-
|
|
6
|
-
module PathCoverage
|
|
7
|
-
# The HTML index page: one sortable row per covered file,
|
|
8
|
-
# each linking to that file's own page, then a Total row; with
|
|
9
|
-
# groups, one such table per tab.
|
|
10
|
-
module HtmlIndex
|
|
11
|
-
# The whole index page. rows are Summary.files rows and total
|
|
12
|
-
# their Summary.total. groups are [name, rows, total] for
|
|
13
|
-
# each group, each given a tab after All files; with none
|
|
14
|
-
# there is no tab bar, just the one table. Any operators
|
|
15
|
-
# ignored are named after the tables.
|
|
16
|
-
def self.page(rows, total, groups = [], ignored: [])
|
|
17
|
-
tables = [['All files', rows, total], *groups]
|
|
18
|
-
names = tables.map(&:first)
|
|
19
|
-
HtmlTemplate.page(
|
|
20
|
-
'index.html',
|
|
21
|
-
'script' => script(groups),
|
|
22
|
-
'tabs' => groups.empty? ? '' : HtmlTabs.bar(names),
|
|
23
|
-
'tables' => tables_of(tables),
|
|
24
|
-
'ignored' => ignored_line(ignored)
|
|
25
|
-
)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
# The paragraph naming the operators ignored, eg
|
|
29
|
-
# "Ignored: &&="; empty when none are.
|
|
30
|
-
def self.ignored_line(ignored)
|
|
31
|
-
return '' if ignored.empty?
|
|
32
|
-
|
|
33
|
-
text = CGI.escapeHTML("Ignored: #{ignored.join(', ')}")
|
|
34
|
-
%(<p class="ignored" data-ignored="">#{text}</p>)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
# Each of tables, [name, rows, total], as the table of its
|
|
38
|
-
# tab.
|
|
39
|
-
def self.tables_of(tables)
|
|
40
|
-
tables.each_with_index.map do |(_, rows, total), index|
|
|
41
|
-
table(index, rows, total)
|
|
42
|
-
end.join("\n")
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
# The page's script: its column sorting, with groups its tab
|
|
46
|
-
# switching, then its settings and its theme button.
|
|
47
|
-
def self.script(groups)
|
|
48
|
-
names = ['sort.js', *('tabs.js' unless groups.empty?),
|
|
49
|
-
'settings.js', 'theme.js']
|
|
50
|
-
names.map { |name| HtmlTemplate.asset(name) }.join
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
# The index-th tab's table of rows, total as its footer; any
|
|
54
|
-
# but the first starts hidden. Only the first, All files,
|
|
55
|
-
# gives its rows ids, as the others repeat its rows.
|
|
56
|
-
def self.table(index, rows, total)
|
|
57
|
-
anchored = index.zero?
|
|
58
|
-
body = rows.map { |row| row(row, anchored:) }.join("\n")
|
|
59
|
-
head = HtmlIndexHead.row
|
|
60
|
-
[
|
|
61
|
-
open_tag(index),
|
|
62
|
-
"<thead>\n#{head}\n</thead>",
|
|
63
|
-
"<tbody>\n#{body}\n</tbody>",
|
|
64
|
-
"<tfoot>\n#{total_row(total)}\n</tfoot>",
|
|
65
|
-
'</table>'
|
|
66
|
-
].join("\n")
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
# The opening tag of the index-th tab's table, which the tab
|
|
70
|
-
# of the same index controls; any but the first is hidden.
|
|
71
|
-
def self.open_tag(index)
|
|
72
|
-
hidden = index.zero? ? '' : ' hidden="hidden"'
|
|
73
|
-
id = %(id="files-#{index}")
|
|
74
|
-
%(<table class="files" #{id} role="tabpanel"#{hidden}>)
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
# The table row of one Summary.files row; each cell has a
|
|
78
|
-
# data-sort value for the page's column sorting. An anchored
|
|
79
|
-
# row has the id row-<path>, which the file's page links to.
|
|
80
|
-
def self.row(row, anchored: false)
|
|
81
|
-
path = CGI.escapeHTML(row[:path])
|
|
82
|
-
link = %(<a href="files/#{path}.html">#{path}</a>)
|
|
83
|
-
id = anchored ? %( id="row-#{path}") : ''
|
|
84
|
-
"<tr#{id}>#{cell(path, link)}#{counts(row).join}</tr>"
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
# The footer row: the sums over the table's files.
|
|
88
|
-
def self.total_row(total)
|
|
89
|
-
"<tr>#{cell('Total', 'Total')}#{counts(total).join}</tr>"
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
# The cells after the file's: its sites, then its total
|
|
93
|
-
# within each method.
|
|
94
|
-
def self.counts(row)
|
|
95
|
-
[cell(row[:sites], row[:sites]), *paths_cells(row[:methods])]
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
# Why a total of no paths shows no percent.
|
|
99
|
-
NONE = 'no method with two or more decisions'.freeze
|
|
100
|
-
|
|
101
|
-
# Three cells showing [taken, possible] paths, eg 3, / 6 and
|
|
102
|
-
# 50%, each sorted by its number, so they read 3 / 6 50%.
|
|
103
|
-
# With no paths to take, as in a group no file is in, or a
|
|
104
|
-
# file with no method of two or more decisions, the percent
|
|
105
|
-
# shows -, titled with NONE, saying why, with an empty sort
|
|
106
|
-
# value, which sort.js keeps last whichever way the column is
|
|
107
|
-
# sorted.
|
|
108
|
-
def self.paths_cells(pair)
|
|
109
|
-
taken, possible = pair
|
|
110
|
-
counts = [cell(taken, taken, css: 'taken'),
|
|
111
|
-
cell(possible, "/ #{possible}", css: 'of')]
|
|
112
|
-
none = cell('', '-', NONE, css: 'percent')
|
|
113
|
-
return [*counts, none] if possible.zero?
|
|
114
|
-
|
|
115
|
-
percent = (100.0 * taken / possible).round
|
|
116
|
-
[*counts, cell(percent, "#{percent}%", css: 'percent')]
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
# One table cell, sorted by sort_value, showing content,
|
|
120
|
-
# with title as its hover text and css as its class, each
|
|
121
|
-
# when there is one.
|
|
122
|
-
def self.cell(sort_value, content, title = nil, css: nil)
|
|
123
|
-
hover = title ? %( title="#{title}") : ''
|
|
124
|
-
klass = css ? %( class="#{css}") : ''
|
|
125
|
-
%(<td#{klass} data-sort="#{sort_value}"#{hover}>#{content}</td>)
|
|
126
|
-
end
|
|
127
|
-
end
|
|
128
|
-
end
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
module PathCoverage
|
|
2
|
-
# The heading row of the HTML index's files tables: File and
|
|
3
|
-
# Sites, then the taken, / of and % columns of each file's total
|
|
4
|
-
# within each method, every column sortable.
|
|
5
|
-
module HtmlIndexHead
|
|
6
|
-
# The class and label of each of a total's three columns.
|
|
7
|
-
PARTS = [%w[taken taken], ['of', '/ of'], %w[percent %]].freeze
|
|
8
|
-
|
|
9
|
-
# The heading row.
|
|
10
|
-
def self.row
|
|
11
|
-
fixed = [
|
|
12
|
-
heading('', 0, 'text', 'File'),
|
|
13
|
-
heading(' class="num"', 1, 'number', 'Sites')
|
|
14
|
-
]
|
|
15
|
-
parts = PARTS.each_with_index.map do |(css, label), i|
|
|
16
|
-
heading(%( class="#{css}"), 2 + i, 'number', label)
|
|
17
|
-
end
|
|
18
|
-
"<tr>\n#{(fixed + parts).join("\n")}\n</tr>"
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
# A sortable heading, attrs its th's, sorting the column-th
|
|
22
|
-
# column as type, its button showing label.
|
|
23
|
-
def self.heading(attrs, column, type, label)
|
|
24
|
-
data = %(data-column="#{column}" data-type="#{type}")
|
|
25
|
-
button = %(<button type="button" #{data}>#{label}</button>)
|
|
26
|
-
%(<th#{attrs} aria-sort="none">#{button}</th>)
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
require_relative 'condition'
|
|
2
|
-
require_relative 'html_syntax'
|
|
3
|
-
require_relative 'kinds'
|
|
4
|
-
|
|
5
|
-
module PathCoverage
|
|
6
|
-
# The labels of a site's tree on a file's page, coloured as the
|
|
7
|
-
# code they quote.
|
|
8
|
-
module HtmlLabels
|
|
9
|
-
# The label of an arm of a ternary, the one kind whose fold
|
|
10
|
-
# shows its arms, as Choice names it, as HTML, coloured as
|
|
11
|
-
# HtmlSyntax.ternary_arm has it.
|
|
12
|
-
def self.arm(arm)
|
|
13
|
-
HtmlSyntax.ternary_arm(Kinds::Choice.arm_label(arm))
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
module PathCoverage
|
|
2
|
-
# What each line of a file's page shows of the methods around
|
|
3
|
-
# it, from its cards, as Card gives them: a method's lines
|
|
4
|
-
# marked for CSS to draw its stripe and band, its def's number
|
|
5
|
-
# marked to open its card, and its body's rows folded under its
|
|
6
|
-
# def line until then. A top card, of sites outside every def,
|
|
7
|
-
# is no method's.
|
|
8
|
-
module HtmlMethods
|
|
9
|
-
# The cards of cards that are methods'.
|
|
10
|
-
def self.of(cards)
|
|
11
|
-
cards.reject(&:top)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
# Example: line 3, f's def at column 2, gives
|
|
15
|
-
# class="src in-method def-line" data-method-status="covered"
|
|
16
|
-
# style="--def-col: 2; --def-end: 15".
|
|
17
|
-
# The attributes of the code of line number, its text text:
|
|
18
|
-
# in a method, its innermost one's status and def's column,
|
|
19
|
-
# marked as its def line, with its text's length, or as its
|
|
20
|
-
# last line when it is; plain in none.
|
|
21
|
-
def self.src_attributes(methods, number, text)
|
|
22
|
-
holders = methods.select { |card| card.holds?(number) }
|
|
23
|
-
return 'class="src"' if holders.empty?
|
|
24
|
-
|
|
25
|
-
inner = holders.max_by(&:first)
|
|
26
|
-
css = ['src', 'in-method', *marks(methods, number)].join(' ')
|
|
27
|
-
style = "--def-col: #{inner.column}"
|
|
28
|
-
style += "; --def-end: #{text.length}" if inner.first == number
|
|
29
|
-
%(class="#{css}" data-method-status="#{inner.status}") +
|
|
30
|
-
%( style="#{style}")
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
# The marks of a line that is some method's first or last.
|
|
34
|
-
def self.marks(methods, number)
|
|
35
|
-
firsts = methods.map(&:first)
|
|
36
|
-
lasts = methods.map(&:last)
|
|
37
|
-
[('def-line' if firsts.include?(number)),
|
|
38
|
-
('method-end' if lasts.include?(number))].compact
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
# The attributes a def's number adds, opening its method's
|
|
42
|
-
# card, which starts closed: none on any other line.
|
|
43
|
-
def self.number_attributes(methods, number)
|
|
44
|
-
card = methods.find { |each| each.first == number }
|
|
45
|
-
return 'class="lineno"' unless card
|
|
46
|
-
|
|
47
|
-
closed = 'aria-expanded="false"'
|
|
48
|
-
%(class="lineno mdef" data-status="#{card.status}" #{closed})
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
# True when line number's row starts folded: in a method's
|
|
52
|
-
# body, after its def line. A row in a method is one line, so
|
|
53
|
-
# a def line's row is never folded under its own def.
|
|
54
|
-
def self.folded?(methods, number)
|
|
55
|
-
methods.any? do |card|
|
|
56
|
-
((card.first + 1)..card.last).cover?(number)
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
# True when line number is in no method, so its site's button
|
|
61
|
-
# opens its lines' top card.
|
|
62
|
-
def self.loose?(methods, number)
|
|
63
|
-
methods.none? { |card| card.holds?(number) }
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
end
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
module PathCoverage
|
|
2
|
-
# The ways around a file's page, from its cards, as Card gives
|
|
3
|
-
# them: the header's row of jumps to each card with gaps, and
|
|
4
|
-
# the arrows in the gutter between the cards of each status.
|
|
5
|
-
module HtmlNav
|
|
6
|
-
# Each status's arrows, gaps first, and how a label names it.
|
|
7
|
-
KINDS = { 'gaps' => 'with gaps', 'covered' => 'covered' }.freeze
|
|
8
|
-
|
|
9
|
-
# The header's row of jumps, labelled Gaps, to the first line
|
|
10
|
-
# of each card with gaps, in line order; marked empty when
|
|
11
|
-
# there are none, so the header keeps its height.
|
|
12
|
-
def self.jumps(cards)
|
|
13
|
-
firsts = firsts(cards, 'gaps')
|
|
14
|
-
links = firsts.map { |first| jump(first) }
|
|
15
|
-
empty = links.empty? ? ' data-empty=""' : ''
|
|
16
|
-
name = '<span class="jump-label">Gaps</span>'
|
|
17
|
-
list = %(<div class="jump-list"#{empty}>#{name}#{links.join})
|
|
18
|
-
%(<nav class="jumps" aria-label="Cards">#{list}</div></nav>)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
# One jump to a card with gaps at line first.
|
|
22
|
-
def self.jump(first)
|
|
23
|
-
attributes = %(data-status="gaps" href="#L#{first}")
|
|
24
|
-
%(<a class="jump" #{attributes}>#{first}</a>)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
# The first lines of the cards of status, in line order.
|
|
28
|
-
def self.firsts(cards, status)
|
|
29
|
-
cards.select { |card| card.status == status }.map(&:first).sort
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
# The gutter of the row of numbers: by each card's first line,
|
|
33
|
-
# an arrow to the card of its status before it, and one to the
|
|
34
|
-
# one after, wrapping round at either end; empty on every
|
|
35
|
-
# other row, so the numbers stay aligned.
|
|
36
|
-
def self.cell(numbers, cards)
|
|
37
|
-
links = KINDS.keys.flat_map do |status|
|
|
38
|
-
firsts = firsts(cards, status)
|
|
39
|
-
(firsts & numbers).flat_map do |first|
|
|
40
|
-
arrows(firsts, first, status)
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
%(<span class="nav" data-nav="">#{links.join}</span>)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
# The arrows by the card of status at line first to those
|
|
47
|
-
# either side of it in firsts, the first lines of the cards of
|
|
48
|
-
# its status.
|
|
49
|
-
def self.arrows(firsts, first, status)
|
|
50
|
-
index = firsts.index(first)
|
|
51
|
-
following = firsts[(index + 1) % firsts.size]
|
|
52
|
-
[arrow('prev', firsts[index - 1], status),
|
|
53
|
-
arrow('next', following, status)]
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
# Each arrow's way and how its label names it.
|
|
57
|
-
WAYS = { 'prev' => 'Previous', 'next' => 'Next' }.freeze
|
|
58
|
-
|
|
59
|
-
# One arrow, way prev or next, to the card of status at line;
|
|
60
|
-
# CSS draws its glyph, in its status's colour.
|
|
61
|
-
def self.arrow(way, line, status)
|
|
62
|
-
label = "#{WAYS[way]} card #{KINDS[status]}, line #{line}"
|
|
63
|
-
%(<a data-#{way}="" data-status="#{status}" href="#L#{line}") +
|
|
64
|
-
%( aria-label="#{label}"></a>)
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
end
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
require 'fileutils'
|
|
2
|
-
require_relative 'html_cards'
|
|
3
|
-
require_relative 'html_file'
|
|
4
|
-
require_relative 'html_index'
|
|
5
|
-
require_relative 'html_syntax'
|
|
6
|
-
require_relative 'site_tree'
|
|
7
|
-
require_relative 'source_lines'
|
|
8
|
-
require_relative 'summary'
|
|
9
|
-
require_relative 'within_methods'
|
|
10
|
-
|
|
11
|
-
module PathCoverage
|
|
12
|
-
# The :html reporter: index.html, and files/<path>.html for
|
|
13
|
-
# each covered file, written to the configuration's
|
|
14
|
-
# output_dir.
|
|
15
|
-
module HtmlReport
|
|
16
|
-
# Writes every page. recorded is [site_paths, reached]:
|
|
17
|
-
# site_paths, like operands, as Result gives them, holding
|
|
18
|
-
# every site in files; reached as Recorder#reached gives it,
|
|
19
|
-
# nil when not known. files is { full path => {source:,
|
|
20
|
-
# sites:} } for each covered file, as the kernel parsed it.
|
|
21
|
-
# The files dir is emptied first, so it holds no page for a
|
|
22
|
-
# file no longer covered.
|
|
23
|
-
def self.write(operands, files, config, recorded)
|
|
24
|
-
site_paths, reached = recorded
|
|
25
|
-
dir = config.output_dir
|
|
26
|
-
FileUtils.rm_rf("#{dir}/files")
|
|
27
|
-
cards = WithinMethods.cards(files, config, site_paths, reached)
|
|
28
|
-
index = index(config, site_paths, cards)
|
|
29
|
-
File.write("#{dir}/index.html", index)
|
|
30
|
-
write_pages(operands, files, config, recorded)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
# Writes each covered file's page, recorded as write has it,
|
|
34
|
-
# with its methods' cards.
|
|
35
|
-
def self.write_pages(operands, files, config, recorded)
|
|
36
|
-
files.each do |full_path, parsed|
|
|
37
|
-
path = config.relative(full_path)
|
|
38
|
-
cards = HtmlCards.methods(path, parsed, recorded)
|
|
39
|
-
out = "#{config.output_dir}/files/#{path}.html"
|
|
40
|
-
write_page(out, path, parsed, [operands, recorded[0]], cards)
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
# The index page: a row per file of its totals within each
|
|
45
|
-
# decision, and, when cards are given, as they are when
|
|
46
|
-
# methods are measured, within each method too, its defs'
|
|
47
|
-
# cards added up; then their Total row. With groups
|
|
48
|
-
# configured, each group, and the files in none, get a tab
|
|
49
|
-
# of their own too. Any operators config ignored are named
|
|
50
|
-
# after them.
|
|
51
|
-
def self.index(config, site_paths, cards)
|
|
52
|
-
rows = Summary.files(site_paths, cards)
|
|
53
|
-
groups = config.groups
|
|
54
|
-
tabs = groups.empty? ? [] : Summary.groups(rows, groups)
|
|
55
|
-
ignored = config.ignored
|
|
56
|
-
HtmlIndex.page(rows, Summary.total(rows), tabs, ignored:)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
# Writes one file's page to out, from its sites' operand
|
|
60
|
-
# counts and paths, with cards, its methods', then a card for
|
|
61
|
-
# each span of its sites at the top level.
|
|
62
|
-
def self.write_page(out, path, parsed,
|
|
63
|
-
(operands, site_paths), cards)
|
|
64
|
-
source, sites = parsed.values_at(:source, :sites)
|
|
65
|
-
plain = SourceLines.of(source, sites, operands)
|
|
66
|
-
lines = coloured(source, plain)
|
|
67
|
-
tops = HtmlCards.tops(path, parsed, [operands, site_paths])
|
|
68
|
-
page = HtmlFile.page(path, lines, cards + tops)
|
|
69
|
-
FileUtils.mkdir_p(File.dirname(out))
|
|
70
|
-
File.write(out, page)
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
# lines, as SourceLines.of gives them for source, each with
|
|
74
|
-
# its coloured tokens, as HtmlSyntax.of gives them.
|
|
75
|
-
def self.coloured(source, lines)
|
|
76
|
-
tokens = HtmlSyntax.of(source)
|
|
77
|
-
lines.map do |line|
|
|
78
|
-
line.merge(tokens: tokens.fetch(line[:number], []))
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
# simplecov:disable
|
|
83
|
-
# SPIKE: tree with an at: of [line, column, line, column]
|
|
84
|
-
# on it and on each of its operands: a leaf's from its byte
|
|
85
|
-
# range, a condition's and an arm's from its extent, the
|
|
86
|
-
# whole of it as written. Columns count characters, not
|
|
87
|
-
# bytes. A node past the condition's operands, eg owner at
|
|
88
|
-
# the end of user&.account&.owner, is kept as it is.
|
|
89
|
-
def self.located(source, condition, tree)
|
|
90
|
-
pairs = condition.operands.zip(tree[:operands])
|
|
91
|
-
operands = pairs.map do |operand, node|
|
|
92
|
-
located_operand(source, operand, node)
|
|
93
|
-
end
|
|
94
|
-
rest = tree[:operands].drop(pairs.size)
|
|
95
|
-
tree.merge(at: at(source, condition.extent),
|
|
96
|
-
operands: operands + rest)
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
# SPIKE: the node of operand with its at:, as located gives
|
|
100
|
-
# a condition's, an arm's or a leaf's.
|
|
101
|
-
def self.located_operand(source, operand, node)
|
|
102
|
-
case operand
|
|
103
|
-
when Condition then located(source, operand, node)
|
|
104
|
-
when Arm then located_arm(source, operand, node)
|
|
105
|
-
else node.merge(at: at(source, operand))
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
# An arm's node with its at:, nil for an arm with no
|
|
110
|
-
# statements, and its body's tree located.
|
|
111
|
-
def self.located_arm(source, arm, node)
|
|
112
|
-
body = arm.body ? located(source, arm.body, node[:body]) : nil
|
|
113
|
-
at = arm.extent ? at(source, arm.extent) : nil
|
|
114
|
-
node.merge(at:, body:)
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
# [line, column, line, column] of the byte range in source.
|
|
118
|
-
def self.at(source, range)
|
|
119
|
-
[*position(source, range.begin), *position(source, range.end)]
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
# [line, column] of a byte offset in source.
|
|
123
|
-
def self.position(source, offset)
|
|
124
|
-
before = source.byteslice(0, offset)
|
|
125
|
-
newline = before.rindex("\n")
|
|
126
|
-
column = before.length - (newline ? newline + 1 : 0)
|
|
127
|
-
[before.count("\n") + 1, column]
|
|
128
|
-
end
|
|
129
|
-
# simplecov:enable
|
|
130
|
-
end
|
|
131
|
-
end
|