[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: gem2deb: support for building using setup.rb



  Hi Lucas !

On Tue, May 17, 2011 at 8:16 AM, Lucas Nussbaum
<lucas@lucas-nussbaum.net> wrote:
>>   I'm unsure about that: the testrunner.rb uses the source directory
>> as library path for loading the test files. Of course, this will work
>> for pure ruby libraries, but, at least for setup.rb, it will fail
>> miserably for built extensions, since the build cleans up the built
>> files in the source after installing. I'm wondering: shouldn't
>> testrunner.rb rather use debian/package/usr/lib/vendor_ruby and co as
>> library path ? This is guaranteed to work, at least if tests are run
>> *after* installation (which is the case) ?
>
> Mmmh, yes, probably. Could you experiment with the idea and provide a
> patch? :)

  Here it is. Changing the load path exposed a bug in the
simpleextension test suite. After that was fixed, gem2deb builds
without failures. Attached is the diff that does the trick (don't
forget to rebuild the simpleextension gem !!).

  BTW: is there any compelling reason to have the test's .gem files in
the source package (and in the git respository) ? They are useless
since they can be rebuilt at build time, and it took me a very long
time to understand why my modifications to the simpleextension test
suite did not seem to have any effect at all ;-)...

  Cheers,

      Vincent
diff --git a/lib/gem2deb/testrunner.rb b/lib/gem2deb/testrunner.rb
index c7f9f76..b98f740 100644
--- a/lib/gem2deb/testrunner.rb
+++ b/lib/gem2deb/testrunner.rb
@@ -16,24 +16,26 @@
 require 'gem2deb'
 require 'yaml'
 
+require 'rbconfig'
+
 module Gem2Deb
   class TestRunner
     def initialize
       @test_files = YAML.load_file('debian/ruby-test-files.yaml')
 
-      $: << File::expand_path('lib')
-      if File::directory?('ext')
-        $: << File::expand_path('ext')
-        # also add subdirs of ext/
-        (Dir::entries('ext') - ['.', '..']).each do |e|
-          if File::directory?(File.join('ext', e))
-            $: << File::expand_path(File.join('ext',e))
-          end
-        end
-      end
-      $: << File::expand_path('test') if File::directory?('test')
-      $: << File::expand_path('spec') if File::directory?('spec')
-      $: << File::expand_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.
+
+      dirs = Dir["debian/*/usr/lib/ruby/vendor_ruby"]
+      dirs += Dir["debian/*" + RbConfig::CONFIG['vendorarchdir']]
+      
+      $:.concat(dirs)
+
+      # And we add the current directory:
+      $: << "."
 
       @test_files.each do |f|
         require f
diff --git a/test/sample/simpleextension/pkg/simpleextension-1.2.3.gem b/test/sample/simpleextension/pkg/simpleextension-1.2.3.gem
index dfdbe9f..e7c7080 100644
Binary files a/test/sample/simpleextension/pkg/simpleextension-1.2.3.gem and b/test/sample/simpleextension/pkg/simpleextension-1.2.3.gem differ
diff --git a/test/sample/simpleextension/test/test_simpleextension.rb b/test/sample/simpleextension/test/test_simpleextension.rb
index b41b079..ac56fa7 100644
--- a/test/sample/simpleextension/test/test_simpleextension.rb
+++ b/test/sample/simpleextension/test/test_simpleextension.rb
@@ -1,5 +1,5 @@
 require 'test/unit'
-require 'simpleextension/simpleextension'
+require 'simpleextension'
 
 class SimpleExtensionTest < Test::Unit::TestCase
   def test_answer

Reply to: