Change soft-fail to use the config, rather than env
[rbx.git] / test / rubygems / test_gem_ext_configure_builder.rb
blobd3d0efb489559365afd2327caf56202285bf6193
1 require 'test/unit'
2 require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
3 require 'rubygems/ext'
5 class TestGemExtConfigureBuilder < RubyGemTestCase
7   def setup
8     super
10     @makefile_body =  "all:\n\t@echo ok\ninstall:\n\t@echo ok"
12     @ext = File.join @tempdir, 'ext'
13     @dest_path = File.join @tempdir, 'prefix'
15     FileUtils.mkdir_p @ext
16     FileUtils.mkdir_p @dest_path
17   end
19   def test_self_build
20     return if RUBY_PLATFORM =~ /mswin/ # HACK
22     File.open File.join(@ext, './configure'), 'w' do |configure|
23       configure.puts "#!/bin/sh\necho \"#{@makefile_body}\" > Makefile"
24     end
26     output = []
28     Dir.chdir @ext do
29       Gem::Ext::ConfigureBuilder.build nil, nil, @dest_path, output
30     end
32     expected = [
33       "sh ./configure --prefix=#{@dest_path}",
34       "", "make", "ok\n", "make install", "ok\n"
35     ]
37     assert_equal expected, output
38   end
40   def test_self_build_fail
41     return if RUBY_PLATFORM =~ /mswin/ # HACK
42     output = []
44     error = assert_raise Gem::InstallError do
45       Dir.chdir @ext do
46         Gem::Ext::ConfigureBuilder.build nil, nil, @dest_path, output
47       end
48     end
50     shell_error_msg = %r{(\./configure: No such file or directory)|(Can't open \./configure)}
51     sh_prefix_configure = "sh ./configure --prefix="
52     
53     expected = %r(configure failed:
55 #{Regexp.escape sh_prefix_configure}#{Regexp.escape @dest_path}
56 .*?: #{shell_error_msg}
59     assert_match expected, error.message
61     assert_equal "#{sh_prefix_configure}#{@dest_path}", output.shift
62     assert_match %r(#{shell_error_msg}\n), output.shift
63     assert_equal true, output.empty?
64   end
66   def test_self_build_has_makefile
67     File.open File.join(@ext, 'Makefile'), 'w' do |makefile|
68       makefile.puts @makefile_body
69     end
71     output = []
72     Dir.chdir @ext do
73       Gem::Ext::ConfigureBuilder.build nil, nil, @dest_path, output
74     end
76     case RUBY_PLATFORM
77     when /mswin/ then
78       assert_equal 'nmake', output[0]
79       assert_equal 'nmake install', output[2]
80     else
81       assert_equal 'make', output[0]
82       assert_equal 'make install', output[2]
83     end
84   end
86 end