~ubuntu-branches/ubuntu/trusty/ruby1.9/trusty

« back to all changes in this revision

Viewing changes to test/rubygems/test_gem_ext_rake_builder.rb

  • Committer: Bazaar Package Importer
  • Author(s): Stephan Hermann
  • Date: 2008-01-24 11:42:29 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20080124114229-jw2f87rdxlq6gp11
Tags: 1.9.0.0-2ubuntu1
* Merge from debian unstable, remaining changes:
  - Robustify check for target_os, fixing build failure on lpia.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'test/unit'
 
2
require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
 
3
require 'rubygems/ext'
 
4
 
 
5
class TestGemExtRakeBuilder < RubyGemTestCase
 
6
 
 
7
  def setup
 
8
    super
 
9
 
 
10
    @ext = File.join @tempdir, 'ext'
 
11
    @dest_path = File.join @tempdir, 'prefix'
 
12
 
 
13
    FileUtils.mkdir_p @ext
 
14
    FileUtils.mkdir_p @dest_path
 
15
  end
 
16
 
 
17
  def test_class_build
 
18
    File.open File.join(@ext, 'mkrf_conf.rb'), 'w' do |mkrf_conf|
 
19
      mkrf_conf.puts <<-EO_MKRF
 
20
        File.open("Rakefile","w") do |f|
 
21
          f.puts "task :default"
 
22
        end
 
23
      EO_MKRF
 
24
    end
 
25
 
 
26
    output = []
 
27
    realdir = nil # HACK /tmp vs. /private/tmp
 
28
 
 
29
    Dir.chdir @ext do
 
30
      realdir = Dir.pwd
 
31
      Gem::Ext::RakeBuilder.build 'mkrf_conf.rb', nil, @dest_path, output
 
32
    end
 
33
 
 
34
    expected = [
 
35
      "#{Gem.ruby} mkrf_conf.rb",
 
36
      "",
 
37
      "rake RUBYARCHDIR=#{@dest_path} RUBYLIBDIR=#{@dest_path}",
 
38
      "(in #{realdir})\n"
 
39
    ]
 
40
 
 
41
    assert_equal expected, output
 
42
  end
 
43
 
 
44
  def test_class_build_fail
 
45
    File.open File.join(@ext, 'mkrf_conf.rb'), 'w' do |mkrf_conf|
 
46
      mkrf_conf.puts <<-EO_MKRF
 
47
        File.open("Rakefile","w") do |f|
 
48
          f.puts "task :default do abort 'fail' end"
 
49
        end
 
50
        EO_MKRF
 
51
    end
 
52
 
 
53
    output = []
 
54
 
 
55
    error = assert_raise Gem::InstallError do
 
56
      Dir.chdir @ext do
 
57
        Gem::Ext::RakeBuilder.build "mkrf_conf.rb", nil, @dest_path, output
 
58
      end
 
59
    end
 
60
 
 
61
    expected = <<-EOF.strip
 
62
rake failed:
 
63
 
 
64
#{Gem.ruby} mkrf_conf.rb
 
65
 
 
66
rake RUBYARCHDIR=#{@dest_path} RUBYLIBDIR=#{@dest_path}
 
67
    EOF
 
68
 
 
69
    assert_equal expected, error.message.split("\n")[0..4].join("\n")
 
70
  end
 
71
 
 
72
end
 
73