[Rake-devel] Another small patch

Greg Fast gdf at speakeasy.net
Fri Aug 19 21:12:53 EDT 2005


Here's another small patch, this time to testtask.rb .  It adds a 
'ruby_opts' attr to the TestTask which lets you supply extra command 
line arguments to ruby when running tests.

I'm using this to run my tests under a custom testrunner 
(http://cken.chi.groogroo.com/svn/misc/trunk/rscm-accurev/lib/test/unit/ui/xml/testrunner.rb, 
which generates xml summaries), using a task definition like this:

   Rake::TestTask.new( :xmltest ) do |t|
     t.libs << "test"
     t.test_files = test_files
     t.verbose = true
     t.ruby_opts << '-rtest/unit/ui/xml/testrunner'
     ENV['XMLTEST_OUTPUT'] = "#{TEST_OUTPUT}/testresults.xml"
     t.options = "--runner=xml"
   end


-- 
Greg Fast
gdf at speakeasy.net
http://cken.chi.groogroo.com/
-------------- next part --------------
Index: lib/rake/testtask.rb
===================================================================
RCS file: /var/cvs/rake/rake/lib/rake/testtask.rb,v
retrieving revision 1.27
diff -u -r1.27 testtask.rb
--- lib/rake/testtask.rb	13 Apr 2005 02:54:16 -0000	1.27
+++ lib/rake/testtask.rb	20 Aug 2005 00:31:35 -0000
@@ -66,6 +66,9 @@
     # 
     attr_accessor :loader
 
+    # Array of commandline options to pass to ruby when running test loader.
+    attr_accessor :ruby_opts
+
     # Explicitly define the list of test files to be included in a
     # test.  +list+ is expected to be an array of file names (a
     # FileList is acceptable).  If both +pattern+ and +test_files+ are
@@ -84,6 +87,7 @@
       @verbose = false
       @warning = false
       @loader = :rake
+      @ruby_opts = []
       yield self if block_given?
       @pattern = 'test/test*.rb' if @pattern.nil? && @test_files.nil?
       define
@@ -92,7 +96,6 @@
     # Create the tasks defined by this task lib.
     def define
       lib_path = @libs.join(File::PATH_SEPARATOR)
-      warning_flag = (@warning ? "-w " : "")
       desc "Run tests" + (@name==:test ? "" : " for #{@name}")
       task @name do
 	run_code = ''
@@ -106,7 +109,12 @@
 	    when :rake
 	      rake_loader
 	    end
-	  ruby "-I#{lib_path} #{warning_flag}\"#{run_code}\" " +
+          @ruby_opts.unshift( "-I#{lib_path}" )
+          if @warning
+            @ruby_opts.unshift( "-w" )
+          end
+	  ruby @ruby_opts.join(" ") +
+            " \"#{run_code}\" " +
 	    file_list.collect { |fn| "\"#{fn}\"" }.join(' ') +
 	    " #{option_list}"
 	end


More information about the Rake-devel mailing list