Add profile config option

This commit is contained in:
Michael Miller 2019-03-25 12:26:45 -06:00
parent 35b887f8f0
commit a02e2ff701
4 changed files with 22 additions and 2 deletions

View file

@ -140,7 +140,7 @@ module Spectator
# Adds the profile output option to the parser. # Adds the profile output option to the parser.
private def profile_option(parser, builder) private def profile_option(parser, builder)
parser.on("-p", "--profile", "Display the 10 slowest specs") do parser.on("-p", "--profile", "Display the 10 slowest specs") do
raise NotImplementedError.new("-p") builder.profile
end end
end end

View file

@ -19,6 +19,9 @@ module Spectator
# Indicates whether tests are run in a random order. # Indicates whether tests are run in a random order.
getter? randomize : Bool getter? randomize : Bool
# Indicates whether profiling information should be displayed.
getter? profile : Bool
# Filter that determines which examples to run. # Filter that determines which examples to run.
getter example_filter : ExampleFilter getter example_filter : ExampleFilter
@ -30,6 +33,7 @@ module Spectator
@dry_run = builder.dry_run? @dry_run = builder.dry_run?
@random = builder.random @random = builder.random
@randomize = builder.randomize? @randomize = builder.randomize?
@profile = builder.profile?
@example_filter = builder.example_filter @example_filter = builder.example_filter
end end

View file

@ -17,6 +17,7 @@ module Spectator
@fail_blank = false @fail_blank = false
@dry_run = false @dry_run = false
@randomize = false @randomize = false
@profile = false
@filters = [] of ExampleFilter @filters = [] of ExampleFilter
# Sets the primary formatter to use for reporting test progress and results. # Sets the primary formatter to use for reporting test progress and results.
@ -109,6 +110,21 @@ module Spectator
@randomize @randomize
end end
# Displays profiling information
def profile
self.profile = true
end
# Enables or disables displaying profiling information.
def profile=(flag)
@profile = flag
end
# Indicates whether profiling information should be displayed.
protected def profile?
@profile
end
# Adds a filter to determine which examples can run. # Adds a filter to determine which examples can run.
def add_example_filter(filter : ExampleFilter) def add_example_filter(filter : ExampleFilter)
@filters << filter @filters << filter

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, false)) # TODO: Profile flag. @config.each_formatter(&.end_suite(report, @config.profile?))
!report.failed? !report.failed?
end end