You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildr.apache.org by bo...@apache.org on 2009/11/18 23:21:21 UTC

svn commit: r881966 - in /buildr/trunk: CHANGELOG lib/buildr/java/bdd.rb lib/buildr/java/jtestr_runner.rb.erb lib/buildr/java/test_result.rb lib/buildr/java/tests.rb spec/java/bdd_spec.rb spec/sandbox.rb

Author: boisvert
Date: Wed Nov 18 22:21:21 2009
New Revision: 881966

URL: http://svn.apache.org/viewvc?rev=881966&view=rev
Log:
Upgrade to JtestR 0.5 and JUnit 4.7

Modified:
    buildr/trunk/CHANGELOG
    buildr/trunk/lib/buildr/java/bdd.rb
    buildr/trunk/lib/buildr/java/jtestr_runner.rb.erb
    buildr/trunk/lib/buildr/java/test_result.rb
    buildr/trunk/lib/buildr/java/tests.rb
    buildr/trunk/spec/java/bdd_spec.rb
    buildr/trunk/spec/sandbox.rb

Modified: buildr/trunk/CHANGELOG
URL: http://svn.apache.org/viewvc/buildr/trunk/CHANGELOG?rev=881966&r1=881965&r2=881966&view=diff
==============================================================================
--- buildr/trunk/CHANGELOG (original)
+++ buildr/trunk/CHANGELOG Wed Nov 18 22:21:21 2009
@@ -11,6 +11,8 @@
 * Added:  Environment variable IGNORE_BUILDFILE can be set to "yes" or
           "true" to ignore changes in Buildfile when running tests.
 * Change: Updated to JRuby 1.4.0
+* Change: Updated to JtestR 0.5
+* Change: Updated to JUnit 4.7
 * Fixed:  BUILDR-223 Release Task: customizable commit message (Alexis Midon)
 * Fixed:  BUILDR-330  Install task should re-install artifact even if they 
           already exist (Alexis Midon)

Modified: buildr/trunk/lib/buildr/java/bdd.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/java/bdd.rb?rev=881966&r1=881965&r2=881966&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/java/bdd.rb (original)
+++ buildr/trunk/lib/buildr/java/bdd.rb Wed Nov 18 22:21:21 2009
@@ -201,14 +201,10 @@
       runner.gems ||= {}
       runner.rspec ||= ['--format', 'progress', '--format', "html:#{runner.html_report}"]
       runner.format.each { |format| runner.rspec << '--format' << format } if runner.format
-      runner.rspec.push '--format', "#{runner_formatter}:#{runner.result}"
+      runner.rspec.push '--format', "Buildr::TestFramework::TestResult::YamlFormatter:#{runner.result}"
       runner
     end
     
-    def runner_formatter
-      "Buildr::TestFramework::TestResult::YamlFormatter"
-    end
-    
   end
 
   # <a href="http://rspec.info">RSpec</a> is the defacto BDD framework for ruby.
@@ -222,7 +218,7 @@
   # * :requires   -- A list of ruby files to require before running the specs
   #                  Mainly used if an rspec format needs to require some file.
   # * :format     -- A list of valid Rspec --format option values. (defaults to 'progress')
-  # * :output     -- File path to output dump. @false@ to supress output
+  # * :output     -- File path to output dump. @false@ to suppress output
   # * :fork       -- Create a new JavaVM to run the tests on
   # * :properties -- Hash of properties passed to the test suite.
   # * :java_args  -- Arguments passed to the JVM.
@@ -304,7 +300,7 @@
 
     include TestFramework::JRubyBased
 
-    VERSION = '0.3.1'
+    VERSION = '0.5'
     
     # pattern for rspec stories
     STORY_PATTERN    = /_(steps|story)\.rb$/
@@ -383,10 +379,6 @@
       Filter::Mapper.new(:erb, binding).transform(File.read(runner_erb), runner_erb)
     end
     
-    def runner_formatter
-      'Buildr::TestFramework::TestResult::JtestRYamlFormatter'
-    end
-    
   end
 
   

Modified: buildr/trunk/lib/buildr/java/jtestr_runner.rb.erb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/java/jtestr_runner.rb.erb?rev=881966&r1=881965&r2=881966&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/java/jtestr_runner.rb.erb (original)
+++ buildr/trunk/lib/buildr/java/jtestr_runner.rb.erb Wed Nov 18 22:21:21 2009
@@ -78,7 +78,7 @@
   end # config
 
   fake_out = StringIO.new
-
+  
   <% if runner.output == false %>
      output = fake_out
   <% elsif runner.output.kind_of?(String) %>
@@ -89,10 +89,11 @@
   
   
   args = [ '<%= spec_dir %>', # the directory to search for jtestr files
-           JtestR::SimpleLogger::ERR, # log level
-           JtestR::GenericResultHandler::QUIET, #output level 
+           JtestR::SimpleLogger::ERR, # log level (DEBUG/WARN/ERR)
+           JtestR::GenericResultHandler::QUIET, #output level (QUIET/VERBOSE)
            fake_out, # output STDOUT
            [], # groups to run 
+           # Use JtestR::GenericResultHandler for debugging
            Buildr::TestFramework::TestResult::RSpecResultHandler, # result handler
            []  # classpath
          ]
@@ -100,6 +101,7 @@
   argv = <%= runner.rspec.inspect %> || []
   argv.push *<%= tests.inspect %>
   Buildr::TestFramework::TestResult::RSpecResultHandler.init(argv, output, output)
+  Buildr::TestFramework::TestResult::RSpecResultHandler.test_files = <%= tests.inspect %>
   
   jtestr.run *args
 

Modified: buildr/trunk/lib/buildr/java/test_result.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/java/test_result.rb?rev=881966&r1=881965&r2=881966&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/java/test_result.rb (original)
+++ buildr/trunk/lib/buildr/java/test_result.rb Wed Nov 18 22:21:21 2009
@@ -16,8 +16,8 @@
 require 'fileutils'
 module Buildr #:nodoc:
   module TestFramework
-    
-    # A class used by buildr for jruby based frameworks, so that buildr can know 
+
+    # A class used by buildr for jruby based frameworks, so that buildr can know
     # which tests succeeded/failed.
     class TestResult
 
@@ -35,14 +35,14 @@
         end
 
         def self.guard(file)
-          begin 
+          begin
             yield
           rescue => e
             dump_yaml(file, e)
           end
         end
       end
-      
+
       attr_accessor :failed, :succeeded
 
       def initialize
@@ -54,7 +54,7 @@
         attr_reader :result
 
         attr_accessor :example_group, :options, :where
-        
+
         def initialize(options, where)
           @options = options
           @where = where
@@ -62,7 +62,7 @@
           @result[:succeeded] = []
           @result[:failed] = []
         end
-        
+
         %w[ example_started
             start_dump dump_failure dump_summary dump_pending ].each do |meth|
           module_eval "def #{meth}(*args); end"
@@ -73,15 +73,15 @@
         end
 
         def example_passed(example)
-          result.succeeded << example_group.location.gsub(/:\d+$/, '')
+          result.succeeded << example_name(example)
         end
 
         def example_pending(example, counter)
-          result.succeeded << example_group.location.gsub(/:\d+$/, '')
+          result.succeeded << example_name(example)
         end
 
         def example_failed(example, counter, failure)
-          result.failed << example_group.location.gsub(/:\d+$/, '')
+          result.failed << example_name(example)
         end
 
         def start(example_count)
@@ -93,69 +93,16 @@
           FileUtils.mkdir_p File.dirname(where)
           File.open(where, 'w') { |f| f.puts YAML.dump(result) }
         end
-      end # YamlFormatter
-
-      # Rspec formatter used for JtestR
-      # (JtestR provides its own version of rspec)
-      class JtestRYamlFormatter
-        attr_reader :result
-
-        attr_accessor :example_group, :options, :where
-        
-        def initialize(options, where)
-          @options = options
-          @where = where
-          @result = Hash.new
-          @result[:succeeded] = []
-          @result[:failed] = []
-        end
-        
-        %w[ example_started
-            start_dump dump_failure dump_summary dump_pending ].each do |meth|
-          module_eval "def #{meth}(*args); end"
-        end
-
-        def add_example_group(example_group)
-          @example_group = example_group
-        end
 
-        def example_passed(example)
-        end
-
-        def example_pending(example, counter, failure)
-        end
-
-        def example_failed(example, counter, failure)
-          if example_group.respond_to?(:spec_path)
-            result.failed << example_group.spec_path.gsub(/:\d+$/, '')
+      private
+        def example_name(example)
+          if Spec::Example::ExampleProxy === example
+            example_group.location.gsub(/:\d+$/, '')
           else
-            path = path_from_bt(failure.exception.backtrace)
-            result.failed << path if path
+            example.name.gsub(/(.+)(\..+\(\))/, '\1')
           end
         end
-
-        def start(example_count)
-          @result = TestResult.new
-        end
-
-        def path_from_bt(ary)
-          files = options.files
-          test = nil
-          ary.find do |bt|
-            bt = bt.split(':').first.strip
-            test = bt if files.include?(bt)
-          end
-          test
-        end
-
-        def close
-          files = options.files
-          result.succeeded = files - result.failed
-          
-          FileUtils.mkdir_p File.dirname(where)
-          File.open(where, 'w') { |f| f.puts YAML.dump(result) }
-        end
-      end # JtestRYamlFormatter
+      end # YamlFormatter
 
       # A JtestR ResultHandler
       # Using this handler we can use RSpec formatters, like html/ci_reporter with JtestR
@@ -177,7 +124,7 @@
             ignore_patterns << /org\.jruby\.javasupport\.JavaMethod\./
             ignore_patterns << /jtestr.*\.jar!/i << /runner\.rb/
           end
-          
+
           def clean_up_double_slashes(line)
             line.gsub!('//','/')
           end
@@ -197,10 +144,11 @@
             error.backtrace.compact!
           end
         end
-        
+
         class << self
           # an rspec reporter used to proxy events to rspec formatters
           attr_reader :reporter
+          attr_accessor :test_files
 
           def init(argv = [], out = STDOUT, err = STDERR)
             ::JtestR::TestNGResultHandler.module_eval { include TestNGResultHandlerMixin }
@@ -218,10 +166,11 @@
             reporter.end
             reporter.dump
           end
+
         end
 
         module ExampleMethods
-          attr_accessor :name, :description, :__full_description
+          attr_accessor :name, :description, :__full_description, :location
         end
 
         def reporter
@@ -239,9 +188,10 @@
           else
             example_group.description = name.to_s
           end
-          reporter.add_example_group(example_group)
+          reporter.example_group_started(example_group)
         end
 
+
         def starting
         end
 
@@ -261,8 +211,8 @@
           current_example.extend ::Spec::Example::ExampleMethods
           current_example.extend ExampleMethods
           name = name.to_s
-          name[/\((pen?ding|error|failure|success)\)?$/]
-          name = $`
+          current_example.location = name.to_s
+          current_example.name = name.gsub(/(.*)\((.+)\)/, '\2')
           current_example.description = name
           if example_group.name[/Spec/]
             current_example.__full_description = "#{example_group.description} #{name}"
@@ -270,31 +220,56 @@
             current_example.__full_description = "#{example_group.name}: #{name}"
           end
           reporter.example_started(current_example)
-          #puts "STARTED #{name} #{current_example.__full_description}"
         end
 
         def succeed_single(name = nil)
-          #puts "SUCC SINGLE #{name}"
           reporter.example_finished(current_example, nil)
         end
-        
+
         def fail_single(name = nil)
-          #puts "FAIL SINGLE #{name}"
+          current_example.name = current_name
           reporter.example_finished(current_example, current_error)
         end
 
         def error_single(name = nil)
-          #puts "ERR SINGLE #{name}"
+          current_example.name = current_name
           reporter.example_finished(current_example, current_error)
         end
 
         def pending_single(name = nil)
-          #puts "PEND SINGLE #{name}"
           error = ::Spec::Example::ExamplePendingError.new(name)
           reporter.example_finished(current_example, error)
         end
 
       private
+        def detect_file(trace)
+          # find first matching test file in stacktrace
+          file = nil
+          first_pos = nil
+          RSpecResultHandler.test_files.each do |f|
+            pos = trace.index(f)
+            if pos && (first_pos.nil? || pos < first_pos)
+              file = f
+              first_pos = pos
+            end
+          end
+          file || fail("RSpecResultHandler.detect_file failed: #{trace}")
+        end
+
+        def current_name(example = current_example, fault = current_failure)
+          return example.name unless fault
+          case fault
+          when Test::Unit::Error
+            detect_file(fault.long_display)
+          when Test::Unit::Failure
+            detect_file(fault.location.to_s)
+          when Spec::Runner::Reporter::Failure
+            detect_file(fault.exception.backtrace.to_s)
+          else
+            example.name
+          end
+        end
+
         def current_error(fault = current_failure)
           case fault
           when nil
@@ -314,8 +289,7 @@
             fault.exception
           when Spec::Runner::Reporter::Failure
             ex = fault.exception
-            fault.example.instance_variable_get(:@_implementation).to_s =~ /@(.+:\d+)/
-            Error.new(ex.message, [$1.to_s] + ex.backtrace)
+            Error.new(ex.message, ex.backtrace)
           when Expectations::Results
             file = fault.file
             line = fault.line
@@ -326,7 +300,7 @@
               test_cls, test_meth = $1.to_s, $`.to_s
               exception = fault.exception
               (class << exception; self; end).module_eval do
-                define_method(:backtrace) do 
+                define_method(:backtrace) do
                   (["#{test_cls}:in `#{test_meth}'"] + stackTrace).map { |s| s.to_s }
                 end
               end
@@ -335,7 +309,7 @@
               test_cls, test_meth = fault.method.test_class.name, fault.method.method_name
               exception = fault.throwable
               (class << exception; self; end).module_eval do
-                define_method(:backtrace) do 
+                define_method(:backtrace) do
                   (["#{test_cls}:in `#{test_meth}'"] + stackTrace).map { |s| s.to_s }
                 end
               end

Modified: buildr/trunk/lib/buildr/java/tests.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/java/tests.rb?rev=881966&r1=881965&r2=881966&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/java/tests.rb (original)
+++ buildr/trunk/lib/buildr/java/tests.rb Wed Nov 18 22:21:21 2009
@@ -167,7 +167,7 @@
     end
 
     # JUnit version number.
-    VERSION = '4.5'
+    VERSION = '4.7'
 
     class << self
       # :call-seq:

Modified: buildr/trunk/spec/java/bdd_spec.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/spec/java/bdd_spec.rb?rev=881966&r1=881965&r2=881966&view=diff
==============================================================================
--- buildr/trunk/spec/java/bdd_spec.rb (original)
+++ buildr/trunk/spec/java/bdd_spec.rb Wed Nov 18 22:21:21 2009
@@ -61,9 +61,6 @@
 describe Buildr::JtestR do
 
   before do
-    # JtestR currently requires JUnit 4.4
-    Buildr.settings.build['junit'] = '4.4'
-
     # clear cached dependencies
     Buildr::JUnit.instance_eval { @dependencies = nil }
     Buildr::JtestR.instance_eval { @dependencies = nil }

Modified: buildr/trunk/spec/sandbox.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/spec/sandbox.rb?rev=881966&r1=881965&r2=881966&view=diff
==============================================================================
--- buildr/trunk/spec/sandbox.rb (original)
+++ buildr/trunk/spec/sandbox.rb Wed Nov 18 22:21:21 2009
@@ -29,8 +29,6 @@
 artifacts(TestFramework.frameworks.map(&:dependencies).flatten, JUnit.ant_taskdef).each do |path|
   file(path).invoke
 end
-# JtestR currently requires JUnit 4.4
-file(artifact("junit:junit:jar:4.4")).invoke
 
 ENV['HOME'] = File.expand_path(File.join(File.dirname(__FILE__), '..', 'tmp', 'home'))