Skip to content

Commit d8e5e92

Browse files
Reorganize summary code.
1 parent 67c6dd7 commit d8e5e92

File tree

6 files changed

+125
-106
lines changed

6 files changed

+125
-106
lines changed

lib/covered.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55

66
require_relative "covered/version"
77
require_relative "covered/policy"
8+
9+
require_relative "covered/brief_summary"
10+
require_relative "covered/partial_summary"

lib/covered/brief_summary.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# frozen_string_literal: true
2+
3+
# Released under the MIT License.
4+
# Copyright, 2018-2025, by Samuel Williams.
5+
6+
require_relative "summary"
7+
8+
module Covered
9+
class BriefSummary < Summary
10+
def call(wrapper, output = $stdout, before: 4, after: 4)
11+
terminal = self.terminal(output)
12+
13+
ordered = []
14+
15+
statistics = self.each(wrapper) do |coverage|
16+
ordered << coverage unless coverage.complete?
17+
end
18+
19+
terminal.puts
20+
statistics.print(output)
21+
22+
if ordered.any?
23+
terminal.puts "", "Least Coverage:"
24+
ordered.sort_by!(&:missing_count).reverse!
25+
26+
ordered.first(5).each do |coverage|
27+
path = wrapper.relative_path(coverage.path)
28+
29+
terminal.write path, style: :brief_path
30+
terminal.puts ": #{coverage.missing_count} lines not executed!"
31+
end
32+
end
33+
end
34+
end
35+
end

lib/covered/partial_summary.rb

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# frozen_string_literal: true
2+
3+
# Released under the MIT License.
4+
# Copyright, 2018-2025, by Samuel Williams.
5+
6+
require_relative "summary"
7+
8+
module Covered
9+
class PartialSummary < Summary
10+
def print_coverage(terminal, coverage, before: 4, after: 4)
11+
return if coverage.zero?
12+
13+
line_offset = 1
14+
counts = coverage.counts
15+
last_line = nil
16+
17+
coverage.read do |file|
18+
print_line_header(terminal)
19+
20+
file.each_line do |line|
21+
range = Range.new([line_offset - before, 0].max, line_offset+after)
22+
23+
if counts[range]&.include?(0)
24+
count = counts[line_offset]
25+
26+
if last_line and last_line != line_offset-1
27+
terminal.puts ":".rjust(16)
28+
end
29+
30+
print_annotations(terminal, coverage, line, line_offset)
31+
print_line(terminal, line, line_offset, count)
32+
33+
last_line = line_offset
34+
end
35+
36+
line_offset += 1
37+
end
38+
end
39+
end
40+
41+
def call(wrapper, output = $stdout, **options)
42+
terminal = self.terminal(output)
43+
complete_files = []
44+
45+
statistics = self.each(wrapper) do |coverage|
46+
path = wrapper.relative_path(coverage.path)
47+
terminal.puts ""
48+
terminal.puts path, style: :path
49+
50+
begin
51+
print_coverage(terminal, coverage, **options)
52+
rescue => error
53+
print_error(terminal, error)
54+
end
55+
56+
coverage.print(output)
57+
end
58+
59+
# Collect files with 100% coverage that were not shown
60+
wrapper.each do |coverage|
61+
if coverage.ratio >= 1.0
62+
complete_files << wrapper.relative_path(coverage.path)
63+
end
64+
end
65+
66+
terminal.puts
67+
statistics.print(output)
68+
69+
# Show information about files with 100% coverage
70+
if complete_files.any?
71+
terminal.puts ""
72+
if complete_files.size == 1
73+
terminal.puts "1 file has 100% coverage and is not shown above:"
74+
else
75+
terminal.puts "#{complete_files.size} files have 100% coverage and are not shown above:"
76+
end
77+
78+
complete_files.sort.each do |path|
79+
terminal.write " - ", style: :covered_prefix
80+
terminal.puts path, style: :brief_path
81+
end
82+
end
83+
end
84+
end
85+
end

lib/covered/summary.rb

Lines changed: 0 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -136,110 +136,6 @@ def initialize
136136
end
137137
end
138138

139-
class BriefSummary < Summary
140-
def call(wrapper, output = $stdout, before: 4, after: 4)
141-
terminal = self.terminal(output)
142-
143-
ordered = []
144-
145-
statistics = self.each(wrapper) do |coverage|
146-
ordered << coverage unless coverage.complete?
147-
end
148-
149-
terminal.puts
150-
statistics.print(output)
151-
152-
if ordered.any?
153-
terminal.puts "", "Least Coverage:"
154-
ordered.sort_by!(&:missing_count).reverse!
155-
156-
ordered.first(5).each do |coverage|
157-
path = wrapper.relative_path(coverage.path)
158-
159-
terminal.write path, style: :brief_path
160-
terminal.puts ": #{coverage.missing_count} lines not executed!"
161-
end
162-
end
163-
end
164-
end
165-
166-
class PartialSummary < Summary
167-
def print_coverage(terminal, coverage, before: 4, after: 4)
168-
return if coverage.zero?
169-
170-
line_offset = 1
171-
counts = coverage.counts
172-
last_line = nil
173-
174-
coverage.read do |file|
175-
print_line_header(terminal)
176-
177-
file.each_line do |line|
178-
range = Range.new([line_offset - before, 0].max, line_offset+after)
179-
180-
if counts[range]&.include?(0)
181-
count = counts[line_offset]
182-
183-
if last_line and last_line != line_offset-1
184-
terminal.puts ":".rjust(16)
185-
end
186-
187-
print_annotations(terminal, coverage, line, line_offset)
188-
print_line(terminal, line, line_offset, count)
189-
190-
last_line = line_offset
191-
end
192-
193-
line_offset += 1
194-
end
195-
end
196-
end
197-
198-
def call(wrapper, output = $stdout, **options)
199-
terminal = self.terminal(output)
200-
complete_files = []
201-
202-
statistics = self.each(wrapper) do |coverage|
203-
path = wrapper.relative_path(coverage.path)
204-
terminal.puts ""
205-
terminal.puts path, style: :path
206-
207-
begin
208-
print_coverage(terminal, coverage, **options)
209-
rescue => error
210-
print_error(terminal, error)
211-
end
212-
213-
coverage.print(output)
214-
end
215-
216-
# Collect files with 100% coverage that were not shown
217-
wrapper.each do |coverage|
218-
if coverage.ratio >= 1.0
219-
complete_files << wrapper.relative_path(coverage.path)
220-
end
221-
end
222-
223-
terminal.puts
224-
statistics.print(output)
225-
226-
# Show information about files with 100% coverage
227-
if complete_files.any?
228-
terminal.puts ""
229-
if complete_files.size == 1
230-
terminal.puts "1 file has 100% coverage and is not shown above:"
231-
else
232-
terminal.puts "#{complete_files.size} files have 100% coverage and are not shown above:"
233-
end
234-
235-
complete_files.sort.each do |path|
236-
terminal.write " - ", style: :covered_prefix
237-
terminal.puts path, style: :brief_path
238-
end
239-
end
240-
end
241-
end
242-
243139
class Quiet
244140
def call(wrapper, output = $stdout)
245141
# Silent.

test/covered/brief_summary.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Released under the MIT License.
44
# Copyright, 2018-2025, by Samuel Williams.
55

6-
require "covered/summary"
6+
require "covered/brief_summary"
77
require "covered/files"
88

99
describe Covered::BriefSummary do

test/covered/partial_summary.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Released under the MIT License.
44
# Copyright, 2018-2025, by Samuel Williams.
55

6-
require "covered/summary"
6+
require "covered/partial_summary"
77
require "covered/files"
88

99
describe Covered::PartialSummary do

0 commit comments

Comments
 (0)