Class: Tryouts::CLI::CompactFormatter
- Inherits:
-
Object
- Object
- Tryouts::CLI::CompactFormatter
show all
- Includes:
- FormatterInterface
- Defined in:
- lib/tryouts/cli/formatters/compact.rb
Overview
Compact single-line formatter focused on results
Instance Attribute Summary
#current_indent, #stderr, #stdout
Instance Method Summary
collapse
-
#batch_summary(failure_collector) ⇒ Object
Summary operations - show failure summary.
-
#debug_info(message, level: 0) ⇒ Object
Debug and diagnostic output - minimal in compact mode.
-
#error_message(message, backtrace: nil) ⇒ Object
-
#file_execution_start(file_path, test_count:, context_mode:) ⇒ Object
-
#file_parsed(_file_path, test_count:, setup_present: false, teardown_present: false) ⇒ Object
-
#file_result(_file_path, total_tests:, failed_count:, error_count:, elapsed_time: nil) ⇒ Object
-
#file_start(file_path, context_info: {}) ⇒ Object
File-level operations - compact single lines.
-
#grand_total(total_tests:, failed_count:, error_count:, successful_files:, total_files:, elapsed_time:) ⇒ Object
-
#initialize(options = {}) ⇒ CompactFormatter
constructor
A new instance of CompactFormatter.
-
#live_status_capabilities ⇒ Object
-
#parser_warnings(file_path, warnings:) ⇒ Object
-
#phase_header(message, file_count: nil) ⇒ Object
Phase-level output - minimal for compact mode.
-
#setup_output(output_text) ⇒ Object
-
#setup_start(line_range:) ⇒ Object
Setup/teardown operations - minimal output.
-
#teardown_output(output_text) ⇒ Object
-
#teardown_start(line_range:) ⇒ Object
-
#test_output(test_case:, output_text:, result_packet:) ⇒ Object
-
#test_result(result_packet) ⇒ Object
-
#test_start(test_case:, index:, total:) ⇒ Object
Test-level operations - only show in debug mode for compact.
-
#trace_info(message, level: 0) ⇒ Object
#file_end, #live_status_manager, #puts, #set_live_status_manager, #test_end, #update_live_status, #write
Constructor Details
Returns a new instance of CompactFormatter.
9
10
11
12
13
14
15
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 9
def initialize(options = {})
super
@show_debug = options.fetch(:debug, false)
@show_trace = options.fetch(:trace, false)
@show_passed = options.fetch(:show_passed, true)
@show_stack_traces = options.fetch(:stack_traces, false) || options.fetch(:debug, false)
end
|
Instance Method Details
#batch_summary(failure_collector) ⇒ Object
Summary operations - show failure summary
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
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 64
def batch_summary(failure_collector)
return unless failure_collector.any_failures?
puts
puts separator
puts Console.color(:red, 'Failed Tests:')
puts
failure_number = 1
failure_collector.failures_by_file.each do |file_path, failures|
failures.each do |failure|
pretty_path = Console.pretty_path(file_path)
location = if failure.line_number > 0
"#{pretty_path}:#{failure.line_number + 1}"
else
pretty_path
end
puts " #{failure_number}) #{location}"
puts " #{Console.color(:red, '✗')} #{failure.description}"
puts " #{failure.failure_reason}"
puts
failure_number += 1
end
end
end
|
#debug_info(message, level: 0) ⇒ Object
Debug and diagnostic output - minimal in compact mode
237
238
239
240
241
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 237
def debug_info(message, level: 0)
return unless @show_debug
@stderr.puts indent_text("DEBUG: #{message}", level)
end
|
#error_message(message, backtrace: nil) ⇒ Object
249
250
251
252
253
254
255
256
257
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 249
def error_message(message, backtrace: nil)
@stderr.puts Console.color(:red, "ERROR: #{message}")
return unless backtrace && @show_stack_traces
Console.pretty_backtrace(backtrace, limit: 3).each do |line|
@stderr.puts indent_text(line, 1)
end
end
|
#file_execution_start(file_path, test_count:, context_mode:) ⇒ Object
57
58
59
60
61
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 57
def file_execution_start(file_path, test_count:, context_mode:)
pretty_path = Console.pretty_path(file_path)
puts
puts "#{pretty_path}: #{test_count} tests"
end
|
#file_parsed(_file_path, test_count:, setup_present: false, teardown_present: false) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 35
def file_parsed(_file_path, test_count:, setup_present: false, teardown_present: false)
return unless @show_debug
= []
<< 'setup' if setup_present
<< 'teardown' if teardown_present
suffix = .empty? ? '' : " +#{.join(',')}"
@stderr.puts indent_text("Parsed #{test_count} tests#{suffix}", 1)
end
|
#file_result(_file_path, total_tests:, failed_count:, error_count:, elapsed_time: nil) ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 94
def file_result(_file_path, total_tests:, failed_count:, error_count:, elapsed_time: nil)
issues_count = failed_count + error_count
passed_count = total_tests - issues_count
details = []
if issues_count > 0
status = Console.color(:red, '✗')
details << "#{passed_count}/#{total_tests} passed"
else
status = Console.color(:green, '✓')
details << "#{total_tests} passed"
end
if error_count > 0
details << "#{error_count} errors"
end
if failed_count > 0
details << "#{failed_count} failed"
end
time_str = format_timing(elapsed_time)
puts " #{status} #{details.join(', ')}#{time_str}"
end
|
#file_start(file_path, context_info: {}) ⇒ Object
File-level operations - compact single lines
31
32
33
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 31
def file_start(file_path, context_info: {})
end
|
#grand_total(total_tests:, failed_count:, error_count:, successful_files:, total_files:, elapsed_time:) ⇒ Object
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 216
def grand_total(total_tests:, failed_count:, error_count:, successful_files:, total_files:, elapsed_time:)
@stderr.puts
issues_count = failed_count + error_count
if issues_count > 0
passed = [total_tests - issues_count, 0].max details = []
details << "#{failed_count} failed" if failed_count > 0
details << "#{error_count} errors" if error_count > 0
result = Console.color(:red, "#{details.join(', ')}, #{passed} passed")
else
result = Console.color(:green, "#{total_tests} tests passed")
end
time_str = format_timing(elapsed_time)
@stderr.puts "#{result}#{time_str}"
@stderr.puts "#{successful_files} of #{total_files} files passed"
end
|
#live_status_capabilities ⇒ Object
259
260
261
262
263
264
265
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 259
def live_status_capabilities
{
supports_coordination: true, output_frequency: :medium, requires_tty: false, }
end
|
#parser_warnings(file_path, warnings:) ⇒ Object
47
48
49
50
51
52
53
54
55
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 47
def parser_warnings(file_path, warnings:)
return if warnings.empty? || !@options.fetch(:warnings, true)
@stderr.puts
@stderr.puts Console.color(:yellow, "Warnings:")
warnings.each do |warning|
@stderr.puts " #{Console.pretty_path(file_path)}:#{warning.line_number}: #{warning.message}"
end
end
|
Phase-level output - minimal for compact mode
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 18
def (message, file_count: nil)
if message.include?('PROCESSING')
text = file_count ? "#{message}" : "#{message}..."
@stderr.puts text
elsif !message.include?('EXECUTING')
@stderr.puts message
end
end
|
#setup_output(output_text) ⇒ Object
192
193
194
195
196
197
198
199
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 192
def setup_output(output_text)
return if output_text.strip.empty?
return unless @show_debug
lines = output_text.lines.count
@stderr.puts " Setup output (#{lines} lines)"
end
|
#setup_start(line_range:) ⇒ Object
Setup/teardown operations - minimal output
188
189
190
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 188
def setup_start(line_range:)
end
|
#teardown_output(output_text) ⇒ Object
207
208
209
210
211
212
213
214
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 207
def teardown_output(output_text)
return if output_text.strip.empty?
return unless @show_debug
lines = output_text.lines.count
@stderr.puts " Teardown output (#{lines} lines)"
end
|
#teardown_start(line_range:) ⇒ Object
201
202
203
204
205
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 201
def teardown_start(line_range:)
return unless @show_debug
@stderr.puts ' Teardown...'
end
|
#test_output(test_case:, output_text:, result_packet:) ⇒ Object
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 169
def test_output(test_case:, output_text:, result_packet:)
return if output_text.nil? || output_text.strip.empty?
return unless @show_debug
return if result_packet.passed?
puts " Output: #{output_text.lines.count} lines"
if output_text.lines.count <= 3
output_text.lines.each do |line|
puts " #{line.chomp}"
end
else
puts " #{output_text.lines.first.chomp}"
puts " ... (#{output_text.lines.count - 2} more lines)"
puts " #{output_text.lines.last.chomp}"
end
end
|
#test_result(result_packet) ⇒ Object
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 129
def test_result(result_packet)
return if result_packet.passed? && !@show_passed
test_case = result_packet.test_case
desc = test_case.description.to_s
desc = 'unnamed test' if desc.empty?
case result_packet.status
when :passed
status = Console.color(:green, '✓')
puts indent_text("#{status} #{desc}", 1)
when :failed
status = Console.color(:red, '✗')
puts indent_text("#{status} #{desc}", 1)
if result_packet.actual_results.any?
failure_info = "got: #{result_packet.first_actual.inspect}"
puts indent_text(" #{failure_info}", 1)
end
if test_case.source_lines && test_case.source_lines.size <= 3
test_case.source_lines.each do |line|
next if line.strip.empty? || line.strip.start_with?('#')
puts indent_text(" #{line.strip}", 1)
break end
end
when :skipped
status = Console.color(:yellow, '-')
puts indent_text("#{status} #{desc}", 1)
else
status = '?'
puts indent_text("#{status} #{desc}", 1)
end
end
|
#test_start(test_case:, index:, total:) ⇒ Object
Test-level operations - only show in debug mode for compact
120
121
122
123
124
125
126
127
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 120
def test_start(test_case:, index:, total:)
return unless @show_debug
desc = test_case.description.to_s
desc = "test #{index}" if desc.empty?
puts " Running: #{desc}"
end
|
#trace_info(message, level: 0) ⇒ Object
243
244
245
246
247
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 243
def trace_info(message, level: 0)
return unless @show_trace
@stderr.puts indent_text("TRACE: #{message}", level)
end
|