summary refs log tree commit diff
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2007-05-31 14:28:35 +0200
committerChristian Neukirchen <chneukirchen@gmail.com>2007-05-31 14:28:35 +0200
commitafa9a65636cdc39c7d913a359689cf972c549bee (patch)
tree5d90ea4ae0b2000655123ea10ab477ff7675a71f
parentf2c89a8c06919e82b17145392a68e0cd402e6c0b (diff)
downloadbacon-afa9a65636cdc39c7d913a359689cf972c549bee.tar.gz
bacon-afa9a65636cdc39c7d913a359689cf972c549bee.tar.xz
bacon-afa9a65636cdc39c7d913a359689cf972c549bee.zip
Add Test::Unit-like output (-q)
darcs-hash:20070531122835-4fc50-fb4b446c031828f7d8e813878ec864423de9c6dc.gz
-rwxr-xr-xbin/bacon13
-rw-r--r--lib/bacon.rb60
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