2 require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
5 class TestGemExtExtConfBuilder < RubyGemTestCase
10 @ext = File.join @tempdir, 'ext'
11 @dest_path = File.join @tempdir, 'prefix'
13 FileUtils.mkdir_p @ext
14 FileUtils.mkdir_p @dest_path
18 File.open File.join(@ext, 'extconf.rb'), 'w' do |extconf|
19 extconf.puts "require 'mkmf'\ncreate_makefile 'foo'"
25 Gem::Ext::ExtConfBuilder.build 'extconf.rb', nil, @dest_path, output
30 "creating Makefile\n",
32 "make: Nothing to be done for `all'.\n",
34 "make: Nothing to be done for `install'.\n"
37 assert_match(/^#{Gem.ruby} extconf.rb/, output[0])
38 assert_equal "creating Makefile\n", output[1]
41 assert_equal "nmake", output[2]
42 assert_equal "nmake install", output[4]
44 assert_equal "make", output[2]
45 assert_equal "make install", output[4]
49 def test_class_build_extconf_fail
50 File.open File.join(@ext, 'extconf.rb'), 'w' do |extconf|
51 extconf.puts "require 'mkmf'"
52 extconf.puts "have_library 'nonexistent' or abort 'need libnonexistent'"
53 extconf.puts "create_makefile 'foo'"
58 error = assert_raise Gem::InstallError do
60 Gem::Ext::ExtConfBuilder.build 'extconf.rb', nil, @dest_path, output
64 assert_match(/\Aextconf failed:
66 #{Gem.ruby} extconf.rb.*
67 checking for main\(\) in .*?nonexistent/m, error.message)
69 assert_match(/^#{Gem.ruby} extconf.rb/, output[0])
74 makefile_path = File.join(@ext, 'Makefile')
75 File.open makefile_path, 'w' do |makefile|
76 makefile.puts "RUBYARCHDIR = $(foo)$(target_prefix)"
77 makefile.puts "RUBYLIBDIR = $(bar)$(target_prefix)"
79 makefile.puts "install:"
83 Gem::Ext::ExtConfBuilder.make @ext, output
88 assert_equal 'nmake', output[0]
89 assert_equal 'nmake install', output[2]
91 assert_equal 'make', output[0]
92 assert_equal 'make install', output[2]
95 edited_makefile = <<-EOF
96 RUBYARCHDIR = #{@ext}$(target_prefix)
97 RUBYLIBDIR = #{@ext}$(target_prefix)
102 assert_equal edited_makefile, File.read(makefile_path)
105 def test_class_make_no_Makefile
106 error = assert_raise Gem::InstallError do
108 Gem::Ext::ExtConfBuilder.make @ext, ['output']
112 expected = <<-EOF.strip
118 assert_equal expected, error.message