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
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
module PathCoverage
|
|
2
|
+
# The algebras CardWays can fold a card's ways in, each giving
|
|
3
|
+
# no ways, the one way through no rows, the one way taking a
|
|
4
|
+
# labelled path, and ways added and joined one after another.
|
|
5
|
+
# A way's label at a row is [row key, path index].
|
|
6
|
+
module WayAlgebras
|
|
7
|
+
# Ways as how many there are.
|
|
8
|
+
module Counted
|
|
9
|
+
# No ways.
|
|
10
|
+
def self.zero = 0
|
|
11
|
+
|
|
12
|
+
# The one way through no rows.
|
|
13
|
+
def self.one = 1
|
|
14
|
+
|
|
15
|
+
# The one way that takes the path label names.
|
|
16
|
+
def self.unit(_label) = 1
|
|
17
|
+
|
|
18
|
+
# The ways of ways, then those of more.
|
|
19
|
+
def self.plus(ways, more) = ways + more
|
|
20
|
+
|
|
21
|
+
# Each way of ways going on to each way of more.
|
|
22
|
+
def self.times(ways, more) = ways * more
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Ways as the labels taken on any of them, so a row's paths
|
|
26
|
+
# that no way takes are those whose labels are missing.
|
|
27
|
+
module Labelled
|
|
28
|
+
# No labels.
|
|
29
|
+
def self.zero = []
|
|
30
|
+
|
|
31
|
+
# The one way through no rows, taking no label.
|
|
32
|
+
def self.one = []
|
|
33
|
+
|
|
34
|
+
# The one way that takes the path label names.
|
|
35
|
+
def self.unit(label) = [label]
|
|
36
|
+
|
|
37
|
+
# The labels of ways or of more.
|
|
38
|
+
def self.plus(ways, more) = ways | more
|
|
39
|
+
|
|
40
|
+
# The labels of each way of ways going on to each of more:
|
|
41
|
+
# every one of either, as CardWays never joins no ways.
|
|
42
|
+
def self.times(ways, more) = ways | more
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Ways as a list of them, each the labels it takes.
|
|
46
|
+
module Listed
|
|
47
|
+
# No ways.
|
|
48
|
+
def self.zero = []
|
|
49
|
+
|
|
50
|
+
# The one way through no rows, taking no label.
|
|
51
|
+
def self.one = [[]]
|
|
52
|
+
|
|
53
|
+
# The one way that takes the path label names.
|
|
54
|
+
def self.unit(label) = [[label]]
|
|
55
|
+
|
|
56
|
+
# The ways of ways, then those of more.
|
|
57
|
+
def self.plus(ways, more) = ways + more
|
|
58
|
+
|
|
59
|
+
# Each way of ways going on to each way of more, its labels
|
|
60
|
+
# then theirs.
|
|
61
|
+
def self.times(ways, more)
|
|
62
|
+
ways.product(more).map { |before, after| before + after }
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Ways in an algebra, each noting an assignment, { local name =>
|
|
67
|
+
# outcome }, as a tally, { assignment => ways in the algebra }.
|
|
68
|
+
# Ways whose assignments disagree, giving a name both outcomes,
|
|
69
|
+
# join into no way, as no call can take them.
|
|
70
|
+
class Tallied
|
|
71
|
+
# Ways in algebra, one of the modules above.
|
|
72
|
+
def initialize(algebra)
|
|
73
|
+
@algebra = algebra
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# No ways.
|
|
77
|
+
def zero = {}
|
|
78
|
+
|
|
79
|
+
# The one way through no rows, assigning nothing.
|
|
80
|
+
def one = { {} => @algebra.one }
|
|
81
|
+
|
|
82
|
+
# The one way that takes the path label names, with
|
|
83
|
+
# assignment.
|
|
84
|
+
def unit(label, assignment = {})
|
|
85
|
+
{ assignment => @algebra.unit(label) }
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# The ways of tally, then those of more, those of one
|
|
89
|
+
# assignment added up.
|
|
90
|
+
def plus(tally, more)
|
|
91
|
+
tally.merge(more) { |_, ways, others| add(ways, others) }
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Each way of tally going on to each way of more, but for
|
|
95
|
+
# those whose assignments disagree.
|
|
96
|
+
def times(tally, more)
|
|
97
|
+
pairs = tally.to_a.product(more.to_a)
|
|
98
|
+
pairs.reduce(zero) do |all, ((was, ways), (now, others))|
|
|
99
|
+
next all unless agree?(was, now)
|
|
100
|
+
|
|
101
|
+
joint = @algebra.times(ways, others)
|
|
102
|
+
plus(all, { was.merge(now) => joint })
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# The ways of tally, whatever their assignments, in the
|
|
107
|
+
# algebra.
|
|
108
|
+
def total(tally)
|
|
109
|
+
each = tally.values
|
|
110
|
+
each.reduce(@algebra.zero) { |all, ways| add(all, ways) }
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
private
|
|
114
|
+
|
|
115
|
+
# The ways of ways, then those of others, in the algebra.
|
|
116
|
+
def add(ways, others)
|
|
117
|
+
@algebra.plus(ways, others)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# True when the assignments was and now give no name both
|
|
121
|
+
# outcomes.
|
|
122
|
+
def agree?(was, now)
|
|
123
|
+
was.all? { |name, value| now.fetch(name, value) == value }
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
module PathCoverage
|
|
4
|
+
# A method card's taken ways, and its loops' passes, as the JSON
|
|
5
|
+
# report lists them: each way the steps one call, or one pass,
|
|
6
|
+
# took, in order, a decision's {"at", "path"}, a loop's {"at",
|
|
7
|
+
# "path", "passes"}, its path how many passes it made, or any
|
|
8
|
+
# other row's {"at"}, with how many took it.
|
|
9
|
+
module WaysReport
|
|
10
|
+
# [{ "way" => [step, ...], "count" => n }] of walked, { way =>
|
|
11
|
+
# n }, one unit's ways as a CallTrace counts them, in the order
|
|
12
|
+
# first taken.
|
|
13
|
+
def self.taken(walked)
|
|
14
|
+
walked.map do |each, count|
|
|
15
|
+
{ 'way' => way(each), 'count' => count }
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# [step, ...] of steps, one way, as the JSON report lists it.
|
|
20
|
+
def self.way(steps)
|
|
21
|
+
steps.map { step(_1) }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# A step as the JSON report lists it: its row's at and, for a
|
|
25
|
+
# decision's or a loop's, its path; for a loop's, the distinct
|
|
26
|
+
# ways its passes took, ordered by their JSON text.
|
|
27
|
+
def self.step(step)
|
|
28
|
+
listed = { 'at' => at(step[0]) }
|
|
29
|
+
return listed if step.size == 1
|
|
30
|
+
|
|
31
|
+
listed['path'] = step[1]
|
|
32
|
+
return listed if step.size == 2
|
|
33
|
+
|
|
34
|
+
passes = step[2].map { way(_1) }.sort_by { JSON.generate(_1) }
|
|
35
|
+
listed.merge('passes' => passes)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# { method's entry, or loop's name => { way => count } } of a
|
|
39
|
+
# JSON report's cards, as a CallTrace counts them: each card
|
|
40
|
+
# listing its calls' ways and its loops' passes; a top card
|
|
41
|
+
# lists neither, as no call runs it.
|
|
42
|
+
def self.ways(report)
|
|
43
|
+
report['cards'].each_with_object({}) do |(entry, card), found|
|
|
44
|
+
next unless card.key?('taken')
|
|
45
|
+
|
|
46
|
+
found[entry] = read(entry, card['taken'])
|
|
47
|
+
card['passes'].each do |at, passes|
|
|
48
|
+
loop = named(entry, at)
|
|
49
|
+
found[loop] = read(loop, passes)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# { way => count } of listed, the unit named unit's ways as
|
|
55
|
+
# taken lists them.
|
|
56
|
+
def self.read(unit, listed)
|
|
57
|
+
listed.to_h do |each|
|
|
58
|
+
[each['way'].map { unlisted(unit, _1) }, each['count']]
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# A step, as a JSON report lists it, of a unit named like
|
|
63
|
+
# unit, as a CallTrace counts it.
|
|
64
|
+
def self.unlisted(unit, step)
|
|
65
|
+
name = named(unit, step['at'])
|
|
66
|
+
return [name] unless step.key?('path')
|
|
67
|
+
return [name, step['path']] unless step.key?('passes')
|
|
68
|
+
|
|
69
|
+
ways = step['passes'].to_set do |way|
|
|
70
|
+
way.map { unlisted(unit, _1) }
|
|
71
|
+
end
|
|
72
|
+
[name, step['path'], ways]
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# The name, in the file of the unit named unit, of the row or
|
|
76
|
+
# loop at, as at gives it: "k.rb:2:2" and "4:06" give
|
|
77
|
+
# "k.rb:4:6".
|
|
78
|
+
def self.named(unit, at)
|
|
79
|
+
line, column = at.split(':')
|
|
80
|
+
file = unit.split(':')[..-3].join(':')
|
|
81
|
+
"#{file}:#{line}:#{Integer(column, 10)}"
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# The line:column of the row or loop named name, the column two
|
|
85
|
+
# digits, as a card's rows have it: "k.rb:4:6" gives "4:06".
|
|
86
|
+
def self.at(name)
|
|
87
|
+
line, column = name.split(':').last(2)
|
|
88
|
+
format('%<line>s:%<column>02d', line:, column: Integer(column))
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require_relative 'console_summary'
|
|
2
|
+
|
|
3
|
+
module PathCoverage
|
|
4
|
+
# The terminal totals of a JSON report, read from its JSON alone,
|
|
5
|
+
# so a person reads what an AI reading the same JSON finds: the
|
|
6
|
+
# ways covered, and the methods with more paths than max paths
|
|
7
|
+
# allows.
|
|
8
|
+
module WaysTotals
|
|
9
|
+
# True when report, a JSON report as a Hash, fails: a method in
|
|
10
|
+
# it has a path no test took, a path taken that was declared
|
|
11
|
+
# impossible, or more paths than its max_paths.
|
|
12
|
+
def self.failed?(report)
|
|
13
|
+
listed, over = methods(report)
|
|
14
|
+
untaken = listed.sum do |card|
|
|
15
|
+
card['gaps'].size + card['impossible_taken'].size
|
|
16
|
+
end
|
|
17
|
+
!over.empty? || untaken.positive?
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# The totals lines of report, a JSON report as a Hash: its
|
|
21
|
+
# listed methods' ways covered out of their ways, then how many
|
|
22
|
+
# methods have more paths than its max_paths, each such one
|
|
23
|
+
# failing.
|
|
24
|
+
def self.lines(report)
|
|
25
|
+
listed, over = methods(report)
|
|
26
|
+
covered = listed.sum { _1['covered'].size }
|
|
27
|
+
ways = listed.sum { _1['ways'] }
|
|
28
|
+
limit = report['max_paths']
|
|
29
|
+
["Paths: #{ConsoleSummary.figure([covered, ways])}",
|
|
30
|
+
"Functions over --max-paths=#{limit}: #{over.size}"]
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# [listed, over] of report's method cards: those listing their
|
|
34
|
+
# ways, and those with more paths than its max_paths, which
|
|
35
|
+
# list none. A top card, run by no call, has no taken ways, so
|
|
36
|
+
# is in neither.
|
|
37
|
+
def self.methods(report)
|
|
38
|
+
found = report['cards'].values.group_by do |card|
|
|
39
|
+
next :top unless card.key?('taken')
|
|
40
|
+
|
|
41
|
+
card.key?('covered') ? :listed : :over
|
|
42
|
+
end
|
|
43
|
+
[found.fetch(:listed, []), found.fetch(:over, [])]
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -1,34 +1,40 @@
|
|
|
1
|
-
|
|
1
|
+
require_relative 'card_context'
|
|
2
|
+
require_relative 'card_scopes'
|
|
2
3
|
require_relative 'card_tree'
|
|
4
|
+
require_relative 'card_way_lists'
|
|
3
5
|
require_relative 'card_ways'
|
|
4
|
-
require_relative '
|
|
6
|
+
require_relative 'loop_forks'
|
|
7
|
+
require_relative 'method_loops'
|
|
5
8
|
require_relative 'method_statements'
|
|
9
|
+
require_relative 'method_ways'
|
|
6
10
|
require_relative 'source_lines'
|
|
7
11
|
|
|
8
12
|
module PathCoverage
|
|
9
13
|
# What is measured within each method of a covered file.
|
|
10
14
|
module WithinMethods
|
|
11
15
|
# Where each statement of the covered file at path, parsed
|
|
12
|
-
# as Manifest.parse gives it, that is no
|
|
13
|
-
# MethodStatements.reaches gives them.
|
|
16
|
+
# as Manifest.parse gives it, that is no decision is reached,
|
|
17
|
+
# as MethodStatements.reaches gives them.
|
|
14
18
|
def self.reaches(path, parsed, config)
|
|
15
|
-
source,
|
|
16
|
-
|
|
19
|
+
source, decisions = parsed.values_at(:source, :decisions)
|
|
20
|
+
relative = config.relative(path)
|
|
21
|
+
MethodStatements.reaches(source, relative, decisions)
|
|
17
22
|
end
|
|
18
23
|
|
|
19
24
|
# Example: { "k.rb:0:0" => [1, 2], "k.rb:1:0" => [2, 4] }.
|
|
20
25
|
# Each def's card total, [taken, size], in every file in
|
|
21
|
-
# files, { full path => {source:,
|
|
26
|
+
# files, { full path => {source:, decisions:} }, from paths, as
|
|
22
27
|
# Result#paths gives them, and reached, as Recorder#reached
|
|
23
|
-
# does; and each file's top level's, its
|
|
28
|
+
# does; and each file's top level's, its decisions on no card,
|
|
24
29
|
# named for line 0, which no def is on.
|
|
25
30
|
def self.cards(files, config, paths, reached)
|
|
26
31
|
files.map do |full_path, parsed|
|
|
27
32
|
path = config.relative(full_path)
|
|
28
|
-
source,
|
|
29
|
-
|
|
30
|
-
MethodStatements.
|
|
31
|
-
|
|
33
|
+
source, decisions = parsed.values_at(:source, :decisions)
|
|
34
|
+
args = [source, path, paths]
|
|
35
|
+
top = MethodStatements.top_level(*args, decisions)
|
|
36
|
+
CardContext.totals(*args, reached, decisions)
|
|
37
|
+
.merge("#{path}:0:0" => top)
|
|
32
38
|
end.reduce({}, :merge)
|
|
33
39
|
end
|
|
34
40
|
|
|
@@ -36,13 +42,15 @@ module PathCoverage
|
|
|
36
42
|
# "last" => 3, "rows" => [{ "at" => "2:04", ... }] } }.
|
|
37
43
|
# Each card in every file in files, a def's and a top card's,
|
|
38
44
|
# as its page draws it, for the JSON report, so a reader
|
|
39
|
-
# finds a card's gap without the page; result a Result
|
|
40
|
-
# reached as cards takes it
|
|
41
|
-
|
|
45
|
+
# finds a card's gap without the page; result a Result;
|
|
46
|
+
# counted [reached, ways], reached as cards takes it, ways as
|
|
47
|
+
# a CallTrace counts them, nil when not known.
|
|
48
|
+
def self.listed(files, config, result, counted)
|
|
42
49
|
files.map do |full_path, parsed|
|
|
43
50
|
path = config.relative(full_path)
|
|
44
51
|
recorded = [result.operands, result.paths]
|
|
45
|
-
|
|
52
|
+
limited = [*counted, config.path_limit, config.loops?]
|
|
53
|
+
listed_in(path, parsed, result.paths, limited)
|
|
46
54
|
.merge(listed_tops(path, parsed, recorded))
|
|
47
55
|
end.reduce({}, :merge)
|
|
48
56
|
end
|
|
@@ -63,39 +71,39 @@ module PathCoverage
|
|
|
63
71
|
# How the rows of each card of the file at path nest, parsed
|
|
64
72
|
# as Manifest.parse gives it, as tree gives them.
|
|
65
73
|
def self.tree_in(path, parsed, result)
|
|
66
|
-
source,
|
|
67
|
-
cards = CardTree.of(source, path,
|
|
74
|
+
source, decisions = parsed.values_at(:source, :decisions)
|
|
75
|
+
cards = CardTree.of(source, path, decisions).to_a +
|
|
68
76
|
tree_tops(path, parsed, result)
|
|
69
|
-
cards.to_h do |
|
|
70
|
-
[
|
|
77
|
+
cards.to_h do |decision, rows|
|
|
78
|
+
[decision.split(':').last(2) * ':', rows]
|
|
71
79
|
end
|
|
72
80
|
end
|
|
73
81
|
|
|
74
|
-
# [[card
|
|
82
|
+
# [[card decision, its rows' places]] for each top card of the
|
|
75
83
|
# file at path, as listed_tops names them.
|
|
76
84
|
def self.tree_tops(path, parsed, result)
|
|
77
|
-
source,
|
|
78
|
-
lines = SourceLines.of(source,
|
|
85
|
+
source, decisions = parsed.values_at(:source, :decisions)
|
|
86
|
+
lines = SourceLines.of(source, decisions, result.operands)
|
|
79
87
|
spans(path, parsed, lines).map do |span, rows|
|
|
80
|
-
nested = CardTree.nested(source,
|
|
88
|
+
nested = CardTree.nested(source, decisions, rows)
|
|
81
89
|
["#{path}:#{span.begin}:0", nested]
|
|
82
90
|
end
|
|
83
91
|
end
|
|
84
92
|
|
|
85
93
|
# The top cards of the file at path, as its page draws them:
|
|
86
|
-
# each under the
|
|
87
|
-
# its scope, as listed gives them; operands and
|
|
88
|
-
# Result gives them.
|
|
89
|
-
def self.listed_tops(path, parsed, (operands,
|
|
90
|
-
source,
|
|
91
|
-
lines = SourceLines.of(source,
|
|
92
|
-
scopes =
|
|
94
|
+
# each under the decision of its first line's start, named for
|
|
95
|
+
# its scope, as listed gives them; operands and decision_paths
|
|
96
|
+
# as Result gives them.
|
|
97
|
+
def self.listed_tops(path, parsed, (operands, decision_paths))
|
|
98
|
+
source, decisions = parsed.values_at(:source, :decisions)
|
|
99
|
+
lines = SourceLines.of(source, decisions, operands)
|
|
100
|
+
scopes = CardScopes.of(source)
|
|
93
101
|
spans(path, parsed, lines).to_h do |span, rows|
|
|
94
|
-
|
|
95
|
-
taken = rows.zip(MethodStatements.taken(rows,
|
|
96
|
-
ways = CardWays.card(source,
|
|
102
|
+
decision = "#{path}:#{span.begin}:0"
|
|
103
|
+
taken = rows.zip(MethodStatements.taken(rows, decision_paths))
|
|
104
|
+
ways = CardWays.card(source, decisions, rows)
|
|
97
105
|
named = [scopes[span.begin], span.end, ways, nil]
|
|
98
|
-
[
|
|
106
|
+
[decision, card(decision, named, taken)]
|
|
99
107
|
end
|
|
100
108
|
end
|
|
101
109
|
|
|
@@ -103,63 +111,110 @@ module PathCoverage
|
|
|
103
111
|
# row under the span its line is in, lines as SourceLines.of
|
|
104
112
|
# gives them.
|
|
105
113
|
def self.spans(path, parsed, lines)
|
|
106
|
-
source,
|
|
107
|
-
rows = MethodStatements.top_rows(source, path,
|
|
114
|
+
source, decisions = parsed.values_at(:source, :decisions)
|
|
115
|
+
rows = MethodStatements.top_rows(source, path, decisions)
|
|
108
116
|
rows.group_by { lines[_1.line - 1][:span] }
|
|
109
117
|
end
|
|
110
118
|
|
|
111
|
-
#
|
|
112
|
-
# gives it,
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
(location.start_line..location.end_line).cover?(line)
|
|
119
|
+
# The cards of the file at path, parsed as Manifest.parse
|
|
120
|
+
# gives it, as listed gives them, each listing its ways too
|
|
121
|
+
# when counted's ways are known, counted being [reached, ways,
|
|
122
|
+
# limit, loops], limit the most ways a card lists, loops
|
|
123
|
+
# whether each loop is a fork.
|
|
124
|
+
def self.listed_in(path, parsed, paths, (reached, *counted))
|
|
125
|
+
source, decisions = parsed.values_at(:source, :decisions)
|
|
126
|
+
titles = titles(source, path, decisions)
|
|
127
|
+
lister = WayLister.new(source, path, decisions, counted)
|
|
128
|
+
context = [source, decisions, paths, reached]
|
|
129
|
+
MethodStatements.of(source, path, decisions).to_h do |key, rows|
|
|
130
|
+
count = lister.count(key, rows)
|
|
131
|
+
named = [*titles[key], count, reached&.fetch(key, 0)]
|
|
132
|
+
shown = method_card(key, rows, named, context)
|
|
133
|
+
[key, shown.merge(lister.lists(key, rows, count))]
|
|
127
134
|
end
|
|
128
|
-
holding.empty? ? 'file' : holding.last.name.to_s
|
|
129
135
|
end
|
|
130
136
|
|
|
131
|
-
# The
|
|
132
|
-
|
|
137
|
+
# The card of the def at key, its rows, named as card takes
|
|
138
|
+
# named; context is [source, decisions, paths, reached], as
|
|
139
|
+
# listed_in has them.
|
|
140
|
+
def self.method_card(key, rows, named, context)
|
|
141
|
+
source, decisions, paths, reached = context
|
|
142
|
+
shown = CardContext.rows(source, decisions, rows, paths,
|
|
143
|
+
reached)
|
|
144
|
+
card(key, named, shown)
|
|
145
|
+
end
|
|
133
146
|
|
|
134
|
-
#
|
|
135
|
-
#
|
|
136
|
-
def self.
|
|
137
|
-
|
|
138
|
-
|
|
147
|
+
# { def decision => [its name, its last line] } for each def in
|
|
148
|
+
# source, at path, as its card is titled.
|
|
149
|
+
def self.titles(source, path, decisions)
|
|
150
|
+
names = MethodStatements.names(source, path, decisions)
|
|
151
|
+
lasts = MethodStatements.lasts(source, path, decisions)
|
|
152
|
+
names.to_h { |key, name| [key, [name, lasts[key]]] }
|
|
139
153
|
end
|
|
140
154
|
|
|
141
|
-
# The
|
|
142
|
-
#
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
155
|
+
# The way lists of each card of a file, as CardWayLists gives
|
|
156
|
+
# them.
|
|
157
|
+
class WayLister
|
|
158
|
+
# The lister of the file at path, source, its decisions as
|
|
159
|
+
# Manifest.parse gives them; counted [ways, limit]: ways as a
|
|
160
|
+
# CallTrace counts them, nil when not known, and limit the
|
|
161
|
+
# most ways a card lists.
|
|
162
|
+
def initialize(source, path, decisions, (ways, limit, loops))
|
|
163
|
+
@source = source
|
|
164
|
+
@decisions = decisions
|
|
165
|
+
@ways = ways
|
|
166
|
+
@limit = limit
|
|
167
|
+
@loops = MethodLoops.of(source, path, decisions)
|
|
168
|
+
@forks = LoopForks.of(source, path, decisions)
|
|
169
|
+
@forking = loops
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
# How many ways go through the card of the def at key, its
|
|
173
|
+
# rows, each loop a fork when loops are.
|
|
174
|
+
def count(key, rows)
|
|
175
|
+
CardWays.card(@source, @decisions, rows,
|
|
176
|
+
WayAlgebras::Counted, [true, forked(key)])
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
# The way lists of the card of the def at key, its rows, with
|
|
180
|
+
# count ways through it: none when the ways are not known;
|
|
181
|
+
# those its calls took and its loops' passes; and, when count
|
|
182
|
+
# is no more than the limit, its covered, gaps and impossible.
|
|
183
|
+
def lists(key, rows, count)
|
|
184
|
+
return {} if @ways.nil?
|
|
185
|
+
|
|
186
|
+
walked = CardWayLists.walked(key, @ways, loops(key))
|
|
187
|
+
return walked if count > @limit
|
|
188
|
+
|
|
189
|
+
forked = forked(key)
|
|
190
|
+
split = MethodWays.split_card(@source, @decisions, rows,
|
|
191
|
+
forked)
|
|
192
|
+
checked = [split, forked.keys]
|
|
193
|
+
walked.merge(CardWayLists.checked(key, @ways, checked))
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
private
|
|
197
|
+
|
|
198
|
+
# The names of the loops of the def at key: those holding a
|
|
199
|
+
# row, and those that fork.
|
|
200
|
+
def loops(key)
|
|
201
|
+
(@loops[key].values.flatten + @forks.fetch(key).keys).uniq
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
# The loops of the def at key that fork, as
|
|
205
|
+
# LoopForks gives them; none unless loops are forks.
|
|
206
|
+
def forked(key)
|
|
207
|
+
@forking ? @forks.fetch(key) : {}
|
|
153
208
|
end
|
|
154
209
|
end
|
|
155
210
|
|
|
156
|
-
# The card of the def at
|
|
211
|
+
# The card of the def at decision, named name, ending on line
|
|
157
212
|
# last, with ways through it, as ways folds them, and calls,
|
|
158
213
|
# how many times it was called, nil for a top card, which is no
|
|
159
|
-
# method's, or when not known: its first line, from
|
|
214
|
+
# method's, or when not known: its first line, from decision, and
|
|
160
215
|
# a row for each [statement, taken] of rows.
|
|
161
|
-
def self.card(
|
|
162
|
-
first = Integer(
|
|
216
|
+
def self.card(decision, (name, last, ways, calls), rows)
|
|
217
|
+
first = Integer(decision.split(':')[-2])
|
|
163
218
|
listed = rows.map { |statement, count| row(statement, count) }
|
|
164
219
|
{ 'name' => name, 'first' => first, 'last' => last,
|
|
165
220
|
'ways' => ways, 'calls' => calls, 'rows' => listed }
|
|
@@ -167,11 +222,11 @@ module PathCoverage
|
|
|
167
222
|
|
|
168
223
|
# A card's row: statement's line:column, as its page labels
|
|
169
224
|
# it, its top, its paths, count, how many were taken, and
|
|
170
|
-
# its
|
|
225
|
+
# its decision, nil for a statement that is no decision.
|
|
171
226
|
def self.row(statement, count)
|
|
172
|
-
{ 'at' =>
|
|
227
|
+
{ 'at' => MethodStatements.at(statement),
|
|
173
228
|
'top' => statement.top, 'paths' => statement.paths,
|
|
174
|
-
'taken' => count, '
|
|
229
|
+
'taken' => count, 'decision' => statement.decision }
|
|
175
230
|
end
|
|
176
231
|
end
|
|
177
232
|
end
|