2016-02-01 12:43:26 +00:00
|
|
|
# frozen_string_literal: true
|
2012-12-10 00:40:39 +00:00
|
|
|
require 'rubygems/test_case'
|
|
|
|
require 'rubygems/ext'
|
|
|
|
|
|
|
|
class TestGemExtCmakeBuilder < Gem::TestCase
|
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
2016-03-04 00:29:40 +00:00
|
|
|
# Details: https://github.com/rubygems/rubygems/issues/1270#issuecomment-177368340
|
|
|
|
skip "CmakeBuilder doesn't work on Windows." if Gem.win_platform?
|
|
|
|
|
[rubygems/rubygems] Make cmake tests less verbose on jruby
These tests work on jruby, but the flags to the system command used to
detect whether `cmake` is present seem to be ignored on jruby and the
output is printed to screen instead of being sent to /dev/null. This
results in very verbose tests, like this:
```
$ rake TESTOPTS=--name=TestGemExtCmakeBuilder#test_self_build
(... warnings skipped ...)
Skipping `gem cert` tests on jruby.
Skipping Gem::Security tests on jruby.
Run options: --name=TestGemExtCmakeBuilder#test_self_build --seed 16839
# Running:
/home/deivid/Code/rubygems/test/rubygems/test_gem_ext_cmake_builder.rb:13: warning: system does not support options in JRuby yet: {:out=>"/dev/null", :err=>[:child, :out]}
Usage
cmake [options] <path-to-source>
cmake [options] <path-to-existing-build>
Specify a source directory to (re-)generate a build system for it in the
current working directory. Specify an existing build directory to
re-generate its build system.
Run 'cmake --help' for more information.
.
Finished in 0.387301s, 2.5820 runs/s, 20.6558 assertions/s.
1 runs, 8 assertions, 0 failures, 0 errors, 0 skips
Coverage report generated for Unit Tests to /home/deivid/Code/rubygems/coverage. 2258 / 8832 LOC (25.57%) covered.
```
By using `Open3`, we get the test output clean:
```
$ rake TESTOPTS=--name=TestGemExtCmakeBuilder#test_self_build
(... warnings skipped ...)
Skipping `gem cert` tests on jruby.
Skipping Gem::Security tests on jruby.
Run options: --name=TestGemExtCmakeBuilder#test_self_build --seed 22605
# Running:
.
Finished in 0.381959s, 2.6181 runs/s, 20.9446 assertions/s.
1 runs, 8 assertions, 0 failures, 0 errors, 0 skips
Coverage report generated for Unit Tests to /home/deivid/Code/rubygems/coverage. 2258 / 8832 LOC (25.57%) covered.
```
https://github.com/rubygems/rubygems/commit/531ce37ea3
2020-03-23 22:22:32 +01:00
|
|
|
_, status = Open3.capture2e('cmake')
|
2012-12-10 00:40:39 +00:00
|
|
|
|
[rubygems/rubygems] Make cmake tests less verbose on jruby
These tests work on jruby, but the flags to the system command used to
detect whether `cmake` is present seem to be ignored on jruby and the
output is printed to screen instead of being sent to /dev/null. This
results in very verbose tests, like this:
```
$ rake TESTOPTS=--name=TestGemExtCmakeBuilder#test_self_build
(... warnings skipped ...)
Skipping `gem cert` tests on jruby.
Skipping Gem::Security tests on jruby.
Run options: --name=TestGemExtCmakeBuilder#test_self_build --seed 16839
# Running:
/home/deivid/Code/rubygems/test/rubygems/test_gem_ext_cmake_builder.rb:13: warning: system does not support options in JRuby yet: {:out=>"/dev/null", :err=>[:child, :out]}
Usage
cmake [options] <path-to-source>
cmake [options] <path-to-existing-build>
Specify a source directory to (re-)generate a build system for it in the
current working directory. Specify an existing build directory to
re-generate its build system.
Run 'cmake --help' for more information.
.
Finished in 0.387301s, 2.5820 runs/s, 20.6558 assertions/s.
1 runs, 8 assertions, 0 failures, 0 errors, 0 skips
Coverage report generated for Unit Tests to /home/deivid/Code/rubygems/coverage. 2258 / 8832 LOC (25.57%) covered.
```
By using `Open3`, we get the test output clean:
```
$ rake TESTOPTS=--name=TestGemExtCmakeBuilder#test_self_build
(... warnings skipped ...)
Skipping `gem cert` tests on jruby.
Skipping Gem::Security tests on jruby.
Run options: --name=TestGemExtCmakeBuilder#test_self_build --seed 22605
# Running:
.
Finished in 0.381959s, 2.6181 runs/s, 20.9446 assertions/s.
1 runs, 8 assertions, 0 failures, 0 errors, 0 skips
Coverage report generated for Unit Tests to /home/deivid/Code/rubygems/coverage. 2258 / 8832 LOC (25.57%) covered.
```
https://github.com/rubygems/rubygems/commit/531ce37ea3
2020-03-23 22:22:32 +01:00
|
|
|
skip 'cmake not present' unless status.success?
|
2012-12-10 00:40:39 +00:00
|
|
|
|
|
|
|
@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|
|
2020-04-20 18:32:51 +02:00
|
|
|
cmakelists.write <<-EO_CMAKE
|
2015-01-09 14:20:10 +00:00
|
|
|
cmake_minimum_required(VERSION 2.6)
|
2019-01-22 06:28:04 +00:00
|
|
|
project(self_build NONE)
|
2012-12-10 00:40:39 +00:00
|
|
|
install (FILES test.txt DESTINATION bin)
|
2020-04-20 18:32:51 +02:00
|
|
|
EO_CMAKE
|
2012-12-10 00:40:39 +00:00
|
|
|
end
|
2012-12-18 03:16:27 +00:00
|
|
|
|
|
|
|
FileUtils.touch File.join(@ext, 'test.txt')
|
2012-12-10 00:40:39 +00:00
|
|
|
|
|
|
|
output = []
|
|
|
|
|
|
|
|
Dir.chdir @ext do
|
2018-05-30 13:01:35 +00:00
|
|
|
Gem::Ext::CmakeBuilder.build nil, @dest_path, output
|
2012-12-10 00:40:39 +00:00
|
|
|
end
|
|
|
|
|
2012-12-18 03:16:27 +00:00
|
|
|
output = output.join "\n"
|
|
|
|
|
|
|
|
assert_match \
|
2020-03-24 19:51:43 +01:00
|
|
|
%r{^cmake \. -DCMAKE_INSTALL_PREFIX=#{Regexp.escape @dest_path}}, output
|
|
|
|
assert_match %r{#{Regexp.escape @ext}}, output
|
2013-06-25 13:28:57 +00:00
|
|
|
assert_contains_make_command '', output
|
|
|
|
assert_contains_make_command 'install', output
|
2020-03-24 19:51:43 +01:00
|
|
|
assert_match %r{test\.txt}, output
|
2012-12-10 00:40:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_self_build_fail
|
|
|
|
output = []
|
|
|
|
|
|
|
|
error = assert_raises Gem::InstallError do
|
|
|
|
Dir.chdir @ext do
|
2018-05-30 13:01:35 +00:00
|
|
|
Gem::Ext::CmakeBuilder.build nil, @dest_path, output
|
2012-12-10 00:40:39 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-18 03:16:27 +00:00
|
|
|
output = output.join "\n"
|
|
|
|
|
2012-12-10 00:40:39 +00:00
|
|
|
shell_error_msg = %r{(CMake Error: .*)}
|
|
|
|
sh_prefix_cmake = "cmake . -DCMAKE_INSTALL_PREFIX="
|
|
|
|
|
2013-10-16 00:14:16 +00:00
|
|
|
assert_match 'cmake failed', error.message
|
2012-12-10 00:40:39 +00:00
|
|
|
|
2020-03-24 19:51:43 +01:00
|
|
|
assert_match %r{^#{sh_prefix_cmake}#{Regexp.escape @dest_path}}, output
|
|
|
|
assert_match %r{#{shell_error_msg}}, output
|
2012-12-10 00:40:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_self_build_has_makefile
|
|
|
|
File.open File.join(@ext, 'Makefile'), 'w' do |makefile|
|
2013-10-16 00:43:14 +00:00
|
|
|
makefile.puts "all:\n\t@echo ok\ninstall:\n\t@echo ok"
|
2012-12-10 00:40:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
output = []
|
2012-12-18 03:16:27 +00:00
|
|
|
|
2012-12-10 00:40:39 +00:00
|
|
|
Dir.chdir @ext do
|
2018-05-30 13:01:35 +00:00
|
|
|
Gem::Ext::CmakeBuilder.build nil, @dest_path, output
|
2012-12-10 00:40:39 +00:00
|
|
|
end
|
|
|
|
|
2012-12-18 03:16:27 +00:00
|
|
|
output = output.join "\n"
|
|
|
|
|
2013-06-25 13:28:57 +00:00
|
|
|
assert_contains_make_command '', output
|
|
|
|
assert_contains_make_command 'install', output
|
2012-12-10 00:40:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|