2012-11-29 01:52:18 -05:00
|
|
|
# coding: UTF-8
|
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
require 'rubygems/test_case'
|
2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems/ext'
|
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
class TestGemExtExtConfBuilder < Gem::TestCase
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
|
|
|
@ext = File.join @tempdir, 'ext'
|
|
|
|
@dest_path = File.join @tempdir, 'prefix'
|
|
|
|
|
|
|
|
FileUtils.mkdir_p @ext
|
|
|
|
FileUtils.mkdir_p @dest_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_build
|
2009-06-09 17:38:59 -04:00
|
|
|
if vc_windows? && !nmake_found?
|
|
|
|
skip("test_class_build skipped - nmake not found")
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
File.open File.join(@ext, 'extconf.rb'), 'w' do |extconf|
|
|
|
|
extconf.puts "require 'mkmf'\ncreate_makefile 'foo'"
|
|
|
|
end
|
|
|
|
|
|
|
|
output = []
|
|
|
|
|
|
|
|
Dir.chdir @ext do
|
2013-07-22 18:46:50 -04:00
|
|
|
result =
|
|
|
|
Gem::Ext::ExtConfBuilder.build 'extconf.rb', nil, @dest_path, output
|
|
|
|
|
|
|
|
assert_same result, output
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2013-03-02 11:16:19 -05:00
|
|
|
assert_match(/^#{Gem.ruby} extconf.rb/, output[0])
|
2011-01-18 19:08:49 -05:00
|
|
|
assert_equal "creating Makefile\n", output[1]
|
2013-06-25 09:28:57 -04:00
|
|
|
assert_contains_make_command '', output[2]
|
|
|
|
assert_contains_make_command 'install', output[4]
|
2013-07-09 18:34:58 -04:00
|
|
|
assert_empty Dir.glob(File.join(@ext, 'siteconf*.rb'))
|
2011-01-18 19:08:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_build_rbconfig_make_prog
|
|
|
|
configure_args = RbConfig::CONFIG['configure_args']
|
|
|
|
|
|
|
|
File.open File.join(@ext, 'extconf.rb'), 'w' do |extconf|
|
|
|
|
extconf.puts "require 'mkmf'\ncreate_makefile 'foo'"
|
|
|
|
end
|
|
|
|
|
|
|
|
output = []
|
|
|
|
|
|
|
|
Dir.chdir @ext do
|
|
|
|
Gem::Ext::ExtConfBuilder.build 'extconf.rb', nil, @dest_path, output
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
assert_equal "creating Makefile\n", output[1]
|
2013-06-25 09:28:57 -04:00
|
|
|
assert_contains_make_command '', output[2]
|
|
|
|
assert_contains_make_command 'install', output[4]
|
2011-01-18 19:08:49 -05:00
|
|
|
ensure
|
|
|
|
RbConfig::CONFIG['configure_args'] = configure_args
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_build_env_make
|
|
|
|
configure_args, env_make = RbConfig::CONFIG['configure_args'], ENV.delete('make')
|
|
|
|
RbConfig::CONFIG['configure_args'] = ''
|
|
|
|
ENV['make'] = 'anothermake'
|
|
|
|
|
|
|
|
File.open File.join(@ext, 'extconf.rb'), 'w' do |extconf|
|
|
|
|
extconf.puts "require 'mkmf'\ncreate_makefile 'foo'"
|
|
|
|
end
|
|
|
|
|
|
|
|
output = []
|
|
|
|
|
|
|
|
assert_raises Gem::InstallError do
|
|
|
|
Dir.chdir @ext do
|
|
|
|
Gem::Ext::ExtConfBuilder.build 'extconf.rb', nil, @dest_path, output
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal "creating Makefile\n", output[1]
|
2013-06-25 09:28:57 -04:00
|
|
|
assert_contains_make_command '', output[2]
|
2011-01-18 19:08:49 -05:00
|
|
|
ensure
|
|
|
|
RbConfig::CONFIG['configure_args'] = configure_args
|
|
|
|
ENV['make'] = env_make
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_build_extconf_fail
|
2009-06-09 17:38:59 -04:00
|
|
|
if vc_windows? && !nmake_found?
|
|
|
|
skip("test_class_build_extconf_fail skipped - nmake not found")
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
File.open File.join(@ext, 'extconf.rb'), 'w' do |extconf|
|
|
|
|
extconf.puts "require 'mkmf'"
|
|
|
|
extconf.puts "have_library 'nonexistent' or abort 'need libnonexistent'"
|
|
|
|
extconf.puts "create_makefile 'foo'"
|
|
|
|
end
|
|
|
|
|
|
|
|
output = []
|
|
|
|
|
2008-10-25 18:58:43 -04:00
|
|
|
error = assert_raises Gem::InstallError do
|
2007-11-10 02:48:56 -05:00
|
|
|
Dir.chdir @ext do
|
|
|
|
Gem::Ext::ExtConfBuilder.build 'extconf.rb', nil, @dest_path, output
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/\Aextconf failed:
|
|
|
|
|
2013-03-02 11:16:19 -05:00
|
|
|
#{Gem.ruby} extconf.rb.*
|
2007-11-10 02:48:56 -05:00
|
|
|
checking for main\(\) in .*?nonexistent/m, error.message)
|
|
|
|
|
2013-03-02 11:16:19 -05:00
|
|
|
assert_equal("#{Gem.ruby} extconf.rb", output[0])
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2013-07-22 18:46:50 -04:00
|
|
|
def test_class_build_unconventional
|
|
|
|
if vc_windows? && !nmake_found?
|
|
|
|
skip("test_class_build skipped - nmake not found")
|
|
|
|
end
|
|
|
|
|
|
|
|
File.open File.join(@ext, 'extconf.rb'), 'w' do |extconf|
|
|
|
|
extconf.puts <<-'EXTCONF'
|
|
|
|
include RbConfig
|
|
|
|
|
2013-07-24 18:16:11 -04:00
|
|
|
ruby =
|
|
|
|
if ENV['RUBY'] then
|
|
|
|
ENV['RUBY']
|
|
|
|
else
|
|
|
|
ruby_exe = "#{CONFIG['RUBY_INSTALL_NAME']}#{CONFIG['EXEEXT']}"
|
|
|
|
File.join CONFIG['bindir'], ruby_exe
|
|
|
|
end
|
2013-07-22 18:46:50 -04:00
|
|
|
|
|
|
|
open 'Makefile', 'w' do |io|
|
|
|
|
io.write <<-Makefile
|
|
|
|
all: ruby
|
|
|
|
install: ruby
|
|
|
|
|
|
|
|
ruby:
|
|
|
|
\t#{ruby} -e0
|
|
|
|
|
|
|
|
Makefile
|
|
|
|
end
|
|
|
|
EXTCONF
|
|
|
|
end
|
|
|
|
|
|
|
|
output = []
|
|
|
|
|
|
|
|
Dir.chdir @ext do
|
|
|
|
Gem::Ext::ExtConfBuilder.build 'extconf.rb', nil, @dest_path, output
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_contains_make_command '', output[2]
|
|
|
|
assert_contains_make_command 'install', output[4]
|
|
|
|
assert_empty Dir.glob(File.join(@ext, 'siteconf*.rb'))
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def test_class_make
|
2009-06-09 17:38:59 -04:00
|
|
|
if vc_windows? && !nmake_found?
|
|
|
|
skip("test_class_make skipped - nmake not found")
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
output = []
|
|
|
|
makefile_path = File.join(@ext, 'Makefile')
|
|
|
|
File.open makefile_path, 'w' do |makefile|
|
2012-11-29 01:52:18 -05:00
|
|
|
makefile.puts "# π"
|
2007-11-10 02:48:56 -05:00
|
|
|
makefile.puts "RUBYARCHDIR = $(foo)$(target_prefix)"
|
|
|
|
makefile.puts "RUBYLIBDIR = $(bar)$(target_prefix)"
|
|
|
|
makefile.puts "all:"
|
|
|
|
makefile.puts "install:"
|
|
|
|
end
|
|
|
|
|
|
|
|
Dir.chdir @ext do
|
|
|
|
Gem::Ext::ExtConfBuilder.make @ext, output
|
|
|
|
end
|
|
|
|
|
2013-06-25 09:28:57 -04:00
|
|
|
assert_contains_make_command '', output[0]
|
|
|
|
assert_contains_make_command 'install', output[2]
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_make_no_Makefile
|
2008-10-25 18:58:43 -04:00
|
|
|
error = assert_raises Gem::InstallError do
|
2007-11-10 02:48:56 -05:00
|
|
|
Dir.chdir @ext do
|
|
|
|
Gem::Ext::ExtConfBuilder.make @ext, ['output']
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
expected = <<-EOF.strip
|
|
|
|
Makefile not found:
|
|
|
|
|
|
|
|
output
|
|
|
|
EOF
|
|
|
|
|
|
|
|
assert_equal expected, error.message
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|