summary refs log tree commit diff
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2007-12-05 01:23:27 +0100
committerChristian Neukirchen <chneukirchen@gmail.com>2007-12-05 01:23:27 +0100
commit73dda4f4af2550068409e72f70186e67b9fa3ecf (patch)
tree16c1464f355910b371796b9be1b5f735e373ca31
parent25e5bcd50892a7e4ae9cee8646b38ace42ca2eb9 (diff)
downloadbacon-73dda4f4af2550068409e72f70186e67b9fa3ecf.tar.gz
bacon-73dda4f4af2550068409e72f70186e67b9fa3ecf.tar.xz
bacon-73dda4f4af2550068409e72f70186e67b9fa3ecf.zip
Add TAP generator
darcs-hash:20071205002327-4fc50-ab781399433c4ab9a58d5b8e5b11a0ed44a221cc.gz
-rwxr-xr-xbin/bacon4
-rw-r--r--lib/bacon.rb28
2 files changed, 31 insertions, 1 deletions
diff --git a/bin/bacon b/bin/bacon
index 8e78bca..60997d8 100755
--- a/bin/bacon
+++ b/bin/bacon
@@ -45,6 +45,10 @@ opts = OptionParser.new("", 24, '  ') { |opts|
     output = 'TestUnitOutput'
   }
 
+  opts.on("-p", "--tap",   "do TAP (Test Anything Protocol) output") {
+    output = 'TapOutput'
+  }
+
   opts.on("-a", "--automatic", "gather tests from ./test/, include ./lib/") {
     $LOAD_PATH.unshift "lib"  if File.directory? "lib"
     automatic = true
diff --git a/lib/bacon.rb b/lib/bacon.rb
index 4b0cf58..eab0716 100644
--- a/lib/bacon.rb
+++ b/lib/bacon.rb
@@ -57,6 +57,32 @@ module Bacon
     end
   end
 
+  module TapOutput
+    def handle_specification(name)
+      yield
+    end
+
+    def handle_requirement(description)
+      Bacon::ErrorLog.replace ""
+      error = yield
+      if error.empty?
+        printf "ok %-8d # %s\n" % [Counter[:specifications], description]
+      else
+        printf "not ok %-4d # %s: %s\n" %
+          [Counter[:specifications], description, error]
+        puts Bacon::ErrorLog.strip.gsub(/^/, '# ') 
+      end
+    end
+
+    def handle_summary
+      puts "1..#{Counter[:specifications]}"
+      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
@@ -95,7 +121,7 @@ module Bacon
           @after.each { |block| instance_eval(&block) }
         rescue Object => e
           ErrorLog << "#{e.class}: #{e.message}\n"
-          e.backtrace.find_all { |line| line !~ /\/bacon.rb:\d+/ }.
+          e.backtrace.find_all { |line| line !~ /bin\/bacon|\/bacon\.rb:\d+/ }.
             each_with_index { |line, i|
             ErrorLog << "\t#{line}#{i==0?": "+@name + " - "+description:""}\n"
           }