[DRE-commits] [SCM] gem2deb.git branch, master, updated. debian/0.2.3-48-gae05bb2

Antonio Terceiro terceiro at softwarelivre.org
Sat Jul 9 05:51:15 UTC 2011


The following commit has been merged in the master branch:
commit ccbc4b454888af1dda44783121fe7e912ff791c3
Author: Antonio Terceiro <terceiro at softwarelivre.org>
Date:   Fri Jul 8 22:31:51 2011 -0700

    Extracting test execution logic to testrunner

diff --git a/lib/gem2deb/dh_ruby.rb b/lib/gem2deb/dh_ruby.rb
index 28786b4..e712579 100644
--- a/lib/gem2deb/dh_ruby.rb
+++ b/lib/gem2deb/dh_ruby.rb
@@ -258,31 +258,11 @@ module Gem2Deb
       if skip_checks?
         return
       end
-      if File::exists?('debian/ruby-test-files.yaml')
-        puts "Running tests for #{rubyver} using gem2deb test runner and debian/ruby-test-files.yaml..."
-        cmd = "#{SUPPORTED_RUBY_VERSIONS[rubyver]} -I#{LIBDIR} #{TEST_RUNNER}"
-        puts(cmd) if $VERBOSE
-        system(cmd)
-      elsif File::exists?('debian/ruby-tests.rb')
-        puts "Running tests for #{rubyver} using debian/ruby-tests.rb..."
-        ENV['RUBY_TEST_VERSION'] = rubyver
-        ENV['RUBY_TEST_BIN'] = SUPPORTED_RUBY_VERSIONS[rubyver]
-        cmd = "#{SUPPORTED_RUBY_VERSIONS[rubyver]} -Ilib debian/ruby-tests.rb"
-        puts(cmd) if $VERBOSE
-        system(cmd)
-      elsif File::exists?('debian/ruby-tests.rake')
-        puts "Running tests for #{rubyver} using debian/ruby-tests.rake..."
-        cmd = [
-          SUPPORTED_RUBY_VERSIONS[rubyver],
-          '-rrake',
-          '-e',
-          'ARGV.unshift("-f", "debian/ruby-tests.rake"); Rake.application.run'
-        ]
-        puts(cmd.join(' ')) if $VERBOSE
-        system(*cmd)
-      else
-        puts "Running tests for #{rubyver}: found no way to run a test suite!"
-      end
+
+      cmd = "#{SUPPORTED_RUBY_VERSIONS[rubyver]} -I#{LIBDIR} #{TEST_RUNNER}"
+      puts(cmd) if $VERBOSE
+      system(cmd)
+
       if $?.exitstatus != 0
         handle_test_failure(rubyver)
         return false
diff --git a/lib/gem2deb/rake/testtask.rb b/lib/gem2deb/rake/testtask.rb
index fac7c7b..9b430de 100644
--- a/lib/gem2deb/rake/testtask.rb
+++ b/lib/gem2deb/rake/testtask.rb
@@ -5,7 +5,10 @@ module Gem2Deb
     class TestTask < ::Rake::TestTask
       def initialize
         super(:default)
-        self.libs = []
+      end
+      def define
+        self.libs.reject! { |path| ['lib','ext'].include?(path) }
+        super
       end
     end
   end
diff --git a/lib/gem2deb/testrunner.rb b/lib/gem2deb/testrunner.rb
index 670fdc0..46f7bbd 100644
--- a/lib/gem2deb/testrunner.rb
+++ b/lib/gem2deb/testrunner.rb
@@ -13,40 +13,137 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-require 'gem2deb'
-require 'yaml'
-
 require 'rbconfig'
 
 module Gem2Deb
   class TestRunner
-    def initialize
-      @test_files = YAML.load_file('debian/ruby-test-files.yaml')
 
+    def load_path
       # We should only use installation paths for the current Ruby
       # version.
       #
       # We assume that installation has already proceeded into
       # subdirectories of the debian/ directory.
+      #
+      # It is important that the directories under debian/ $LOAD_PATH in the
+      # same order than their system-wide equivalent
 
-      dirs = Dir["debian/*/usr/lib/ruby/vendor_ruby"]
-      dirs += Dir["debian/*" + RbConfig::CONFIG['vendorarchdir']]
-
-      $:.concat(dirs)
+      dirs = []
+      $LOAD_PATH.grep(/vendor/).each do |dir|
+        dirs += Dir.glob('debian/*/' + dir)
+      end
 
       # And we add the current directory:
-      $: << "."
+      dirs << "."
+
+      dirs
+    end
+
+    def run_tests
+      if activate?
+        execute_tests
+      end
+    end
+
+    # override in subclasses
+    def execute_tests
+    end
+
+    # override in subclasses
+    def required_file
+      nil
+    end
+
+    def activate?
+      required_file && File.exists?(required_file)
+    end
+
+    def run_ruby(*cmd)
+      rubylib = load_path.join(':')
+      cmd.unshift(rubyver)
+      if $VERBOSE
+        print "RUBYLIB=#{rubylib} "
+        puts cmd.map { |part| part =~ /['"]/ ? part.inspect : part }.join(' ')
+      end
+      ENV['RUBYLIB'] = (ENV['RUBYLIB'] ? ENV['RUBYLIB'] + ':' : '') + rubylib
+      exec(*cmd)
+    end
+
+    def self.inherited(subclass)
+      @subclasses ||= []
+      @subclasses << subclass
+    end
+    def self.subclasses
+      @subclasses
+    end
+    def self.detect_and_run
+      subclasses.each do |klass|
+        klass.new.run_tests
+      end
+    end
+    def rubyver
+      @rubyver ||= RbConfig::CONFIG['ruby_install_name']
+    end
+    def ruby_binary
+      @ruby_binary ||= File.join('/usr/bin', rubyver)
+    end
+
+    class TestsListedInMetadata < TestRunner
+      def required_file
+        'debian/ruby-test-files.yaml'
+      end
+      def execute_tests
+        puts "Running tests for #{rubyver} with test file list from debian/ruby-test-files.yaml ..."
+        run_ruby(
+          '-ryaml', 
+          '-e',
+          'YAML.load_file("debian/ruby-test-files.yaml").each { |f| require f }'
+        )
+      end
+    end
+
+    class DebianRakefile < TestRunner
+      def required_file
+        'debian/ruby-tests.rake'
+      end
+      def execute_tests
+        puts "Running tests for #{rubyver} using debian/ruby-tests.rake ..."
+        run_ruby(
+          '-rrake',
+          '-e',
+          'ARGV.unshift("-f", "debian/ruby-tests.rake"); Rake.application.run'
+        )
+      end
+    end
+
+    class DebianRubyFile < TestRunner
+      def required_file
+        'debian/ruby-tests.rb'
+      end
+      def execute_tests
+        puts "Running tests for #{rubyver} using debian/ruby-tests.rb..."
+        ENV['RUBY_TEST_VERSION'] = rubyver
+        ENV['RUBY_TEST_BIN'] = ruby_binary
+        run_ruby(required_file)
+      end
+    end
 
-      @test_files.each do |f|
-        require f
+    class DontKnownHowToRunTests < TestRunner
+      def required_file
+        'debian/rules'
+      end
+      def execute_tests
+        puts "Running tests for #{rubyver}: found no way to run a test suite!"
       end
     end
+
   end
+
 end
 
 if $PROGRAM_NAME == __FILE__
   if ARGV.length == 0
-    Gem2Deb::TestRunner::new
+    Gem2Deb::TestRunner.detect_and_run
   else
     puts "usage: #{File.basename($PROGRAM_NAME)}"
     exit(1)

-- 
gem2deb.git



More information about the Pkg-ruby-extras-commits mailing list