2 require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
5 class TestGemExtConfigureBuilder < RubyGemTestCase
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
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"
29 Gem::Ext::ConfigureBuilder.build nil, nil, @dest_path, output
33 "sh ./configure --prefix=#{@dest_path}",
34 "", "make", "ok\n", "make install", "ok\n"
37 assert_equal expected, output
40 def test_self_build_fail
41 return if RUBY_PLATFORM =~ /mswin/ # HACK
44 error = assert_raise Gem::InstallError do
46 Gem::Ext::ConfigureBuilder.build nil, nil, @dest_path, output
50 shell_error_msg = %r{(\./configure: No such file or directory)|(Can't open \./configure)}
51 sh_prefix_configure = "sh ./configure --prefix="
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?
66 def test_self_build_has_makefile
67 File.open File.join(@ext, 'Makefile'), 'w' do |makefile|
68 makefile.puts @makefile_body
73 Gem::Ext::ConfigureBuilder.build nil, nil, @dest_path, output
78 assert_equal 'nmake', output[0]
79 assert_equal 'nmake install', output[2]
81 assert_equal 'make', output[0]
82 assert_equal 'make install', output[2]