[rubygems/rubygems] Unify win_platform? to Gem.win_platform?

https://github.com/rubygems/rubygems/commit/b18a4ef076
This commit is contained in:
Hiroshi SHIBATA 2023-04-05 10:50:15 +09:00 committed by git
parent cbeea5f3e6
commit a464951fc7
24 changed files with 63 additions and 77 deletions

View File

@ -414,7 +414,7 @@ class Gem::TestCase < Test::Unit::TestCase
@orig_arch = RbConfig::CONFIG["arch"]
if win_platform?
if Gem.win_platform?
util_set_arch "i386-mswin32"
else
util_set_arch "i686-darwin8.10.1"
@ -1131,20 +1131,6 @@ Also, a list:
Object.send :remove_const, :RUBY_ENGINE_VERSION
end
##
# Is this test being run on a Windows platform?
def self.win_platform?
Gem.win_platform?
end
##
# see ::win_platform?
def win_platform?
self.class.win_platform?
end
##
# Returns whether or not we're on a version of Ruby built with VC++ (or
# Borland) versus Cygwin, Mingw, etc.

View File

@ -152,10 +152,10 @@ class TestGem < Gem::TestCase
end
def assert_self_install_permissions(format_executable: false)
mask = win_platform? ? 0700 : 0777
mask = Gem.win_platform? ? 0700 : 0777
options = {
:dir_mode => 0500,
:prog_mode => win_platform? ? 0410 : 0510,
:prog_mode => Gem.win_platform? ? 0410 : 0510,
:data_mode => 0640,
:wrappers => true,
:format_executable => format_executable,
@ -192,7 +192,7 @@ class TestGem < Gem::TestCase
"gems/foo-1/data/foo.txt" => data_mode,
}
# add Windows script
expected["bin/#{prog_name}.bat"] = mask.to_s(8) if win_platform?
expected["bin/#{prog_name}.bat"] = mask.to_s(8) if Gem.win_platform?
result = {}
Dir.chdir @gemhome do
expected.each_key do |n|
@ -645,7 +645,7 @@ class TestGem < Gem::TestCase
assert_equal 0750, File::Stat.new(@gemhome).mode & 0777
assert_equal 0750, File::Stat.new(File.join(@gemhome, "cache")).mode & 0777
end unless win_platform?
end unless Gem.win_platform?
def test_self_ensure_gem_directories_safe_permissions
FileUtils.rm_r @gemhome
@ -659,7 +659,7 @@ class TestGem < Gem::TestCase
assert_equal 0, File::Stat.new(File.join(@gemhome, "cache")).mode & 002
ensure
File.umask old_umask
end unless win_platform?
end unless Gem.win_platform?
def test_self_ensure_gem_directories_missing_parents
gemdir = File.join @tempdir, "a/b/c/gemdir"
@ -677,7 +677,7 @@ class TestGem < Gem::TestCase
assert_directory_exists util_cache_dir
end
unless win_platform? || Process.uid.zero? # only for FS that support write protection
unless Gem.win_platform? || Process.uid.zero? # only for FS that support write protection
def test_self_ensure_gem_directories_write_protected
gemdir = File.join @tempdir, "egd"
begin

View File

@ -79,7 +79,7 @@ class TestGemBundlerVersionFinder < Gem::TestCase
end
def test_deleted_directory
pend "Cannot perform this test on windows" if win_platform?
pend "Cannot perform this test on windows" if Gem.win_platform?
pend "Cannot perform this test on Solaris" if RUBY_PLATFORM.include?("solaris")
require "tmpdir"

View File

@ -500,7 +500,7 @@ Removed '/CN=alternate/DC=example'
mask = 0100600 & (~File.umask)
assert_equal mask, File.stat(path).mode unless win_platform?
assert_equal mask, File.stat(path).mode unless Gem.win_platform?
end
def test_execute_sign_encrypted_key
@ -529,7 +529,7 @@ Removed '/CN=alternate/DC=example'
mask = 0100600 & (~File.umask)
assert_equal mask, File.stat(path).mode unless win_platform?
assert_equal mask, File.stat(path).mode unless Gem.win_platform?
end
def test_execute_sign_default
@ -561,7 +561,7 @@ Removed '/CN=alternate/DC=example'
mask = 0100600 & (~File.umask)
assert_equal mask, File.stat(path).mode unless win_platform?
assert_equal mask, File.stat(path).mode unless Gem.win_platform?
end
def test_execute_sign_default_encrypted_key
@ -593,7 +593,7 @@ Removed '/CN=alternate/DC=example'
mask = 0100600 & (~File.umask)
assert_equal mask, File.stat(path).mode unless win_platform?
assert_equal mask, File.stat(path).mode unless Gem.win_platform?
end
def test_execute_sign_no_cert

View File

@ -184,7 +184,7 @@ class TestGemCommandsCleanupCommand < Gem::TestCase
assert_path_exist @a_1_1.gem_dir
ensure
FileUtils.chmod 0755, @gemhome
end unless win_platform? || Process.uid.zero?
end unless Gem.win_platform? || Process.uid.zero?
def test_execute_dry_run
@cmd.options[:args] = %w[a]

View File

@ -35,7 +35,7 @@ class TestGemCommandsGenerateIndexCommand < Gem::TestCase
end
def test_handle_options_directory
return if win_platform?
return if Gem.win_platform?
refute_equal "/nonexistent", @cmd.options[:directory]
@cmd.handle_options %w[--directory /nonexistent]
@ -44,7 +44,7 @@ class TestGemCommandsGenerateIndexCommand < Gem::TestCase
end
def test_handle_options_directory_windows
return unless win_platform?
return unless Gem.win_platform?
refute_equal "/nonexistent", @cmd.options[:directory]

View File

@ -189,7 +189,7 @@ ERROR: Could not find a valid gem 'bar' (= 0.5) (required by 'foo' (>= 0)) in a
end
def test_execute_no_user_install
pend "skipped on MS Windows (chmod has no effect)" if win_platform?
pend "skipped on MS Windows (chmod has no effect)" if Gem.win_platform?
pend "skipped in root privilege" if Process.uid.zero?
specs = spec_fetcher do |fetcher|

View File

@ -160,7 +160,7 @@ class TestGemCommandsPristineCommand < Gem::TestCase
ruby_exec = sprintf Gem.default_exec_format, "ruby"
bin_env = win_platform? ? "" : %w[/usr/bin/env /bin/env].find {|f| File.executable?(f) } + " "
bin_env = Gem.win_platform? ? "" : %w[/usr/bin/env /bin/env].find {|f| File.executable?(f) } + " "
assert_match %r{\A#!\s*#{bin_env}#{ruby_exec}}, File.read(gem_exec)
end

View File

@ -142,7 +142,7 @@ class TestGemCommandsSetupCommand < Gem::TestCase
ruby_exec = sprintf Gem.default_exec_format, "ruby"
bin_env = win_platform? ? "" : %w[/usr/bin/env /bin/env].find {|f| File.executable?(f) } + " "
bin_env = Gem.win_platform? ? "" : %w[/usr/bin/env /bin/env].find {|f| File.executable?(f) } + " "
assert_match %r{\A#!\s*#{bin_env}#{ruby_exec}}, File.read(default_gem_bin_path)
assert_match %r{\A#!\s*#{bin_env}#{ruby_exec}}, File.read(default_bundle_bin_path)
assert_match %r{\A#!\s*#{bin_env}#{ruby_exec}}, File.read(default_bundler_bin_path)

View File

@ -114,7 +114,7 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
def test_execute_removes_executable
initial_install
if win_platform?
if Gem.win_platform?
assert File.exist?(@executable)
else
assert File.symlink?(@executable)

View File

@ -152,7 +152,7 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
end
def test_execute_sudo
pend "Cannot perform this test on windows (chmod)" if win_platform?
pend "Cannot perform this test on windows (chmod)" if Gem.win_platform?
util_make_gems

View File

@ -196,7 +196,7 @@ class TestGemConfigFile < Gem::TestCase
end
def test_check_credentials_permissions
pend "chmod not supported" if win_platform?
pend "chmod not supported" if Gem.win_platform?
@cfg.rubygems_api_key = "x"
@ -335,7 +335,7 @@ if you believe they were disclosed to a third party.
end
def test_load_api_keys_bad_permission
pend "chmod not supported" if win_platform?
pend "chmod not supported" if Gem.win_platform?
@cfg.rubygems_api_key = "x"
@ -369,7 +369,7 @@ if you believe they were disclosed to a third party.
assert_equal expected, load_yaml_file(@cfg.credentials_path)
unless win_platform?
unless Gem.win_platform?
stat = File.stat @cfg.credentials_path
assert_equal 0600, stat.mode & 0600
@ -377,7 +377,7 @@ if you believe they were disclosed to a third party.
end
def test_rubygems_api_key_equals_bad_permission
pend "chmod not supported" if win_platform?
pend "chmod not supported" if Gem.win_platform?
@cfg.rubygems_api_key = "x"

View File

@ -895,7 +895,7 @@ class TestGemDependencyInstaller < Gem::TestCase
end
# Wrappers don't work on mswin
unless win_platform?
unless Gem.win_platform?
def test_install_no_wrappers
util_setup_gems

View File

@ -137,7 +137,7 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase
util_build_gem @spec
@gem = @spec.cache_file
if win_platform?
if Gem.win_platform?
pend("test_user_install_disabled_read_only test skipped on MS Windows")
elsif Process.uid.zero?
pend("test_user_install_disabled_read_only test skipped in root privilege")

View File

@ -213,7 +213,7 @@ gem 'other', version
assert_empty @ui.error
return unless win_platform?
return unless Gem.win_platform?
ENV["PATH"] = [orig_PATH, bin_dir.tr(File::SEPARATOR, File::ALT_SEPARATOR)].join(File::PATH_SEPARATOR)
@ -227,7 +227,7 @@ gem 'other', version
end
def test_check_that_user_bin_dir_is_in_path_tilde
pend "Tilde is PATH is not supported under MS Windows" if win_platform?
pend "Tilde is PATH is not supported under MS Windows" if Gem.win_platform?
orig_PATH = ENV["PATH"]
ENV["PATH"] = [ENV["PATH"], "~/bin"].join(File::PATH_SEPARATOR)
@ -241,7 +241,7 @@ gem 'other', version
assert_empty @ui.error
ensure
ENV["PATH"] = orig_PATH unless win_platform?
ENV["PATH"] = orig_PATH unless Gem.win_platform?
end
def test_check_that_user_bin_dir_is_in_path_not_in_path
@ -335,7 +335,7 @@ gem 'other', version
assert_directory_exists util_inst_bindir
installed_exec = File.join(util_inst_bindir, "executable")
assert_path_exist installed_exec
assert_equal mask, File.stat(installed_exec).mode unless win_platform?
assert_equal mask, File.stat(installed_exec).mode unless Gem.win_platform?
wrapper = File.read installed_exec
assert_match %r{generated by RubyGems}, wrapper
@ -380,7 +380,7 @@ gem 'other', version
assert_directory_exists util_inst_bindir
installed_exec = File.join util_inst_bindir, "executable"
assert_path_exist installed_exec
assert_equal mask, File.stat(installed_exec).mode unless win_platform?
assert_equal mask, File.stat(installed_exec).mode unless Gem.win_platform?
wrapper = File.read installed_exec
assert_match %r{generated by RubyGems}, wrapper
@ -439,7 +439,7 @@ gem 'other', version
installed_exec = File.join("#{@gemhome}2", "bin", "executable")
assert_path_exist installed_exec
assert_equal mask, File.stat(installed_exec).mode unless win_platform?
assert_equal mask, File.stat(installed_exec).mode unless Gem.win_platform?
wrapper = File.read installed_exec
assert_match %r{generated by RubyGems}, wrapper
@ -464,7 +464,7 @@ gem 'other', version
Dir.mkdir util_inst_bindir
if win_platform?
if Gem.win_platform?
pend("test_generate_bin_script_no_perms skipped on MS Windows")
elsif Process.uid.zero?
pend("test_generate_bin_script_no_perms skipped in root privilege")
@ -476,7 +476,7 @@ gem 'other', version
end
end
ensure
FileUtils.chmod 0755, util_inst_bindir unless $DEBUG || win_platform?
FileUtils.chmod 0755, util_inst_bindir unless $DEBUG || Gem.win_platform?
end
def test_generate_bin_script_no_shebang
@ -496,7 +496,7 @@ gem 'other', version
installed_exec = File.join @gemhome, "bin", "executable"
assert_path_exist installed_exec
assert_equal mask, File.stat(installed_exec).mode unless win_platform?
assert_equal mask, File.stat(installed_exec).mode unless Gem.win_platform?
wrapper = File.read installed_exec
assert_match %r{generated by RubyGems}, wrapper
@ -523,7 +523,7 @@ gem 'other', version
installer.generate_bin
assert_directory_exists util_inst_bindir
assert_path_exist installed_exec
assert_equal mask, File.stat(installed_exec).mode unless win_platform?
assert_equal mask, File.stat(installed_exec).mode unless Gem.win_platform?
assert_match %r{generated by RubyGems}, File.read(installed_exec)
@ -568,7 +568,7 @@ gem 'other', version
Dir.mkdir util_inst_bindir
if win_platform?
if Gem.win_platform?
pend("test_generate_bin_symlink_no_perms skipped on MS Windows")
elsif Process.uid.zero?
pend("test_user_install_disabled_read_only test skipped in root privilege")
@ -580,7 +580,7 @@ gem 'other', version
end
end
ensure
FileUtils.chmod 0755, util_inst_bindir unless $DEBUG || win_platform?
FileUtils.chmod 0755, util_inst_bindir unless $DEBUG || Gem.win_platform?
end
def test_generate_bin_symlink_update_newer
@ -987,7 +987,7 @@ gem 'other', version
assert_path_exist exe
exe_mode = File.stat(exe).mode & 0111
assert_equal 0111, exe_mode, "0%o" % exe_mode unless win_platform?
assert_equal 0111, exe_mode, "0%o" % exe_mode unless Gem.win_platform?
assert_path_exist File.join gemdir, "lib", "code.rb"
@ -2118,7 +2118,7 @@ gem 'other', version
end
def get_bin_env
if win_platform?
if Gem.win_platform?
""
else
%w[/usr/bin/env /bin/env].find {|f| File.executable?(f) }

View File

@ -189,7 +189,7 @@ class TestGemPackage < Gem::Package::TarTestCase
File.symlink("code.rb", "lib/code_sym.rb")
File.symlink("../lib/code.rb", "lib/code_sym2.rb")
rescue Errno::EACCES => e
if win_platform?
if Gem.win_platform?
pend "symlink - must be admin with no UAC on Windows"
else
raise e
@ -482,7 +482,7 @@ class TestGemPackage < Gem::Package::TarTestCase
mask = 0100666 & (~File.umask)
assert_equal mask.to_s(8), File.stat(extracted).mode.to_s(8) unless
win_platform?
Gem.win_platform?
end
def test_extract_files_empty
@ -512,7 +512,7 @@ class TestGemPackage < Gem::Package::TarTestCase
end
def test_extract_file_permissions
pend "chmod not supported" if win_platform?
pend "chmod not supported" if Gem.win_platform?
gem_with_long_permissions = File.expand_path("packages/Bluebie-legs-0.6.2.gem", __dir__)
@ -559,7 +559,7 @@ class TestGemPackage < Gem::Package::TarTestCase
begin
package.extract_tar_gz tgz_io, @destination
rescue Errno::EACCES => e
if win_platform?
if Gem.win_platform?
pend "symlink - must be admin with no UAC on Windows"
else
raise e
@ -612,7 +612,7 @@ class TestGemPackage < Gem::Package::TarTestCase
destination_subdir = File.join @destination, "subdir"
FileUtils.mkdir_p destination_subdir
expected_exceptions = win_platform? ? [Gem::Package::SymlinkError, Errno::EACCES] : [Gem::Package::SymlinkError]
expected_exceptions = Gem.win_platform? ? [Gem::Package::SymlinkError, Errno::EACCES] : [Gem::Package::SymlinkError]
e = assert_raise(*expected_exceptions) do
package.extract_tar_gz tgz_io, destination_subdir
@ -647,7 +647,7 @@ class TestGemPackage < Gem::Package::TarTestCase
tar.add_symlink "link/dir", ".", 16_877
end
expected_exceptions = win_platform? ? [Gem::Package::SymlinkError, Errno::EACCES] : [Gem::Package::SymlinkError]
expected_exceptions = Gem.win_platform? ? [Gem::Package::SymlinkError, Errno::EACCES] : [Gem::Package::SymlinkError]
e = assert_raise(*expected_exceptions) do
package.extract_tar_gz tgz_io, destination_subdir

View File

@ -41,7 +41,7 @@ unless Gem.java_platform? # jruby can't require the simple_gem file
mask = 0100644 & (~File.umask)
assert_equal mask, File.stat(extracted).mode unless win_platform?
assert_equal mask, File.stat(extracted).mode unless Gem.win_platform?
end
def test_extract_files_security_policy

View File

@ -212,7 +212,7 @@ class TestGemPlatform < Gem::TestCase
end
def test_to_s
if win_platform?
if Gem.win_platform?
assert_equal "x86-mswin32-60", Gem::Platform.local.to_s
else
assert_equal "x86-darwin-8", Gem::Platform.local.to_s

View File

@ -354,7 +354,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
assert File.exist?(a1_cache_gem)
end
unless win_platform? || Process.uid.zero? # File.chmod doesn't work
unless Gem.win_platform? || Process.uid.zero? # File.chmod doesn't work
def test_download_local_read_only
FileUtils.mv @a1_gem, @tempdir
local_path = File.join @tempdir, @a1.file_name

View File

@ -679,7 +679,7 @@ end
end
def test_platform_mswin
if win_platform?
if Gem.win_platform?
util_set_arch "x86-mswin32-60" do
@gda.platform :mswin do
@gda.gem "a"
@ -740,7 +740,7 @@ end
end
def test_platforms
unless win_platform?
unless Gem.win_platform?
util_set_arch "i686-darwin8.10.1" do
@gda.platforms :ruby do
@gda.gem "a"

View File

@ -58,7 +58,7 @@ class TestGemSecurityTrustDir < Gem::TestCase
mask = 0100600 & (~File.umask)
assert_equal mask, File.stat(trusted).mode unless win_platform?
assert_equal mask, File.stat(trusted).mode unless Gem.win_platform?
assert_equal PUBLIC_CERT.to_pem, File.read(trusted)
end
@ -73,7 +73,7 @@ class TestGemSecurityTrustDir < Gem::TestCase
mask = 040700 & (~File.umask)
mask |= 0200000 if RUBY_PLATFORM.include?("aix")
assert_equal mask, File.stat(@dest_dir).mode unless win_platform?
assert_equal mask, File.stat(@dest_dir).mode unless Gem.win_platform?
end
def test_verify_file
@ -94,6 +94,6 @@ class TestGemSecurityTrustDir < Gem::TestCase
mask = 040700 & (~File.umask)
mask |= 0200000 if RUBY_PLATFORM.include?("aix")
assert_equal mask, File.stat(@dest_dir).mode unless win_platform?
assert_equal mask, File.stat(@dest_dir).mode unless Gem.win_platform?
end
end if Gem::HAVE_OPENSSL

View File

@ -1451,7 +1451,7 @@ dependencies: []
@ext.build_extensions
assert_path_not_exist @ext.extension_dir
ensure
unless $DEBUG || win_platform? || Process.uid.zero? || Gem.java_platform?
unless $DEBUG || Gem.win_platform? || Process.uid.zero? || Gem.java_platform?
FileUtils.chmod 0755, File.join(@ext.base_dir, "extensions")
FileUtils.chmod 0755, @ext.base_dir
end
@ -1858,7 +1858,7 @@ dependencies: []
@a1.instance_variable_set :@new_platform, "mswin32"
assert_equal "a-1-mswin32", @a1.full_name, "legacy"
return if win_platform?
return if Gem.win_platform?
@a1 = Gem::Specification.new "a", 1
@a1.platform = "current"
@ -2380,7 +2380,7 @@ end
expected = <<-SPEC
# -*- encoding: utf-8 -*-
# stub: a 1 #{win_platform? ? "x86-mswin32-60" : "x86-darwin-8"} #{stub_require_paths}
# stub: a 1 #{Gem.win_platform? ? "x86-mswin32-60" : "x86-darwin-8"} #{stub_require_paths}
# stub: #{extensions}
Gem::Specification.new do |s|
@ -2897,7 +2897,7 @@ duplicate dependency on c (>= 1.2.3, development), (~> 1.2) use:
end
def test_validate_empty_require_paths
if win_platform?
if Gem.win_platform?
pend "test_validate_empty_require_paths skipped on MS Windows (symlink)"
else
util_setup_validate
@ -2913,7 +2913,7 @@ duplicate dependency on c (>= 1.2.3, development), (~> 1.2) use:
end
def test_validate_files
pend "test_validate_files skipped on MS Windows (symlink)" if win_platform?
pend "test_validate_files skipped on MS Windows (symlink)" if Gem.win_platform?
util_setup_validate
@a1.files += ["lib", "lib2"]

View File

@ -252,12 +252,12 @@ class TestGemUninstaller < Gem::InstallerTestCase
gem_dir = File.join @gemhome, "gems", @spec.full_name
Gem.pre_uninstall do
sleep(0.1) if win_platform?
sleep(0.1) if Gem.win_platform?
assert File.exist?(gem_dir), "gem_dir should exist"
end
Gem.post_uninstall do
sleep(0.1) if win_platform?
sleep(0.1) if Gem.win_platform?
refute File.exist?(gem_dir), "gem_dir should not exist"
end

View File

@ -36,7 +36,7 @@ class TestGemUtil < Gem::TestCase
end
def test_traverse_parents_does_not_crash_on_permissions_error
pend "skipped on MS Windows (chmod has no effect)" if win_platform? || Gem.java_platform?
pend "skipped on MS Windows (chmod has no effect)" if Gem.win_platform? || Gem.java_platform?
FileUtils.mkdir_p "d/e/f"
# remove 'execute' permission from "e" directory and make it
@ -53,7 +53,7 @@ class TestGemUtil < Gem::TestCase
assert_equal File.realpath("../..", @tempdir), paths[3]
ensure
# restore default permissions, allow the directory to be removed
FileUtils.chmod(0775, "d/e") unless win_platform? || Gem.java_platform?
FileUtils.chmod(0775, "d/e") unless Gem.win_platform? || Gem.java_platform?
end
def test_glob_files_in_dir