[DRE-commits] [gem2deb] 01/03: Gem2Deb::Metadata: make git usage workaround more robust

Antonio Terceiro terceiro at moszumanska.debian.org
Thu Mar 17 14:50:38 UTC 2016


This is an automated email from the git hooks/post-receive script.

terceiro pushed a commit to branch master
in repository gem2deb.

commit 329344b416bcdc335155c90b7f3a16f8049e03ae
Author: Antonio Terceiro <terceiro at debian.org>
Date:   Thu Mar 17 11:15:54 2016 -0300

    Gem2Deb::Metadata: make git usage workaround more robust
---
 debian/changelog           |   7 +++
 lib/gem2deb/metadata.rb    |   6 +-
 test/unit/metadata_test.rb | 136 +++++++++++++++++++++++++++++++++------------
 3 files changed, 111 insertions(+), 38 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index bbd4e00..36c601a 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+gem2deb (0.30.1) UNRELEASED; urgency=medium
+
+  * Gem2Deb::Metadata:
+    - make the workaround attempt for gemspecs using git more robust.
+
+ -- Antonio Terceiro <terceiro at debian.org>  Thu, 17 Mar 2016 10:23:58 -0300
+
 gem2deb (0.30) unstable; urgency=medium
 
   * Gem2Deb::Metadata:
diff --git a/lib/gem2deb/metadata.rb b/lib/gem2deb/metadata.rb
index cfc25c8..c7fbd24 100644
--- a/lib/gem2deb/metadata.rb
+++ b/lib/gem2deb/metadata.rb
@@ -124,9 +124,9 @@ module Gem2Deb
     end
 
     GIT_USAGE_MODIFIERS = {
-      /\.files\s*=\s*`[^`]*git\s+ls-files[^`]*`.*/ => '.files = (Dir["**/*"] - Dir["debian/**/*"] - Dir["*.gemspec.gem2deb"]).select { |f| !File.directory?(f) }',
-      /\.test_files\s*=\s*`[^`]*git\s+ls-files[^`]*`.*/ => '.test_files = []',
-      /(\w+)\.executables\s*=\s*`[^`]*git\s+ls-files[^`]*`.*/ => '\1.executables = Dir[\1.bindir + "/*"]',
+      /\.files\s*=\s*`[^`]*git\s+ls-files[^`]*`\.split(\([^)]*\))?/ => '.files = ((Dir["**/*"] - Dir["debian/**/*"] - Dir["*.gemspec.gem2deb"]).select { |f| !File.directory?(f) })',
+      /\.test_files\s*=\s*`[^`]*git\s+ls-files[^`]*`\.split(\([^)]*\))?/ => '.test_files = []',
+      /(\w+)\.executables\s*=\s*`[^`]*git\s+ls-files[^`]*`\.split(\([^)]*\))?/ => '\1.executables = Dir[\1.bindir + "/*"]',
     }
 
     def load_modified_gemspec(original_gemspec_path)
diff --git a/test/unit/metadata_test.rb b/test/unit/metadata_test.rb
index 6aaf8a1..5dc9ea7 100644
--- a/test/unit/metadata_test.rb
+++ b/test/unit/metadata_test.rb
@@ -2,6 +2,83 @@ require_relative '../test_helper'
 require 'gem2deb/metadata'
 require 'yaml'
 
+$GIT_ABUSER_GEMSPEC_1 = <<EOF
+Gem::Specification.new do |s|
+  s.name        = "gitabuser1"
+  s.version     = "1"
+  s.platform    = Gem::Platform::RUBY
+  s.authors     = ["Antonio Terceiro"]
+  s.email       = ["terceiro at debian.org"]
+  s.homepage    = ""
+  s.summary     = %q{Sample gem that }
+  s.description = %q{This gem is used to test the case where dh-make-ruby is called on a directory}
+
+  s.rubyforge_project = "simplegit"
+  s.files             = `/unexisting/git ls-files`.split
+  s.executables       = `/unexisting/git ls-files`.split.select { |f| File.executable?(f) }
+  s.test_files        = `/unexisting/git ls-files`.split.select { |f| f =~ /^(test|spec|features)/ }
+  s.require_paths     = ["lib"]
+end
+EOF
+
+$GIT_ABUSER_GEMSPEC_2 = <<'EOF'
+Gem::Specification.new do |s|
+  s.name        = "gitabuser2"
+  s.version     = "1"
+  s.platform    = Gem::Platform::RUBY
+  s.authors     = ["Antonio Terceiro"]
+  s.email       = ["terceiro at debian.org"]
+  s.homepage    = ""
+  s.summary     = %q{Sample gem that }
+  s.description = %q{This gem is used to test the case where dh-make-ruby is called on a directory}
+
+  s.rubyforge_project = "simplegit"
+  s.files             = `/unexisting/git ls-files`.split("\n")
+  s.executables       = `/unexisting/git ls-files`.split("\n").select { |f| File.executable?(f) }
+  s.test_files        = `/unexisting/git ls-files`.split("\n").select { |f| f =~ /^(test|spec|features)/ }
+  s.require_paths     = ["lib"]
+end
+EOF
+
+$GIT_ABUSER_GEMSPEC_3 = <<'EOF'
+Gem::Specification.new do |s|
+  s.name        = "gitabuser3"
+  s.version     = "1"
+  s.platform    = Gem::Platform::RUBY
+  s.authors     = ["Antonio Terceiro"]
+  s.email       = ["terceiro at debian.org"]
+  s.homepage    = ""
+  s.summary     = %q{Sample gem that }
+  s.description = %q{This gem is used to test the case where dh-make-ruby is called on a directory}
+
+  s.rubyforge_project = "simplegit"
+  s.files             = `/unexisting/git ls-files`.split($/)
+  s.executables       = `/unexisting/git ls-files`.split($/).select { |f| File.executable?(f) }
+  s.test_files        = `/unexisting/git ls-files`.split($/).select { |f| f =~ /^(test|spec|features)/ }
+  s.require_paths     = ["lib"]
+end
+EOF
+
+$GIT_ABUSER_GEMSPEC_4 = <<'EOF'
+Gem::Specification.new do |s|
+  s.name        = "gitabuser4"
+  s.version     = "1"
+  s.platform    = Gem::Platform::RUBY
+  s.authors     = ["Antonio Terceiro"]
+  s.email       = ["terceiro at debian.org"]
+  s.homepage    = ""
+  s.summary     = %q{Sample gem that }
+  s.description = %q{This gem is used to test the case where dh-make-ruby is called on a directory}
+
+  s.rubyforge_project = "simplegit"
+  s.files             = `/unexisting/git ls-files`.split($/).
+    select { |f| File.basename(f) != '.foobar' }
+  s.executables       = `/unexisting/git ls-files`.split($/).select { |f| File.executable?(f) }
+  s.test_files        = `/unexisting/git ls-files`.split($/).select { |f| f =~ /^(test|spec|features)/ }
+  s.require_paths     = ["lib"]
+end
+EOF
+
 class MetaDataTest < Gem2DebTestCase
 
   {
@@ -169,45 +246,34 @@ class MetaDataTest < Gem2DebTestCase
   end
 
   context 'when upstream abuses git in gemspecs' do
-
-    should 'workaround git usage' do
-      # create
-      dir = File.join(tmpdir, 'gitabuser')
-      FileUtils.mkdir_p(dir)
-      Dir.chdir dir do
-        File.open('gitabuser.gemspec', 'w') do |f|
-          f.puts($GIT_ABUSER_GEMSPEC)
-        end
-        FileUtils.mkdir 'lib'
-        File.open('lib/gitabuser.rb', 'w') do |f|
-          f.puts 'module GitAbuser; end'
+    [
+      $GIT_ABUSER_GEMSPEC_1,
+      $GIT_ABUSER_GEMSPEC_2,
+      $GIT_ABUSER_GEMSPEC_3,
+      $GIT_ABUSER_GEMSPEC_4,
+    ].each_with_index do |gemspec,i|
+      n = i + 1
+      should "workaround git usage (#{n})" do
+        # create
+        dir = File.join(tmpdir, "gitabuser#{n}")
+        FileUtils.mkdir_p(dir)
+        Dir.chdir dir do
+          File.open("gitabuser#{n}.gemspec", 'w') do |f|
+            f.puts(gemspec)
+          end
+          FileUtils.mkdir 'lib'
+          File.open("lib/gitabuser#{n}.rb", 'w') do |f|
+            f.puts "module GitAbuser#{n}; end"
+          end
         end
-      end
 
-      @metadata = self.class.silently { Gem2Deb::Metadata.new(dir) }
-      assert_not_nil @metadata.gemspec
-      assert_equal ['gitabuser.gemspec', 'lib/gitabuser.rb'], @metadata.gemspec.files
+
+        @metadata = self.class.silently { Gem2Deb::Metadata.new(dir) }
+        assert_not_nil @metadata.gemspec
+        assert_equal ["gitabuser#{n}.gemspec", "lib/gitabuser#{i+1}.rb"], @metadata.gemspec.files
+      end
     end
 
   end
 
 end
-
-$GIT_ABUSER_GEMSPEC = <<EOF
-Gem::Specification.new do |s|
-  s.name        = "gitabuser"
-  s.version     = "1"
-  s.platform    = Gem::Platform::RUBY
-  s.authors     = ["Antonio Terceiro"]
-  s.email       = ["terceiro at debian.org"]
-  s.homepage    = ""
-  s.summary     = %q{Sample gem that }
-  s.description = %q{This gem is used to test the case where dh-make-ruby is called on a directory}
-
-  s.rubyforge_project = "simplegit"
-  s.files             = `/unexisting/git ls-files`.split
-  s.executables       = `/unexisting/git ls-files`.split.select { |f| File.executable?(f) }
-  s.test_files        = `/unexisting/git ls-files`.split.select { |f| f =~ /^(test|spec|features)/ }
-  s.require_paths     = ["lib"]
-end
-EOF

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/gem2deb.git



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