path_coverage 0.0.2 → 0.2.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 +330 -84
- data/exe/path_coverage_collector +12 -1
- data/lib/path_coverage/calls.rb +106 -0
- data/lib/path_coverage/collector.rb +88 -22
- data/lib/path_coverage/condition.rb +77 -3
- data/lib/path_coverage/configuration.rb +52 -12
- data/lib/path_coverage/configuration_paths.rb +56 -0
- data/lib/path_coverage/console_summary.rb +77 -0
- data/lib/path_coverage/gaps.rb +25 -9
- data/lib/path_coverage/html/index.html +3 -14
- data/lib/path_coverage/html/side.js +36 -6
- data/lib/path_coverage/html/sort.js +27 -21
- data/lib/path_coverage/html/style.css +32 -1
- data/lib/path_coverage/html/tabs.js +15 -0
- data/lib/path_coverage/html_index.rb +105 -19
- data/lib/path_coverage/html_index_head.rb +49 -0
- data/lib/path_coverage/html_report.rb +44 -12
- data/lib/path_coverage/html_tabs.rb +26 -0
- data/lib/path_coverage/html_tree.rb +47 -17
- data/lib/path_coverage/json_reader.rb +94 -0
- data/lib/path_coverage/json_writer.rb +44 -8
- data/lib/path_coverage/kernel.rb +53 -45
- data/lib/path_coverage/kinds/base.rb +71 -0
- data/lib/path_coverage/kinds/block.rb +136 -0
- data/lib/path_coverage/kinds/case.rb +89 -0
- data/lib/path_coverage/kinds/chain.rb +45 -0
- data/lib/path_coverage/kinds/choice.rb +68 -0
- data/lib/path_coverage/kinds/contains.rb +111 -0
- data/lib/path_coverage/kinds/safe.rb +151 -0
- data/lib/path_coverage/kinds/write.rb +54 -0
- data/lib/path_coverage/kinds.rb +37 -0
- data/lib/path_coverage/manifest.rb +93 -26
- data/lib/path_coverage/manifest_blocks.rb +96 -0
- data/lib/path_coverage/manifest_case.rb +54 -0
- data/lib/path_coverage/manifest_chains.rb +76 -0
- data/lib/path_coverage/manifest_choices.rb +64 -32
- data/lib/path_coverage/manifest_folding.rb +91 -0
- data/lib/path_coverage/manifest_ignoring.rb +35 -0
- data/lib/path_coverage/manifest_writes.rb +67 -0
- data/lib/path_coverage/merge.rb +19 -3
- data/lib/path_coverage/post.rb +8 -8
- data/lib/path_coverage/recorder.rb +43 -0
- data/lib/path_coverage/recorder_blocks.rb +68 -0
- data/lib/path_coverage/recorder_cases.rb +23 -0
- data/lib/path_coverage/recorder_chains.rb +40 -0
- data/lib/path_coverage/recorder_writes.rb +26 -0
- data/lib/path_coverage/render.rb +58 -46
- data/lib/path_coverage/result.rb +19 -0
- data/lib/path_coverage/rewriter.rb +64 -37
- data/lib/path_coverage/rewriter_nested.rb +62 -0
- data/lib/path_coverage/site.rb +6 -1
- data/lib/path_coverage/site_paths.rb +9 -46
- data/lib/path_coverage/site_tree.rb +31 -36
- data/lib/path_coverage/summary.rb +64 -17
- data/lib/path_coverage/totals.rb +29 -0
- data/lib/path_coverage/version.rb +1 -1
- metadata +35 -7
|
@@ -56,10 +56,12 @@
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
// Opens panel, a tree or a grid, alone; null closes all. Any
|
|
59
|
-
// path shown or pinned goes with the grid it was in.
|
|
59
|
+
// path shown or pinned goes with the grid it was in. The box
|
|
60
|
+
// drops any height a tree it held gave it.
|
|
60
61
|
function openOnly(panel) {
|
|
61
62
|
pin(null);
|
|
62
63
|
clear();
|
|
64
|
+
box.style.minHeight = '';
|
|
63
65
|
trees.forEach(function (tree) {
|
|
64
66
|
tree.hidden = tree !== panel;
|
|
65
67
|
buttonOf(tree).setAttribute('aria-expanded', tree === panel ? 'true' : 'false');
|
|
@@ -70,33 +72,61 @@
|
|
|
70
72
|
bands[i].classList.toggle('open', grid === panel);
|
|
71
73
|
});
|
|
72
74
|
var side = !panel ? '' : panel.classList.contains('tree') ? 'cc' : 'pc';
|
|
75
|
+
fitRail(side === 'cc' ? panel : null);
|
|
73
76
|
document.body.setAttribute('data-open', side);
|
|
74
|
-
slide();
|
|
77
|
+
slide(panel);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// The narrowest the condition rail opens to, as style.css has it.
|
|
81
|
+
var RAIL_MIN = 560;
|
|
82
|
+
|
|
83
|
+
// Widens the condition rail to tree's own width, so a tree with
|
|
84
|
+
// many paths or long labels sits wholly beside the code; null,
|
|
85
|
+
// for no tree open, gives the rail back its own width.
|
|
86
|
+
function fitRail(tree) {
|
|
87
|
+
var style = document.body.style;
|
|
88
|
+
if (!tree) { style.removeProperty('--cc-rail'); return; }
|
|
89
|
+
var width = Math.max(RAIL_MIN, Math.ceil(tree.offsetWidth));
|
|
90
|
+
style.setProperty('--cc-rail', width + 'px');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Scrolls the page just enough to show all of panel when it
|
|
94
|
+
// is a tree, eg one opened from a line near the bottom of the
|
|
95
|
+
// window, so its last rows are not below the fold. Its first
|
|
96
|
+
// row stays level with its site's line.
|
|
97
|
+
function showWhole(panel) {
|
|
98
|
+
if (panel && panel.classList.contains('tree')) {
|
|
99
|
+
panel.scrollIntoView({ block: 'nearest', behavior: 'smooth' });
|
|
100
|
+
}
|
|
75
101
|
}
|
|
76
102
|
|
|
77
103
|
// How long a rail takes to open or close, as style.css has it.
|
|
78
104
|
var SLIDE_MS = 250;
|
|
79
105
|
|
|
80
106
|
// Places everything on every frame while the rails slide, as
|
|
81
|
-
// the bars and bands follow the code across
|
|
82
|
-
|
|
107
|
+
// the bars and bands follow the code across, then shows all
|
|
108
|
+
// of panel, the one just opened, once it is in its place.
|
|
109
|
+
function slide(panel) {
|
|
83
110
|
var end = performance.now() + SLIDE_MS + 50;
|
|
84
111
|
function frame(now) {
|
|
85
112
|
place();
|
|
86
|
-
if (now < end) { requestAnimationFrame(frame); }
|
|
113
|
+
if (now < end) { requestAnimationFrame(frame); } else { showWhole(panel); }
|
|
87
114
|
}
|
|
88
115
|
requestAnimationFrame(frame);
|
|
89
116
|
}
|
|
90
117
|
|
|
91
118
|
// Sets an open tree's top so its first site's row, naming its
|
|
92
119
|
// operator and path counts, is level with the first line of
|
|
93
|
-
// its site's code.
|
|
120
|
+
// its site's code. The box grows to hold the whole tree, as
|
|
121
|
+
// one overflowing it would make the box scroll, sliding the
|
|
122
|
+
// code's first lines out of sight.
|
|
94
123
|
function placeTree(tree) {
|
|
95
124
|
var block = buttonOf(tree).closest('.block');
|
|
96
125
|
tree.style.top = '0px';
|
|
97
126
|
var line = spot(block.querySelector('.src'), ccRail).middle;
|
|
98
127
|
var row = spot(tree.querySelector('.site .row'), tree).middle;
|
|
99
128
|
tree.style.top = (line - row) + 'px';
|
|
129
|
+
box.style.minHeight = Math.ceil(spot(tree, box).bottom) + 'px';
|
|
100
130
|
}
|
|
101
131
|
|
|
102
132
|
// Sets an open grid's top level with its def, its calls row
|
|
@@ -1,27 +1,33 @@
|
|
|
1
|
-
// Sorts
|
|
2
|
-
// a second click on the same column reverses the order.
|
|
1
|
+
// Sorts a files table by the clicked column's data-sort values;
|
|
2
|
+
// a second click on the same column reverses the order. A cell
|
|
3
|
+
// with an empty data-sort, one with no value such as a -, stays
|
|
4
|
+
// last in both orders, so either end of the values can be first.
|
|
5
|
+
// Each table, one per tab, sorts on its own.
|
|
3
6
|
(function () {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
document.querySelectorAll('table.files').forEach(function (table) {
|
|
8
|
+
var body = table.tBodies[0];
|
|
9
|
+
var state = { column: -1, ascending: true };
|
|
7
10
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
table.querySelectorAll('thead button').forEach(function (button) {
|
|
12
|
+
button.addEventListener('click', function () {
|
|
13
|
+
var column = Number(button.dataset.column);
|
|
14
|
+
var numeric = button.dataset.type === 'number';
|
|
15
|
+
state.ascending = state.column === column ? !state.ascending : true;
|
|
16
|
+
state.column = column;
|
|
17
|
+
var rows = Array.from(body.rows);
|
|
18
|
+
rows.sort(function (a, b) {
|
|
19
|
+
var x = a.cells[column].dataset.sort;
|
|
20
|
+
var y = b.cells[column].dataset.sort;
|
|
21
|
+
if (x === '' || y === '') { return (x === '') - (y === ''); }
|
|
22
|
+
var order = numeric ? Number(x) - Number(y) : x.localeCompare(y);
|
|
23
|
+
return state.ascending ? order : -order;
|
|
24
|
+
});
|
|
25
|
+
rows.forEach(function (row) { body.appendChild(row); });
|
|
23
26
|
var sort = state.ascending ? 'ascending' : 'descending';
|
|
24
|
-
|
|
27
|
+
table.querySelectorAll('thead button').forEach(function (other) {
|
|
28
|
+
var mine = Number(other.dataset.column) === column;
|
|
29
|
+
other.parentNode.setAttribute('aria-sort', mine ? sort : 'none');
|
|
30
|
+
});
|
|
25
31
|
});
|
|
26
32
|
});
|
|
27
33
|
});
|
|
@@ -46,7 +46,26 @@ th, td { padding: 10px 16px; text-align: left; }
|
|
|
46
46
|
th { background: var(--panel); }
|
|
47
47
|
td { border-top: 1px solid var(--rule); }
|
|
48
48
|
td:first-child { font-family: var(--font-code); }
|
|
49
|
+
/* The Total row frames the table's foot as the headings do its
|
|
50
|
+
head, so it reads as a sum, not as one more file. */
|
|
51
|
+
tfoot td { background: var(--panel); font-weight: 600; border-top: 1px solid var(--fg); }
|
|
52
|
+
tfoot td:first-child { font-family: inherit; }
|
|
53
|
+
/* The index page's tabs, one per group of files; the selected
|
|
54
|
+
one framed as the table's headings are. */
|
|
55
|
+
.tabs { display: flex; flex-wrap: wrap; gap: 4px; margin: 0 0 8px; }
|
|
56
|
+
.tabs [role="tab"] { font: inherit; font-size: 13px; padding: 6px 12px; border: 1px solid var(--rule); border-radius: 6px; background: var(--surface); color: var(--muted); cursor: pointer; }
|
|
57
|
+
.tabs [role="tab"][aria-selected="true"] { background: var(--panel); color: var(--fg); border-color: var(--fg); font-weight: 600; }
|
|
58
|
+
.tabs [role="tab"]:focus-visible { outline: 3px solid var(--link); outline-offset: 2px; }
|
|
49
59
|
.num, td:not(:first-child) { text-align: right; }
|
|
60
|
+
/* A total's taken, / of and % sit close, so a row still reads
|
|
61
|
+
3 / 4 75%; its name heads all three. The File column takes
|
|
62
|
+
the table's spare width, so it never spreads them apart. */
|
|
63
|
+
table.files tr > :first-child { width: 100%; }
|
|
64
|
+
table.files th, table.files td:not(:first-child) { white-space: nowrap; }
|
|
65
|
+
th.group { text-align: center; padding-bottom: 0; }
|
|
66
|
+
.taken { text-align: right; padding-left: 32px; padding-right: 4px; }
|
|
67
|
+
td.of, th.of { text-align: left; padding-left: 0; padding-right: 6px; }
|
|
68
|
+
.percent { text-align: right; padding-left: 6px; }
|
|
50
69
|
th button {
|
|
51
70
|
font: 600 13px var(--font-body); color: var(--fg); background: none; border: 0;
|
|
52
71
|
padding: 4px 0; cursor: pointer;
|
|
@@ -199,6 +218,8 @@ body[data-layout="beside"] .box:has(> .code) {
|
|
|
199
218
|
body[data-layout="beside"] .code {
|
|
200
219
|
min-width: 0; overflow-x: auto;
|
|
201
220
|
display: grid; grid-template-columns: minmax(max-content, 1fr);
|
|
221
|
+
/* Lines keep their height when the box grows to hold a tree. */
|
|
222
|
+
align-content: start;
|
|
202
223
|
}
|
|
203
224
|
body[data-layout="beside"] .box:has(> .code)::before {
|
|
204
225
|
left: calc(var(--cc-rail) + 38px); right: calc(var(--pc-rail) + 12px);
|
|
@@ -213,7 +234,17 @@ body[data-layout="beside"] .box:has(> .code)::before {
|
|
|
213
234
|
/* The rail's tree has narrower columns, to fit its width; a
|
|
214
235
|
thin rule under each site's counts row, across the tree's
|
|
215
236
|
full width through its 16px side padding. */
|
|
216
|
-
|
|
237
|
+
/* Each row lays its branch and label out at their own width, the
|
|
238
|
+
label pushing its cells to the row's right edge, so a site's
|
|
239
|
+
cells line up in columns however long or deep its labels. */
|
|
240
|
+
.rail .row { display: flex; align-items: center; gap: 8px; }
|
|
241
|
+
.rail .row > :is(.text, .arm, .operator) { margin-right: auto; padding-right: 8px; }
|
|
242
|
+
/* An explicit width, not just a flex basis, so a row's natural
|
|
243
|
+
width counts each cell as 26px, not as its one letter. */
|
|
244
|
+
.rail .row > :is(.cell, .count) { flex: none; width: 26px; }
|
|
245
|
+
/* The tree is as wide as its widest row, and at least the rail;
|
|
246
|
+
side.js widens the rail to it. */
|
|
247
|
+
.rail .tree { width: max-content; min-width: 100%; right: auto; }
|
|
217
248
|
.rail .site > .row:first-child {
|
|
218
249
|
border-bottom: 1px solid var(--tree-rule); margin: 0 -16px 6px; padding: 0 16px 4px;
|
|
219
250
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Switches the index page's tabs: a click on a tab selects it and
|
|
2
|
+
// shows the table it controls, hiding every other tab's table.
|
|
3
|
+
(function () {
|
|
4
|
+
var tabs = Array.from(document.querySelectorAll('[role="tab"]'));
|
|
5
|
+
tabs.forEach(function (tab) {
|
|
6
|
+
tab.addEventListener('click', function () {
|
|
7
|
+
tabs.forEach(function (other) {
|
|
8
|
+
var selected = other === tab;
|
|
9
|
+
other.setAttribute('aria-selected', selected ? 'true' : 'false');
|
|
10
|
+
var table = document.getElementById(other.getAttribute('aria-controls'));
|
|
11
|
+
table.hidden = !selected;
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
})();
|
|
@@ -1,43 +1,129 @@
|
|
|
1
1
|
require 'cgi/escape'
|
|
2
|
+
require_relative 'html_index_head'
|
|
3
|
+
require_relative 'html_tabs'
|
|
2
4
|
require_relative 'html_template'
|
|
3
5
|
|
|
4
6
|
module PathCoverage
|
|
5
7
|
# The HTML index page: one sortable row per covered file,
|
|
6
|
-
# each linking to that file's own page
|
|
8
|
+
# each linking to that file's own page, then a Total row; with
|
|
9
|
+
# groups, one such table per tab.
|
|
7
10
|
module HtmlIndex
|
|
8
|
-
# The whole index page
|
|
9
|
-
#
|
|
10
|
-
|
|
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)
|
|
11
19
|
HtmlTemplate.fill(
|
|
12
20
|
HtmlTemplate.asset('index.html'),
|
|
13
21
|
'style' => HtmlTemplate.asset('style.css'),
|
|
14
|
-
'script' =>
|
|
15
|
-
'
|
|
22
|
+
'script' => script(groups),
|
|
23
|
+
'tabs' => groups.empty? ? '' : HtmlTabs.bar(names),
|
|
24
|
+
'tables' => tables_of(tables),
|
|
25
|
+
'ignored' => ignored_line(ignored)
|
|
16
26
|
)
|
|
17
27
|
end
|
|
18
28
|
|
|
29
|
+
# The paragraph naming the operators ignored, eg
|
|
30
|
+
# "Ignored: &&="; empty when none are.
|
|
31
|
+
def self.ignored_line(ignored)
|
|
32
|
+
return '' if ignored.empty?
|
|
33
|
+
|
|
34
|
+
text = CGI.escapeHTML("Ignored: #{ignored.join(', ')}")
|
|
35
|
+
%(<p class="ignored" data-ignored="">#{text}</p>)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Each of tables, [name, rows, total], as the table of its
|
|
39
|
+
# tab.
|
|
40
|
+
def self.tables_of(tables)
|
|
41
|
+
tables.each_with_index.map do |(_, rows, total), index|
|
|
42
|
+
table(index, rows, total)
|
|
43
|
+
end.join("\n")
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# The page's script: its column sorting, and, with groups,
|
|
47
|
+
# its tab switching.
|
|
48
|
+
def self.script(groups)
|
|
49
|
+
sort = HtmlTemplate.asset('sort.js')
|
|
50
|
+
groups.empty? ? sort : sort + HtmlTemplate.asset('tabs.js')
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# The index-th tab's table of rows, total as its footer; any
|
|
54
|
+
# but the first starts hidden.
|
|
55
|
+
def self.table(index, rows, total)
|
|
56
|
+
body = rows.map { |row| row(row) }.join("\n")
|
|
57
|
+
head = HtmlIndexHead.of(total[:methods])
|
|
58
|
+
[
|
|
59
|
+
open_tag(index),
|
|
60
|
+
"<thead>\n#{head}\n</thead>",
|
|
61
|
+
"<tbody>\n#{body}\n</tbody>",
|
|
62
|
+
"<tfoot>\n#{total_row(total)}\n</tfoot>",
|
|
63
|
+
'</table>'
|
|
64
|
+
].join("\n")
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# The opening tag of the index-th tab's table, which the tab
|
|
68
|
+
# of the same index controls; any but the first is hidden.
|
|
69
|
+
def self.open_tag(index)
|
|
70
|
+
hidden = index.zero? ? '' : ' hidden="hidden"'
|
|
71
|
+
id = %(id="files-#{index}")
|
|
72
|
+
%(<table class="files" #{id} role="tabpanel"#{hidden}>)
|
|
73
|
+
end
|
|
74
|
+
|
|
19
75
|
# The table row of one Summary.files row; each cell has a
|
|
20
76
|
# data-sort value for the page's column sorting.
|
|
21
77
|
def self.row(row)
|
|
22
|
-
"<tr>#{cells(row).join}</tr>"
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
# The four cells: file, sites, outcomes seen, missing.
|
|
26
|
-
def self.cells(row)
|
|
27
78
|
path = CGI.escapeHTML(row[:path])
|
|
28
79
|
link = %(<a href="files/#{path}.html">#{path}</a>)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
80
|
+
"<tr>#{cell(path, link)}#{counts(row).join}</tr>"
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# The footer row: the sums over the table's files.
|
|
84
|
+
def self.total_row(total)
|
|
85
|
+
"<tr>#{cell('Total', 'Total')}#{counts(total).join}</tr>"
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# The cells after the file's: its sites, then its total
|
|
89
|
+
# within each decision, then, when methods are measured, its
|
|
90
|
+
# total within each method.
|
|
91
|
+
def self.counts(row)
|
|
92
|
+
cells = [
|
|
32
93
|
cell(row[:sites], row[:sites]),
|
|
33
|
-
|
|
34
|
-
cell(row[:missing], row[:missing])
|
|
94
|
+
*paths_cells(row[:decisions], 'no decisions')
|
|
35
95
|
]
|
|
96
|
+
return cells unless row[:methods]
|
|
97
|
+
|
|
98
|
+
none = 'no method with two or more decisions'
|
|
99
|
+
cells + paths_cells(row[:methods], none)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# Three cells showing [taken, possible] paths, eg 3, / 6 and
|
|
103
|
+
# 50%, each sorted by its number, so they read 3 / 6 50%.
|
|
104
|
+
# With no paths to take, as in a group no file is in, or a
|
|
105
|
+
# file with no method of two or more decisions, the percent
|
|
106
|
+
# shows -, titled with none, saying why, with an empty sort
|
|
107
|
+
# value, which sort.js keeps last whichever way the column
|
|
108
|
+
# is sorted.
|
|
109
|
+
def self.paths_cells(pair, none)
|
|
110
|
+
taken, possible = pair
|
|
111
|
+
counts = [cell(taken, taken, css: 'taken'),
|
|
112
|
+
cell(possible, "/ #{possible}", css: 'of')]
|
|
113
|
+
none_cell = cell('', '-', none, css: 'percent')
|
|
114
|
+
return [*counts, none_cell] if possible.zero?
|
|
115
|
+
|
|
116
|
+
percent = (100.0 * taken / possible).round
|
|
117
|
+
[*counts, cell(percent, "#{percent}%", css: 'percent')]
|
|
36
118
|
end
|
|
37
119
|
|
|
38
|
-
# One table cell, sorted by sort_value, showing content
|
|
39
|
-
|
|
40
|
-
|
|
120
|
+
# One table cell, sorted by sort_value, showing content,
|
|
121
|
+
# with title as its hover text and css as its class, each
|
|
122
|
+
# when there is one.
|
|
123
|
+
def self.cell(sort_value, content, title = nil, css: nil)
|
|
124
|
+
hover = title ? %( title="#{title}") : ''
|
|
125
|
+
klass = css ? %( class="#{css}") : ''
|
|
126
|
+
%(<td#{klass} data-sort="#{sort_value}"#{hover}>#{content}</td>)
|
|
41
127
|
end
|
|
42
128
|
end
|
|
43
129
|
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
module PathCoverage
|
|
2
|
+
# The two heading rows of the HTML index's files tables: File
|
|
3
|
+
# and Sites, then each total's name over its taken, / of and %
|
|
4
|
+
# columns, 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 two heading rows; methods' total only when methods are
|
|
10
|
+
# measured.
|
|
11
|
+
def self.of(methods)
|
|
12
|
+
names = ['Within each decision']
|
|
13
|
+
names << 'Within each method' if methods
|
|
14
|
+
rows = [top_row(names), part_row(names)]
|
|
15
|
+
rows.map { |row| "<tr>\n#{row}\n</tr>" }.join("\n")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# The first heading row: File and Sites, each over both rows,
|
|
19
|
+
# then each total's name over its three columns.
|
|
20
|
+
def self.top_row(names)
|
|
21
|
+
fixed = [
|
|
22
|
+
heading(' rowspan="2"', 0, 'text', 'File'),
|
|
23
|
+
heading(' class="num" rowspan="2"', 1, 'number', 'Sites')
|
|
24
|
+
]
|
|
25
|
+
groups = names.map do |name|
|
|
26
|
+
%(<th class="group" colspan="3">#{name}</th>)
|
|
27
|
+
end
|
|
28
|
+
(fixed + groups).join("\n")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# The second heading row: each total's taken, / of and %.
|
|
32
|
+
def self.part_row(names)
|
|
33
|
+
names.each_index.flat_map do |group|
|
|
34
|
+
PARTS.each_with_index.map do |(css, label), i|
|
|
35
|
+
column = 2 + (3 * group) + i
|
|
36
|
+
heading(%( class="#{css}"), column, 'number', label)
|
|
37
|
+
end
|
|
38
|
+
end.join("\n")
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# A sortable heading, attrs its th's, sorting the column-th
|
|
42
|
+
# column as type, its button showing label.
|
|
43
|
+
def self.heading(attrs, column, type, label)
|
|
44
|
+
data = %(data-column="#{column}" data-type="#{type}")
|
|
45
|
+
button = %(<button type="button" #{data}>#{label}</button>)
|
|
46
|
+
%(<th#{attrs} aria-sort="none">#{button}</th>)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -15,10 +15,12 @@ module PathCoverage
|
|
|
15
15
|
# Writes every page. operands and site_paths are as Result
|
|
16
16
|
# gives them, site_paths holding every site in files; files
|
|
17
17
|
# is { full path => {source:, sites:} } for each covered
|
|
18
|
-
# file, as the kernel parsed it.
|
|
18
|
+
# file, as the kernel parsed it. The files dir is emptied
|
|
19
|
+
# first, so it holds no page for a file no longer covered.
|
|
19
20
|
def self.write(operands, files, config, paths = nil, site_paths:)
|
|
20
21
|
dir = config.output_dir
|
|
21
|
-
|
|
22
|
+
FileUtils.rm_rf("#{dir}/files")
|
|
23
|
+
index = index(files, config, paths, site_paths)
|
|
22
24
|
File.write("#{dir}/index.html", index)
|
|
23
25
|
files.each do |full_path, parsed|
|
|
24
26
|
path = config.relative(full_path)
|
|
@@ -30,6 +32,25 @@ module PathCoverage
|
|
|
30
32
|
end
|
|
31
33
|
end
|
|
32
34
|
|
|
35
|
+
# The index page: a row per file of its totals within each
|
|
36
|
+
# decision, and, when paths are given, as they are when
|
|
37
|
+
# methods are measured, within each method too;
|
|
38
|
+
# then their Total row. With groups configured, each group,
|
|
39
|
+
# and the files in none, get a tab of their own too. Any
|
|
40
|
+
# operators config ignored are named after them.
|
|
41
|
+
def self.index(files, config, paths, site_paths)
|
|
42
|
+
methods = files.map do |full_path, parsed|
|
|
43
|
+
path = config.relative(full_path)
|
|
44
|
+
PathManifest.methods(parsed[:source], path)
|
|
45
|
+
end
|
|
46
|
+
all = methods.reduce({}, :merge)
|
|
47
|
+
rows = Summary.files(site_paths, all, paths)
|
|
48
|
+
groups = config.groups
|
|
49
|
+
tabs = groups.empty? ? [] : Summary.groups(rows, groups)
|
|
50
|
+
ignored = config.ignored
|
|
51
|
+
HtmlIndex.page(rows, Summary.total(rows), tabs, ignored:)
|
|
52
|
+
end
|
|
53
|
+
|
|
33
54
|
# simplecov:disable
|
|
34
55
|
# SPIKE: the hidden path grids of one file's methods.
|
|
35
56
|
def self.path_grids(path, parsed, paths)
|
|
@@ -67,23 +88,34 @@ module PathCoverage
|
|
|
67
88
|
# on it and on each of its operands: a leaf's from its byte
|
|
68
89
|
# range, a condition's and an arm's from its extent, the
|
|
69
90
|
# whole of it as written. Columns count characters, not
|
|
70
|
-
# bytes.
|
|
91
|
+
# bytes. A node past the condition's operands, eg owner at
|
|
92
|
+
# the end of user&.account&.owner, is kept as it is.
|
|
71
93
|
def self.located(source, condition, tree)
|
|
72
94
|
pairs = condition.operands.zip(tree[:operands])
|
|
73
95
|
operands = pairs.map do |operand, node|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
96
|
+
located_operand(source, operand, node)
|
|
97
|
+
end
|
|
98
|
+
rest = tree[:operands].drop(pairs.size)
|
|
99
|
+
tree.merge(at: at(source, condition.extent),
|
|
100
|
+
operands: operands + rest)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# SPIKE: the node of operand with its at:, as located gives
|
|
104
|
+
# a condition's, an arm's or a leaf's.
|
|
105
|
+
def self.located_operand(source, operand, node)
|
|
106
|
+
case operand
|
|
107
|
+
when Condition then located(source, operand, node)
|
|
108
|
+
when Arm then located_arm(source, operand, node)
|
|
109
|
+
else node.merge(at: at(source, operand))
|
|
79
110
|
end
|
|
80
|
-
tree.merge(at: at(source, condition.extent), operands:)
|
|
81
111
|
end
|
|
82
112
|
|
|
83
|
-
# An arm's node with its at:,
|
|
113
|
+
# An arm's node with its at:, nil for an arm with no
|
|
114
|
+
# statements, and its body's tree located.
|
|
84
115
|
def self.located_arm(source, arm, node)
|
|
85
|
-
body = arm.body
|
|
86
|
-
|
|
116
|
+
body = arm.body ? located(source, arm.body, node[:body]) : nil
|
|
117
|
+
at = arm.extent ? at(source, arm.extent) : nil
|
|
118
|
+
node.merge(at:, body:)
|
|
87
119
|
end
|
|
88
120
|
|
|
89
121
|
# [line, column, line, column] of the byte range in source.
|
|
@@ -0,0 +1,26 @@
|
|
|
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,12 +1,21 @@
|
|
|
1
1
|
require 'cgi/escape'
|
|
2
|
+
require_relative 'condition'
|
|
3
|
+
require_relative 'kinds'
|
|
2
4
|
|
|
3
5
|
module PathCoverage
|
|
4
6
|
# The tree of a span's sites on a file's page, from SiteTree.of
|
|
5
7
|
# for each site: a grid whose columns are a site's paths.
|
|
6
8
|
module HtmlTree
|
|
7
|
-
OUTCOMES = {
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
OUTCOMES = {
|
|
10
|
+
true => 'T', false => 'F', nil => '',
|
|
11
|
+
ITEMS[0] => '0', ITEMS[1] => '1', ITEMS[2] => '*',
|
|
12
|
+
ANSWERS[0] => 'T', ANSWERS[1] => 'F', ANSWERS[2] => 'TF',
|
|
13
|
+
PRESENCE[0] => [0x25CF].pack('U'),
|
|
14
|
+
PRESENCE[1] => [0x2205].pack('U')
|
|
15
|
+
}.freeze
|
|
16
|
+
|
|
17
|
+
# A tick marks a path taking an arm.
|
|
18
|
+
TAKEN = { true => [0x2713].pack('U'), false => '' }.freeze
|
|
10
19
|
|
|
11
20
|
# The tree of a span, open when its sites have gaps, else
|
|
12
21
|
# hidden: each site's rows in a group of their own.
|
|
@@ -36,10 +45,13 @@ module PathCoverage
|
|
|
36
45
|
end.join
|
|
37
46
|
end
|
|
38
47
|
|
|
39
|
-
# One cell per path, naming each with names
|
|
48
|
+
# One cell per path, naming each with names; a &. receiver's,
|
|
49
|
+
# shown as a glyph, titled not nil or nil for its hover text.
|
|
40
50
|
def self.cells(values, names = OUTCOMES)
|
|
41
51
|
values.map do |value|
|
|
42
|
-
%(
|
|
52
|
+
title = PRESENCE.include?(value) ? %( title="#{value}") : ''
|
|
53
|
+
attrs = %(class="cell" data-cell=""#{title})
|
|
54
|
+
%(<span #{attrs}>#{names[value]}</span>)
|
|
43
55
|
end.join
|
|
44
56
|
end
|
|
45
57
|
|
|
@@ -52,10 +64,16 @@ module PathCoverage
|
|
|
52
64
|
# The rows of a condition's operands, each branching from
|
|
53
65
|
# its operator after indent; a nested condition's operands,
|
|
54
66
|
# and those of an arm's condition, follow its own row,
|
|
55
|
-
# indented under its branch.
|
|
67
|
+
# indented under its branch. A leaf with sites inside it
|
|
68
|
+
# branches as those sites, then the leaf, in the order they
|
|
69
|
+
# run.
|
|
56
70
|
def self.operand_rows(condition, indent)
|
|
57
|
-
|
|
58
|
-
|
|
71
|
+
own = Kinds.of(condition[:operator]).rows(condition, indent)
|
|
72
|
+
return own if own
|
|
73
|
+
|
|
74
|
+
operands = unfolded(condition[:operands])
|
|
75
|
+
last = operands.size - 1
|
|
76
|
+
operands.each_with_index.flat_map do |operand, i|
|
|
59
77
|
tip = i == last
|
|
60
78
|
branch = indent + (tip ? '└─ ' : '├─ ')
|
|
61
79
|
under = indent + (tip ? ' ' : '│ ')
|
|
@@ -82,7 +100,7 @@ module PathCoverage
|
|
|
82
100
|
# plain arm marks the paths taking it.
|
|
83
101
|
def self.arm_rows(arm, branch, under, choice)
|
|
84
102
|
body = arm[:body]
|
|
85
|
-
values = cells(
|
|
103
|
+
values = body ? cells(body[:cells]) : cells(arm[:cells], TAKEN)
|
|
86
104
|
text = CGI.escapeHTML(arm_label(arm, choice))
|
|
87
105
|
lead = branch_cell(branch) +
|
|
88
106
|
%(<span class="arm" data-label="">#{text}</span>)
|
|
@@ -90,13 +108,20 @@ module PathCoverage
|
|
|
90
108
|
body ? [row, *operand_rows(body, under)] : [row]
|
|
91
109
|
end
|
|
92
110
|
|
|
93
|
-
# The name of an arm of a condition whose operator is choice
|
|
111
|
+
# The name of an arm of a condition whose operator is choice,
|
|
112
|
+
# as its kind names it, eg then for an if's.
|
|
94
113
|
def self.arm_label(arm, choice)
|
|
95
|
-
|
|
114
|
+
Kinds.of(choice).arm_label(arm, choice)
|
|
115
|
+
end
|
|
96
116
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
117
|
+
# operands with each node standing for the nodes its kind
|
|
118
|
+
# unfolds it into, eg a leaf with sites inside it for those
|
|
119
|
+
# sites, then the leaf; a leaf or an arm for itself.
|
|
120
|
+
def self.unfolded(operands)
|
|
121
|
+
operands.flat_map do |operand|
|
|
122
|
+
operator = operand[:operator]
|
|
123
|
+
operator ? Kinds.of(operator).unfold(operand) : [operand]
|
|
124
|
+
end
|
|
100
125
|
end
|
|
101
126
|
|
|
102
127
|
# A nested condition's row: its branch, its operator, and
|
|
@@ -113,20 +138,25 @@ module PathCoverage
|
|
|
113
138
|
%(<div class="row"#{attrs}>#{lead}#{values}</div>)
|
|
114
139
|
end
|
|
115
140
|
|
|
116
|
-
# The cell naming a condition's operator
|
|
141
|
+
# The cell naming a condition's operator, or its label when
|
|
142
|
+
# it has one, eg select { for a site inside a leaf.
|
|
117
143
|
def self.operator(condition)
|
|
118
|
-
name = CGI.escapeHTML(condition[:operator])
|
|
144
|
+
name = CGI.escapeHTML(condition[:label] || condition[:operator])
|
|
119
145
|
%(<span class="operator" data-operator="">#{name}</span>)
|
|
120
146
|
end
|
|
121
147
|
|
|
122
148
|
# One operand's row: its branch, text, and its outcome on
|
|
123
149
|
# each path.
|
|
150
|
+
# An operand that is only called, eg owner at the end of
|
|
151
|
+
# user&.account&.owner, has a tick on each path that called
|
|
152
|
+
# it instead.
|
|
124
153
|
def self.operand_row(operand, branch)
|
|
125
154
|
text = CGI.escapeHTML(operand[:text].to_s)
|
|
126
155
|
lead = branch_cell(branch) +
|
|
127
156
|
%(<span class="text" data-text="">#{text}</span>)
|
|
128
157
|
attrs = %( data-operand=""#{at(operand)})
|
|
129
|
-
|
|
158
|
+
names = operand[:called] ? TAKEN : OUTCOMES
|
|
159
|
+
row(attrs, lead, cells(operand[:cells], names))
|
|
130
160
|
end
|
|
131
161
|
|
|
132
162
|
# The cell drawing a row's branch from its operator.
|