summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2019-11-11 15:03:57 +0900
committerSHIBATA Hiroshi <hsbt@ruby-lang.org>2019-11-11 16:59:49 +0900
commit7d463e360b9c4718b17378eb52783116a01b884b (patch)
treeee6951d298d76fcbf0c5e062712e54de56a3fa39 /test
parent31416423809f64d4b5ea6b9651cced3179cc5ced (diff)
downloadruby-7d463e360b9c4718b17378eb52783116a01b884b.tar.gz
Merge RubyGems 3.1.0.pre3
* Fix gem pristine not accounting for user installed gems. Pull request #2914 by Luis Sagastume. * Refactor keyword argument test for Ruby 2.7. Pull request #2947 by SHIBATA Hiroshi. * Fix errors at frozen Gem::Version. Pull request #2949 by Nobuyoshi Nakada. * Remove taint usage on Ruby 2.7+. Pull request #2951 by Jeremy Evans. * Check Manifest.txt is up to date. Pull request #2953 by David Rodríguez. * Clarify symlink conditionals in tests. Pull request #2962 by David Rodríguez. * Update command line parsing to work under ps. Pull request #2966 by David Rodríguez. * Properly test `Gem::Specifications.stub_for`. Pull request #2970 by David Rodríguez. * Fix Gem::LOADED_SPECS_MUTEX handling for recursive locking. Pull request #2985 by MSP-Greg.
Diffstat (limited to 'test')
-rw-r--r--test/rubygems/test_gem.rb20
-rw-r--r--test/rubygems/test_gem_command_manager.rb2
-rw-r--r--test/rubygems/test_gem_commands_pristine_command.rb49
-rw-r--r--test/rubygems/test_gem_ext_ext_conf_builder.rb6
-rw-r--r--test/rubygems/test_gem_installer.rb13
-rw-r--r--test/rubygems/test_gem_package.rb8
-rw-r--r--test/rubygems/test_gem_specification.rb33
-rw-r--r--test/rubygems/test_gem_version.rb7
-rw-r--r--test/rubygems/test_project_sanity.rb58
-rw-r--r--test/rubygems/test_rake_package.rb26
10 files changed, 157 insertions, 65 deletions
diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb
index 23f8249e34..859aba6588 100644
--- a/test/rubygems/test_gem.rb
+++ b/test/rubygems/test_gem.rb
@@ -14,14 +14,14 @@ end
# TODO: push this up to test_case.rb once battle tested
$LOAD_PATH.map! do |path|
- path.dup.untaint
+ path.dup.tap(&Gem::UNTAINT)
end
class TestGem < Gem::TestCase
PLUGINS_LOADED = [] # rubocop:disable Style/MutableConstant
- PROJECT_DIR = File.expand_path('../../..', __FILE__).untaint
+ PROJECT_DIR = File.expand_path('../../..', __FILE__).tap(&Gem::UNTAINT)
def setup
super
@@ -220,7 +220,7 @@ class TestGem < Gem::TestCase
end
assert_equal(expected, result)
ensure
- File.chmod(0755, *Dir.glob(@gemhome + '/gems/**/').map {|path| path.untaint})
+ File.chmod(0755, *Dir.glob(@gemhome + '/gems/**/').map {|path| path.tap(&Gem::UNTAINT)})
end
def test_require_missing
@@ -1617,8 +1617,8 @@ class TestGem < Gem::TestCase
assert_equal expected_specs, Gem.use_gemdeps.sort_by { |s| s.name }
end
- LIB_PATH = File.expand_path "../../../lib".dup.untaint, __FILE__.dup.untaint
- BUNDLER_LIB_PATH = File.expand_path $LOAD_PATH.find {|lp| File.file?(File.join(lp, "bundler.rb")) }.dup.untaint
+ LIB_PATH = File.expand_path "../../../lib".dup.tap(&Gem::UNTAINT), __FILE__.dup.tap(&Gem::UNTAINT)
+ BUNDLER_LIB_PATH = File.expand_path $LOAD_PATH.find {|lp| File.file?(File.join(lp, "bundler.rb")) }.dup.tap(&Gem::UNTAINT)
BUNDLER_FULL_NAME = "bundler-#{Bundler::VERSION}".freeze
def add_bundler_full_name(names)
@@ -1645,8 +1645,8 @@ class TestGem < Gem::TestCase
ENV['RUBYGEMS_GEMDEPS'] = "-"
path = File.join @tempdir, "gem.deps.rb"
- cmd = [Gem.ruby.dup.untaint, "-I#{LIB_PATH.untaint}",
- "-I#{BUNDLER_LIB_PATH.untaint}", "-rrubygems"]
+ cmd = [Gem.ruby.dup.tap(&Gem::UNTAINT), "-I#{LIB_PATH.tap(&Gem::UNTAINT)}",
+ "-I#{BUNDLER_LIB_PATH.tap(&Gem::UNTAINT)}", "-rrubygems"]
cmd << "-eputs Gem.loaded_specs.values.map(&:full_name).sort"
File.open path, "w" do |f|
@@ -1683,8 +1683,8 @@ class TestGem < Gem::TestCase
Dir.mkdir "sub1"
path = File.join @tempdir, "gem.deps.rb"
- cmd = [Gem.ruby.dup.untaint, "-Csub1", "-I#{LIB_PATH.untaint}",
- "-I#{BUNDLER_LIB_PATH.untaint}", "-rrubygems"]
+ cmd = [Gem.ruby.dup.tap(&Gem::UNTAINT), "-Csub1", "-I#{LIB_PATH.tap(&Gem::UNTAINT)}",
+ "-I#{BUNDLER_LIB_PATH.tap(&Gem::UNTAINT)}", "-rrubygems"]
cmd << "-eputs Gem.loaded_specs.values.map(&:full_name).sort"
File.open path, "w" do |f|
@@ -1732,7 +1732,7 @@ class TestGem < Gem::TestCase
end
def test_use_gemdeps
- gem_deps_file = 'gem.deps.rb'.untaint
+ gem_deps_file = 'gem.deps.rb'.tap(&Gem::UNTAINT)
spec = util_spec 'a', 1
install_specs spec
diff --git a/test/rubygems/test_gem_command_manager.rb b/test/rubygems/test_gem_command_manager.rb
index 6f00fe634c..45be9f01be 100644
--- a/test/rubygems/test_gem_command_manager.rb
+++ b/test/rubygems/test_gem_command_manager.rb
@@ -4,7 +4,7 @@ require 'rubygems/command_manager'
class TestGemCommandManager < Gem::TestCase
- PROJECT_DIR = File.expand_path('../../..', __FILE__).untaint
+ PROJECT_DIR = File.expand_path('../../..', __FILE__).tap(&Gem::UNTAINT)
def setup
super
diff --git a/test/rubygems/test_gem_commands_pristine_command.rb b/test/rubygems/test_gem_commands_pristine_command.rb
index 962ea96a2a..e872a80957 100644
--- a/test/rubygems/test_gem_commands_pristine_command.rb
+++ b/test/rubygems/test_gem_commands_pristine_command.rb
@@ -53,6 +53,55 @@ class TestGemCommandsPristineCommand < Gem::TestCase
assert_empty out, out.inspect
end
+ def test_execute_user_install
+ FileUtils.chmod 0555, @gemhome
+
+ a = util_spec "a" do |s|
+ s.executables = %w[foo]
+ s.files = %w[bin/foo lib/a.rb]
+ end
+
+ write_file File.join(@tempdir, "lib", "a.rb") do |fp|
+ fp.puts "puts __FILE__"
+ end
+
+ write_file File.join(@tempdir, "bin", "foo") do |fp|
+ fp.puts "#!/usr/bin/ruby"
+ end
+
+ install_gem_user(a)
+
+ Gem::Specification.dirs = [Gem.dir, Gem.user_dir]
+
+ foo_path = File.join(Gem.user_dir, "gems", a.full_name, "bin", "foo")
+ a_rb_path = File.join(Gem.user_dir, "gems", a.full_name, "lib", "a.rb")
+
+ write_file foo_path do |io|
+ io.puts("I changed it!")
+ end
+
+ write_file a_rb_path do |io|
+ io.puts("I changed it!")
+ end
+
+ @cmd.options[:args] = %w[a]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_equal "#!/usr/bin/ruby\n", File.read(foo_path), foo_path
+ assert_equal "puts __FILE__\n", File.read(a_rb_path), a_rb_path
+
+ out = @ui.output.split("\n")
+
+ assert_equal "Restoring gems to pristine condition...", out.shift
+ assert_equal "Restored #{a.full_name}", out.shift
+ assert_empty out, out.inspect
+ ensure
+ FileUtils.chmod(0755, @gemhome)
+ end
+
def test_execute_all
a = util_spec 'a' do |s|
s.executables = %w[foo]
diff --git a/test/rubygems/test_gem_ext_ext_conf_builder.rb b/test/rubygems/test_gem_ext_ext_conf_builder.rb
index d92da46f92..556761c979 100644
--- a/test/rubygems/test_gem_ext_ext_conf_builder.rb
+++ b/test/rubygems/test_gem_ext_ext_conf_builder.rb
@@ -17,7 +17,7 @@ class TestGemExtExtConfBuilder < Gem::TestCase
end
def test_class_build
- if java_platform? && ENV["CI"]
+ if java_platform?
skip("failing on jruby")
end
@@ -49,7 +49,7 @@ class TestGemExtExtConfBuilder < Gem::TestCase
end
def test_class_build_rbconfig_make_prog
- if java_platform? && ENV["CI"]
+ if java_platform?
skip("failing on jruby")
end
@@ -76,7 +76,7 @@ class TestGemExtExtConfBuilder < Gem::TestCase
env_make = ENV.delete 'MAKE'
ENV['MAKE'] = 'anothermake'
- if java_platform? && ENV["CI"]
+ if java_platform?
skip("failing on jruby")
end
diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb
index 52eea77b46..7a5fb972a4 100644
--- a/test/rubygems/test_gem_installer.rb
+++ b/test/rubygems/test_gem_installer.rb
@@ -5,6 +5,9 @@ class TestGemInstaller < Gem::InstallerTestCase
@@symlink_supported = nil
+ # Our CI does not currently hit the "symlink not supported" case, but this is
+ # needed for Windows developers without symlink support enabled (the default
+ # for non admin) to be able to run the tests successfully
def symlink_supported?
if @@symlink_supported.nil?
begin
@@ -544,7 +547,7 @@ gem 'other', version
end
def test_generate_bin_symlink
- return if win_platform? #Windows FS do not support symlinks
+ skip "Symlinks not supported or not enabled" unless symlink_supported?
installer = setup_base_installer
@@ -596,7 +599,7 @@ gem 'other', version
end
def test_generate_bin_symlink_update_newer
- return if win_platform? #Windows FS do not support symlinks
+ skip "Symlinks not supported or not enabled" unless symlink_supported?
installer = setup_base_installer
@@ -628,7 +631,7 @@ gem 'other', version
end
def test_generate_bin_symlink_update_older
- return if !symlink_supported?
+ skip "Symlinks not supported or not enabled" unless symlink_supported?
installer = setup_base_installer
@@ -666,7 +669,7 @@ gem 'other', version
end
def test_generate_bin_symlink_update_remove_wrapper
- return if !symlink_supported?
+ skip "Symlinks not supported or not enabled" unless symlink_supported?
installer = setup_base_installer
@@ -739,7 +742,7 @@ gem 'other', version
end
def test_generate_bin_uses_default_shebang
- return if !symlink_supported?
+ skip "Symlinks not supported or not enabled" unless symlink_supported?
installer = setup_base_installer
diff --git a/test/rubygems/test_gem_package.rb b/test/rubygems/test_gem_package.rb
index 0604a2cfc7..5da247e141 100644
--- a/test/rubygems/test_gem_package.rb
+++ b/test/rubygems/test_gem_package.rb
@@ -703,12 +703,12 @@ class TestGemPackage < Gem::Package::TarTestCase
package = Gem::Package.new @gem
file = 'file.rb'.dup
- file.taint
+ file.taint if RUBY_VERSION < '2.7'
destination = package.install_location file, @destination
assert_equal File.join(@destination, 'file.rb'), destination
- refute destination.tainted?
+ refute destination.tainted? if RUBY_VERSION < '2.7'
end
def test_install_location_absolute
@@ -742,14 +742,14 @@ class TestGemPackage < Gem::Package::TarTestCase
package = Gem::Package.new @gem
file = 'foo//file.rb'.dup
- file.taint
+ file.taint if RUBY_VERSION < '2.7'
destination = @destination.sub '/', '//'
destination = package.install_location file, destination
assert_equal File.join(@destination, 'foo', 'file.rb'), destination
- refute destination.tainted?
+ refute destination.tainted? if RUBY_VERSION < '2.7'
end
def test_install_location_relative
diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb
index 3d166910c0..8f345f87a2 100644
--- a/test/rubygems/test_gem_specification.rb
+++ b/test/rubygems/test_gem_specification.rb
@@ -939,22 +939,24 @@ dependencies: []
assert_equal File.join(@tempdir, 'a-2.gemspec'), spec.loaded_from
end
- def test_self_load_tainted
- full_path = @a2.spec_file
- write_file full_path do |io|
- io.write @a2.to_ruby_for_cache
- end
+ if RUBY_VERSION < '2.7'
+ def test_self_load_tainted
+ full_path = @a2.spec_file
+ write_file full_path do |io|
+ io.write @a2.to_ruby_for_cache
+ end
- full_path.taint
- loader = Thread.new { $SAFE = 1; Gem::Specification.load full_path }
- spec = loader.value
+ full_path.taint
+ loader = Thread.new { $SAFE = 1; Gem::Specification.load full_path }
+ spec = loader.value
- @a2.files.clear
+ @a2.files.clear
- assert_equal @a2, spec
+ assert_equal @a2, spec
- ensure
- $SAFE = 0
+ ensure
+ $SAFE = 0
+ end
end
def test_self_load_escape_curly
@@ -1160,12 +1162,11 @@ dependencies: []
# Create gemspecs in three locations used in stubs
loaded_spec = Gem::Specification.new 'a', '3'
Gem.loaded_specs['a'] = loaded_spec
- save_gemspec 'a', '2', dir_default_specs
- save_gemspec 'a', '1', dir_standard_specs
+ save_gemspec('a-2', '2', dir_default_specs) { |s| s.name = 'a' }
+ save_gemspec('a-1', '1', dir_standard_specs) { |s| s.name = 'a' }
full_names = ['a-3', 'a-2', 'a-1']
- full_names = Gem::Specification.stubs_for('a').map { |s| s.full_name }
assert_equal full_names, Gem::Specification.stubs_for('a').map { |s| s.full_name }
assert_equal 1, Gem::Specification.class_variable_get(:@@stubs_by_name).length
@@ -2472,7 +2473,7 @@ Gem::Specification.new do |s|
s.email = "example@example.com".freeze
s.files = ["lib/code.rb".freeze]
s.homepage = "http://example.com".freeze
- s.rubygems_version = "3.1.0.pre2".freeze
+ s.rubygems_version = "#{Gem::VERSION}".freeze
s.summary = "this is a summary".freeze
end
SPEC
diff --git a/test/rubygems/test_gem_version.rb b/test/rubygems/test_gem_version.rb
index c90648f562..1deecc0eed 100644
--- a/test/rubygems/test_gem_version.rb
+++ b/test/rubygems/test_gem_version.rb
@@ -217,6 +217,13 @@ class TestGemVersion < Gem::TestCase
assert_equal [1, 2, 3, "pre", 1], v("1.2.3-1").canonical_segments
end
+ def test_frozen_version
+ v = v('1.freeze.test').freeze
+ assert_less_than v, v('1')
+ assert_version_equal v('1'), v.release
+ assert_version_equal v('2'), v.bump
+ end
+
# Asserts that +version+ is a prerelease.
def assert_prerelease(version)
diff --git a/test/rubygems/test_project_sanity.rb b/test/rubygems/test_project_sanity.rb
new file mode 100644
index 0000000000..72f5e3b36e
--- /dev/null
+++ b/test/rubygems/test_project_sanity.rb
@@ -0,0 +1,58 @@
+# frozen_string_literal: true
+
+require "rubygems/test_case"
+require "open3"
+
+class TestProjectSanity < Minitest::Test
+
+ def test_rake_package_builds_ok
+ skip unless File.exist?(File.expand_path("../../../Rakefile", __FILE__))
+
+ with_empty_pkg_folder do
+ output, status = Open3.capture2e("rake package")
+
+ assert_equal true, status.success?, <<~MSG.chomp
+ Expected `rake package` to work, but got errors:
+
+ ```
+ #{output}
+ ```
+
+ If you have added or removed files, make sure you run `rake update_manifest` to update the `Manifest.txt` accordingly
+ MSG
+ end
+ end
+
+ def test_manifest_is_up_to_date
+ skip unless File.exist?(File.expand_path("../../../Rakefile", __FILE__))
+
+ _, status = Open3.capture2e("rake check_manifest")
+
+ assert status.success?, "Expected Manifest.txt to be up to date, but it's not. Run `rake update_manifest` to sync it."
+ end
+
+ private
+
+ def with_empty_pkg_folder
+ if File.exist?("pkg")
+ FileUtils.cp_r("pkg", "tmp")
+
+ begin
+ FileUtils.rm_rf("pkg")
+ yield
+ ensure
+ FileUtils.rm_rf("pkg")
+ FileUtils.cp_r("tmp/pkg", ".")
+ end
+ else
+ Dir.mkdir("pkg")
+
+ begin
+ yield
+ ensure
+ FileUtils.rm_rf("pkg")
+ end
+ end
+ end
+
+end
diff --git a/test/rubygems/test_rake_package.rb b/test/rubygems/test_rake_package.rb
deleted file mode 100644
index 165da798f5..0000000000
--- a/test/rubygems/test_rake_package.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-# frozen_string_literal: true
-
-require "rubygems/test_case"
-require "open3"
-
-class TestRakePackage < Minitest::Test
-
- def test_builds_ok
- skip unless File.exist?(File.expand_path("../../../Rakefile", __FILE__))
-
- output, status = Open3.capture2e("rake package")
-
- assert_equal true, status.success?, <<~MSG.chomp
- Expected `rake package` to work, but got errors:
-
- ```
- #{output}
- ```
-
- If you have added or removed files, make sure you run `rake update_manifest` to update the `Manifest.txt` accordingly
- MSG
-
- FileUtils.rm_f "pkg"
- end
-
-end