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.
11
12
13
14
15
16
17
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 11
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
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
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 66
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
239
240
241
242
243
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 239
def debug_info(message, level: 0)
return unless @show_debug
@stderr.puts indent_text("DEBUG: #{message}", level)
end
|
#error_message(message, backtrace: nil) ⇒ Object
251
252
253
254
255
256
257
258
259
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 251
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
59
60
61
62
63
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 59
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
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 37
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 96
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
33
34
35
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 33
def file_start(file_path, context_info: {})
end
|
#grand_total(total_tests:, failed_count:, error_count:, successful_files:, total_files:, elapsed_time:) ⇒ Object
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 218
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
261
262
263
264
265
266
267
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 261
def live_status_capabilities
{
supports_coordination: true, output_frequency: :medium, requires_tty: false, }
end
|
#parser_warnings(file_path, warnings:) ⇒ Object
49
50
51
52
53
54
55
56
57
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 49
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
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 20
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
194
195
196
197
198
199
200
201
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 194
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
190
191
192
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 190
def setup_start(line_range:)
end
|
#teardown_output(output_text) ⇒ Object
209
210
211
212
213
214
215
216
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 209
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
203
204
205
206
207
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 203
def teardown_start(line_range:)
return unless @show_debug
@stderr.puts ' Teardown...'
end
|
#test_output(test_case:, output_text:, result_packet:) ⇒ Object
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 171
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
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
168
169
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 131
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
122
123
124
125
126
127
128
129
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 122
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
245
246
247
248
249
|
# File 'lib/tryouts/cli/formatters/compact.rb', line 245
def trace_info(message, level: 0)
return unless @show_trace
@stderr.puts indent_text("TRACE: #{message}", level)
end
|