diff options
author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2022-08-22 11:50:00 +0900 |
---|---|---|
committer | nagachika <nagachika@ruby-lang.org> | 2022-09-03 15:54:07 +0900 |
commit | 522b75f1b666051f86a3c8961fd4255e560c5020 (patch) | |
tree | 85315021fac815517ce3e68f1883533aa4b35747 /test | |
parent | 44c926f3a94346809c68574e0277dae3917992c6 (diff) |
Merge RubyGems-3.3.20 and Bundler-2.3.20
Diffstat (limited to 'test')
19 files changed, 144 insertions, 41 deletions
diff --git a/test/rubygems/helper.rb b/test/rubygems/helper.rb index dab3cd4d4c..df85a056c9 100644 --- a/test/rubygems/helper.rb +++ b/test/rubygems/helper.rb @@ -599,7 +599,7 @@ class Gem::TestCase < Test::Unit::TestCase end def in_path?(executable) # :nodoc: - return true if %r{\A([A-Z]:|/)} =~ executable and File.exist? executable + return true if %r{\A([A-Z]:|/)} =~ executable && File.exist?(executable) ENV["PATH"].split(File::PATH_SEPARATOR).any? do |directory| File.exist? File.join directory, executable @@ -849,7 +849,7 @@ class Gem::TestCase < Test::Unit::TestCase # or a +block+ can be given for full customization of the specification. def util_spec(name, version = 2, deps = nil, *files) # :yields: specification - raise "deps or block, not both" if deps and block_given? + raise "deps or block, not both" if deps && block_given? spec = Gem::Specification.new do |s| s.platform = Gem::Platform::RUBY @@ -1279,10 +1279,10 @@ Also, a list: rubyexe = "#{ruby}.exe" 3.times do - if File.exist? ruby and File.executable? ruby and !File.directory? ruby + if File.exist?(ruby) && File.executable?(ruby) && !File.directory?(ruby) return File.expand_path(ruby) end - if File.exist? rubyexe and File.executable? rubyexe + if File.exist?(rubyexe) && File.executable?(rubyexe) return File.expand_path(rubyexe) end ruby = File.join("..", ruby) @@ -1592,7 +1592,7 @@ class Object metaclass = class << self; self; end - if respond_to? name and not methods.map(&:to_s).include? name.to_s + if respond_to?(name) && !methods.map(&:to_s).include?(name.to_s) metaclass.send :define_method, name do |*args| super(*args) end diff --git a/test/rubygems/test_gem_config_file.rb b/test/rubygems/test_gem_config_file.rb index fbc7c85757..e23773a133 100644 --- a/test/rubygems/test_gem_config_file.rb +++ b/test/rubygems/test_gem_config_file.rb @@ -35,7 +35,7 @@ class TestGemConfigFile < Gem::TestCase def test_initialize assert_equal @temp_conf, @cfg.config_file_name - assert_equal false, @cfg.backtrace + assert_equal true, @cfg.backtrace assert_equal true, @cfg.update_sources assert_equal Gem::ConfigFile::DEFAULT_BULK_THRESHOLD, @cfg.bulk_threshold assert_equal true, @cfg.verbose @@ -239,6 +239,12 @@ if you believe they were disclosed to a third party. end def test_handle_arguments_backtrace + File.open @temp_conf, "w" do |fp| + fp.puts ":backtrace: false" + end + + util_config_file %W[--config-file=#{@temp_conf}] + assert_equal false, @cfg.backtrace args = %w[--backtrace] @@ -275,6 +281,12 @@ if you believe they were disclosed to a third party. end def test_handle_arguments_traceback + File.open @temp_conf, "w" do |fp| + fp.puts ":backtrace: false" + end + + util_config_file %W[--config-file=#{@temp_conf}] + assert_equal false, @cfg.backtrace args = %w[--traceback] @@ -288,7 +300,7 @@ if you believe they were disclosed to a third party. assert_equal @temp_conf, @cfg.config_file_name File.open @temp_conf, "w" do |fp| - fp.puts ":backtrace: true" + fp.puts ":backtrace: false" fp.puts ":update_sources: false" fp.puts ":bulk_threshold: 10" fp.puts ":verbose: false" @@ -300,7 +312,7 @@ if you believe they were disclosed to a third party. util_config_file args - assert_equal false, @cfg.backtrace + assert_equal true, @cfg.backtrace assert_equal true, @cfg.update_sources assert_equal Gem::ConfigFile::DEFAULT_BULK_THRESHOLD, @cfg.bulk_threshold assert_equal true, @cfg.verbose @@ -386,7 +398,7 @@ if you believe they were disclosed to a third party. end def test_write - @cfg.backtrace = true + @cfg.backtrace = false @cfg.update_sources = false @cfg.bulk_threshold = 10 @cfg.verbose = false @@ -398,7 +410,7 @@ if you believe they were disclosed to a third party. util_config_file # These should not be written out to the config file. - assert_equal false, @cfg.backtrace, "backtrace" + assert_equal true, @cfg.backtrace, "backtrace" assert_equal Gem::ConfigFile::DEFAULT_BULK_THRESHOLD, @cfg.bulk_threshold, "bulk_threshold" assert_equal true, @cfg.update_sources, "update_sources" diff --git a/test/rubygems/test_gem_dependency_installer.rb b/test/rubygems/test_gem_dependency_installer.rb index 9db904ba53..2b0b874b2d 100644 --- a/test/rubygems/test_gem_dependency_installer.rb +++ b/test/rubygems/test_gem_dependency_installer.rb @@ -1051,8 +1051,8 @@ class TestGemDependencyInstaller < Gem::TestCase releases = set.all_specs - assert releases.any? {|s| s.name == "a" and s.version.to_s == "1" } - refute releases.any? {|s| s.name == "a" and s.version.to_s == "1.a" } + assert releases.any? {|s| s.name == "a" && s.version.to_s == "1" } + refute releases.any? {|s| s.name == "a" && s.version.to_s == "1.a" } dependency.prerelease = true diff --git a/test/rubygems/test_gem_ext_cargo_builder/custom_name/Cargo.lock b/test/rubygems/test_gem_ext_cargo_builder/custom_name/Cargo.lock index 498ee26c7e..da09e717f0 100644 --- a/test/rubygems/test_gem_ext_cargo_builder/custom_name/Cargo.lock +++ b/test/rubygems/test_gem_ext_cargo_builder/custom_name/Cargo.lock @@ -160,9 +160,9 @@ dependencies = [ [[package]] name = "rb-sys" -version = "0.9.26" +version = "0.9.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "723f7560e878bec9d1d49538a17fb6a4e3a04688c1dc6f14eef17918634a54e4" +checksum = "0317cb843cdeef14c5622917c55c0a170cee31348eb600c4a1683fb8c9e87e7a" dependencies = [ "bindgen", "linkify", @@ -171,9 +171,9 @@ dependencies = [ [[package]] name = "rb-sys-build" -version = "0.9.26" +version = "0.9.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ccd93f0d9767385cd7a23076c47e3dca4c86144e510ea4c61d04dbce0cbac7e" +checksum = "c4b8274327aecb7edcff86e290d9cbe7b572b7889c1cfc7476358f4831f78ce5" dependencies = [ "regex", "shell-words", diff --git a/test/rubygems/test_gem_ext_cargo_builder/custom_name/Cargo.toml b/test/rubygems/test_gem_ext_cargo_builder/custom_name/Cargo.toml index b144f930e5..2a215a55dd 100644 --- a/test/rubygems/test_gem_ext_cargo_builder/custom_name/Cargo.toml +++ b/test/rubygems/test_gem_ext_cargo_builder/custom_name/Cargo.toml @@ -7,4 +7,4 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -rb-sys = { version = "0.9.26", features = ["gem"] } +rb-sys = { version = "0.9.29", features = ["gem"] } diff --git a/test/rubygems/test_gem_ext_cargo_builder/custom_name/build.rb b/test/rubygems/test_gem_ext_cargo_builder/custom_name/build.rb index 21c4fd1c8d..0e04f0de5e 100644 --- a/test/rubygems/test_gem_ext_cargo_builder/custom_name/build.rb +++ b/test/rubygems/test_gem_ext_cargo_builder/custom_name/build.rb @@ -1,4 +1,4 @@ -if ENV["RUBYOPT"] or defined? Gem +if ENV["RUBYOPT"] || defined? Gem ENV.delete "RUBYOPT" require "rbconfig" diff --git a/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/Cargo.lock b/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/Cargo.lock index 376d11cf3e..e351819848 100644 --- a/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/Cargo.lock +++ b/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/Cargo.lock @@ -153,9 +153,9 @@ dependencies = [ [[package]] name = "rb-sys" -version = "0.9.26" +version = "0.9.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "723f7560e878bec9d1d49538a17fb6a4e3a04688c1dc6f14eef17918634a54e4" +checksum = "0317cb843cdeef14c5622917c55c0a170cee31348eb600c4a1683fb8c9e87e7a" dependencies = [ "bindgen", "linkify", @@ -164,9 +164,9 @@ dependencies = [ [[package]] name = "rb-sys-build" -version = "0.9.26" +version = "0.9.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ccd93f0d9767385cd7a23076c47e3dca4c86144e510ea4c61d04dbce0cbac7e" +checksum = "c4b8274327aecb7edcff86e290d9cbe7b572b7889c1cfc7476358f4831f78ce5" dependencies = [ "regex", "shell-words", diff --git a/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/Cargo.toml b/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/Cargo.toml index 7d3cd133a8..1867db8e66 100644 --- a/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/Cargo.toml +++ b/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/Cargo.toml @@ -7,4 +7,4 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -rb-sys = { version = "0.9.26", features = ["gem"] } +rb-sys = { version = "0.9.29", features = ["gem"] } diff --git a/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/build.rb b/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/build.rb index 81b12f99ec..f404aa3468 100644 --- a/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/build.rb +++ b/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/build.rb @@ -1,4 +1,4 @@ -if ENV["RUBYOPT"] or defined? Gem +if ENV["RUBYOPT"] || defined? Gem ENV.delete "RUBYOPT" require "rbconfig" diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb index 4600317578..3d02de13d5 100644 --- a/test/rubygems/test_gem_installer.rb +++ b/test/rubygems/test_gem_installer.rb @@ -473,7 +473,7 @@ gem 'other', version end end ensure - FileUtils.chmod 0755, util_inst_bindir unless ($DEBUG or win_platform?) + FileUtils.chmod 0755, util_inst_bindir unless ($DEBUG || win_platform?) end def test_generate_bin_script_no_shebang @@ -577,7 +577,7 @@ gem 'other', version end end ensure - FileUtils.chmod 0755, util_inst_bindir unless ($DEBUG or win_platform?) + FileUtils.chmod 0755, util_inst_bindir unless ($DEBUG || win_platform?) end def test_generate_bin_symlink_update_newer @@ -756,7 +756,10 @@ gem 'other', version end end - assert_match %r{bin/ascii_binder` is dangling symlink pointing to `bin/asciibinder`}, @ui.error + errors = @ui.error.split("\n") + assert_equal "WARNING: ascii_binder-0.1.10.1 ships with a dangling symlink named bin/ascii_binder pointing to missing bin/asciibinder file. Ignoring", errors.shift + assert_empty errors + assert_empty @ui.output end diff --git a/test/rubygems/test_gem_package.rb b/test/rubygems/test_gem_package.rb index 9e18dacba1..9295f42dba 100644 --- a/test/rubygems/test_gem_package.rb +++ b/test/rubygems/test_gem_package.rb @@ -529,6 +529,7 @@ class TestGemPackage < Gem::Package::TarTestCase def test_extract_tar_gz_symlink_relative_path package = Gem::Package.new @gem + package.verify tgz_io = util_tar_gz do |tar| tar.add_file "relative.rb", 0644 do |io| @@ -557,6 +558,27 @@ class TestGemPackage < Gem::Package::TarTestCase File.read(extracted) end + def test_extract_tar_gz_symlink_broken_relative_path + package = Gem::Package.new @gem + package.verify + + tgz_io = util_tar_gz do |tar| + tar.mkdir "lib", 0755 + tar.add_symlink "lib/foo.rb", "../broken.rb", 0644 + end + + ui = Gem::MockGemUi.new + + use_ui ui do + package.extract_tar_gz tgz_io, @destination + end + + assert_equal "WARNING: a-2 ships with a dangling symlink named lib/foo.rb pointing to missing ../broken.rb file. Ignoring\n", ui.error + + extracted = File.join @destination, "lib/foo.rb" + assert_path_not_exist extracted + end + def test_extract_symlink_parent package = Gem::Package.new @gem diff --git a/test/rubygems/test_gem_package_tar_reader.rb b/test/rubygems/test_gem_package_tar_reader.rb index 86ffff4fe5..19860eb7e8 100644 --- a/test/rubygems/test_gem_package_tar_reader.rb +++ b/test/rubygems/test_gem_package_tar_reader.rb @@ -29,7 +29,7 @@ class TestGemPackageTarReader < Gem::Package::TarTestCase str = tar_file_header("lib/foo", "", 010644, content.size, Time.now) + - content + "\0" * (512 - content.size) + content + "\0" * (512 - content.size) str << "\0" * 1024 io = TempIO.new(str) diff --git a/test/rubygems/test_gem_requirement.rb b/test/rubygems/test_gem_requirement.rb index 37137dbdad..5ecdbeddae 100644 --- a/test/rubygems/test_gem_requirement.rb +++ b/test/rubygems/test_gem_requirement.rb @@ -129,7 +129,9 @@ class TestGemRequirement < Gem::TestCase assert_satisfied_by "1.3", r assert_raise ArgumentError do - assert_satisfied_by nil, r + Gem::Deprecate.skip_during do + assert_satisfied_by nil, r + end end end @@ -141,7 +143,9 @@ class TestGemRequirement < Gem::TestCase refute_satisfied_by "1.3", r assert_raise ArgumentError do - assert_satisfied_by nil, r + Gem::Deprecate.skip_during do + assert_satisfied_by nil, r + end end end @@ -153,7 +157,9 @@ class TestGemRequirement < Gem::TestCase refute_satisfied_by "1.3", r assert_raise ArgumentError do - assert_satisfied_by nil, r + Gem::Deprecate.skip_during do + assert_satisfied_by nil, r + end end end diff --git a/test/rubygems/test_gem_resolver_index_specification.rb b/test/rubygems/test_gem_resolver_index_specification.rb index 339445cb44..b479757bd5 100644 --- a/test/rubygems/test_gem_resolver_index_specification.rb +++ b/test/rubygems/test_gem_resolver_index_specification.rb @@ -26,7 +26,7 @@ class TestGemResolverIndexSpecification < Gem::TestCase spec = Gem::Resolver::IndexSpecification.new( set, "rails", version, source, Gem::Platform.local) - assert_equal Gem::Platform.local.to_s, spec.platform + assert_equal Gem::Platform.local, spec.platform end def test_install diff --git a/test/rubygems/test_gem_resolver_installer_set.rb b/test/rubygems/test_gem_resolver_installer_set.rb index 8d84c28172..7617919e2c 100644 --- a/test/rubygems/test_gem_resolver_installer_set.rb +++ b/test/rubygems/test_gem_resolver_installer_set.rb @@ -51,6 +51,38 @@ class TestGemResolverInstallerSet < Gem::TestCase assert_equal %w[a-1], set.always_install.map {|s| s.full_name } end + def test_add_always_install_platform_if_gem_platforms_modified_by_platform_flag + freebsd = Gem::Platform.new "x86-freebsd-9" + + spec_fetcher do |fetcher| + fetcher.download "a", 1 + fetcher.download "a", 1 do |s| + s.platform = freebsd + end + end + + # equivalent to --platform=x86-freebsd-9 + Gem.platforms << freebsd + set = Gem::Resolver::InstallerSet.new :both + + set.add_always_install dep("a") + + assert_equal %w[a-1-x86-freebsd-9], set.always_install.map {|s| s.full_name } + end + + def test_add_always_install_index_spec_platform + _, a_1_local_gem = util_gem "a", 1 do |s| + s.platform = Gem::Platform.local + end + + FileUtils.mv a_1_local_gem, @tempdir + + set = Gem::Resolver::InstallerSet.new :both + set.add_always_install dep("a") + + assert_equal [Gem::Platform.local], set.always_install.map {|s| s.platform } + end + def test_add_always_install_prerelease spec_fetcher do |fetcher| fetcher.gem "a", 1 @@ -187,6 +219,18 @@ class TestGemResolverInstallerSet < Gem::TestCase set.find_all(req).map {|spec| spec.full_name }.sort end + def test_find_all_prerelease_dependencies_with_add_local + activesupport_7_1_0_alpha = util_spec "activesupport", "7.1.0.alpha" + + install_gem activesupport_7_1_0_alpha + + set = Gem::Resolver::InstallerSet.new :both + + req = Gem::Resolver::DependencyRequest.new dep("activesupport", ">= 4.2.0"), nil + + assert_equal %w[activesupport-7.1.0.alpha], set.find_all(req).map {|spec| spec.full_name } + end + def test_load_spec specs = spec_fetcher do |fetcher| fetcher.spec "a", 2 diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb index 0c67f600ea..3361b31173 100644 --- a/test/rubygems/test_gem_specification.rb +++ b/test/rubygems/test_gem_specification.rb @@ -796,7 +796,7 @@ dependencies: [] assert_equal File.join(@tempdir, "a-2.gemspec"), spec.loaded_from end - if RUBY_ENGINE == "ruby" and RUBY_VERSION < "2.7" + if RUBY_ENGINE == "ruby" && RUBY_VERSION < "2.7" def test_self_load_tainted full_path = @a2.spec_file write_file full_path do |io| @@ -1220,6 +1220,15 @@ dependencies: [] assert_equal "1.0.0.dev", spec.version.to_s end + def test_initialize_nil_version + expected = "nil versions are discouraged and will be deprecated in Rubygems 4\n" + actual_stdout, actual_stderr = capture_output do + Gem::Specification.new.version = nil + end + assert_empty actual_stdout + assert_equal(expected, actual_stderr) + end + def test__dump @a2.platform = Gem::Platform.local @a2.instance_variable_set :@original_platform, "old_platform" @@ -1441,7 +1450,7 @@ dependencies: [] @ext.build_extensions assert_path_not_exist @ext.extension_dir ensure - unless ($DEBUG or win_platform? or Process.uid.zero? or Gem.java_platform?) + unless ($DEBUG || win_platform? || Process.uid.zero? || Gem.java_platform?) FileUtils.chmod 0755, File.join(@ext.base_dir, "extensions") FileUtils.chmod 0755, @ext.base_dir end diff --git a/test/rubygems/test_gem_version.rb b/test/rubygems/test_gem_version.rb index e907eabb34..9237608d4a 100644 --- a/test/rubygems/test_gem_version.rb +++ b/test/rubygems/test_gem_version.rb @@ -32,8 +32,15 @@ class TestGemVersion < Gem::TestCase def test_class_create real = Gem::Version.new(1.0) - assert_same real, Gem::Version.create(real) - assert_nil Gem::Version.create(nil) + assert_same real, Gem::Version.create(real) + + expected = "nil versions are discouraged and will be deprecated in Rubygems 4\n" + actual_stdout, actual_stderr = capture_output do + assert_nil Gem::Version.create(nil) + end + assert_empty actual_stdout + assert_equal(expected, actual_stderr) + assert_equal v("5.1"), Gem::Version.create("5.1") ver = "1.1".freeze diff --git a/test/rubygems/test_require.rb b/test/rubygems/test_require.rb index f933bbb5d5..6135acea92 100644 --- a/test/rubygems/test_require.rb +++ b/test/rubygems/test_require.rb @@ -269,7 +269,7 @@ class TestGemRequire < Gem::TestCase assert_includes $LOAD_PATH, rubylibdir message = proc { "this test relies on the b-2 gem lib/ to be before stdlib to make sense\n" + - $LOAD_PATH.pretty_inspect + $LOAD_PATH.pretty_inspect } assert_operator $LOAD_PATH.index(b2.load_paths[0]), :<, $LOAD_PATH.index(rubylibdir), message diff --git a/test/rubygems/utilities.rb b/test/rubygems/utilities.rb index 5f8f763cb5..c01f7acd48 100644 --- a/test/rubygems/utilities.rb +++ b/test/rubygems/utilities.rb @@ -39,9 +39,9 @@ class Gem::FakeFetcher end def find_data(path) - return Gem.read_binary path.path if URI === path and "file" == path.scheme + return Gem.read_binary path.path if URI === path && "file" == path.scheme - if URI === path and "URI::#{path.scheme.upcase}" != path.class.name + if URI === path && "URI::#{path.scheme.upcase}" != path.class.name raise ArgumentError, "mismatch for scheme #{path.scheme} and class #{path.class}" end @@ -67,7 +67,7 @@ class Gem::FakeFetcher if data.respond_to?(:call) data.call else - if path.to_s.end_with?(".gz") and not data.nil? and not data.empty? + if path.to_s.end_with?(".gz") && !data.nil? && !data.empty? data = Gem::Util.gunzip data end data @@ -76,7 +76,7 @@ class Gem::FakeFetcher def cache_update_path(uri, path = nil, update = true) if data = fetch_path(uri) - File.open(path, "wb") {|io| io.write data } if path and update + File.open(path, "wb") {|io| io.write data } if path && update data else Gem.read_binary(path) if path |