good printing for results

This commit is contained in:
John Bintz 2012-03-02 15:04:41 -05:00
parent 04a77f9595
commit a39daffdbb
7 changed files with 151 additions and 29 deletions

View File

@ -20,6 +20,12 @@ module Flowerbox
autoload :Rack, 'flowerbox/rack' autoload :Rack, 'flowerbox/rack'
autoload :ResultSet, 'flowerbox/result_set'
autoload :GatheredResult, 'flowerbox/gathered_result'
autoload :Result, 'flowerbox/result'
autoload :Failure, 'flowerbox/failure'
autoload :Exception, 'flowerbox/exception'
class << self class << self
def spec_patterns def spec_patterns
@spec_patterns ||= [] @spec_patterns ||= []
@ -64,11 +70,14 @@ module Flowerbox
Tilt::CoffeeScriptTemplate.default_bare = Flowerbox.bare_coffeescript Tilt::CoffeeScriptTemplate.default_bare = Flowerbox.bare_coffeescript
result = Flowerbox.runner_environment.collect do |env| result_set = ResultSet.new
env.run(build_sprockets_for(dir))
Flowerbox.runner_environment.each do |env|
result_set << env.run(build_sprockets_for(dir))
end end
result.max result_set.print
result_set.exitstatus
end end
def build_sprockets_for(dir) def build_sprockets_for(dir)

View File

@ -0,0 +1,15 @@
module Flowerbox
class Exception < Result
attr_reader :message
def initialize(message)
@message = message
end
def print
puts message
puts
end
end
end

22
lib/flowerbox/failure.rb Normal file
View File

@ -0,0 +1,22 @@
module Flowerbox
class Failure < Result
attr_reader :name, :message, :file
def initialize(name, message, file)
@name, @message, @file = name, message, file
end
def runners
@runners ||= []
end
def ==(other)
@name == other.name && @message == other.message
end
def to_s
"#{message} [#{runners.join(',')}] (#{file})"
end
end
end

View File

@ -0,0 +1,28 @@
module Flowerbox
class GatheredResult
attr_reader :name
def initialize(name)
@name = name
end
def <<(result)
results << result
end
def results
@results ||= []
end
def print
puts name.join(' ')
results.each do |result|
puts " #{result}"
end
puts
end
end
end

6
lib/flowerbox/result.rb Normal file
View File

@ -0,0 +1,6 @@
module Flowerbox
class Result
end
end

View File

@ -0,0 +1,67 @@
module Flowerbox
class ResultSet
attr_reader :results, :options
def self.from_failures(failures, options)
results = failures.collect do |result_data|
if name = result_data.first['splitName']
result_data.collect do |failure|
Failure.new(name, failure['message'], failure['trace']['stack'].first)
end
else
Exception.new(result_data['trace']['stack'])
end
end.flatten
results.each { |result| result.runners << options[:runner] }
new(results, options)
end
def initialize(results = [], options = {})
@results, @options = results, options
end
def <<(other)
other.results.each do |other_result|
if existing_result = results.find { |result| result == other_result }
existing_result.runners << other_result.runners
else
results << other_result
end
end
end
def exitstatus
@results.empty? ? 0 : 1
end
def print
gathered_results.each(&:print)
end
def gathered_results
return @gathered_results if @gathered_results
@gathered_results = []
results.each do |result|
case result
when Flowerbox::Exception
@gathered_results << result
when Flowerbox::Failure
if !(gathered_result = @gathered_results.find { |g| g.name == result.name })
gathered_result = GatheredResult.new(result.name)
@gathered_results << gathered_result
end
gathered_result << result
end
end
@gathered_results
end
end
end

View File

@ -18,32 +18,7 @@ module Flowerbox
puts puts
failures.each do |failure_set| ResultSet.from_failures(failures, :runner => name, :time => time)
if failure_set.first['splitName']
puts failure_set.first['splitName'].join(' ')
end
failure_set.each do |failure|
case failure['trace']['stack']
when String
# exception
puts failure['trace']['stack']
else
# failed test
puts %{#{failure['message']} (#{failure['trace']['stack'].first})}
end
end
puts
end
puts "#{total_count} tests, #{failure_count} failures, #{time.to_f / 1000} sec"
if failures.length == 0
$?.exitstatus
else
1
end
end end
def type def type