[DRE-commits] [SCM] gem2deb.git branch, master, updated. f9dba1422e9fb793fd0778f5d74265ec88250907

Antonio Terceiro terceiro at softwarelivre.org
Mon Apr 11 18:48:45 UTC 2011


The following commit has been merged in the master branch:
commit 77ffd649335589f3222da5d4c79d3f7ca3eed353
Author: Antonio Terceiro <terceiro at softwarelivre.org>
Date:   Mon Apr 11 11:42:07 2011 -0700

    Extract logic for running a gem2deb command

diff --git a/test/integration/gem2deb_test.rb b/test/integration/gem2deb_test.rb
index c313878..181f58e 100644
--- a/test/integration/gem2deb_test.rb
+++ b/test/integration/gem2deb_test.rb
@@ -2,21 +2,6 @@ require 'test_helper'
 
 class Gem2DebTest < Gem2DebTestCase
 
-  one_time_setup do
-    # setup Perl lib for debhelper7
-    perl5lib = File.join(tmpdir, 'perl5')
-    debhelper_buildsystems = File.join(perl5lib, 'Debian/Debhelper/Buildsystem')
-    FileUtils.mkdir_p debhelper_buildsystems
-    FileUtils.cp 'debhelper7/buildsystem/ruby.pm', debhelper_buildsystems
-    debhelper_sequences = File.join(perl5lib, 'Debian/Debhelper/Sequence')
-    FileUtils.mkdir_p debhelper_sequences
-    FileUtils.cp 'debhelper7/sequence/ruby.pm', debhelper_sequences
-
-    ENV['PERL5LIB'] = perl5lib
-    ENV['PATH'] = [File.join(GEM2DEB_ROOT_SOURCE_DIR, 'bin'), ENV['PATH']].join(':')
-    ENV['RUBYLIB'] = File.join(GEM2DEB_ROOT_SOURCE_DIR, 'lib')
-  end
-
   Dir.glob('test/sample/*/pkg/*.gem').each do |gem|
     should "build #{gem} correcly" do
       self.class.build(gem)
@@ -34,12 +19,7 @@ class Gem2DebTest < Gem2DebTestCase
     gem = File.basename(gem)
     Dir.chdir(tmpdir) do
       cmd = "gem2deb -d #{gem}"
-      silence_all_output do
-        system(cmd)
-      end
-      if $?.exitstatus != 0
-        raise "Command [#{cmd}] failed!"
-      end
+      run_command(cmd)
     end
   end
 
diff --git a/test/test_helper.rb b/test/test_helper.rb
index a118aeb..c959987 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -95,14 +95,50 @@ class Gem2DebTestCase < Test::Unit::TestCase
     end
   end
 
-  def self.silence_all_output
-    silence_stream(STDOUT) do
-      silence_stream(STDERR) do
-        yield
-      end
+  # Runs a command with the current (in-development) gem2deb environment
+  # loaded. PATH, PERL5LIB and RUBYLIB environment variables are tweaked to
+  # make sure that everything that comes from gem2deb has precedence over
+  # system-wide installed versions.
+  def self.run_command(cmd)
+    # setup Perl lib for debhelper7
+    perl5lib = File.join(tmpdir, 'perl5')
+    debhelper_buildsystems = File.join(perl5lib, 'Debian/Debhelper/Buildsystem')
+    FileUtils.mkdir_p debhelper_buildsystems
+    FileUtils.cp "#{GEM2DEB_ROOT_SOURCE_DIR}/debhelper7/buildsystem/ruby.pm", debhelper_buildsystems
+    debhelper_sequences = File.join(perl5lib, 'Debian/Debhelper/Sequence')
+    FileUtils.mkdir_p debhelper_sequences
+    FileUtils.cp "#{GEM2DEB_ROOT_SOURCE_DIR}/debhelper7/sequence/ruby.pm", debhelper_sequences
+
+    # setup the environment
+    ENV['PERL5LIB'] = perl5lib
+    ENV['PATH'] = [File.join(GEM2DEB_ROOT_SOURCE_DIR, 'bin'), ENV['PATH']].join(':')
+    ENV['RUBYLIB'] = File.join(GEM2DEB_ROOT_SOURCE_DIR, 'lib')
+
+    @run_command_id ||= -1
+    @run_command_id += 1
+
+    # run the command
+    stdout = File.join(tmpdir, 'stdout.' + self.name + '.' + @run_command_id.to_s)
+    stderr = File.join(tmpdir, 'stderr.' + self.name + '.' + @run_command_id.to_s)
+    error = nil
+    system("#{cmd} >#{stdout} 2>#{stderr}")
+    if $?.exitstatus != 0
+      error = "Command [#{cmd}] failed!\n"
+      error << "Standard output:\n" << File.read(stdout).lines.map { |line| "  #{line}"}.join
+      error << "Standard error:\n" << File.read(stderr).lines.map { |line| "  #{line}"}.join
+    end
+    FileUtils.rm_f(stdout)
+    FileUtils.rm_f(stderr)
+    if error
+      raise error
     end
   end
 
+  # See above
+  def run_command(cmd)
+    self.class.run_command(cmd)
+  end
+
 end
 
 class Test::Unit::AutoRunner

-- 
gem2deb.git



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