-
Notifications
You must be signed in to change notification settings - Fork 192
/
verify_reporter.rb
97 lines (81 loc) · 2.16 KB
/
verify_reporter.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
module Recog
class VerifyReporter
attr_reader :formatter
attr_reader :success_count, :warning_count, :failure_count
def initialize(options, formatter, path=nil)
@options = options
@formatter = formatter
@path = path
reset_counts
end
def report(fingerprint_count)
reset_counts
if detail? and !@path.to_s.empty?
formatter.status_message("\n#{@path}:\n")
end
yield self
summarize(fingerprint_count) unless @options.quiet
end
def success(text)
@success_count += 1
formatter.success_message("#{padding}#{text}") if detail?
end
def warning(text, line=nil)
return unless @options.warnings
@warning_count += 1
formatter.warning_message("#{path_label(line)}#{padding}#{text}")
end
def failure(text, line=nil)
@failure_count += 1
formatter.failure_message("#{path_label(line)}#{padding}#{text}")
end
def print_name(fingerprint)
if detail? && fingerprint.tests.any?
name = fingerprint.name.empty? ? '[unnamed]' : fingerprint.name
formatter.status_message("\n#{name}")
end
end
def summarize(fingerprint_count)
print_fingerprint_count(fingerprint_count) if detail?
print_summary
end
def print_fingerprint_count(count)
formatter.status_message("\nVerified #{count} fingerprints:")
end
def print_summary
colorize_summary(summary_line)
end
private
def reset_counts
@success_count = @failure_count = @warning_count = 0
end
def detail?
@options.detail
end
def path_label(line=nil)
unless detail?
line_label = line ? line.to_s + ":" : ""
@path.to_s.empty? ? "" : "#{@path}:#{line_label} "
end
end
def padding
' ' if @options.detail
end
def summary_line
summary = "#{path_label}SUMMARY: Test completed with "
summary << "#{@success_count} successful"
summary << ", #{@warning_count} warnings"
summary << ", and #{@failure_count} failures"
summary
end
def colorize_summary(summary)
if @failure_count > 0
formatter.failure_message(summary)
elsif @warning_count > 0
formatter.warning_message(summary)
else
formatter.success_message(summary)
end
end
end
end