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 2010/01/21 06:12:24 UTC

svn commit: r901531 - in /buildr/trunk: CHANGELOG lib/buildr/core/test.rb spec/core/test_spec.rb

Author: boisvert
Date: Thu Jan 21 05:12:12 2010
New Revision: 901531

URL: http://svn.apache.org/viewvc?rev=901531&view=rev
Log:
BUILDR-363 New "test:failed" task to execute only tests that failed during last run (Antoine Toulme)

Modified:
    buildr/trunk/CHANGELOG
    buildr/trunk/lib/buildr/core/test.rb
    buildr/trunk/spec/core/test_spec.rb

Modified: buildr/trunk/CHANGELOG
URL: http://svn.apache.org/viewvc/buildr/trunk/CHANGELOG?rev=901531&r1=901530&r2=901531&view=diff
==============================================================================
--- buildr/trunk/CHANGELOG (original)
+++ buildr/trunk/CHANGELOG Thu Jan 21 05:12:12 2010
@@ -1,4 +1,6 @@
 1.4.0 (Pending)
+* Added:  New "test:failed" task to execute only tests that failed during last
+          run (Antoine Toulme)
 * Added:  Project extensions (before/after_define) now support dependency ordering
           similar to Rake (e.g. before_define(:my_setup => :compile)
 * Added:  BUILDR-328 Detect Eclipse plugin project with META-INF/MANIFEST.MF 

Modified: buildr/trunk/lib/buildr/core/test.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/core/test.rb?rev=901531&r1=901530&r2=901531&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/core/test.rb (original)
+++ buildr/trunk/lib/buildr/core/test.rb Thu Jan 21 05:12:12 2010
@@ -176,6 +176,13 @@
         # all sub-projects, but only invoke test on the local project.
         Project.projects.each { |project| project.test.send :only_run, tests }
       end
+      
+      # Used by the test/integration rule to only run tests that failed the last time.
+      def only_run_failed() #:nodoc:
+        # Since the tests may reside in a sub-project, we need to set the include/exclude pattern on
+        # all sub-projects, but only invoke test on the local project.
+        Project.projects.each { |project| project.test.send :only_run_failed }
+      end
     end
 
     # Default options already set on each test task.
@@ -399,6 +406,25 @@
     def report_to
       @report_to ||= file(@project.path_to(:reports, framework)=>self)
     end
+    
+    # :call-seq:
+    #   failures_to => file
+    #
+    # We record the list of failed tests for the current framework in this file.
+    #
+    # 
+    def failures_to
+      @failures_to ||= file(@project.path_to(:target, "#{framework}-failed")=>self)
+    end
+    
+    # :call-seq:
+    #    last_failures => array
+    #
+    # We read the last test failures if any and return them.
+    #
+    def last_failures
+      @last_failures ||= failures_to.exist? ? File.read(failures_to.to_s).split('\n') : []
+    end
 
     # The path to the file that stores the time stamp of the last successful test run.
     def last_successful_run_file #:nodoc:
@@ -442,6 +468,7 @@
     def run_tests
       dependencies = Buildr.artifacts(self.dependencies).map(&:to_s).uniq
       rm_rf report_to.to_s
+      rm_rf failures_to.to_s
       @tests = @framework.tests(dependencies).select { |test| include?(test) }.sort
       if @tests.empty?
         @passed_tests, @failed_tests = [], []
@@ -458,6 +485,7 @@
         end
         @failed_tests = @tests - @passed_tests
         unless @failed_tests.empty?
+          Buildr::write(failures_to.to_s, @failed_tests.join("\n"))
           error "The following tests failed:\n#{@failed_tests.join("\n")}"
           fail 'Tests failed!'
         end
@@ -477,6 +505,13 @@
       @exclude.clear
       @forced_need = true
     end
+    
+    # Limit running tests to those who failed the last time.
+    def only_run_failed()
+      @include = Array(last_failures)
+      @exclude.clear
+      @forced_need = true
+    end
 
     def invoke_prerequisites(args, chain) #:nodoc:
       @prerequisites |= FileList[@dependencies.uniq]
@@ -547,6 +582,12 @@
     first_time do
       desc 'Run all tests'
       task('test') { TestTask.run_local_tests false }
+      
+      desc 'Run failed tests'
+      task('test:failed') {
+        TestTask.only_run_failed 
+        task('test').invoke
+      }
 
       # This rule takes a suffix and runs that tests in the current project. For example;
       #   buildr test:MyTest
@@ -591,6 +632,8 @@
       # Define these tasks once, otherwise we may get a namespace error.
       test.setup ; test.teardown
     end
+    
+    
 
     after_define(:test => :compile) do |project|
       test = project.test

Modified: buildr/trunk/spec/core/test_spec.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/spec/core/test_spec.rb?rev=901531&r1=901530&r2=901531&view=diff
==============================================================================
--- buildr/trunk/spec/core/test_spec.rb (original)
+++ buildr/trunk/spec/core/test_spec.rb Thu Jan 21 05:12:12 2010
@@ -382,6 +382,11 @@
   it 'should report failed tests' do
     lambda { verbose(true) { test_task.invoke rescue nil } }.should show_error(/FailingTest/)
   end
+  
+  it 'should record failed tests' do
+    test_task.invoke rescue nil
+    File.read(project('foo').path_to('target', "#{test_task.framework}-failed")).should == 'FailingTest'
+  end
 
   it 'should return failed tests' do
     test_task.invoke rescue nil
@@ -392,6 +397,11 @@
     test_task.invoke rescue nil
     test_task.passed_tests.should == ['PassingTest']
   end
+  
+  it 'should know what tests failed last time' do
+    test_task.invoke rescue nil
+    project('foo').test.last_failures.should == ['FailingTest']
+  end
 
   it 'should not fail if fail_on_failure is false' do
     test_task.using(:fail_on_failure=>false).invoke
@@ -788,8 +798,7 @@
     lambda { task('test').invoke rescue nil }.should_not run_tasks('foo:test', 'bar:test')
   end
 end
-
-
+  
 describe 'test rule' do
   include TestHelper
   
@@ -875,6 +884,38 @@
   end
 end
 
+describe 'test failed' do
+  include TestHelper
+  
+  def test_task
+    @test_task ||= begin
+      define 'foo' do
+        test.using(:junit)
+        test.instance_eval do
+          @framework.stub!(:tests).and_return(['FailingTest', 'PassingTest'])
+          @framework.stub!(:run).and_return(['PassingTest'])
+        end
+      end
+      project('foo').test
+    end
+  end
+  
+  it 'should run the tests that failed the last time' do
+    define 'foo' do
+      test.using(:junit)
+      test.instance_eval do
+        @framework.stub!(:tests).and_return(['FailingTest', 'PassingTest'])
+        @framework.stub!(:run).and_return(['PassingTest'])
+      end
+    end
+    write project('foo').path_to(:target, "junit-failed"), "FailingTest"
+    task('test:failed').invoke rescue nil
+    project('foo').test.tests.should include('FailingTest')
+    project('foo').test.tests.should_not include('PassingTest')
+  end
+  
+end
+
 
 describe Buildr::Options, 'test' do
   it 'should be true by default' do