Change formatters to take nillable profile

This commit is contained in:
Michael Miller 2019-03-25 16:05:38 -06:00
parent 6dd4c4bc2f
commit aabc25ad4f
8 changed files with 25 additions and 19 deletions

View file

@ -28,7 +28,7 @@ class SpyFormatter < Spectator::Formatting::Formatter
# Stores all invocatiosn made to `#end_suite`. # Stores all invocatiosn made to `#end_suite`.
# Each element is an invocation and the value is the arguments passed to the method. # Each element is an invocation and the value is the arguments passed to the method.
getter end_suite_calls = [] of NamedTuple(report: Spectator::Report, profile: Bool) getter end_suite_calls = [] of NamedTuple(report: Spectator::Report, profile: Spectator::Profile?)
# Number of times the `#end_suite` method was called. # Number of times the `#end_suite` method was called.
def end_suite_call_count def end_suite_call_count

View file

@ -14,8 +14,8 @@ module Spectator::Formatting
# Called when a test suite finishes. # Called when a test suite finishes.
# The results from the entire suite are provided. # The results from the entire suite are provided.
# The *profile* flag is set to true when profiling results should be generated. # The *profile* value is not nil when profiling results should be displayed.
abstract def end_suite(report : Report, profile : Bool) abstract def end_suite(report : Report, profile : Profile?)
# Called before a test starts. # Called before a test starts.
abstract def start_example(example : Example) abstract def start_example(example : Example)

View file

@ -20,12 +20,12 @@ module Spectator::Formatting
# Called when a test suite finishes. # Called when a test suite finishes.
# The results from the entire suite are provided. # The results from the entire suite are provided.
# The *profile* flag is set to true when profiling results should be generated. # The *profile* value is not nil when profiling results should be displayed.
def end_suite(report : Report, profile : Bool) def end_suite(report : Report, profile : Profile?)
@json.end_array # examples @json.end_array # examples
totals(report) totals(report)
timing(report) timing(report)
profile(report) if profile profile(profile) if profile
@json.field("result", report.failed? ? "fail" : "success") @json.field("result", report.failed? ? "fail" : "success")
@json.end_object @json.end_object
end end
@ -66,7 +66,7 @@ module Spectator::Formatting
end end
# Adds the profile information to the document. # Adds the profile information to the document.
private def profile(report) private def profile(profile)
raise NotImplementedError.new("profile") raise NotImplementedError.new("profile")
end end
end end

View file

@ -24,8 +24,8 @@ module Spectator::Formatting
# Called when a test suite finishes. # Called when a test suite finishes.
# The results from the entire suite are provided. # The results from the entire suite are provided.
# The *profile* flag does nothing for this formatter. # The *profile* value does nothing for this formatter.
def end_suite(report : Report, profile : Bool) def end_suite(report : Report, profile : Profile?)
test_suites_block(report) test_suites_block(report)
@xml.end_document @xml.end_document
@xml.flush @xml.flush

View file

@ -9,7 +9,7 @@ module Spectator::Formatting
# Called when a test suite finishes. # Called when a test suite finishes.
# The results from the entire suite are provided. # The results from the entire suite are provided.
def end_suite(report : Report, profile : Bool) def end_suite(report : Report, profile : Profile?)
# ... crickets ... # ... crickets ...
end end

View file

@ -9,14 +9,14 @@ module Spectator::Formatting
# Produces the summary of test suite from a report. # Produces the summary of test suite from a report.
# A block describing each failure is displayed. # A block describing each failure is displayed.
# At the end, the totals and runtime are printed. # At the end, the totals and runtime are printed.
# The *profile* flag is set to true when profiling results should be generated. # The *profile* value is not nil when profiling results should be displayed.
def end_suite(report, profile : Bool) def end_suite(report, profile : Profile?)
if report.example_count > 0 if report.example_count > 0
@io.puts if is_a?(DotsFormatter) @io.puts if is_a?(DotsFormatter)
@io.puts @io.puts
end end
failures(report.failures) if report.failed_count > 0 failures(report.failures) if report.failed_count > 0
profile(report) if profile profile(profile) if profile
stats(report) stats(report)
remaining(report) if report.remaining? remaining(report) if report.remaining?
if report.failed? if report.failed?
@ -39,7 +39,7 @@ module Spectator::Formatting
end end
# Produces the profiling section of the summary. # Produces the profiling section of the summary.
private def profile(report) private def profile(profile)
raise NotImplementedError.new("profile") raise NotImplementedError.new("profile")
end end

View file

@ -16,9 +16,10 @@ module Spectator::Formatting
# Called when a test suite finishes. # Called when a test suite finishes.
# The results from the entire suite are provided. # The results from the entire suite are provided.
def end_suite(report : Report, profile : Bool) # The *profile* value is not nil when profiling results should be displayed.
def end_suite(report : Report, profile : Profile?)
@io.puts "Bail out!" if report.remaining? @io.puts "Bail out!" if report.remaining?
profile(report) if profile profile(profile) if profile
end end
# Called before a test starts. # Called before a test starts.
@ -32,8 +33,8 @@ module Spectator::Formatting
@index += 1 @index += 1
end end
# Generates profiling information for the report. # Displays profiling information.
private def profile(report) private def profile(profile)
raise NotImplementedError.new("profile") raise NotImplementedError.new("profile")
end end
end end

View file

@ -24,7 +24,7 @@ module Spectator
# Generate a report and pass it along to the formatter. # Generate a report and pass it along to the formatter.
remaining = @suite.size - results.size remaining = @suite.size - results.size
report = Report.new(results, elapsed, remaining, @config.fail_blank?) report = Report.new(results, elapsed, remaining, @config.fail_blank?)
@config.each_formatter(&.end_suite(report, @config.profile?)) @config.each_formatter(&.end_suite(report, profile(report)))
!report.failed? !report.failed?
end end
@ -66,5 +66,10 @@ module Spectator
example_expectations = Expectations::ExampleExpectations.new(expectations) example_expectations = Expectations::ExampleExpectations.new(expectations)
SuccessfulResult.new(example, Time::Span.zero, example_expectations) SuccessfulResult.new(example, Time::Span.zero, example_expectations)
end end
# Generates and returns a profile if one should be displayed.
private def profile(report)
Profile.generate(report) if @config.profile?
end
end end
end end