path_coverage 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +316 -177
- 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 +199 -0
- data/lib/path_coverage/card_way_lists.rb +72 -0
- data/lib/path_coverage/card_ways.rb +196 -0
- data/lib/path_coverage/{html_syntax.rb → code_tokens.rb} +38 -25
- 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} +18 -8
- 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/fold_rows.rb +140 -0
- 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 +31 -16
- data/lib/path_coverage/kernel.rb +56 -57
- 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 -17
- data/lib/path_coverage/kinds/chain.rb +40 -11
- data/lib/path_coverage/kinds/choice.rb +7 -10
- data/lib/path_coverage/kinds/contains.rb +43 -33
- data/lib/path_coverage/kinds/safe.rb +44 -46
- data/lib/path_coverage/kinds/write.rb +6 -12
- 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 +94 -59
- 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 +52 -29
- data/lib/path_coverage/manifest_disabled.rb +97 -0
- data/lib/path_coverage/manifest_folding.rb +66 -26
- 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 +147 -139
- 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 +61 -27
- 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 +184 -44
- metadata +36 -29
- 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 -470
- data/lib/path_coverage/html/sort.js +0 -34
- data/lib/path_coverage/html/style.css +0 -470
- 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 -111
- data/lib/path_coverage/html_cells.rb +0 -66
- 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 -23
- 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 -166
- data/lib/path_coverage/html_tabs.rb +0 -26
- data/lib/path_coverage/html_template.rb +0 -26
- data/lib/path_coverage/html_tree.rb +0 -131
|
@@ -1,47 +1,81 @@
|
|
|
1
1
|
module PathCoverage
|
|
2
2
|
# The lists of statements a method's card has rows for: a def's
|
|
3
|
-
# body, the arms of each
|
|
3
|
+
# body, the arms of each decision in it whose arms are statements,
|
|
4
4
|
# and the body of each block in it, as the card lays them out
|
|
5
|
-
# flat. It relies on its includer's rows_in,
|
|
6
|
-
#
|
|
5
|
+
# flat. It relies on its includer's rows_in, decision? and
|
|
6
|
+
# decision_name.
|
|
7
7
|
module StatementArms
|
|
8
|
-
# The nodes a statement's
|
|
8
|
+
# The nodes a statement's decisions are never looked for in: a
|
|
9
9
|
# block's, a lambda's and a begin's statements are rows of
|
|
10
10
|
# their own, after the statement holding them, and a def's
|
|
11
|
-
# body runs only when it is called, its
|
|
11
|
+
# body runs only when it is called, its decisions rows of its own
|
|
12
12
|
# card.
|
|
13
13
|
UNSEEN = %i[block_node begin_node def_node lambda_node].freeze
|
|
14
14
|
|
|
15
|
+
# Example: if/else for if a then 1 else 2 end.
|
|
16
|
+
# operator, a decision node's, with /else after it when node is an
|
|
17
|
+
# if or an unless with an else, so its row names both arms;
|
|
18
|
+
# operator alone for any other, eg a ?:, whose arms are ? and :.
|
|
19
|
+
def with_else(operator, node)
|
|
20
|
+
return operator unless %w[if unless].include?(operator)
|
|
21
|
+
|
|
22
|
+
clause = operator == 'if' ? node.subsequent : node.else_clause
|
|
23
|
+
clause&.type == :else_node ? "#{operator}/else" : operator
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# The tops of statements that end a path, leaving the method.
|
|
27
|
+
LEAVING = %w[return raise].freeze
|
|
28
|
+
|
|
29
|
+
# True for a row that shapes its method's paths: a decision, or a
|
|
30
|
+
# return or a raise, which ends a path. Any other, eg x = 1,
|
|
31
|
+
# runs exactly where what holds it does, so is no row.
|
|
32
|
+
def shapes?(node)
|
|
33
|
+
decision?(node) || LEAVING.include?(top_of(node))
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Where node, a def, is entered: its body's start, or, for an
|
|
37
|
+
# endless def, whose body is one expression, its byte range,
|
|
38
|
+
# to be wrapped; before its end for an empty body.
|
|
39
|
+
def entry_at(node)
|
|
40
|
+
body = node.body
|
|
41
|
+
return node.end_keyword_loc.start_offset if body.nil?
|
|
42
|
+
|
|
43
|
+
loc = body.location
|
|
44
|
+
start = loc.start_offset
|
|
45
|
+
node.equal_loc ? start...loc.end_offset : start
|
|
46
|
+
end
|
|
47
|
+
|
|
15
48
|
# Example: return a ? 1 : 2 if x gives the ?:.
|
|
16
|
-
# The
|
|
17
|
-
# order they are written: in its leaves, eg a
|
|
18
|
-
# arm or a &. call's receiver; not in its arms
|
|
19
|
-
# nor in a body, which have rows of their own.
|
|
20
|
-
# named where it starts, so a node starting
|
|
21
|
-
# does, eg a ?:'s predicate, names that
|
|
22
|
-
# once, and
|
|
23
|
-
#
|
|
24
|
-
def
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
named.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
49
|
+
# The decisions inside decision that are decisions of their
|
|
50
|
+
# own, in the order they are written: in its leaves, eg a
|
|
51
|
+
# modifier if's arm or a &. call's receiver; not in its arms
|
|
52
|
+
# of statements, nor in a body, which have rows of their own.
|
|
53
|
+
# A decision is named where it starts, so a node starting
|
|
54
|
+
# where a decision does, eg a ?:'s predicate, names that
|
|
55
|
+
# decision: each is kept once, and decision itself not at
|
|
56
|
+
# all. None for a top that is no decision, eg a def inside a
|
|
57
|
+
# def, whose decisions are on its own card.
|
|
58
|
+
def inner_decisions(decision)
|
|
59
|
+
return [] unless decision?(decision)
|
|
60
|
+
|
|
61
|
+
found = heads(decision).flat_map { decisions_within(_1) }
|
|
62
|
+
named = found.to_h { [decision_name(_1), _1] }
|
|
63
|
+
named.except(decision_name(decision)).values
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# node when it is a decision, then each decision within it, in
|
|
33
67
|
# order; none in a body or a def.
|
|
34
|
-
def
|
|
68
|
+
def decisions_within(node)
|
|
35
69
|
return [] if UNSEEN.include?(node.type)
|
|
36
70
|
|
|
37
|
-
own =
|
|
38
|
-
own + heads(node).flat_map {
|
|
71
|
+
own = decision?(node) ? [node] : []
|
|
72
|
+
own + heads(node).flat_map { decisions_within(_1) }
|
|
39
73
|
end
|
|
40
74
|
|
|
41
75
|
# Example: items.map { |i| i.price } gives the price row.
|
|
42
76
|
# The rows of the bodies in statement: of each block's and
|
|
43
77
|
# lambda's statements, a block method's included,
|
|
44
|
-
# as its block's
|
|
78
|
+
# as its block's decisions are decisions of their own, and a reach
|
|
45
79
|
# call before its one expression sits outside the
|
|
46
80
|
# expression's own record call; and of each begin's parts.
|
|
47
81
|
def body_rows(statement)
|
|
@@ -75,7 +109,7 @@ module PathCoverage
|
|
|
75
109
|
|
|
76
110
|
# The statements of node's arms, then's before else's; none
|
|
77
111
|
# when node has no arms of statements, as a modifier's arm,
|
|
78
|
-
# and a ?:'s, are part of the
|
|
112
|
+
# and a ?:'s, are part of the decision's own expression.
|
|
79
113
|
def arms_of(node)
|
|
80
114
|
case node.type
|
|
81
115
|
when :if_node then if_arms(node)
|
|
@@ -1,57 +1,8 @@
|
|
|
1
1
|
require_relative 'configuration'
|
|
2
|
-
require_relative 'totals'
|
|
3
2
|
|
|
4
3
|
module PathCoverage
|
|
5
|
-
#
|
|
6
|
-
# total over every file.
|
|
4
|
+
# Which file a decision is in, and whether a file is in a group.
|
|
7
5
|
module Summary
|
|
8
|
-
# One row per file that has sites in site_paths, as
|
|
9
|
-
# Result#paths gives them, in path order: its sites, and
|
|
10
|
-
# its decisions total, and its methods total, its defs' cards
|
|
11
|
-
# in cards, { def site => [taken, size] }, added up.
|
|
12
|
-
def self.files(site_paths, cards)
|
|
13
|
-
by_path = site_paths.group_by { |site, _| path_of(site) }
|
|
14
|
-
by_path.sort.map do |path, sites|
|
|
15
|
-
{
|
|
16
|
-
path:, sites: sites.size,
|
|
17
|
-
decisions: Totals.decisions(sites.to_h),
|
|
18
|
-
methods: methods_of(path, cards)
|
|
19
|
-
}
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
# The methods total of the file at path, its defs' cards
|
|
24
|
-
# added up; [0, 0] for a file with no def.
|
|
25
|
-
def self.methods_of(path, cards)
|
|
26
|
-
Totals.methods(cards.select { |site, _| path_of(site) == path })
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
# The sum of each column over rows; no rows, as for a group
|
|
30
|
-
# no file is in, gives 0 sites and [0, 0] totals.
|
|
31
|
-
def self.total(rows)
|
|
32
|
-
{
|
|
33
|
-
sites: rows.sum { |row| row[:sites] },
|
|
34
|
-
decisions: add(rows.map { |row| row[:decisions] }),
|
|
35
|
-
methods: add(rows.map { |row| row[:methods] })
|
|
36
|
-
}
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
# [name, rows, total] for each of groups, { name => [glob,
|
|
40
|
-
# ...] }, in order: the rows whose path matches any of its
|
|
41
|
-
# globs, and their total. Then Ungrouped, the rows no group
|
|
42
|
-
# matches, when there are any.
|
|
43
|
-
def self.groups(rows, groups)
|
|
44
|
-
grouped = groups.map do |name, globs|
|
|
45
|
-
own = rows.select { |row| matches?(row[:path], globs) }
|
|
46
|
-
[name, own, total(own)]
|
|
47
|
-
end
|
|
48
|
-
every = groups.values.flatten
|
|
49
|
-
rest = rows.reject { |row| matches?(row[:path], every) }
|
|
50
|
-
return grouped if rest.empty?
|
|
51
|
-
|
|
52
|
-
grouped << ['Ungrouped', rest, total(rest)]
|
|
53
|
-
end
|
|
54
|
-
|
|
55
6
|
# True when path matches any of globs.
|
|
56
7
|
def self.matches?(path, globs)
|
|
57
8
|
globs.any? do |glob|
|
|
@@ -59,18 +10,9 @@ module PathCoverage
|
|
|
59
10
|
end
|
|
60
11
|
end
|
|
61
12
|
|
|
62
|
-
#
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
def self.add(pairs)
|
|
66
|
-
pairs.reduce([0, 0]) do |(taken, possible), (more, of)|
|
|
67
|
-
[taken + more, possible + of]
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
# The file a site is in: its name minus :line:column.
|
|
72
|
-
def self.path_of(site)
|
|
73
|
-
site.sub(/:\d+:\d+\z/, '')
|
|
13
|
+
# The file a decision is in: its name minus :line:column.
|
|
14
|
+
def self.path_of(decision)
|
|
15
|
+
decision.sub(/:\d+:\d+\z/, '')
|
|
74
16
|
end
|
|
75
17
|
end
|
|
76
18
|
end
|
data/lib/path_coverage/totals.rb
CHANGED
|
@@ -3,18 +3,20 @@ module PathCoverage
|
|
|
3
3
|
# every covered file. They count the very paths the gap
|
|
4
4
|
# lines list as never taken.
|
|
5
5
|
module Totals
|
|
6
|
-
# Paths
|
|
7
|
-
# gives them, lists every
|
|
8
|
-
# its count; one with a
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
# Paths alone, each decision's counted on its own:
|
|
7
|
+
# decision_paths, as Result#paths gives them, lists every
|
|
8
|
+
# possible path of each decision with its count; one with a
|
|
9
|
+
# count above zero was taken.
|
|
10
|
+
def self.alone(decision_paths)
|
|
11
|
+
every = decision_paths.values.flatten
|
|
11
12
|
[every.count { |each| each[:count].positive? }, every.size]
|
|
12
13
|
end
|
|
13
14
|
|
|
14
15
|
# Example: cards [4, 6] and [17, 21] give [21, 27].
|
|
15
|
-
# Paths
|
|
16
|
-
# size] }, each method's card's paths taken of its
|
|
17
|
-
|
|
16
|
+
# Paths combined through each method: cards is { def decision =>
|
|
17
|
+
# [taken, size] }, each method's card's paths taken of its
|
|
18
|
+
# size, its rows' paths added up.
|
|
19
|
+
def self.combined(cards)
|
|
18
20
|
cards.values.reduce([0, 0]) do |(taken, possible), (more, of)|
|
|
19
21
|
[taken + more, possible + of]
|
|
20
22
|
end
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
require_relative 'condition'
|
|
2
|
+
|
|
3
|
+
module PathCoverage
|
|
4
|
+
# The way one call is taking through its method, kept as a stack
|
|
5
|
+
# of units: the call's own, then each loop under way, innermost
|
|
6
|
+
# last. A step goes to the innermost loop holding its row,
|
|
7
|
+
# closing first any loop under way that does not hold it. Each
|
|
8
|
+
# pass of a loop is a way of its own, counted under the loop;
|
|
9
|
+
# the unit holding the loop takes it as one step: how many
|
|
10
|
+
# passes it made, 0, 1 or 2+, and the set of ways they took. So
|
|
11
|
+
# a way holds each row at most once, however many passes a loop
|
|
12
|
+
# makes.
|
|
13
|
+
class Walk
|
|
14
|
+
# A call, or a loop under way, named by its entry or its loop,
|
|
15
|
+
# with the steps of its way so far, or of its latest pass, how
|
|
16
|
+
# many passes it has made, and the distinct ways of those ended.
|
|
17
|
+
Unit = Struct.new(:name, :steps, :passes, :seen)
|
|
18
|
+
|
|
19
|
+
# A call of the method whose entry is named entry, just
|
|
20
|
+
# entered, counting each way it ends on ways, { unit's name =>
|
|
21
|
+
# { way => count } }; loops is { row's name => the names of
|
|
22
|
+
# the loops holding it, outermost first }, and repeats { row's
|
|
23
|
+
# name => the while or until whose test holds it }.
|
|
24
|
+
def initialize(entry, ways, loops, repeats = {})
|
|
25
|
+
@ways = ways
|
|
26
|
+
@loops = loops
|
|
27
|
+
@repeats = repeats
|
|
28
|
+
@units = [unit(entry)]
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# The name of the entry of the method being called.
|
|
32
|
+
def entry = @units.first.name
|
|
33
|
+
|
|
34
|
+
# Adds step, a row's [name, ...], to the way of the innermost
|
|
35
|
+
# loop under way holding its row, or the call's own; but no
|
|
36
|
+
# step of a row in the test of a while under way, as each test
|
|
37
|
+
# after its first repeats its first.
|
|
38
|
+
def step(step)
|
|
39
|
+
name = step[0]
|
|
40
|
+
return if @units.map(&:name).include?(@repeats[name])
|
|
41
|
+
|
|
42
|
+
close_to(@loops[name])
|
|
43
|
+
@units.last.steps << step
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Starts a pass of the loop named loop, counting its pass
|
|
47
|
+
# before when there is one.
|
|
48
|
+
def passed(loop)
|
|
49
|
+
opened = opened(loop)
|
|
50
|
+
if opened.passes.positive?
|
|
51
|
+
count(opened)
|
|
52
|
+
opened.steps = []
|
|
53
|
+
end
|
|
54
|
+
opened.passes += 1
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Ends the loop named loop, its items all given.
|
|
58
|
+
def exhausted(loop)
|
|
59
|
+
opened(loop)
|
|
60
|
+
close
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Ends the call, closing every loop under way, and counts its
|
|
64
|
+
# way.
|
|
65
|
+
def finish
|
|
66
|
+
close_to([])
|
|
67
|
+
count(@units.first)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
private
|
|
71
|
+
|
|
72
|
+
# A unit named name, with no step or pass yet.
|
|
73
|
+
def unit(name) = Unit.new(name, [], 0, Set.new)
|
|
74
|
+
|
|
75
|
+
# The unit of the loop named loop, innermost, any loop under
|
|
76
|
+
# way inside it closed; a new one when it is not under way.
|
|
77
|
+
def opened(loop)
|
|
78
|
+
close_to([*@loops[loop], loop])
|
|
79
|
+
@units << unit(loop) unless @units.last.name == loop
|
|
80
|
+
@units.last
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# Closes each loop under way, innermost first, until one of
|
|
84
|
+
# holding, the loops holding a row, is innermost.
|
|
85
|
+
def close_to(holding)
|
|
86
|
+
close while @units.size > 1 && holding.none?(@units.last.name)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# Ends the innermost loop under way: counts its last pass, if
|
|
90
|
+
# it made one, and adds it to the way holding it as one step.
|
|
91
|
+
def close
|
|
92
|
+
ended = @units.pop
|
|
93
|
+
count(ended) if ended.passes.positive?
|
|
94
|
+
items = ITEMS[[ended.passes, 2].min]
|
|
95
|
+
@units.last.steps << [ended.name, [items], ended.seen]
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# Counts unit's steps as one more taking of its way, noting it
|
|
99
|
+
# among the ways seen.
|
|
100
|
+
def count(unit)
|
|
101
|
+
way = unit.steps.dup.freeze
|
|
102
|
+
(@ways[unit.name] ||= Hash.new(0))[way] += 1
|
|
103
|
+
unit.seen << way
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
@@ -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
|