File: source_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 (93 lines) | stat: -rw-r--r-- 2,844 bytes parent folder | download
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
require_relative '../test_helper'
require 'gem2deb/source'

class SourceTest < Gem2DebTestCase

  def debian_control
    @debian_control ||= []
  end

  def t_tmpdir
    @t_tmpdir ||= File.join(tmpdir, method_name).tap do |dir|
      FileUtils.mkdir_p(File.join(dir, "debian"))
    end
  end

  def source
    @source ||= Dir.chdir(t_tmpdir) do
      File.write("debian/control", debian_control.join("\n"))
      Gem2Deb::Source.new
    end
  end

  context "selecting package layout" do

    should 'default to single-binary' do
      debian_control << 'Package: ruby-foo'
      debian_control << 'Package: ruby-bar'
      ruby_foo = { :binary_package => 'ruby-foo', :root => '.' }
      assert_equal [ruby_foo], source.send(:packages)
    end

    should 'ignore packages without X-DhRuby-Root when one of them has it' do
      debian_control << 'Package: ruby-foo'
      debian_control << 'Package: ruby-bar'
      debian_control << 'X-DhRuby-Root: bar'

      ruby_bar = { :binary_package => 'ruby-bar', :root => 'bar' }
      assert_equal [ruby_bar], source.send(:packages)
    end

    should 'detect multibinary' do
      debian_control << 'Package: ruby-foo'
      debian_control << 'X-DhRuby-Root: foo'
      debian_control << 'Package: ruby-bar'
      debian_control << 'X-DhRuby-Root: bar'
      ruby_foo = { :binary_package => 'ruby-foo', :root => 'foo' }
      ruby_bar = { :binary_package => 'ruby-bar', :root => 'bar' }
      assert_equal [ruby_foo, ruby_bar], source.send(:packages)
    end

  end

  context "determining debhelper compat level" do
    should 'detect from DH_COMPAT' do
      ENV.expects(:[]).with("DH_COMPAT").returns("14").at_least_once
      assert_equal 14, source.debhelper_compat
    end

    should 'detect from debian/compat' do
      File.write(File.join(t_tmpdir, "debian", "compat"), "12\n")
      assert_equal 12, source.debhelper_compat
    end

    should 'detect from Build-Depends' do
      debian_control << 'Source: ruby-foobar'
      debian_control << 'Build-Depends: gem2deb, debhelper-compat (= 11), ruby-baz'
      assert_equal 11, source.debhelper_compat
    end

    should 'detect from Build-Depends with multiple lines' do
      debian_control << 'Source: ruby-foobar'
      debian_control << "Build-Depends: gem2deb,\n debhelper-compat (= 11),\n ruby-baz"
      assert_equal 11, source.debhelper_compat
    end

    should 'always be a number' do
      assert_kind_of Integer, source.debhelper_compat
    end
  end

  should 'handle debian/control in a case-insensitive way' do
    debian_control << 'build-depends: ruby'
    debian_control << 'package: ruby-foo'
    debian_control << 'x-dhruby-root: foo'
    assert_equal(["ruby"], source.build_depends)
    assert_equal(
      { :binary_package => 'ruby-foo', :root => 'foo' },
      source.send(:packages).first
    )
  end

end