2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2012-12-09 19:40:39 -05:00
|
|
|
require 'rubygems/test_case'
|
|
|
|
require 'rubygems/ext'
|
|
|
|
|
|
|
|
class TestGemExtCmakeBuilder < Gem::TestCase
|
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
2016-03-03 19:29:40 -05:00
|
|
|
# Details: https://github.com/rubygems/rubygems/issues/1270#issuecomment-177368340
|
|
|
|
skip "CmakeBuilder doesn't work on Windows." if Gem.win_platform?
|
|
|
|
|
2012-12-09 19:40:39 -05:00
|
|
|
`cmake #{Gem::Ext::Builder.redirector}`
|
|
|
|
|
|
|
|
skip 'cmake not present' unless $?.success?
|
|
|
|
|
|
|
|
@ext = File.join @tempdir, 'ext'
|
|
|
|
@dest_path = File.join @tempdir, 'prefix'
|
|
|
|
|
|
|
|
FileUtils.mkdir_p @ext
|
|
|
|
FileUtils.mkdir_p @dest_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_self_build
|
|
|
|
File.open File.join(@ext, 'CMakeLists.txt'), 'w' do |cmakelists|
|
|
|
|
cmakelists.write <<-eo_cmake
|
2015-01-09 09:20:10 -05:00
|
|
|
cmake_minimum_required(VERSION 2.6)
|
2012-12-09 19:40:39 -05:00
|
|
|
install (FILES test.txt DESTINATION bin)
|
|
|
|
eo_cmake
|
|
|
|
end
|
2012-12-17 22:16:27 -05:00
|
|
|
|
|
|
|
FileUtils.touch File.join(@ext, 'test.txt')
|
2012-12-09 19:40:39 -05:00
|
|
|
|
|
|
|
output = []
|
|
|
|
|
|
|
|
Dir.chdir @ext do
|
|
|
|
Gem::Ext::CmakeBuilder.build nil, nil, @dest_path, output
|
|
|
|
end
|
|
|
|
|
2012-12-17 22:16:27 -05:00
|
|
|
output = output.join "\n"
|
|
|
|
|
|
|
|
assert_match \
|
|
|
|
%r%^cmake \. -DCMAKE_INSTALL_PREFIX=#{Regexp.escape @dest_path}%, output
|
|
|
|
assert_match %r%#{Regexp.escape @ext}%, output
|
2013-06-25 09:28:57 -04:00
|
|
|
assert_contains_make_command '', output
|
|
|
|
assert_contains_make_command 'install', output
|
2012-12-17 22:16:27 -05:00
|
|
|
assert_match %r%test\.txt%, output
|
2012-12-09 19:40:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_self_build_fail
|
|
|
|
output = []
|
|
|
|
|
|
|
|
error = assert_raises Gem::InstallError do
|
|
|
|
Dir.chdir @ext do
|
|
|
|
Gem::Ext::CmakeBuilder.build nil, nil, @dest_path, output
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-17 22:16:27 -05:00
|
|
|
output = output.join "\n"
|
|
|
|
|
2012-12-09 19:40:39 -05:00
|
|
|
shell_error_msg = %r{(CMake Error: .*)}
|
|
|
|
sh_prefix_cmake = "cmake . -DCMAKE_INSTALL_PREFIX="
|
|
|
|
|
2013-10-15 20:14:16 -04:00
|
|
|
assert_match 'cmake failed', error.message
|
2012-12-09 19:40:39 -05:00
|
|
|
|
2012-12-17 22:16:27 -05:00
|
|
|
assert_match %r%^#{sh_prefix_cmake}#{Regexp.escape @dest_path}%, output
|
|
|
|
assert_match %r%#{shell_error_msg}%, output
|
2012-12-09 19:40:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_self_build_has_makefile
|
|
|
|
File.open File.join(@ext, 'Makefile'), 'w' do |makefile|
|
2013-10-15 20:43:14 -04:00
|
|
|
makefile.puts "all:\n\t@echo ok\ninstall:\n\t@echo ok"
|
2012-12-09 19:40:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
output = []
|
2012-12-17 22:16:27 -05:00
|
|
|
|
2012-12-09 19:40:39 -05:00
|
|
|
Dir.chdir @ext do
|
|
|
|
Gem::Ext::CmakeBuilder.build nil, nil, @dest_path, output
|
|
|
|
end
|
|
|
|
|
2012-12-17 22:16:27 -05:00
|
|
|
output = output.join "\n"
|
|
|
|
|
2013-06-25 09:28:57 -04:00
|
|
|
assert_contains_make_command '', output
|
|
|
|
assert_contains_make_command 'install', output
|
2012-12-09 19:40:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|