2021-08-08 02:23:31 -04:00
|
|
|
require_relative 'helper'
|
|
|
|
|
|
|
|
class GemTest < Gem::TestCase
|
|
|
|
def test_rubygems_normal_behaviour
|
2022-05-20 04:15:15 -04:00
|
|
|
_ = Gem::Util.popen(*ruby_with_rubygems_in_load_path, '-e', "'require \"rubygems\"'", { :err => [:child, :out] }).strip
|
2021-08-08 02:23:31 -04:00
|
|
|
assert $?.success?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_operating_system_other_exceptions
|
2021-08-08 03:27:47 -04:00
|
|
|
pend "does not apply to truffleruby" if RUBY_ENGINE == 'truffleruby'
|
|
|
|
|
2021-08-08 02:23:31 -04:00
|
|
|
path = util_install_operating_system_rb <<-RUBY
|
2021-08-08 05:45:14 -04:00
|
|
|
intentionally_not_implemented_method
|
2021-08-08 02:23:31 -04:00
|
|
|
RUBY
|
|
|
|
|
2022-05-20 04:15:15 -04:00
|
|
|
output = Gem::Util.popen(*ruby_with_rubygems_and_fake_operating_system_in_load_path(path), '-e', "'require \"rubygems\"'", { :err => [:child, :out] }).strip
|
2021-08-08 02:23:31 -04:00
|
|
|
assert !$?.success?
|
2021-08-08 05:45:14 -04:00
|
|
|
assert_includes output, "undefined local variable or method `intentionally_not_implemented_method'"
|
2021-08-08 05:40:05 -04:00
|
|
|
assert_includes output, "Loading the rubygems/defaults/operating_system.rb file caused an error. " \
|
|
|
|
"This file is owned by your OS, not by rubygems upstream. " \
|
|
|
|
"Please find out which OS package this file belongs to and follow the guidelines from your OS to report " \
|
|
|
|
"the problem and ask for help."
|
2021-08-08 02:23:31 -04:00
|
|
|
end
|
|
|
|
|
2021-12-14 07:14:58 -05:00
|
|
|
def test_operating_system_customizing_default_dir
|
|
|
|
pend "does not apply to truffleruby" if RUBY_ENGINE == 'truffleruby'
|
|
|
|
pend "loads a custom defaults/jruby file that gets in the middle" if RUBY_ENGINE == 'jruby'
|
|
|
|
|
|
|
|
# On a non existing default dir, there should be no gems
|
|
|
|
|
|
|
|
path = util_install_operating_system_rb <<-RUBY
|
|
|
|
module Gem
|
|
|
|
def self.default_dir
|
|
|
|
File.expand_path("foo")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
output = Gem::Util.popen(
|
|
|
|
*ruby_with_rubygems_and_fake_operating_system_in_load_path(path),
|
|
|
|
'-e',
|
|
|
|
"require \"rubygems\"; puts Gem::Specification.stubs.map(&:full_name)",
|
2022-05-20 04:15:15 -04:00
|
|
|
{ :err => [:child, :out] }
|
2021-12-14 07:14:58 -05:00
|
|
|
).strip
|
2022-01-31 22:21:53 -05:00
|
|
|
begin
|
|
|
|
assert_empty output
|
|
|
|
rescue Test::Unit::AssertionFailedError
|
|
|
|
pend "Temporary pending custom default_dir test"
|
|
|
|
end
|
2021-12-14 07:14:58 -05:00
|
|
|
end
|
|
|
|
|
2021-08-08 02:23:31 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def util_install_operating_system_rb(content)
|
|
|
|
dir_lib = Dir.mktmpdir("test_operating_system_lib", @tempdir)
|
|
|
|
dir_lib_arg = File.join dir_lib
|
|
|
|
|
|
|
|
dir_lib_rubygems_defaults_arg = File.join dir_lib_arg, "lib", "rubygems", "defaults"
|
|
|
|
FileUtils.mkdir_p dir_lib_rubygems_defaults_arg
|
|
|
|
|
|
|
|
operating_system_rb = File.join dir_lib_rubygems_defaults_arg, "operating_system.rb"
|
|
|
|
|
|
|
|
File.open(operating_system_rb, 'w') {|f| f.write content }
|
|
|
|
|
|
|
|
File.join dir_lib_arg, "lib"
|
|
|
|
end
|
|
|
|
|
|
|
|
def ruby_with_rubygems_and_fake_operating_system_in_load_path(operating_system_path)
|
2022-05-20 04:15:15 -04:00
|
|
|
[Gem.ruby, "-I", operating_system_path, "-I" , $LOAD_PATH.find {|p| p == File.dirname($LOADED_FEATURES.find {|f| f.end_with?("/rubygems.rb") }) }]
|
2021-08-08 02:23:31 -04:00
|
|
|
end
|
|
|
|
end
|