File: test_cook.rb

package info (click to toggle)
ruby-mini-portile2 2.8.7-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 332 kB
  • sloc: ruby: 1,834; ansic: 38; sh: 8; makefile: 4
file content (199 lines) | stat: -rw-r--r-- 6,657 bytes parent folder | download | duplicates (2)
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
require File.expand_path('../helper', __FILE__)

class TestCook < TestCase
  attr_accessor :assets_path, :tar_path, :recipe

  def before_all
    super
    @assets_path = File.expand_path("../assets", __FILE__)
    @tar_path = File.expand_path("../../tmp/test mini portile-1.0.0.tar.gz", __FILE__)

    FileUtils.rm_rf("tmp") # remove any previous test files

    create_tar(@tar_path, @assets_path, "test mini portile-1.0.0")
    start_webrick(File.dirname(@tar_path))

    @logger = StringIO.new # IO to keep recipe logs in case we need to debug
    @recipe = MiniPortile.new("test mini portile", "1.0.0").tap do |recipe|
      recipe.logger = @logger
      recipe.files << "http://localhost:#{HTTP_PORT}/#{ERB::Util.url_encode(File.basename(@tar_path))}"
      recipe.patch_files << File.join(@assets_path, "patch 1.diff")
      recipe.configure_options << "--option=\"path with 'space'\""
      git_dir = File.join(@assets_path, "git")
      with_custom_git_dir(git_dir) do
        recipe.cook
      end
    end
  rescue => e
    puts @logger.string
    raise e
  end

  def after_all
    super
    stop_webrick
    FileUtils.rm_rf("tmp") # remove test files
  end

  def test_download
    download = "ports/archives/test%20mini%20portile-1.0.0.tar.gz"
    assert File.exist?(download), download
  end

  def test_untar
    configure = File.join(work_dir, "configure")
    assert File.exist?(configure), configure
    assert_match( /^#!\/bin\/sh/, IO.read(configure) )
  end

  def test_patch
    patch1 = File.join(work_dir, "patch 1.txt")
    assert File.exist?(patch1), patch1
    assert_match( /^\tchange 1/, IO.read(patch1) )
  end

  def test_configure
    txt = File.join(work_dir, "configure.txt")
    assert File.exist?(txt), txt
    opts = recipe.configure_options + ["--prefix=#{recipe.path}"]
    assert_equal( opts.inspect, IO.read(txt).chomp )
  end

  def test_compile
    txt = File.join(work_dir, "compile.txt")
    assert File.exist?(txt), txt
    assert_equal( ["all"].inspect, IO.read(txt).chomp )
  end

  def test_install
    txt = File.join(work_dir, "install.txt")
    assert File.exist?(txt), txt
    assert_equal( ["install"].inspect, IO.read(txt).chomp )
  end
end

class TestCookConfiguration < TestCase
  def test_make_command_configuration
    without_env("MAKE") do
      #assert_equal("make", MiniPortile.new("test", "1.0.0").make_cmd)
      assert_equal("xyzzy", MiniPortile.new("test", "1.0.0", make_command: "xyzzy").make_cmd)
    end
    with_env("MAKE"=>"asdf") do
      assert_equal("asdf", MiniPortile.new("test", "1.0.0").make_cmd)
      assert_equal("asdf", MiniPortile.new("test", "1.0.0", make_command: "xyzzy").make_cmd)
    end
  end

  def test_cc_command_configuration
    without_env("CC") do
      expected_compiler = RbConfig::CONFIG["CC"] || "gcc"
      assert_equal(expected_compiler, MiniPortile.new("test", "1.0.0").cc_cmd)
      assert_equal(expected_compiler, MiniPortile.new("test", "1.0.0").gcc_cmd)
      assert_equal("xyzzy", MiniPortile.new("test", "1.0.0", cc_command: "xyzzy").cc_cmd)
      assert_equal("xyzzy", MiniPortile.new("test", "1.0.0", gcc_command: "xyzzy").cc_cmd)
      assert_equal("xyzzy", MiniPortile.new("test", "1.0.0", cc_command: "xyzzy").gcc_cmd)
      assert_equal("xyzzy", MiniPortile.new("test", "1.0.0", gcc_command: "xyzzy").gcc_cmd)
    end
    with_env("CC"=>"asdf") do
      assert_equal("asdf", MiniPortile.new("test", "1.0.0").cc_cmd)
      assert_equal("asdf", MiniPortile.new("test", "1.0.0").gcc_cmd)
      assert_equal("asdf", MiniPortile.new("test", "1.0.0", cc_command: "xyzzy").cc_cmd)
      assert_equal("asdf", MiniPortile.new("test", "1.0.0", gcc_command: "xyzzy").cc_cmd)
      assert_equal("asdf", MiniPortile.new("test", "1.0.0", cc_command: "xyzzy").gcc_cmd)
      assert_equal("asdf", MiniPortile.new("test", "1.0.0", gcc_command: "xyzzy").gcc_cmd)
    end
  end

  def test_cxx_command_configuration
    without_env("CXX") do
      expected_compiler = RbConfig::CONFIG["CXX"] || "g++"
      assert_equal(expected_compiler, MiniPortile.new("test", "1.0.0").cxx_cmd)
      assert_equal("xyzzy", MiniPortile.new("test", "1.0.0", cxx_command: "xyzzy").cxx_cmd)
    end
    with_env("CXX"=>"asdf") do
      assert_equal("asdf", MiniPortile.new("test", "1.0.0").cxx_cmd)
      assert_equal("asdf", MiniPortile.new("test", "1.0.0", cxx_command: "xyzzy").cxx_cmd)
    end
  end
end


class TestCookWithBrokenGitDir < TestCase
  #
  #  this is a test for #69
  #  https://github.com/flavorjones/mini_portile/issues/69
  #
  attr_accessor :assets_path, :tar_path, :recipe

  def before_all
    super
    @assets_path = File.expand_path("../assets", __FILE__)
    @tar_path = File.expand_path("../../tmp/test-mini-portile-1.0.0.tar.gz", __FILE__)

    @git_dir = File.join(@assets_path, "git-broken")
    FileUtils.rm_rf @git_dir
    FileUtils.mkdir_p @git_dir
    Dir.chdir(@git_dir) do
      File.open ".git", "w" do |f|
        f.write "gitdir: /nonexistent"
      end
    end

    create_tar(@tar_path, @assets_path, "test mini portile-1.0.0")

    @logger = StringIO.new # IO to keep recipe logs in case we need to debug
    @recipe = MiniPortile.new("test mini portile", "1.0.0").tap do |recipe|
      recipe.logger = @logger
      recipe.files << "file://#{@tar_path}"
      recipe.patch_files << File.join(@assets_path, "patch 1.diff")
      recipe.configure_options << "--option=\"path with 'space'\""
    end

    Dir.chdir(@git_dir) do
      @recipe.cook
    end
  end

  def after_all
    FileUtils.rm_rf @git_dir
  end

  def test_patch
    Dir.chdir(@git_dir) do
      patch1 = File.join(work_dir, "patch 1.txt")
      assert File.exist?(patch1), patch1
      assert_match( /^\tchange 1/, IO.read(patch1) )
    end
  end
end

class TestCookAgainstSourceDirectory < TestCase
  attr_accessor :recipe

  def setup
    super

    @logger = StringIO.new # IO to keep recipe logs in case we need to debug
    @recipe ||= MiniPortile.new("test mini portile", "1.0.0").tap do |recipe|
      recipe.logger = @logger
      recipe.source_directory = File.expand_path("../assets/test mini portile-1.0.0", __FILE__)
    end
  end

  def test_source_directory
    recipe.cook

    path = File.join(work_dir, "configure.txt")
    assert(File.exist?(path))
    assert_equal((recipe.configure_options + ["--prefix=#{recipe.path}"]).inspect,
                 File.read(path).chomp);

    path = File.join(work_dir, "compile.txt")
    assert(File.exist?(path))
    assert_equal("[\"all\"]", File.read(path).chomp);

    path = File.join(work_dir, "install.txt")
    assert(File.exist?(path))
    assert_equal("[\"install\"]", File.read(path).chomp);
  end
end