1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/rubygems/test_gem_ext_rake_builder.rb
Yusuke Endoh b957c3dbcb [rubygems/rubygems] Rename test/rubygems/test_{case,utilities}.rb to avoid "test_" prefix
This changes "test/rubygems/test_case.rb" to "test/rubygems/helper.rb",
and "test/rubygems/test_utilities.rb" to "test/rubygems/utilities.rb".

The two files are a helper for tests, not test files. However, a file
starting with "test_" prefix is handled as a test file directly loaded
by test-unit because Rakefile specifies:

```
t.test_files = FileList['test/**/test_*.rb']
```

Directly loading test/rubygems/test_utilities.rb caused "uninitialized
constant Gem::TestCase". This issue was fixed by
59c6820971, but the fix caused a
"circular require" warning because test_utilities.rb and test_case.rb
are now requiring each other.

Anyway, adding "test_" prefix to a test helper file is confusing, so
this changeset reverts the fix and solve the issue by renaming them.

https://github.com/rubygems/rubygems/commit/6460e018df
2021-06-03 12:23:22 +09:00

110 lines
3 KiB
Ruby

# frozen_string_literal: true
require_relative 'helper'
require 'rubygems/ext'
class TestGemExtRakeBuilder < Gem::TestCase
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
create_temp_mkrf_file('task :default')
output = []
build_rake_in do |rake|
Gem::Ext::RakeBuilder.build 'mkrf_conf.rb', @dest_path, output, [], nil, @ext
output = output.join "\n"
refute_match %r{^rake failed:}, output
assert_match %r{^#{Regexp.escape Gem.ruby} mkrf_conf\.rb}, output
assert_match %r{^#{Regexp.escape rake} RUBYARCHDIR\\=#{Regexp.escape @dest_path} RUBYLIBDIR\\=#{Regexp.escape @dest_path}}, output
end
end
# https://github.com/rubygems/rubygems/pull/1819
#
# It should not fail with a non-empty args list either
def test_class_build_with_args
create_temp_mkrf_file('task :default')
output = []
build_rake_in do |rake|
non_empty_args_list = ['']
Gem::Ext::RakeBuilder.build 'mkrf_conf.rb', @dest_path, output, non_empty_args_list, nil, @ext
output = output.join "\n"
refute_match %r{^rake failed:}, output
assert_match %r{^#{Regexp.escape Gem.ruby} mkrf_conf\.rb}, output
assert_match %r{^#{Regexp.escape rake} RUBYARCHDIR\\=#{Regexp.escape @dest_path} RUBYLIBDIR\\=#{Regexp.escape @dest_path}}, output
end
end
def test_class_no_openssl_override
create_temp_mkrf_file('task :default')
rake = util_spec 'rake' do |s|
s.executables = %w[rake]
s.files = %w[bin/rake]
end
output = []
write_file File.join(@tempdir, 'bin', 'rake') do |fp|
fp.puts "#!/usr/bin/ruby"
fp.puts "require 'openssl'; puts OpenSSL"
end
install_gem rake
Gem::Ext::RakeBuilder.build 'mkrf_conf.rb', @dest_path, output, [''], nil, @ext
output = output.join "\n"
assert_match "OpenSSL", output
assert_match %r{^#{Regexp.escape Gem.ruby} mkrf_conf\.rb}, output
end
def test_class_build_no_mkrf_passes_args
output = []
build_rake_in do |rake|
Gem::Ext::RakeBuilder.build "ext/Rakefile", @dest_path, output, ["test1", "test2"], nil, @ext
output = output.join "\n"
refute_match %r{^rake failed:}, output
assert_match %r{^#{Regexp.escape rake} RUBYARCHDIR\\=#{Regexp.escape @dest_path} RUBYLIBDIR\\=#{Regexp.escape @dest_path} test1 test2}, output
end
end
def test_class_build_fail
create_temp_mkrf_file("task :default do abort 'fail' end")
output = []
build_rake_in(false) do |rake|
error = assert_raise Gem::InstallError do
Gem::Ext::RakeBuilder.build "mkrf_conf.rb", @dest_path, output, [], nil, @ext
end
assert_match %r{^rake failed}, error.message
end
end
def create_temp_mkrf_file(rakefile_content)
File.open File.join(@ext, 'mkrf_conf.rb'), 'w' do |mkrf_conf|
mkrf_conf.puts <<-EO_MKRF
File.open("Rakefile","w") do |f|
f.puts "#{rakefile_content}"
end
EO_MKRF
end
end
end