From afa9a65636cdc39c7d913a359689cf972c549bee Mon Sep 17 00:00:00 2001 From: Christian Neukirchen Date: Thu, 31 May 2007 14:28:35 +0200 Subject: Add Test::Unit-like output (-q) darcs-hash:20070531122835-4fc50-fb4b446c031828f7d8e813878ec864423de9c6dc.gz --- bin/bacon | 13 ++++++++----- lib/bacon.rb | 60 +++++++++++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 53 insertions(+), 20 deletions(-) diff --git a/bin/bacon b/bin/bacon index 404ceb5..d898345 100755 --- a/bin/bacon +++ b/bin/bacon @@ -4,6 +4,7 @@ require 'optparse' automatic = false +output = 'SpecDoxOutput' opts = OptionParser.new("", 24, ' ') { |opts| opts.banner = "Usage: bacon [options] [files | -a] [-- untouched arguments]" @@ -37,9 +38,11 @@ opts = OptionParser.new("", 24, ' ') { |opts| opts.separator "" opts.separator "bacon options:" - opts.on("-s", "--specdox", "do AgileDox-like output (default)") { } + opts.on("-s", "--specdox", "do AgileDox-like output (default)") { + output = 'SpecDoxOutput' + } opts.on("-q", "--quiet", "do Test::Unit-like non-verbose output") { - # TODO + output = 'TestUnitOutput' } opts.on("-a", "--automatic", "gather tests from ./test/, include ./lib/") { @@ -89,10 +92,10 @@ end require 'bacon' +Bacon.extend Bacon.const_get(output) +at_exit { Bacon.handle_summary } + files.each { |file| load file } -puts Bacon::ErrorLog -puts Bacon.result_string -p Bacon::Counter diff --git a/lib/bacon.rb b/lib/bacon.rb index df2cee6..4b0cf58 100644 --- a/lib/bacon.rb +++ b/lib/bacon.rb @@ -7,28 +7,58 @@ module Bacon Counter = Hash.new(0) ErrorLog = "" - def self.result_string - "%d specifications (%d requirements), %d failures, %d errors" % - [Counter[:specifications], Counter[:requirements], - Counter[:failed], Counter[:errors]] - end + module SpecDoxOutput + def handle_specification(name) + puts name + yield + puts + end - def self.handle_specification(name) - puts name - yield - puts + def handle_requirement(description) + print "- #{description}" + error = yield + if error.empty? + puts + else + puts " [#{error}]" + end + end + + def handle_summary + puts Bacon::ErrorLog + puts "%d specifications (%d requirements), %d failures, %d errors" % + [Counter[:specifications], Counter[:requirements], + Counter[:failed], Counter[:errors]] + p Bacon::Counter + end end - def self.handle_requirement(description) - print "- #{description}" - error = yield - if error.empty? + module TestUnitOutput + def handle_specification(name) + yield + end + + def handle_requirement(description) + error = yield + if error.empty? + print "." + else + print error[0..0] + end + end + + def handle_summary puts - else - puts " [#{error}]" + puts Bacon::ErrorLog + puts "%d tests, %d assertions, %d failures, %d errors" % + [Counter[:specifications], Counter[:requirements], + Counter[:failed], Counter[:errors]] + p Bacon::Counter end end + extend SpecDoxOutput # default + class Error < RuntimeError attr_accessor :count_as -- cgit 1.4.1