File: gem2deb_test.rb

package info (click to toggle)
gem2deb 2.2.6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,228 kB
  • sloc: ruby: 5,562; sh: 140; perl: 46; ansic: 33; makefile: 31
file content (116 lines) | stat: -rw-r--r-- 3,960 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
require_relative '../test_helper'

class Gem2DebTest < Gem2DebTestCase

  def self.build(gem)
    FileUtils.cp gem, tmpdir
    gem = File.basename(gem)
    Dir.chdir(tmpdir) do
      cmd = "gem2deb -d #{gem}"
      run_command(cmd)
    end
  end

  Dir.glob('test/sample/*/pkg/*.gem').each do |gem|
    puts "Building #{gem} ..."
    self.build(gem)
    should "build #{gem} correcly" do
      package_name = 'ruby-' + File.basename(File.dirname(File.dirname(gem))).gsub('_', '-').downcase
      binary_packages = File.join(self.class.tmpdir, "#{package_name}_*.deb")
      packages = Dir.glob(binary_packages)
      assert !packages.empty?, "building #{gem} produced no binary packages! (expected to find #{binary_packages})"
    end
  end

  should 'install executables for altbindir' do
    assert_match '/usr/bin/altbindir', `dpkg --contents #{self.class.tmpdir}/ruby-altbindir*.deb`
  end

  should 'not install non-listed executables from altbindir' do
    assert_no_match %r{/usr/bin/dont-install}, `dpkg --contents #{self.class.tmpdir}/ruby-altbindir*.deb`
  end

  def self.build_tree(directory)
    FileUtils.cp_r(directory, tmpdir)
    dir = File.join(tmpdir, File.basename(directory))
    yield(dir)
    puts "Building #{directory} ..."
    Dir.chdir(dir) do
      run_command('fakeroot debian/rules binary')
    end
  end

  self.build_tree('test/sample/examples') do |dir|

    should 'not compress *.rb files installed as examples' do
      assert_no_file_exists "#{dir}/debian/ruby-examples/usr/share/doc/ruby-examples/examples/test.rb.gz"
      assert_file_exists "#{dir}/debian/ruby-examples/usr/share/doc/ruby-examples/examples/test.rb"
    end

    should 'install CHANGELOG.rdoc as upstream changelog' do
      changelog = "#{dir}/debian/ruby-examples/usr/share/doc/ruby-examples/changelog.gz"
      assert_file_exists changelog
    end

  end

  self.build_tree('test/sample/multibinary') do |dir|
    context "multibinary source package" do
      should "install foo in ruby-foo" do
        assert_file_exists "#{dir}/debian/ruby-foo/usr/bin/foo"
      end
      should 'install foo.rb in ruby-foo' do
        assert_file_exists "#{dir}/debian/ruby-foo/usr/lib/ruby/vendor_ruby/foo.rb"
      end
      should 'install bar in ruby-bar' do
        assert_file_exists "#{dir}/debian/ruby-bar/usr/bin/bar"
      end
      should 'install bar.rb ruby-bar' do
        assert_file_exists "#{dir}/debian/ruby-bar/usr/lib/ruby/vendor_ruby/bar.rb"
      end
      should 'support installing upstream CHANGELOG in multibinary package' do
        assert_file_exists "#{dir}/debian/ruby-bar/usr/share/doc/ruby-bar/changelog.gz"
      end

      should 'support native extensions' do
        assert Dir.glob("#{dir}/debian/ruby-baz/**/baz.so").size > 0, 'baz.so not found!!!'
      end

      should 'inject dependency on ruby (>= something)' do
        deps = File.readlines("#{dir}/debian/ruby-baz/DEBIAN/control").find do |line|
          line =~ /^Depends:\s*/
        end.sub(/^Depends:\s*/, '').split(/\s*,\s*/)
        assert deps.any? { |dep| dep =~ /ruby \(>= [^)]+\)/}, "#{deps.inspect} expected to include 'ruby (>= something)'"
      end
    end
  end

  self.build_tree('test/sample/simpleextension_dh_auto_install_destdir') do |dir|
    should 'honor DH_RUBY_USE_DH_AUTO_INSTALL_DESTDIR when building extensions' do
      assert Dir.glob("#{dir}/debian/tmp/**/*.so").size > 0, 'no .so files found in debian/tmp/'
    end
  end

  self.build_tree('test/sample/install_as_gem') do |dir|
    context 'using --gem-install' do
      should 'install' do
        assert Dir.glob("#{dir}/debian/*/**/*.so").size > 0 , '.so file is installed'
      end
    end
  end

  %w[
    13
    14
  ].each do |level|
    self.build_tree("test/sample/simplegem#{level}") do |dir|
      context "compatiblity level #{level}" do
        should 'work' do
          assert Dir.glob("#{dir}/debian/*/**/*.rb").size > 0
        end
      end
    end
  end


end