buildr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From as...@apache.org
Subject svn commit: r689307 - in /incubator/buildr/trunk: lib/buildr/core/test.rb spec/test_spec.rb
Date Wed, 27 Aug 2008 00:46:45 GMT
Author: assaf
Date: Tue Aug 26 17:46:45 2008
New Revision: 689307

URL: http://svn.apache.org/viewvc?rev=689307&view=rev
Log:
Using inject instead of sort_by to find maximum timestamp and return associated task buys
about about 0ns of performance boost!
Hiding record_succesful_run so it doesn't show up as public method.

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

Modified: incubator/buildr/trunk/lib/buildr/core/test.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core/test.rb?rev=689307&r1=689306&r2=689307&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/test.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core/test.rb Tue Aug 26 17:46:45 2008
@@ -405,12 +405,6 @@
       File.exist?(last_successful_run_file) ? File.mtime(last_successful_run_file) : Rake::EARLY
     end
     
-    # Call this method when a test run is successful to record the current system time.
-    def record_successful_run #:nodoc:
-      mkdir_p report_to.to_s
-      touch last_successful_run_file
-    end
-    
     # The project this task belongs to.
     attr_reader :project
 
@@ -458,6 +452,12 @@
       record_successful_run unless @forced_need
     end
 
+    # Call this method when a test run is successful to record the current system time.
+    def record_successful_run #:nodoc:
+      mkdir_p report_to.to_s
+      touch last_successful_run_file
+    end
+    
     # Limit running tests to specific list.
     def only_run(tests)
       @include = Array(tests)
@@ -471,7 +471,8 @@
     end
 
     def needed? #:nodoc:
-      latest_prerequisite = @prerequisites.map { |p| application[p, @scope] }.sort_by(&:timestamp).last
+      latest_prerequisite = @prerequisites.map { |p| application[p, @scope] }.
+        inject { |latest, task| task.timestamp > latest.timestamp ? task :latest }
       needed = (timestamp == Rake::EARLY) || latest_prerequisite.timestamp > timestamp
       trace "Testing#{needed ? ' ' : ' not '}needed. " +
         "Latest prerequisite change: #{latest_prerequisite.timestamp} (#{latest_prerequisite.to_s}).
" +

Modified: incubator/buildr/trunk/spec/test_spec.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/test_spec.rb?rev=689307&r1=689306&r2=689307&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/test_spec.rb (original)
+++ incubator/buildr/trunk/spec/test_spec.rb Tue Aug 26 17:46:45 2008
@@ -18,9 +18,11 @@
 
 
 module TestHelper
-  def set_last_successful_test_run test_task, timestamp
-    test_task.record_successful_run
-    File.utime(timestamp, timestamp, test_task.last_successful_run_file)
+  def touch_last_successful_test_run(test_task, timestamp = Time.now)
+    test_task.instance_eval do
+      record_successful_run
+      File.utime(timestamp, timestamp, last_successful_run_file)
+    end
   end
 end
 
@@ -387,7 +389,7 @@
   
   it 'should not update the last successful run timestamp' do
     a_second_ago = Time.now - 1
-    set_last_successful_test_run test_task, a_second_ago
+    touch_last_successful_test_run test_task, a_second_ago
     test_task.invoke rescue nil
     test_task.timestamp.should <= a_second_ago
   end
@@ -611,7 +613,7 @@
       files = ['buildfile'] + src + target
       files.each { |file| write file }
       (files + files.map { |file| file.pathmap('%d') }).each { |file| File.utime(@a_second_ago,
@a_second_ago, file) }
-      set_last_successful_test_run test_task, @a_second_ago
+      touch_last_successful_test_run test_task, @a_second_ago
     end
     
     it 'should not run tests if nothing changed' do
@@ -797,7 +799,7 @@
       test.using(:junit)
       test.instance_eval { @framework.stub!(:tests).and_return(['something', 'nothing'])
}
     end
-    project('foo').test.record_successful_run
+    touch_last_successful_test_run project('foo').test
     task('test:something').invoke
     project('foo').test.tests.should include('something')
   end
@@ -808,7 +810,7 @@
       test.instance_eval { @framework.stub!(:tests).and_return(['something', 'nothing'])
}
     end
     a_second_ago = Time.now - 1
-    set_last_successful_test_run project('foo').test, a_second_ago
+    touch_last_successful_test_run project('foo').test, a_second_ago
     task('test:something').invoke
     project('foo').test.timestamp.should <= a_second_ago
   end



Mime
View raw message