summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-20 08:39:12 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-20 08:39:12 +0000
commit8289771e326006cc4e15a667e3eff3a72cfb3327 (patch)
treef6d367888b42848fd6a660fad57fa2020e38c097
parent40d8543fbdec5485a638a2cb1008089d106b978d (diff)
Import RubyGems 1.0.0, r1575
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14361 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog4
-rw-r--r--gem_prelude.rb13
-rw-r--r--lib/rubygems.rb48
-rw-r--r--lib/rubygems/commands/install_command.rb2
-rw-r--r--lib/rubygems/commands/mirror_command.rb10
-rw-r--r--lib/rubygems/commands/query_command.rb4
-rw-r--r--lib/rubygems/commands/server_command.rb6
-rw-r--r--lib/rubygems/commands/unpack_command.rb15
-rw-r--r--lib/rubygems/commands/update_command.rb222
-rw-r--r--lib/rubygems/defaults.rb46
-rw-r--r--lib/rubygems/dependency_installer.rb15
-rw-r--r--lib/rubygems/indexer.rb2
-rw-r--r--lib/rubygems/install_update_options.rb7
-rw-r--r--lib/rubygems/installer.rb72
-rw-r--r--lib/rubygems/package.rb1
-rw-r--r--lib/rubygems/platform.rb45
-rw-r--r--lib/rubygems/remote_fetcher.rb10
-rw-r--r--lib/rubygems/remote_installer.rb195
-rw-r--r--lib/rubygems/rubygems_version.rb2
-rw-r--r--lib/rubygems/security.rb2
-rw-r--r--lib/rubygems/server.rb21
-rw-r--r--lib/rubygems/source_index.rb43
-rw-r--r--lib/rubygems/source_info_cache.rb6
-rw-r--r--lib/rubygems/specification.rb95
-rw-r--r--lib/rubygems/uninstaller.rb2
-rwxr-xr-xlib/rubygems/validator.rb5
-rw-r--r--lib/rubygems/version.rb13
-rw-r--r--test/rubygems/gemutilities.rb21
-rw-r--r--test/rubygems/test_gem.rb122
-rw-r--r--test/rubygems/test_gem_commands_build_command.rb24
-rw-r--r--test/rubygems/test_gem_commands_dependency_command.rb20
-rw-r--r--test/rubygems/test_gem_commands_mirror_command.rb13
-rw-r--r--test/rubygems/test_gem_commands_query_command.rb10
-rw-r--r--test/rubygems/test_gem_commands_server_command.rb27
-rw-r--r--test/rubygems/test_gem_commands_unpack_command.rb22
-rw-r--r--test/rubygems/test_gem_format.rb2
-rw-r--r--test/rubygems/test_gem_indexer.rb10
-rw-r--r--test/rubygems/test_gem_install_update_options.rb2
-rw-r--r--test/rubygems/test_gem_installer.rb198
-rw-r--r--test/rubygems/test_gem_platform.rb17
-rw-r--r--test/rubygems/test_gem_remote_fetcher.rb21
-rw-r--r--test/rubygems/test_gem_remote_installer.rb161
-rw-r--r--test/rubygems/test_gem_server.rb45
-rw-r--r--test/rubygems/test_gem_source_index.rb4
-rw-r--r--test/rubygems/test_gem_specification.rb468
-rw-r--r--test/rubygems/test_gem_version.rb15
-rw-r--r--test/rubygems/test_kernel.rb38
47 files changed, 1153 insertions, 993 deletions
diff --git a/ChangeLog b/ChangeLog
index 19d679642f..a62f86d02f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Thu Dec 20 17:36:01 2007 Eric Hodel <drbrain@segment7.net>
+
+ * lib/rubygems*: Import RubyGems 1.0.0, r1575.
+
Thu Dec 20 17:18:38 2007 Koichi Sasada <ko1@atdot.net>
* proc.c: support Proc#binding.
diff --git a/gem_prelude.rb b/gem_prelude.rb
index 997dae4699..88ffe17538 100644
--- a/gem_prelude.rb
+++ b/gem_prelude.rb
@@ -131,6 +131,7 @@ module Gem
Dir.entries(gems_directory).each do |gem_directory_name|
next if gem_directory_name == "." || gem_directory_name == ".."
dash = gem_directory_name.rindex("-")
+ next if dash.nil?
gem_name = gem_directory_name[0...dash]
current_version = GemVersions[gem_name]
new_version = calculate_integers_for_gem_version(gem_directory_name[dash+1..-1])
@@ -167,6 +168,7 @@ module Gem
def method_missing(method, *args, &block)
QuickLoader.load_full_rubygems_library
+ super unless Gem.respond_to?(method)
Gem.send(method, *args, &block)
end
end
@@ -174,9 +176,14 @@ module Gem
extend QuickLoader
end
-
-Gem.push_all_highest_version_gems_on_load_path
-$".unshift File.join(Gem::ConfigMap[:libdir], "ruby", Gem::ConfigMap[:ruby_version], "rubygems.rb")
+begin
+ Gem.push_all_highest_version_gems_on_load_path
+ $".unshift File.join(Gem::ConfigMap[:libdir], "ruby", Gem::ConfigMap[:ruby_version], "rubygems.rb")
+rescue Exception => e
+ puts "Error loading gem paths on load path in gem_prelude"
+ puts e
+ puts e.backtrace.join("\n")
+end
#puts "Gem load in #{Time.now - t} seconds"
end # Gem::Enable \ No newline at end of file
diff --git a/lib/rubygems.rb b/lib/rubygems.rb
index f233b520f1..72f735ce50 100644
--- a/lib/rubygems.rb
+++ b/lib/rubygems.rb
@@ -6,6 +6,7 @@
#++
require 'rubygems/rubygems_version'
+require 'rubygems/defaults'
require 'thread'
module Gem
@@ -29,8 +30,8 @@ module Kernel
# version).
#
# You can define the environment variable GEM_SKIP as a way to not
- # load specified gems. you might do this to test out changes that
- # haven't been intsalled yet. Example:
+ # load specified gems. You might do this to test out changes that
+ # haven't been installed yet. Example:
#
# GEM_SKIP=libA:libB ruby-I../libA -I../libB ./mycode.rb
#
@@ -49,17 +50,6 @@ module Kernel
active_gem_with_options(gem_name, version_requirements)
end
- # Same as the +gem+ command, but will also require a file if the gem
- # provides an auto-required file name.
- #
- # DEPRECATED! Use +gem+ instead.
- #
- def require_gem(gem_name, *version_requirements)
- file, lineno = location_of_caller
- warn "#{file}:#{lineno}:Warning: require_gem is obsolete. Use gem instead."
- active_gem_with_options(gem_name, version_requirements, :auto_require=>true)
- end
-
# Return the file name (string) and line number (integer) of the caller of
# the caller of this method.
def location_of_caller
@@ -84,15 +74,17 @@ module Gem
ConfigMap = {} unless defined?(ConfigMap)
require 'rbconfig'
ConfigMap.merge!(
- :sitedir => RbConfig::CONFIG["sitedir"],
- :ruby_version => RbConfig::CONFIG["ruby_version"],
- :libdir => RbConfig::CONFIG["libdir"],
- :sitelibdir => RbConfig::CONFIG["sitelibdir"],
- :arch => RbConfig::CONFIG["arch"],
- :bindir => RbConfig::CONFIG["bindir"],
+ :BASERUBY => RbConfig::CONFIG["BASERUBY"],
:EXEEXT => RbConfig::CONFIG["EXEEXT"],
+ :RUBY_INSTALL_NAME => RbConfig::CONFIG["RUBY_INSTALL_NAME"],
:RUBY_SO_NAME => RbConfig::CONFIG["RUBY_SO_NAME"],
- :ruby_install_name => RbConfig::CONFIG["ruby_install_name"]
+ :arch => RbConfig::CONFIG["arch"],
+ :bindir => RbConfig::CONFIG["bindir"],
+ :libdir => RbConfig::CONFIG["libdir"],
+ :ruby_install_name => RbConfig::CONFIG["ruby_install_name"],
+ :ruby_version => RbConfig::CONFIG["ruby_version"],
+ :sitedir => RbConfig::CONFIG["sitedir"],
+ :sitelibdir => RbConfig::CONFIG["sitelibdir"]
)
MUTEX = Mutex.new
@@ -207,10 +199,6 @@ module Gem
@sources
end
- # An Array of the default sources that come with RubyGems.
- def default_sources
- %w[http://gems.rubyforge.org]
- end
# Provide an alias for the old name.
alias cache source_index
@@ -536,18 +524,6 @@ module Gem
end
end
- public
-
- # Default home directory path to be used if an alternate value is
- # not specified in the environment.
- def default_dir
- if defined? RUBY_FRAMEWORK_VERSION
- return File.join(File.dirname(ConfigMap[:sitedir]), "Gems", ConfigMap[:ruby_version])
- else
- File.join(ConfigMap[:libdir], 'ruby', 'gems', ConfigMap[:ruby_version])
- end
- end
-
end
end
diff --git a/lib/rubygems/commands/install_command.rb b/lib/rubygems/commands/install_command.rb
index 4c67c0487b..aa9f480c2a 100644
--- a/lib/rubygems/commands/install_command.rb
+++ b/lib/rubygems/commands/install_command.rb
@@ -17,6 +17,7 @@ class Gem::Commands::InstallCommand < Gem::Command
:generate_rdoc => true,
:generate_ri => true,
:install_dir => Gem.dir,
+ :format_executable => false,
:test => false,
:version => Gem::Requirement.default,
})
@@ -56,6 +57,7 @@ class Gem::Commands::InstallCommand < Gem::Command
:env_shebang => options[:env_shebang],
:domain => options[:domain],
:force => options[:force],
+ :format_executable => options[:format_executable],
:ignore_dependencies => options[:ignore_dependencies],
:install_dir => options[:install_dir],
:security_policy => options[:security_policy],
diff --git a/lib/rubygems/commands/mirror_command.rb b/lib/rubygems/commands/mirror_command.rb
index 74f6970e9e..fc4f086ad3 100644
--- a/lib/rubygems/commands/mirror_command.rb
+++ b/lib/rubygems/commands/mirror_command.rb
@@ -60,10 +60,16 @@ Multiple sources and destinations may be specified.
if get_from.scheme.nil? then
get_from = get_from.to_s
elsif get_from.scheme == 'file' then
- get_from = get_from.to_s[5..-1]
+ # check if specified URI contains a drive letter (file:/D:/Temp)
+ get_from = get_from.to_s
+ get_from = if get_from =~ /^file:.*[a-z]:/i then
+ get_from[6..-1]
+ else
+ get_from[5..-1]
+ end
end
- open File.join(get_from, "Marshal.#{Gem.marshal_version}.Z"), "rb" do |y|
+ open File.join(get_from.to_s, "Marshal.#{Gem.marshal_version}.Z"), "rb" do |y|
sourceindex_data = Zlib::Inflate.inflate y.read
open File.join(save_to, "Marshal.#{Gem.marshal_version}"), "wb" do |out|
out.write sourceindex_data
diff --git a/lib/rubygems/commands/query_command.rb b/lib/rubygems/commands/query_command.rb
index 581d4bb734..4f957625ee 100644
--- a/lib/rubygems/commands/query_command.rb
+++ b/lib/rubygems/commands/query_command.rb
@@ -82,8 +82,10 @@ class Gem::Commands::QueryCommand < Gem::Command
end
entry = gem_name.dup
+
if options[:versions] then
- entry << " (#{list_of_matching.map{|gem| gem.version.to_s}.join(", ")})"
+ versions = list_of_matching.map { |s| s.version }.uniq
+ entry << " (#{versions.join ', '})"
end
entry << "\n" << format_text(list_of_matching[0].summary, 68, 4) if
diff --git a/lib/rubygems/commands/server_command.rb b/lib/rubygems/commands/server_command.rb
index 34e5e46fec..992ae1c8f8 100644
--- a/lib/rubygems/commands/server_command.rb
+++ b/lib/rubygems/commands/server_command.rb
@@ -7,17 +7,17 @@ class Gem::Commands::ServerCommand < Gem::Command
super 'server', 'Documentation and gem repository HTTP server',
:port => 8808, :gemdir => Gem.dir, :daemon => false
- add_option '-p', '--port=PORT',
+ add_option '-p', '--port=PORT', Integer,
'port to listen on' do |port, options|
options[:port] = port
end
add_option '-d', '--dir=GEMDIR',
'directory from which to serve gems' do |gemdir, options|
- options[:gemdir] = gemdir
+ options[:gemdir] = File.expand_path gemdir
end
- add_option '--[no]-daemon', 'run as a daemon' do |daemon, options|
+ add_option '--[no-]daemon', 'run as a daemon' do |daemon, options|
options[:daemon] = daemon
end
end
diff --git a/lib/rubygems/commands/unpack_command.rb b/lib/rubygems/commands/unpack_command.rb
index ece24745a2..23ebabc21a 100644
--- a/lib/rubygems/commands/unpack_command.rb
+++ b/lib/rubygems/commands/unpack_command.rb
@@ -9,7 +9,13 @@ class Gem::Commands::UnpackCommand < Gem::Command
def initialize
super 'unpack', 'Unpack an installed gem to the current directory',
- :version => Gem::Requirement.default
+ :version => Gem::Requirement.default,
+ :target => Dir.pwd
+
+ add_option('--target', 'target directory for unpacking') do |value, options|
+ options[:target] = value
+ end
+
add_version_option
end
@@ -32,10 +38,11 @@ class Gem::Commands::UnpackCommand < Gem::Command
def execute
gemname = get_one_gem_name
path = get_path(gemname, options[:version])
- if path
- target_dir = File.basename(path).sub(/\.gem$/, '')
+ if path then
+ basename = File.basename(path).sub(/\.gem$/, '')
+ target_dir = File.expand_path File.join(options[:target], basename)
FileUtils.mkdir_p target_dir
- Gem::Installer.new(path).unpack(File.expand_path(target_dir))
+ Gem::Installer.new(path).unpack target_dir
say "Unpacked gem: '#{target_dir}'"
else
alert_error "Gem '#{gemname}' not installed."
diff --git a/lib/rubygems/commands/update_command.rb b/lib/rubygems/commands/update_command.rb
index e17ba2516a..7a11ec9554 100644
--- a/lib/rubygems/commands/update_command.rb
+++ b/lib/rubygems/commands/update_command.rb
@@ -4,146 +4,152 @@ require 'rubygems/local_remote_options'
require 'rubygems/source_info_cache'
require 'rubygems/version_option'
-module Gem
- module Commands
- class UpdateCommand < Command
+class Gem::Commands::UpdateCommand < Gem::Command
- include Gem::InstallUpdateOptions
- include Gem::LocalRemoteOptions
- include Gem::VersionOption
+ include Gem::InstallUpdateOptions
+ include Gem::LocalRemoteOptions
+ include Gem::VersionOption
- def initialize
- super(
- 'update',
+ def initialize
+ super 'update',
'Update the named gems (or all installed gems) in the local repository',
- {
- :generate_rdoc => true,
- :generate_ri => true,
- :force => false,
- :test => false,
- :install_dir => Gem.dir
- })
-
- add_install_update_options
-
- add_option('--system',
- 'Update the RubyGems system software') do |value, options|
- options[:system] = value
- end
+ :generate_rdoc => true,
+ :generate_ri => true,
+ :force => false,
+ :test => false,
+ :install_dir => Gem.dir
- add_local_remote_options
+ add_install_update_options
- add_platform_option
- end
+ add_option('--system',
+ 'Update the RubyGems system software') do |value, options|
+ options[:system] = value
+ end
- def arguments # :nodoc:
- "GEMNAME name of gem to update"
- end
+ add_local_remote_options
- def defaults_str # :nodoc:
- "--rdoc --ri --no-force --no-test\n" +
- "--install-dir #{Gem.dir}"
- end
+ add_platform_option
+ end
+
+ def arguments # :nodoc:
+ "GEMNAME name of gem to update"
+ end
- def usage # :nodoc:
- "#{program_name} GEMNAME [GEMNAME ...]"
+ def defaults_str # :nodoc:
+ "--rdoc --ri --no-force --no-test --install-dir #{Gem.dir}"
+ end
+
+ def usage # :nodoc:
+ "#{program_name} GEMNAME [GEMNAME ...]"
+ end
+
+ def execute
+ if options[:system] then
+ say "Updating RubyGems..."
+
+ unless options[:args].empty? then
+ fail "No gem names are allowed with the --system option"
end
- def execute
- if options[:system] then
- say "Updating RubyGems..."
+ options[:args] = ["rubygems-update"]
+ else
+ say "Updating installed gems..."
+ end
- unless options[:args].empty? then
- fail "No gem names are allowed with the --system option"
- end
+ hig = highest_installed_gems = {}
- options[:args] = ["rubygems-update"]
- else
- say "Updating installed gems..."
- end
+ Gem::SourceIndex.from_installed_gems.each do |name, spec|
+ if hig[spec.name].nil? or hig[spec.name].version < spec.version then
+ hig[spec.name] = spec
+ end
+ end
- hig = highest_installed_gems = {}
+ remote_gemspecs = Gem::SourceInfoCache.search(//)
- Gem::SourceIndex.from_installed_gems.each do |name, spec|
- if hig[spec.name].nil? or hig[spec.name].version < spec.version
- hig[spec.name] = spec
- end
- end
+ gems_to_update = if options[:args].empty? then
+ which_to_update(highest_installed_gems, remote_gemspecs)
+ else
+ options[:args]
+ end
- remote_gemspecs = Gem::SourceInfoCache.search(//)
+ options[:domain] = :remote # install from remote source
- gems_to_update = if options[:args].empty? then
- which_to_update(highest_installed_gems, remote_gemspecs)
- else
- options[:args]
- end
+ # HACK use the real API
+ install_command = Gem::CommandManager.instance['install']
- options[:domain] = :remote # install from remote source
+ gems_to_update.uniq.sort.each do |name|
+ say "Attempting remote update of #{name}"
+ options[:args] = [name]
+ options[:ignore_dependencies] = true # HACK skip seen gems instead
+ install_command.merge_options(options)
+ install_command.execute
+ end
- # HACK use the real API
- install_command = Gem::CommandManager.instance['install']
+ if gems_to_update.include? "rubygems-update" then
+ latest_ruby_gem = remote_gemspecs.select do |s|
+ s.name == 'rubygems-update'
+ end
- gems_to_update.uniq.sort.each do |name|
- say "Attempting remote update of #{name}"
- options[:args] = [name]
- options[:ignore_dependencies] = true # HACK skip seen gems instead
- install_command.merge_options(options)
- install_command.execute
- end
+ latest_ruby_gem = latest_ruby_gem.sort_by { |s| s.version }.last
- if gems_to_update.include?("rubygems-update") then
- latest_ruby_gem = remote_gemspecs.select { |s|
- s.name == 'rubygems-update'
- }.sort_by { |s|
- s.version
- }.last
+ say "Updating version of RubyGems to #{latest_ruby_gem.version}"
+ installed = do_rubygems_update latest_ruby_gem.version
- say "Updating version of RubyGems to #{latest_ruby_gem.version}"
- installed = do_rubygems_update(latest_ruby_gem.version.to_s)
+ say "RubyGems system software updated" if installed
+ else
+ updated = gems_to_update.uniq.sort.collect { |g| g.to_s }
- say "RubyGems system software updated" if installed
- else
- say "Gems: [#{gems_to_update.uniq.sort.collect{|g| g.to_s}.join(', ')}] updated"
- end
+ if updated.empty? then
+ say "Nothing to update"
+ else
+ say "Gems updated: #{updated.join ', '}"
end
+ end
+ end
- def do_rubygems_update(version_string)
- args = []
- args.push '--prefix', Gem.prefix unless Gem.prefix.nil?
- args << '--no-rdoc' unless options[:generate_rdoc]
- args << '--no-ri' unless options[:generate_ri]
+ def do_rubygems_update(version)
+ args = []
+ args.push '--prefix', Gem.prefix unless Gem.prefix.nil?
+ args << '--no-rdoc' unless options[:generate_rdoc]
+ args << '--no-ri' unless options[:generate_ri]
- update_dir = File.join(Gem.dir, 'gems',
- "rubygems-update-#{version_string}")
+ update_dir = File.join Gem.dir, 'gems', "rubygems-update-#{version}"
- success = false
+ success = false
- Dir.chdir update_dir do
- say "Installing RubyGems #{version_string}"
- setup_cmd = "#{Gem.ruby} setup.rb #{args.join ' '}"
+ Dir.chdir update_dir do
+ say "Installing RubyGems #{version}"
+ setup_cmd = "#{Gem.ruby} setup.rb #{args.join ' '}"
- # Make sure old rubygems isn't loaded
- if Gem.win_platform? then
- system "set RUBYOPT= & #{setup_cmd}"
- else
- system "RUBYOPT=\"\" #{setup_cmd}"
- end
- end
+ # Make sure old rubygems isn't loaded
+ if Gem.win_platform? then
+ system "set RUBYOPT= & #{setup_cmd}"
+ else
+ system "RUBYOPT=\"\" #{setup_cmd}"
end
+ end
+ end
+
+ def which_to_update(highest_installed_gems, remote_gemspecs)
+ result = []
- def which_to_update(highest_installed_gems, remote_gemspecs)
- result = []
- highest_installed_gems.each do |l_name, l_spec|
- highest_remote_gem =
- remote_gemspecs.select { |spec| spec.name == l_name }.
- sort_by { |spec| spec.version }.
- last
- if highest_remote_gem and l_spec.version < highest_remote_gem.version
- result << l_name
- end
+ highest_installed_gems.each do |l_name, l_spec|
+ matching_gems = remote_gemspecs.select do |spec|
+ spec.name == l_name and Gem.platforms.any? do |platform|
+ platform == spec.platform
end
- result
+ end
+
+ highest_remote_gem = matching_gems.sort_by { |spec| spec.version }.last
+
+ if highest_remote_gem and
+ l_spec.version < highest_remote_gem.version then
+ result << l_name
end
end
+
+ result
end
+
end
+
diff --git a/lib/rubygems/defaults.rb b/lib/rubygems/defaults.rb
new file mode 100644
index 0000000000..3a6229511b
--- /dev/null
+++ b/lib/rubygems/defaults.rb
@@ -0,0 +1,46 @@
+module Gem
+
+ # An Array of the default sources that come with RubyGems.
+ def self.default_sources
+ %w[http://gems.rubyforge.org]
+ end
+
+ # Default home directory path to be used if an alternate value is not
+ # specified in the environment.
+ def self.default_dir
+ if defined? RUBY_FRAMEWORK_VERSION then
+ File.join File.dirname(ConfigMap[:sitedir]), 'Gems',
+ ConfigMap[:ruby_version]
+ else
+ File.join ConfigMap[:libdir], 'ruby', 'gems', ConfigMap[:ruby_version]
+ end
+ end
+
+ # Default gem path.
+ def self.default_path
+ default_dir
+ end
+
+ # Deduce Ruby's --program-prefix and --program-suffix from its install name.
+ def self.default_exec_format
+ baseruby = ConfigMap[:BASERUBY] || 'ruby'
+ ConfigMap[:RUBY_INSTALL_NAME].sub(baseruby, '%s') rescue '%s'
+ end
+
+ # The default directory for binaries
+ def self.default_bindir
+ Config::CONFIG['bindir']
+ end
+
+ # The default system-wide source info cache directory.
+ def self.default_system_source_cache_dir
+ File.join Gem.dir, 'source_cache'
+ end
+
+ # The default user-specific source info cache directory.
+ def self.default_user_source_cache_dir
+ File.join Gem.user_home, '.gem', 'source_cache'
+ end
+
+end
+
diff --git a/lib/rubygems/dependency_installer.rb b/lib/rubygems/dependency_installer.rb
index e189e800a0..ec8a50d912 100644
--- a/lib/rubygems/dependency_installer.rb
+++ b/lib/rubygems/dependency_installer.rb
@@ -15,8 +15,9 @@ class Gem::DependencyInstaller
:env_shebang => false,
:domain => :both, # HACK dup
:force => false,
+ :format_executable => false, # HACK dup
:ignore_dependencies => false,
- :security_policy => Gem::Security::NoSecurity, # HACK AlmostNo? Low?
+ :security_policy => nil, # HACK NoSecurity requires OpenSSL. AlmostNo? Low?
:wrappers => true
}
@@ -30,6 +31,7 @@ class Gem::DependencyInstaller
# current directory. :remote searches only gems in Gem::sources.
# :both searches both.
# :force:: See Gem::Installer#install.
+ # :format_executable:: See Gem::Installer#initialize.
# :ignore_dependencies: Don't install any dependencies.
# :install_dir: See Gem::Installer#install.
# :security_policy: See Gem::Installer::new and Gem::Security.
@@ -39,6 +41,7 @@ class Gem::DependencyInstaller
@env_shebang = options[:env_shebang]
@domain = options[:domain]
@force = options[:force]
+ @format_executable = options[:format_executable]
@ignore_dependencies = options[:ignore_dependencies]
@install_dir = options[:install_dir] || Gem.dir
@security_policy = options[:security_policy]
@@ -48,7 +51,14 @@ class Gem::DependencyInstaller
spec_and_source = nil
- local_gems = Dir["#{gem_name}*"].sort.reverse
+ glob = if File::ALT_SEPARATOR then
+ gem_name.gsub File::ALT_SEPARATOR, File::SEPARATOR
+ else
+ gem_name
+ end
+
+ local_gems = Dir["#{glob}*"].sort.reverse
+
unless local_gems.empty? then
local_gems.each do |gem_file|
next unless gem_file =~ /gem$/
@@ -217,6 +227,7 @@ class Gem::DependencyInstaller
inst = Gem::Installer.new local_gem_path,
:env_shebang => @env_shebang,
:force => @force,
+ :format_executable => @format_executable,
:ignore_dependencies => @ignore_dependencies,
:install_dir => @install_dir,
:security_policy => @security_policy,
diff --git a/lib/rubygems/indexer.rb b/lib/rubygems/indexer.rb
index dc94f51b1a..272cee3fd3 100644
--- a/lib/rubygems/indexer.rb
+++ b/lib/rubygems/indexer.rb
@@ -98,7 +98,7 @@ class Gem::Indexer
files = @master_index.files + @quick_index.files + @marshal_index.files
files.each do |file|
- relative_name = file[/\A#{@directory}.(.*)/, 1]
+ relative_name = file[/\A#{Regexp.escape @directory}.(.*)/, 1]
dest_name = File.join @dest_directory, relative_name
FileUtils.rm_rf dest_name, :verbose => verbose
diff --git a/lib/rubygems/install_update_options.rb b/lib/rubygems/install_update_options.rb
index 01c3a8af27..b93e21551c 100644
--- a/lib/rubygems/install_update_options.rb
+++ b/lib/rubygems/install_update_options.rb
@@ -76,6 +76,13 @@ module Gem::InstallUpdateOptions
'dependent gems') do |value, options|
options[:include_dependencies] = value
end
+
+ add_option(:"Install/Update", '--[no-]format-executable',
+ 'Make installed executable names match ruby.',
+ 'If ruby is ruby18, foo_exec will be',
+ 'foo_exec18') do |value, options|
+ options[:format_executable] = value
+ end
end
# Default options for the gem install command.
diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb
index 46d0144a88..e652ac9c6d 100644
--- a/lib/rubygems/installer.rb
+++ b/lib/rubygems/installer.rb
@@ -28,9 +28,20 @@ class Gem::Installer
class ExtensionBuildError < Gem::InstallError; end
include Gem::UserInteraction
-
+
include Gem::RequirePathsBuilder
+ class << self
+
+ attr_writer :exec_format
+
+ # Defaults to use Ruby's program prefix and suffix.
+ def exec_format
+ @exec_format ||= Gem.default_exec_format
+ end
+
+ end
+
##
# Constructs an Installer instance that will install the gem located at
# +gem+. +options+ is a Hash with the following keys:
@@ -40,18 +51,26 @@ class Gem::Installer
# for a signed-gems-only policy.
# :ignore_dependencies:: Don't raise if a dependency is missing.
# :install_dir:: The directory to install the gem into.
+ # :format_executable:: Format the executable the same as the ruby executable.
+ # If your ruby is ruby18, foo_exec will be installed as
+ # foo_exec18.
# :security_policy:: Use the specified security policy. See Gem::Security
# :wrappers:: Install wrappers if true, symlinks if false.
def initialize(gem, options={})
@gem = gem
- options = { :force => false, :install_dir => Gem.dir }.merge options
+ options = {
+ :force => false,
+ :install_dir => Gem.dir,
+ :exec_format => false,
+ }.merge options
@env_shebang = options[:env_shebang]
@force = options[:force]
gem_home = options[:install_dir]
@gem_home = Pathname.new(gem_home).expand_path
@ignore_dependencies = options[:ignore_dependencies]
+ @format_executable = options[:format_executable]
@security_policy = options[:security_policy]
@wrappers = options[:wrappers]
@@ -114,7 +133,7 @@ class Gem::Installer
generate_bin
build_extensions
write_spec
-
+
write_require_paths_file_if_needed
# HACK remove? Isn't this done in multiple places?
@@ -190,9 +209,12 @@ class Gem::Installer
def generate_windows_script(bindir, filename)
if Gem.win_platform? then
script_name = filename + ".bat"
- File.open(File.join(bindir, File.basename(script_name)), "w") do |file|
+ script_path = File.join bindir, File.basename(script_name)
+ File.open script_path, 'w' do |file|
file.puts windows_stub_script(bindir, filename)
end
+
+ say script_path if Gem.configuration.really_verbose
end
end
@@ -209,7 +231,7 @@ class Gem::Installer
@spec.executables.each do |filename|
filename.untaint
- bin_path = File.join @gem_dir, 'bin', filename
+ bin_path = File.expand_path File.join(@gem_dir, @spec.bindir, filename)
mode = File.stat(bin_path).mode | 0111
File.chmod mode, bin_path
@@ -229,10 +251,24 @@ class Gem::Installer
# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/193379
#
def generate_bin_script(filename, bindir)
- File.open(File.join(bindir, File.basename(filename)), "w", 0755) do |file|
- file.print app_script_text(filename)
- end
- generate_windows_script bindir, filename
+ bin_script_path = File.join bindir, formatted_program_filename(filename)
+
+ exec_path = File.join @gem_dir, @spec.bindir, filename
+
+ # HACK some gems don't have #! in their executables, restore 2008/06
+ #if File.read(exec_path, 2) == '#!' then
+ File.open bin_script_path, 'w', 0755 do |file|
+ file.print app_script_text(filename)
+ end
+
+ say bin_script_path if Gem.configuration.really_verbose
+
+ generate_windows_script bindir, filename
+ #else
+ # FileUtils.rm_f bin_script_path
+ # FileUtils.cp exec_path, bin_script_path,
+ # :verbose => Gem.configuration.really_verbose
+ #end
end
##
@@ -247,7 +283,7 @@ class Gem::Installer
end
src = File.join @gem_dir, 'bin', filename
- dst = File.join bindir, File.basename(filename)
+ dst = File.join bindir, formatted_program_filename(filename)
if File.exist? dst then
if File.symlink? dst then
@@ -258,7 +294,7 @@ class Gem::Installer
File.unlink dst
end
- File.symlink src, dst
+ FileUtils.symlink src, dst, :verbose => Gem.configuration.really_verbose
end
##
@@ -351,6 +387,9 @@ TEXT
begin
Dir.chdir File.join(@gem_dir, File.dirname(extension))
results = builder.build(extension, @gem_dir, dest_path, results)
+
+ say results.join("\n") if Gem.configuration.really_verbose
+
rescue => ex
results = results.join "\n"
@@ -402,6 +441,17 @@ Results logged to #{File.join(Dir.pwd, 'gem_make.out')}
File.open(path, "wb") do |out|
out.write file_data
end
+
+ say path if Gem.configuration.really_verbose
+ end
+ end
+
+ # Prefix and suffix the program filename the same as ruby.
+ def formatted_program_filename(filename)
+ if @format_executable then
+ self.class.exec_format % File.basename(filename)
+ else
+ filename
end
end
diff --git a/lib/rubygems/package.rb b/lib/rubygems/package.rb
index b613b7fa05..ee136b6267 100644
--- a/lib/rubygems/package.rb
+++ b/lib/rubygems/package.rb
@@ -142,6 +142,7 @@ module Gem::Package
end
def calculate_checksum(hdr)
+ #hdr.split('').map { |c| c[0] }.inject { |a, b| a + b } # HACK rubinius
hdr.unpack("C*").inject{|a,b| a+b}
end
diff --git a/lib/rubygems/platform.rb b/lib/rubygems/platform.rb
index 496c4b1fb8..7abc15ef94 100644
--- a/lib/rubygems/platform.rb
+++ b/lib/rubygems/platform.rb
@@ -12,6 +12,23 @@ class Gem::Platform
attr_accessor :version
+ DEPRECATED_CONSTS = [
+ :DARWIN,
+ :LINUX_586,
+ :MSWIN32,
+ :PPC_DARWIN,
+ :WIN32,
+ :X86_LINUX
+ ]
+
+ def self.const_missing(name) # TODO remove six months from 2007/12
+ if DEPRECATED_CONSTS.include? name then
+ raise NameError, "#{name} has been removed, use CURRENT instead"
+ else
+ super
+ end
+ end
+
def self.local
arch = Gem::ConfigMap[:arch]
arch = "#{arch}_60" if arch =~ /mswin32$/
@@ -160,33 +177,5 @@ class Gem::Platform
CURRENT = 'current'
- ##
- # A One Click Installer-compatible gem, built with VC6 for 32 bit Windows.
- #
- # CURRENT is preferred over this constant, avoid its use at all costs.
-
- MSWIN32 = new ['x86', 'mswin32', '60']
-
- ##
- # An x86 Linux-compatible gem
- #
- # CURRENT is preferred over this constant, avoid its use at all costs.
-
- X86_LINUX = new ['x86', 'linux', nil]
-
- ##
- # A PowerPC Darwin-compatible gem
- #
- # CURRENT is preferred over this constant, avoid its use at all costs.
-
- PPC_DARWIN = new ['ppc', 'darwin', nil]
-
- # :stopdoc:
- # Here lie legacy constants. These are deprecated.
- WIN32 = 'mswin32'
- LINUX_586 = 'i586-linux'
- DARWIN = 'powerpc-darwin'
- # :startdoc:
-
end
diff --git a/lib/rubygems/remote_fetcher.rb b/lib/rubygems/remote_fetcher.rb
index eac4ccaf01..cb22e1f1b1 100644
--- a/lib/rubygems/remote_fetcher.rb
+++ b/lib/rubygems/remote_fetcher.rb
@@ -16,7 +16,7 @@ class Gem::RemoteFetcher
# Cached RemoteFetcher instance.
def self.fetcher
- @fetcher ||= new Gem.configuration[:http_proxy]
+ @fetcher ||= self.new Gem.configuration[:http_proxy]
end
# Initialize a remote fetcher using the source URI and possible proxy
@@ -45,8 +45,12 @@ class Gem::RemoteFetcher
end
rescue Timeout::Error
raise FetchError, "timed out fetching #{uri}"
- rescue OpenURI::HTTPError, IOError, SocketError, SystemCallError => e
+ rescue IOError, SocketError, SystemCallError => e
raise FetchError, "#{e.class}: #{e} reading #{uri}"
+ rescue OpenURI::HTTPError => e
+ body = e.io.readlines.join "\n\t"
+ message = "#{e.class}: #{e} reading #{uri}\n\t#{body}"
+ raise FetchError, message
end
# Returns the size of +uri+ in bytes.
@@ -79,7 +83,7 @@ class Gem::RemoteFetcher
end
rescue SocketError, SystemCallError, Timeout::Error => e
- raise FetchError, "#{e.message} (#{e.class})"
+ raise FetchError, "#{e.message} (#{e.class})\n\tgetting size of #{uri}"
end
private
diff --git a/lib/rubygems/remote_installer.rb b/lib/rubygems/remote_installer.rb
deleted file mode 100644
index e33fd548f2..0000000000
--- a/lib/rubygems/remote_installer.rb
+++ /dev/null
@@ -1,195 +0,0 @@
-#--
-# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
-# All rights reserved.
-# See LICENSE.txt for permissions.
-#++
-
-require 'fileutils'
-
-require 'rubygems'
-require 'rubygems/installer'
-require 'rubygems/source_info_cache'
-
-module Gem
-
- class RemoteInstaller
-
- include UserInteraction
-
- # <tt>options[:http_proxy]</tt>::
- # * [String]: explicit specification of proxy; overrides any
- # environment variable setting
- # * nil: respect environment variables (HTTP_PROXY, HTTP_PROXY_USER, HTTP_PROXY_PASS)
- # * <tt>:no_proxy</tt>: ignore environment variables and _don't_
- # use a proxy
- #
- # * <tt>:cache_dir</tt>: override where downloaded gems are cached.
- def initialize(options={})
- @options = options
- @source_index_hash = nil
- end
-
- # This method will install package_name onto the local system.
- #
- # gem_name::
- # [String] Name of the Gem to install
- #
- # version_requirement::
- # [default = ">= 0"] Gem version requirement to install
- #
- # Returns::
- # an array of Gem::Specification objects, one for each gem installed.
- #
- def install(gem_name, version_requirement = Gem::Requirement.default,
- force = false, install_dir = Gem.dir)
- unless version_requirement.respond_to?(:satisfied_by?)
- version_requirement = Gem::Requirement.new [version_requirement]
- end
- installed_gems = []
- begin
- spec, source = find_gem_to_install(gem_name, version_requirement)
- dependencies = find_dependencies_not_installed(spec.dependencies)
-
- installed_gems << install_dependencies(dependencies, force, install_dir)
-
- cache_dir = @options[:cache_dir] || File.join(install_dir, "cache")
- destination_file = File.join(cache_dir, spec.full_name + ".gem")
-
- download_gem(destination_file, source, spec)
-
- installer = new_installer(destination_file)
- installed_gems.unshift installer.install(force, install_dir)
- rescue RemoteInstallationSkipped => e
- alert_error e.message
- end
- installed_gems.flatten
- end
-
- # Return a hash mapping the available source names to the source
- # index of that source.
- def source_index_hash
- return @source_index_hash if @source_index_hash
- @source_index_hash = {}
- Gem::SourceInfoCache.cache_data.each do |source_uri, sic_entry|
- @source_index_hash[source_uri] = sic_entry.source_index
- end
- @source_index_hash
- end
-
- # Finds the Gem::Specification objects and the corresponding source URI
- # for gems matching +gem_name+ and +version_requirement+
- def specs_n_sources_matching(gem_name, version_requirement)
- specs_n_sources = []
-
- source_index_hash.each do |source_uri, source_index|
- specs = source_index.search(/^#{Regexp.escape gem_name}$/i,
- version_requirement)
- # TODO move to SourceIndex#search?
- ruby_version = Gem::Version.new RUBY_VERSION
- specs = specs.select do |spec|
- spec.required_ruby_version.nil? or
- spec.required_ruby_version.satisfied_by? ruby_version
- end
- specs.each { |spec| specs_n_sources << [spec, source_uri] }
- end
-
- if specs_n_sources.empty? then
- raise GemNotFoundException, "Could not find #{gem_name} (#{version_requirement}) in any repository"
- end
-
- specs_n_sources = specs_n_sources.sort_by { |gs,| gs.version }.reverse
-
- specs_n_sources
- end
-
- # Find a gem to be installed by interacting with the user.
- def find_gem_to_install(gem_name, version_requirement)
- specs_n_sources = specs_n_sources_matching gem_name, version_requirement
-
- top_3_versions = specs_n_sources.map{|gs| gs.first.version}.uniq[0..3]
- specs_n_sources.reject!{|gs| !top_3_versions.include?(gs.first.version)}
-
- binary_gems = specs_n_sources.reject { |item|
- item[0].platform.nil? || item[0].platform==Platform::RUBY
- }
-
- # only non-binary gems...return latest
- return specs_n_sources.first if binary_gems.empty?
-
- list = specs_n_sources.collect { |spec, source_uri|
- "#{spec.name} #{spec.version} (#{spec.platform})"
- }
-
- list << "Skip this gem"
- list << "Cancel installation"
-
- string, index = choose_from_list(
- "Select which gem to install for your platform (#{RUBY_PLATFORM})",
- list)
-
- if index.nil? or index == (list.size - 1) then
- raise RemoteInstallationCancelled, "Installation of #{gem_name} cancelled."
- end
-
- if index == (list.size - 2) then
- raise RemoteInstallationSkipped, "Installation of #{gem_name} skipped."
- end
-
- specs_n_sources[index]
- end
-
- def find_dependencies_not_installed(dependencies)
- to_install = []
- dependencies.each do |dependency|
- srcindex = Gem::SourceIndex.from_installed_gems
- matches = srcindex.find_name(dependency.name, dependency.requirement_list)
- to_install.push dependency if matches.empty?
- end
- to_install
- end
-
- # Install all the given dependencies. Returns an array of
- # Gem::Specification objects, one for each dependency installed.
- #
- # TODO: For now, we recursively install, but this is not the right
- # way to do things (e.g. if a package fails to download, we
- # shouldn't install anything).
- def install_dependencies(dependencies, force, install_dir)
- return if @options[:ignore_dependencies]
- installed_gems = []
- dependencies.each do |dep|
- if @options[:include_dependencies] ||
- ask_yes_no("Install required dependency #{dep.name}?", true)
- remote_installer = RemoteInstaller.new @options
- installed_gems << remote_installer.install(dep.name,
- dep.version_requirements,
- force, install_dir)
- elsif force then
- # ignore
- else
- raise DependencyError, "Required dependency #{dep.name} not installed"
- end
- end
- installed_gems
- end
-
- def download_gem(destination_file, source, spec)
- return if File.exist? destination_file
- uri = source + "/gems/#{spec.full_name}.gem"
- response = Gem::RemoteFetcher.fetcher.fetch_path uri
- write_gem_to_file response, destination_file
- end
-
- def write_gem_to_file(body, destination_file)
- FileUtils.mkdir_p(File.dirname(destination_file)) unless File.exist?(destination_file)
- File.open(destination_file, 'wb') do |out|
- out.write(body)
- end
- end
-
- def new_installer(gem)
- return Installer.new(gem, @options)
- end
- end
-
-end
diff --git a/lib/rubygems/rubygems_version.rb b/lib/rubygems/rubygems_version.rb
index d08789baf6..85e18d48a4 100644
--- a/lib/rubygems/rubygems_version.rb
+++ b/lib/rubygems/rubygems_version.rb
@@ -2,5 +2,5 @@
# This file is auto-generated by build scripts.
# See: rake update_version
module Gem
- RubyGemsVersion = '0.9.5'
+ RubyGemsVersion = '1.0.0'
end
diff --git a/lib/rubygems/security.rb b/lib/rubygems/security.rb
index 6f6586e9cf..415e98ffc0 100644
--- a/lib/rubygems/security.rb
+++ b/lib/rubygems/security.rb
@@ -318,7 +318,7 @@ require 'rubygems/gem_openssl'
module Gem::Security
- class Exception < Exception; end
+ class Exception < Gem::Exception; end
#
# default options for most of the methods below
diff --git a/lib/rubygems/server.rb b/lib/rubygems/server.rb
index 212ccc5f7e..ed957dd38a 100644
--- a/lib/rubygems/server.rb
+++ b/lib/rubygems/server.rb
@@ -368,19 +368,34 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; }
when '/quick/index.rz' then
index = @source_index.map { |name,_| name }.join("\n")
res.body << Zlib::Deflate.deflate(index)
- when %r|^/quick/(.*)-([0-9.]+)\.gemspec(\.marshal)?\.rz$| then
- specs = @source_index.search $1, $2
+ when %r|^/quick/(Marshal.#{Regexp.escape Gem.marshal_version}/)?(.*?)-([0-9.]+)(-.*?)?\.gemspec\.rz$| then
+ dep = Gem::Dependency.new $2, $3
+ specs = @source_index.search dep
+
+ selector = [$2, $3, $4].map { |s| s.inspect }.join ' '
+
+ platform = if $4 then
+ Gem::Platform.new $4.sub(/^-/, '')
+ else
+ Gem::Platform::RUBY
+ end
+
+ specs = specs.select { |s| s.platform == platform }
+
if specs.empty? then
res.status = 404
+ res.body = "No gems found matching #{selector}"
elsif specs.length > 1 then
res.status = 500
- elsif $3 # marshal quickindex instead of YAML
+ res.body = "Multiple gems found matching #{selector}"
+ elsif $1 then # marshal quickindex instead of YAML
res.body << Zlib::Deflate.deflate(Marshal.dump(specs.first))
else # deprecated YAML format
res.body << Zlib::Deflate.deflate(specs.first.to_yaml)
end
else
res.status = 404
+ res.body = "#{req.request_uri} not found"
end
end
diff --git a/lib/rubygems/source_index.rb b/lib/rubygems/source_index.rb
index 759718d45c..2df28d9561 100644
--- a/lib/rubygems/source_index.rb
+++ b/lib/rubygems/source_index.rb
@@ -4,8 +4,6 @@
# See LICENSE.txt for permissions.
#++
-require 'forwardable'
-
require 'rubygems'
require 'rubygems/user_interaction'
require 'rubygems/specification'
@@ -23,7 +21,6 @@ module Gem
# YAMLized source index objects to load properly.
#
class SourceIndex
- extend Forwardable
include Enumerable
@@ -186,40 +183,40 @@ module Gem
Gem::SHA256.new.hexdigest(@gems[gem_full_name].to_yaml).to_s
end
- def_delegators :@gems, :size, :length
+ def size
+ @gems.size
+ end
+ alias length size
# Find a gem by an exact match on the short name.
def find_name(gem_name, version_requirement = Gem::Requirement.default)
search(/^#{gem_name}$/, version_requirement)
end
- # Search for a gem by short name pattern and optional version
- #
- # gem_name::
- # [String] a partial for the (short) name of the gem, or
- # [Regex] a pattern to match against the short name
- # version_requirement::
- # [String | default=Gem::Requirement.default] version to
- # find
- # return::
- # [Array] list of Gem::Specification objects in sorted (version)
- # order. Empty if not found.
+ # Search for a gem by Gem::Dependency +gem_pattern+. If +only_platform+
+ # is true, only gems matching Gem::Platform.local will be returned. An
+ # Array of matching Gem::Specification objects is returned.
#
- def search(gem_pattern, platform_only_or_version_req = false)
+ # For backwards compatibility, a String or Regexp pattern may be passed as
+ # +gem_pattern+, and a Gem::Requirement for +platform_only+. This
+ # behavior is deprecated and will be removed.
+ def search(gem_pattern, platform_only = false)
version_requirement = nil
only_platform = false
- case gem_pattern
+ case gem_pattern # TODO warn after 2008/03, remove three months after
when Regexp then
- version_requirement = platform_only_or_version_req ||
- Gem::Requirement.default
+ version_requirement = platform_only || Gem::Requirement.default
when Gem::Dependency then
- only_platform = platform_only_or_version_req
+ only_platform = platform_only
version_requirement = gem_pattern.version_requirements
- gem_pattern = gem_pattern.name.empty? ? // : /^#{gem_pattern.name}$/
+ gem_pattern = if gem_pattern.name.empty? then
+ //
+ else
+ /^#{Regexp.escape gem_pattern.name}$/
+ end
else
- version_requirement = platform_only_or_version_req ||
- Gem::Requirement.default
+ version_requirement = platform_only || Gem::Requirement.default
gem_pattern = /#{gem_pattern}/i
end
diff --git a/lib/rubygems/source_info_cache.rb b/lib/rubygems/source_info_cache.rb
index 0498e895a4..c84868a5f5 100644
--- a/lib/rubygems/source_info_cache.rb
+++ b/lib/rubygems/source_info_cache.rb
@@ -176,7 +176,7 @@ class Gem::SourceInfoCache
# The name of the system cache file. (class method)
def self.system_cache_file
- @system_cache_file ||= File.join(Gem.dir, "source_cache")
+ @system_cache_file ||= Gem.default_system_source_cache_dir
end
# The name of the user cache file.
@@ -187,7 +187,7 @@ class Gem::SourceInfoCache
# The name of the user cache file. (class method)
def self.user_cache_file
@user_cache_file ||=
- ENV['GEMCACHE'] || File.join(Gem.user_home, ".gem", "source_cache")
+ ENV['GEMCACHE'] || Gem.default_user_source_cache_dir
end
# Write data to the proper cache.
@@ -217,7 +217,7 @@ class Gem::SourceInfoCache
unless File.exist? dir then
begin
FileUtils.mkdir_p(dir)
- rescue RuntimeError
+ rescue RuntimeError, SystemCallError
return nil
end
end
diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb
index 4a785fa600..35f2ffdffe 100644
--- a/lib/rubygems/specification.rb
+++ b/lib/rubygems/specification.rb
@@ -4,17 +4,18 @@
# See LICENSE.txt for permissions.
#++
-require 'time'
require 'rubygems'
require 'rubygems/version'
require 'rubygems/platform'
# :stopdoc:
# Time::today has been deprecated in 0.9.5 and will be removed.
-def Time.today
- t = Time.now
- t - ((t.to_i + t.gmt_offset) % 86400)
-end unless defined? Time.today
+if RUBY_VERSION < '1.9' then
+ def Time.today
+ t = Time.now
+ t - ((t.to_i + t.gmt_offset) % 86400)
+ end unless defined? Time.today
+end
# :startdoc:
module Gem
@@ -239,7 +240,7 @@ module Gem
@specification_version,
@name,
@version,
- (Time === @date ? @date : Time.parse(@date.to_s)),
+ (Time === @date ? @date : (require 'time'; Time.parse(@date.to_s))),
@summary,
@required_ruby_version,
@required_rubygems_version,
@@ -293,14 +294,9 @@ module Gem
spec
end
- def warn_deprecated(old, new)
- # How (if at all) to implement this? We only want to warn when
- # a gem is being built, I should think.
- end
-
# REQUIRED gemspec attributes ------------------------------------
- required_attribute :rubygems_version, RubyGemsVersion
+ required_attribute :rubygems_version, Gem::RubyGemsVersion
required_attribute :specification_version, CURRENT_SPECIFICATION_VERSION
required_attribute :name
required_attribute :version
@@ -349,12 +345,12 @@ module Gem
# DEPRECATED gemspec attributes ----------------------------------
def test_suite_file
- warn_deprecated(:test_suite_file, :test_files)
+ warn 'test_suite_file deprecated, use test_files'
test_files.first
end
def test_suite_file=(val)
- warn_deprecated(:test_suite_file, :test_files)
+ warn 'test_suite_file= deprecated, use test_files='
@test_files = [] unless defined? @test_files
@test_files << val
end
@@ -386,6 +382,7 @@ module Gem
case platform
when Gem::Platform::CURRENT then
@new_platform = Gem::Platform.local
+ @original_platform = @new_platform.to_s
when Gem::Platform then
@new_platform = platform
@@ -393,14 +390,14 @@ module Gem
# legacy constants
when nil, Gem::Platform::RUBY then
@new_platform = Gem::Platform::RUBY
- when Gem::Platform::WIN32 then
- @new_platform = Gem::Platform::MSWIN32
- when Gem::Platform::LINUX_586 then
- @new_platform = Gem::Platform::X86_LINUX
- when Gem::Platform::DARWIN then
- @new_platform = Gem::Platform::PPC_DARWIN
+ when 'mswin32' then # was Gem::Platform::WIN32
+ @new_platform = Gem::Platform.new 'x86-mswin32'
+ when 'i586-linux' then # was Gem::Platform::LINUX_586
+ @new_platform = Gem::Platform.new 'x86-linux'
+ when 'powerpc-darwin' then # was Gem::Platform::DARWIN
+ @new_platform = Gem::Platform.new 'ppc-darwin'
else
- @new_platform = platform
+ @new_platform = Gem::Platform.new platform
end
@platform = @new_platform.to_s
@@ -422,11 +419,16 @@ module Gem
# way to do it.
case date
when String then
- @date = Time.parse date
+ @date = if /\A(\d{4})-(\d{2})-(\d{2})\Z/ =~ date then
+ Time.local($1.to_i, $2.to_i, $3.to_i)
+ else
+ require 'time'
+ Time.parse date
+ end
when Time then
- @date = Time.parse date.strftime("%Y-%m-%d")
+ @date = Time.local(date.year, date.month, date.day)
when Date then
- @date = Time.parse date.to_s
+ @date = Time.local(date.year, date.month, date.day)
else
@date = TODAY
end
@@ -751,7 +753,10 @@ module Gem
out.map taguri, to_yaml_style do |map|
map.add 'name', @name
map.add 'version', @version
- platform = if String === @original_platform then
+ platform = case @original_platform
+ when nil, '' then
+ 'ruby'
+ when String then
@original_platform
else
@original_platform.to_s
@@ -801,13 +806,14 @@ module Gem
:version,
]
- attributes = @@attributes.sort_by { |name,| name.to_s }
+ attributes = @@attributes.sort_by { |attr_name,| attr_name.to_s }
- attributes.each do |name, default|
- next if handled.include? name
- current_value = self.send(name)
- if current_value != default or self.class.required_attribute? name then
- result << " s.#{name} = #{ruby_code current_value}"
+ attributes.each do |attr_name, default|
+ next if handled.include? attr_name
+ current_value = self.send(attr_name)
+ if current_value != default or
+ self.class.required_attribute? attr_name then
+ result << " s.#{attr_name} = #{ruby_code current_value}"
end
end
@@ -832,6 +838,8 @@ module Gem
# Raises InvalidSpecificationException if the spec does not pass
# the checks..
def validate
+ extend Gem::UserInteraction
+
normalize
if rubygems_version != RubyGemsVersion then
@@ -858,6 +866,31 @@ module Gem
"invalid platform #{platform.inspect}, see Gem::Platform"
end
+ unless Array === authors and
+ authors.all? { |author| String === author } then
+ raise Gem::InvalidSpecificationException,
+ 'authors must be Array of Strings'
+ end
+
+ # Warnings
+
+ %w[author email homepage rubyforge_project summary].each do |attribute|
+ value = self.send attribute
+ alert_warning "no #{attribute} specified" if value.nil? or value.empty?
+ end
+
+ alert_warning "RDoc will not be generated (has_rdoc == false)" unless
+ has_rdoc
+
+ alert_warning "deprecated autorequire specified" if autorequire
+
+ executables.each do |executable|
+ executable_path = File.join bindir, executable
+ shebang = File.read(executable_path, 2) == '#!'
+
+ alert_warning "#{executable_path} is missing #! line" unless shebang
+ end
+
true
end
diff --git a/lib/rubygems/uninstaller.rb b/lib/rubygems/uninstaller.rb
index f26de152dd..268c0b3b83 100644
--- a/lib/rubygems/uninstaller.rb
+++ b/lib/rubygems/uninstaller.rb
@@ -144,7 +144,7 @@ class Gem::Uninstaller
cache_dir = File.join spec.installation_path, 'cache'
gem = File.join cache_dir, "#{spec.full_name}.gem"
- unless File.exist? gemspec then
+ unless File.exist? gem then
gem = File.join cache_dir, "#{original_platform_name}.gem"
end
diff --git a/lib/rubygems/validator.rb b/lib/rubygems/validator.rb
index 8130f49bc8..41c457c3cf 100755
--- a/lib/rubygems/validator.rb
+++ b/lib/rubygems/validator.rb
@@ -157,8 +157,9 @@ module Gem
# XXX: why do we need this gem_spec when we've already got 'spec'?
test_files = gem_spec.test_files
if test_files.empty?
- say "There are no unit tests to run for #{gem_spec.name}-#{gem_spec.version}"
- return
+ say "There are no unit tests to run for #{gem_spec.full_name}"
+ require 'test/unit/ui/console/testrunner'
+ return Test::Unit::TestResult.new
end
gem gem_spec.name, "= #{gem_spec.version.version}"
test_files.each do |f| require f end
diff --git a/lib/rubygems/version.rb b/lib/rubygems/version.rb
index 35dd60a74a..87a1bc72ed 100644
--- a/lib/rubygems/version.rb
+++ b/lib/rubygems/version.rb
@@ -75,7 +75,7 @@ class Gem::Version
# Strip ignored trailing zeros.
def normalize
- @ints = @version.to_s.scan(/\d+/).map { |s| s.to_i }
+ @ints = build_array_from_version_string
return if @ints.length == 1
@@ -127,19 +127,26 @@ class Gem::Version
@ints <=> other.ints
end
- def hash
+ alias eql? == # :nodoc:
+
+ def hash # :nodoc:
to_ints.inject { |hash_code, n| hash_code + n }
end
# Return a new version object where the next to the last revision
# number is one greater. (e.g. 5.3.1 => 5.4)
def bump
- ints = @ints.dup
+ ints = build_array_from_version_string
ints.pop if ints.size > 1
ints[-1] += 1
self.class.new(ints.join("."))
end
+ def build_array_from_version_string
+ @version.to_s.scan(/\d+/).map { |s| s.to_i }
+ end
+ private :build_array_from_version_string
+
#:stopdoc:
require 'rubygems/requirement'
diff --git a/test/rubygems/gemutilities.rb b/test/rubygems/gemutilities.rb
index bb54ff6362..460d8f2080 100644
--- a/test/rubygems/gemutilities.rb
+++ b/test/rubygems/gemutilities.rb
@@ -89,6 +89,9 @@ class RubyGemTestCase < Test::Unit::TestCase
@gem_repo = "http://gems.example.com"
Gem.sources.replace [@gem_repo]
+ @orig_BASERUBY = Gem::ConfigMap[:BASERUBY]
+ Gem::ConfigMap[:BASERUBY] = Gem::ConfigMap[:RUBY_INSTALL_NAME]
+
@orig_arch = Gem::ConfigMap[:arch]
if win_platform?
@@ -101,6 +104,7 @@ class RubyGemTestCase < Test::Unit::TestCase
end
def teardown
+ Gem::ConfigMap[:BASERUBY] = @orig_BASERUBY
Gem::ConfigMap[:arch] = @orig_arch
if defined? Gem::RemoteFetcher then
@@ -153,7 +157,7 @@ class RubyGemTestCase < Test::Unit::TestCase
path
end
- def quick_gem(gemname, version='0.0.2')
+ def quick_gem(gemname, version='2')
require 'rubygems/specification'
spec = Gem::Specification.new do |s|
@@ -166,6 +170,7 @@ class RubyGemTestCase < Test::Unit::TestCase
s.has_rdoc = true
s.summary = "this is a summary"
s.description = "This is a test description"
+
yield(s) if block_given?
end
@@ -205,9 +210,9 @@ class RubyGemTestCase < Test::Unit::TestCase
s.require_paths = %w[lib]
end
- @a0_0_1 = quick_gem('a', '0.0.1', &spec)
- @a0_0_2 = quick_gem('a', '0.0.2', &spec)
- @b0_0_2 = quick_gem('b', '0.0.2', &spec)
+ @a1 = quick_gem('a', '1', &spec)
+ @a2 = quick_gem('a', '2', &spec)
+ @b2 = quick_gem('b', '2', &spec)
@c1_2 = quick_gem('c', '1.2', &spec)
@pl1 = quick_gem 'pl', '1' do |s| # l for legacy
s.files = %w[lib/code.rb]
@@ -216,13 +221,13 @@ class RubyGemTestCase < Test::Unit::TestCase
s.instance_variable_set :@original_platform, 'i386-linux'
end
- write_file File.join(*%W[gems #{@a0_0_1.original_name} lib code.rb]) do end
- write_file File.join(*%W[gems #{@a0_0_2.original_name} lib code.rb]) do end
- write_file File.join(*%W[gems #{@b0_0_2.original_name} lib code.rb]) do end
+ write_file File.join(*%W[gems #{@a1.original_name} lib code.rb]) do end
+ write_file File.join(*%W[gems #{@a2.original_name} lib code.rb]) do end
+ write_file File.join(*%W[gems #{@b2.original_name} lib code.rb]) do end
write_file File.join(*%W[gems #{@c1_2.original_name} lib code.rb]) do end
write_file File.join(*%W[gems #{@pl1.original_name} lib code.rb]) do end
- [@a0_0_1, @a0_0_2, @b0_0_2, @c1_2, @pl1].each { |spec| util_build_gem spec }
+ [@a1, @a2, @b2, @c1_2, @pl1].each { |spec| util_build_gem spec }
FileUtils.rm_r File.join(@gemhome, 'gems', @pl1.original_name)
diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb
index 4fe5e8661c..c5ed86a489 100644
--- a/test/rubygems/test_gem.rb
+++ b/test/rubygems/test_gem.rb
@@ -2,6 +2,7 @@ require 'test/unit'
require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
require 'rubygems'
require 'rubygems/gem_openssl'
+require 'rubygems/installer'
require 'pathname'
class TestGem < RubyGemTestCase
@@ -17,9 +18,9 @@ class TestGem < RubyGemTestCase
util_make_gems
expected = [
- File.join(@gemhome, *%W[gems #{@a0_0_1.full_name} lib]),
- File.join(@gemhome, *%W[gems #{@a0_0_2.full_name} lib]),
- File.join(@gemhome, *%W[gems #{@b0_0_2.full_name} lib]),
+ File.join(@gemhome, *%W[gems #{@a1.full_name} lib]),
+ File.join(@gemhome, *%W[gems #{@a2.full_name} lib]),
+ File.join(@gemhome, *%W[gems #{@b2.full_name} lib]),
File.join(@gemhome, *%W[gems #{@c1_2.full_name} lib]),
File.join(@gemhome, *%W[gems #{@pl1.full_name} lib]),
]
@@ -89,6 +90,42 @@ class TestGem < RubyGemTestCase
assert_match @default_dir_re, Gem.default_dir
end
+ def test_self_default_exec_format
+ orig_BASERUBY = Gem::ConfigMap[:BASERUBY]
+ orig_RUBY_INSTALL_NAME = Gem::ConfigMap[:RUBY_INSTALL_NAME]
+ Gem::ConfigMap[:BASERUBY] = 'ruby'
+ Gem::ConfigMap[:RUBY_INSTALL_NAME] = 'ruby'
+
+ assert_equal '%s', Gem.default_exec_format
+ ensure
+ Gem::ConfigMap[:BASERUBY] = orig_BASERUBY
+ Gem::ConfigMap[:RUBY_INSTALL_NAME] = orig_RUBY_INSTALL_NAME
+ end
+
+ def test_self_default_exec_format_18
+ orig_BASERUBY = Gem::ConfigMap[:BASERUBY]
+ orig_RUBY_INSTALL_NAME = Gem::ConfigMap[:RUBY_INSTALL_NAME]
+ Gem::ConfigMap[:BASERUBY] = 'ruby'
+ Gem::ConfigMap[:RUBY_INSTALL_NAME] = 'ruby18'
+
+ assert_equal '%s18', Gem.default_exec_format
+ ensure
+ Gem::ConfigMap[:BASERUBY] = orig_BASERUBY
+ Gem::ConfigMap[:RUBY_INSTALL_NAME] = orig_RUBY_INSTALL_NAME
+ end
+
+ def test_self_default_exec_format_jruby
+ orig_BASERUBY = Gem::ConfigMap[:BASERUBY]
+ orig_RUBY_INSTALL_NAME = Gem::ConfigMap[:RUBY_INSTALL_NAME]
+ Gem::ConfigMap[:BASERUBY] = 'ruby'
+ Gem::ConfigMap[:RUBY_INSTALL_NAME] = 'jruby'
+
+ assert_equal 'j%s', Gem.default_exec_format
+ ensure
+ Gem::ConfigMap[:BASERUBY] = orig_BASERUBY
+ Gem::ConfigMap[:RUBY_INSTALL_NAME] = orig_RUBY_INSTALL_NAME
+ end
+
def test_self_default_sources
assert_equal %w[http://gems.rubyforge.org], Gem.default_sources
end
@@ -174,8 +211,8 @@ class TestGem < RubyGemTestCase
util_make_gems
expected = [
- File.join(@gemhome, *%W[gems #{@a0_0_2.full_name} lib]),
- File.join(@gemhome, *%W[gems #{@b0_0_2.full_name} lib]),
+ File.join(@gemhome, *%W[gems #{@a2.full_name} lib]),
+ File.join(@gemhome, *%W[gems #{@b2.full_name} lib]),
File.join(@gemhome, *%W[gems #{@c1_2.full_name} lib]),
File.join(@gemhome, *%W[gems #{@pl1.full_name} lib]),
]
@@ -251,10 +288,10 @@ class TestGem < RubyGemTestCase
assert_equal File.join(@tempdir, *%w[gemhome gems c-1.2 lib code.rb]),
Gem.required_location("c", "code.rb")
- assert_equal File.join(@tempdir, *%w[gemhome gems a-0.0.1 lib code.rb]),
- Gem.required_location("a", "code.rb", "<0.0.2")
- assert_equal File.join(@tempdir, *%w[gemhome gems a-0.0.2 lib code.rb]),
- Gem.required_location("a", "code.rb", "=0.0.2")
+ assert_equal File.join(@tempdir, *%w[gemhome gems a-1 lib code.rb]),
+ Gem.required_location("a", "code.rb", "< 2")
+ assert_equal File.join(@tempdir, *%w[gemhome gems a-2 lib code.rb]),
+ Gem.required_location("a", "code.rb", "= 2")
end
def test_self_searcher
@@ -298,73 +335,6 @@ class TestGem < RubyGemTestCase
end
end
- def test_require_gem_autorequire
- name = "AutorequireArray"
- files = %w(a.rb b.rb)
- gem = quick_gem(name) do |s|
- s.files = files.map { |f| File.join("lib", f) }
- s.autorequire = files
- end
-
- fullname = gem.full_name
-
- write_file "gems/#{fullname}/lib/a.rb" do |io|
- io.puts "$LOADED_A = true"
- end
-
- write_file "gems/#{fullname}/lib/b.rb" do |io|
- io.puts "$LOADED_B = true"
- end
-
- Gem.source_index = nil
-
- old_loaded = $".dup
- old_verbose = $VERBOSE
- $VERBOSE = nil
- require_gem name
- $VERBOSE = old_verbose
- new_loaded = $".dup
-
- if RUBY_VERSION > "1.9" then
- files = files.map do |file|
- File.join @gemhome, 'gems', gem.full_name, 'lib', file
- end
- end
-
- assert_equal files, (new_loaded - old_loaded)
- assert defined?($LOADED_A)
- assert defined?($LOADED_B)
- end
-
- def test_require_gem_autorequire_string
- name = "AutorequireString"
- file = "c.rb"
- gem = quick_gem(name) do |s|
- s.files = File.join("lib", file)
- s.autorequire = file
- end
-
- fullname = gem.full_name
-
- write_file("gems/#{fullname}/lib/c.rb") do |io|
- io.puts "$LOADED_C = true"
- end
-
- old_loaded = $".dup
- old_verbose = $VERBOSE
- $VERBOSE = nil
- require_gem name
- $VERBOSE = old_verbose
- new_loaded = $".dup
-
- if RUBY_VERSION > "1.9" then
- file = File.join @gemhome, 'gems', gem.full_name, 'lib', file
- end
-
- assert_equal(Array(file), (new_loaded - old_loaded))
- assert(defined? $LOADED_C)
- end
-
def util_ensure_gem_dirs
Gem.ensure_gem_subdirectories @gemhome
@additional.each do |dir|
diff --git a/test/rubygems/test_gem_commands_build_command.rb b/test/rubygems/test_gem_commands_build_command.rb
index f1fd1503ba..a49b6777bd 100644
--- a/test/rubygems/test_gem_commands_build_command.rb
+++ b/test/rubygems/test_gem_commands_build_command.rb
@@ -8,31 +8,31 @@ class TestGemCommandsBuildCommand < RubyGemTestCase
def setup
super
+ @gem = quick_gem 'some_gem' do |s|
+ s.rubyforge_project = 'example'
+ end
+
@cmd = Gem::Commands::BuildCommand.new
end
def test_execute
- gem = quick_gem 'some_gem'
-
- gemspec_file = File.join(@tempdir, "#{gem.full_name}.gemspec")
+ gemspec_file = File.join(@tempdir, "#{@gem.full_name}.gemspec")
File.open gemspec_file, 'w' do |gs|
- gs.write gem.to_ruby
+ gs.write @gem.to_ruby
end
- util_test_build_gem gem, gemspec_file
+ util_test_build_gem @gem, gemspec_file
end
def test_execute_yaml
- gem = quick_gem 'some_gem'
-
- gemspec_file = File.join(@tempdir, "#{gem.full_name}.gemspec")
+ gemspec_file = File.join(@tempdir, "#{@gem.full_name}.gemspec")
File.open gemspec_file, 'w' do |gs|
- gs.write gem.to_yaml
+ gs.write @gem.to_yaml
end
- util_test_build_gem gem, gemspec_file
+ util_test_build_gem @gem, gemspec_file
end
def test_execute_bad_gem
@@ -57,8 +57,8 @@ class TestGemCommandsBuildCommand < RubyGemTestCase
output = @ui.output.split "\n"
assert_equal " Successfully built RubyGem", output.shift
assert_equal " Name: some_gem", output.shift
- assert_equal " Version: 0.0.2", output.shift
- assert_equal " File: some_gem-0.0.2.gem", output.shift
+ assert_equal " Version: 2", output.shift
+ assert_equal " File: some_gem-2.gem", output.shift
assert_equal [], output
assert_equal '', @ui.error
diff --git a/test/rubygems/test_gem_commands_dependency_command.rb b/test/rubygems/test_gem_commands_dependency_command.rb
index 9bf59537fd..0f0d95695d 100644
--- a/test/rubygems/test_gem_commands_dependency_command.rb
+++ b/test/rubygems/test_gem_commands_dependency_command.rb
@@ -13,7 +13,7 @@ class TestGemCommandsDependencyCommand < RubyGemTestCase
def test_execute
quick_gem 'foo' do |gem|
- gem.add_dependency 'bar', '> 1.0.0'
+ gem.add_dependency 'bar', '> 1'
end
@cmd.options[:args] = %w[foo]
@@ -22,7 +22,7 @@ class TestGemCommandsDependencyCommand < RubyGemTestCase
@cmd.execute
end
- assert_equal "Gem foo-0.0.2\n bar (> 1.0.0)\n\n", @ui.output
+ assert_equal "Gem foo-2\n bar (> 1)\n\n", @ui.output
assert_equal '', @ui.error
end
@@ -41,7 +41,7 @@ class TestGemCommandsDependencyCommand < RubyGemTestCase
def test_execute_pipe_format
quick_gem 'foo' do |gem|
- gem.add_dependency 'bar', '> 1.0.0'
+ gem.add_dependency 'bar', '> 1'
end
@cmd.options[:args] = %w[foo]
@@ -51,13 +51,13 @@ class TestGemCommandsDependencyCommand < RubyGemTestCase
@cmd.execute
end
- assert_equal "bar --version '> 1.0.0'\n", @ui.output
+ assert_equal "bar --version '> 1'\n", @ui.output
assert_equal '', @ui.error
end
def test_execute_reverse
quick_gem 'foo' do |gem|
- gem.add_dependency 'bar', '> 1.0.0'
+ gem.add_dependency 'bar', '> 1'
end
quick_gem 'baz' do |gem|
@@ -72,10 +72,10 @@ class TestGemCommandsDependencyCommand < RubyGemTestCase
end
expected = <<-EOF
-Gem foo-0.0.2
- bar (> 1.0.0)
+Gem foo-2
+ bar (> 1)
Used by
- baz-0.0.2 (foo (>= 0))
+ baz-2 (foo (>= 0))
EOF
@@ -85,7 +85,7 @@ Gem foo-0.0.2
def test_execute_remote
foo = quick_gem 'foo' do |gem|
- gem.add_dependency 'bar', '> 1.0.0'
+ gem.add_dependency 'bar', '> 1'
end
util_setup_source_info_cache foo
@@ -100,7 +100,7 @@ Gem foo-0.0.2
@cmd.execute
end
- assert_equal "Gem foo-0.0.2\n bar (> 1.0.0)\n\n", @ui.output
+ assert_equal "Gem foo-2\n bar (> 1)\n\n", @ui.output
assert_equal '', @ui.error
end
diff --git a/test/rubygems/test_gem_commands_mirror_command.rb b/test/rubygems/test_gem_commands_mirror_command.rb
index 7ddc8b92f8..359ba5481e 100644
--- a/test/rubygems/test_gem_commands_mirror_command.rb
+++ b/test/rubygems/test_gem_commands_mirror_command.rb
@@ -34,7 +34,12 @@ class TestGemCommandsMirrorCommand < RubyGemTestCase
File.open File.join(Gem.user_home, '.gemmirrorrc'), 'w' do |fp|
fp.puts "---"
- fp.puts "- from: file://#{@tempdir}"
+ # tempdir could be a drive+path (under windows)
+ if @tempdir.match(/[a-z]:/i)
+ fp.puts "- from: file:///#{@tempdir}"
+ else
+ fp.puts "- from: file://#{@tempdir}"
+ end
fp.puts " to: #{mirror}"
end
@@ -42,9 +47,9 @@ class TestGemCommandsMirrorCommand < RubyGemTestCase
@cmd.execute
end
- assert File.exist?(File.join(mirror, 'gems', "#{@a0_0_1.full_name}.gem"))
- assert File.exist?(File.join(mirror, 'gems', "#{@a0_0_2.full_name}.gem"))
- assert File.exist?(File.join(mirror, 'gems', "#{@b0_0_2.full_name}.gem"))
+ assert File.exist?(File.join(mirror, 'gems', "#{@a1.full_name}.gem"))
+ assert File.exist?(File.join(mirror, 'gems', "#{@a2.full_name}.gem"))
+ assert File.exist?(File.join(mirror, 'gems', "#{@b2.full_name}.gem"))
assert File.exist?(File.join(mirror, 'gems', "#{@c1_2.full_name}.gem"))
assert File.exist?(File.join(mirror, "Marshal.#{@marshal_version}"))
ensure
diff --git a/test/rubygems/test_gem_commands_query_command.rb b/test/rubygems/test_gem_commands_query_command.rb
index e2b6a45e92..4430ccfd33 100644
--- a/test/rubygems/test_gem_commands_query_command.rb
+++ b/test/rubygems/test_gem_commands_query_command.rb
@@ -10,13 +10,17 @@ class TestGemCommandsQueryCommand < RubyGemTestCase
@foo_gem = quick_gem 'foo' do |spec|
spec.summary = 'This is a lot of text. ' * 5
end
+ @foo_gem_p = quick_gem 'foo' do |spec|
+ spec.summary = 'This is a lot of text. ' * 5
+ spec.platform = Gem::Platform::CURRENT
+ end
@bar_gem = quick_gem 'bar'
@cmd = Gem::Commands::QueryCommand.new
end
def test_execute
- util_setup_source_info_cache @foo_gem
+ util_setup_source_info_cache @foo_gem, @foo_gem_p
@cmd.handle_options %w[-r]
@@ -28,7 +32,7 @@ class TestGemCommandsQueryCommand < RubyGemTestCase
*** REMOTE GEMS ***
-foo (0.0.2)
+foo (2)
EOF
assert_equal expected, @ui.output
@@ -48,7 +52,7 @@ foo (0.0.2)
*** REMOTE GEMS ***
-foo (0.0.2)
+foo (2)
This is a lot of text. This is a lot of text. This is a lot of
text. This is a lot of text. This is a lot of text.
EOF
diff --git a/test/rubygems/test_gem_commands_server_command.rb b/test/rubygems/test_gem_commands_server_command.rb
new file mode 100644
index 0000000000..3e6af2e11c
--- /dev/null
+++ b/test/rubygems/test_gem_commands_server_command.rb
@@ -0,0 +1,27 @@
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/commands/server_command'
+
+class TestGemCommandsServerCommand < RubyGemTestCase
+
+ def setup
+ super
+
+ @cmd = Gem::Commands::ServerCommand.new
+ end
+
+ def test_handle_options
+ @cmd.send :handle_options, %w[-p 8808 --no-daemon]
+
+ assert_equal false, @cmd.options[:daemon]
+ assert_equal @gemhome, @cmd.options[:gemdir]
+ assert_equal 8808, @cmd.options[:port]
+
+ @cmd.send :handle_options, %w[-p 9999 -d /nonexistent --daemon]
+
+ assert_equal true, @cmd.options[:daemon]
+ assert_equal '/nonexistent', @cmd.options[:gemdir]
+ assert_equal 9999, @cmd.options[:port]
+ end
+end
+
diff --git a/test/rubygems/test_gem_commands_unpack_command.rb b/test/rubygems/test_gem_commands_unpack_command.rb
index ff3d4e0eae..427f9403c3 100644
--- a/test/rubygems/test_gem_commands_unpack_command.rb
+++ b/test/rubygems/test_gem_commands_unpack_command.rb
@@ -7,7 +7,9 @@ class TestGemCommandsUnpackCommand < RubyGemTestCase
def setup
super
- @cmd = Gem::Commands::UnpackCommand.new
+ Dir.chdir @tempdir do
+ @cmd = Gem::Commands::UnpackCommand.new
+ end
end
def test_execute
@@ -15,13 +17,29 @@ class TestGemCommandsUnpackCommand < RubyGemTestCase
@cmd.options[:args] = %w[a]
+ use_ui @ui do
+ Dir.chdir @tempdir do
+ @cmd.execute
+ end
+ end
+
+ assert File.exist?(File.join(@tempdir, 'a-2'))
+ end
+
+ def test_execute_with_target_option
+ util_make_gems
+
+ target = 'with_target'
+ @cmd.options[:args] = %w[a]
+ @cmd.options[:target] = target
+
use_ui @ui do
Dir.chdir @tempdir do
@cmd.execute
end
end
- assert File.exist?(File.join(@tempdir, 'a-0.0.2'))
+ assert File.exist?(File.join(@tempdir, target, 'a-2'))
end
def test_execute_exact_match
diff --git a/test/rubygems/test_gem_format.rb b/test/rubygems/test_gem_format.rb
index 6bc7a42e81..35eee6bae2 100644
--- a/test/rubygems/test_gem_format.rb
+++ b/test/rubygems/test_gem_format.rb
@@ -22,7 +22,7 @@ class TestGemFormat < RubyGemTestCase
gems = Dir[File.join(@gemhome, 'cache', '*.gem')]
- names = [@a0_0_1, @a0_0_2, @b0_0_2, @c1_2, @pl1].map do |spec|
+ names = [@a1, @a2, @b2, @c1_2, @pl1].map do |spec|
spec.original_name
end
diff --git a/test/rubygems/test_gem_indexer.rb b/test/rubygems/test_gem_indexer.rb
index 116a29c562..9eb78500c9 100644
--- a/test/rubygems/test_gem_indexer.rb
+++ b/test/rubygems/test_gem_indexer.rb
@@ -53,16 +53,16 @@ class TestGemIndexer < RubyGemTestCase
assert_indexed quickdir, "index"
assert_indexed quickdir, "index.rz"
- assert_indexed quickdir, "#{@a0_0_1.full_name}.gemspec.rz"
- assert_indexed quickdir, "#{@a0_0_2.full_name}.gemspec.rz"
- assert_indexed quickdir, "#{@b0_0_2.full_name}.gemspec.rz"
+ assert_indexed quickdir, "#{@a1.full_name}.gemspec.rz"
+ assert_indexed quickdir, "#{@a2.full_name}.gemspec.rz"
+ assert_indexed quickdir, "#{@b2.full_name}.gemspec.rz"
assert_indexed quickdir, "#{@c1_2.full_name}.gemspec.rz"
assert_indexed quickdir, "#{@pl1.original_name}.gemspec.rz"
deny_indexed quickdir, "#{@pl1.full_name}.gemspec.rz"
- assert_indexed marshal_quickdir, "#{@a0_0_1.full_name}.gemspec.rz"
- assert_indexed marshal_quickdir, "#{@a0_0_2.full_name}.gemspec.rz"
+ assert_indexed marshal_quickdir, "#{@a1.full_name}.gemspec.rz"
+ assert_indexed marshal_quickdir, "#{@a2.full_name}.gemspec.rz"
deny_indexed quickdir, "#{@c1_2.full_name}.gemspec"
deny_indexed marshal_quickdir, "#{@c1_2.full_name}.gemspec"
diff --git a/test/rubygems/test_gem_install_update_options.rb b/test/rubygems/test_gem_install_update_options.rb
index dafdf65920..8c7a5ce3f7 100644
--- a/test/rubygems/test_gem_install_update_options.rb
+++ b/test/rubygems/test_gem_install_update_options.rb
@@ -16,7 +16,7 @@ class TestGemInstallUpdateOptions < RubyGemTestCase
@cmd.add_install_update_options
args = %w[-i /install_to --rdoc --ri -E -f -t -w -P HighSecurity
- --ignore-dependencies --include-dependencies]
+ --ignore-dependencies --format-exec --include-dependencies]
assert @cmd.handles?(args)
end
diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb
index 9a091a291e..442ed6cfc3 100644
--- a/test/rubygems/test_gem_installer.rb
+++ b/test/rubygems/test_gem_installer.rb
@@ -9,11 +9,13 @@ require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
require 'rubygems/installer'
class Gem::Installer
+ attr_accessor :gem_dir
+
attr_writer :format
- attr_writer :gem_dir
attr_writer :gem_home
attr_writer :env_shebang
attr_writer :ignore_dependencies
+ attr_writer :format_executable
attr_writer :security_policy
attr_writer :spec
attr_writer :wrappers
@@ -37,11 +39,11 @@ class TestGemInstaller < RubyGemTestCase
@installer.spec = @spec
end
- def util_gem_dir(version = '0.0.2')
+ def util_gem_dir(version = '2')
File.join @gemhome, "gems", "a-#{version}" # HACK
end
- def util_gem_bindir(version = '0.0.2')
+ def util_gem_bindir(version = '2')
File.join util_gem_dir(version), "bin"
end
@@ -49,18 +51,19 @@ class TestGemInstaller < RubyGemTestCase
File.join @gemhome, "bin"
end
- def util_make_exec(version = '0.0.2', shebang = "#!/usr/bin/ruby")
+ def util_make_exec(version = '2', shebang = "#!/usr/bin/ruby")
@spec.executables = ["my_exec"]
FileUtils.mkdir_p util_gem_bindir(version)
- exec_file = File.join(util_gem_bindir(version), "my_exec")
- File.open exec_file, 'w' do |f|
+ exec_file = @installer.formatted_program_filename "my_exec"
+ exec_path = File.join util_gem_bindir(version), exec_file
+ File.open exec_path, 'w' do |f|
f.puts shebang
end
end
def test_app_script_text
- util_make_exec '0.0.2', ''
+ util_make_exec '2', ''
expected = <<-EOF
#!#{Gem.ruby}
@@ -144,15 +147,15 @@ load 'my_exec'
end
def test_ensure_dependency
- dep = Gem::Dependency.new 'a', '>= 0.0.2'
+ dep = Gem::Dependency.new 'a', '>= 2'
assert @installer.ensure_dependency(@spec, dep)
- dep = Gem::Dependency.new 'b', '> 0.0.2'
+ dep = Gem::Dependency.new 'b', '> 2'
e = assert_raise Gem::InstallError do
@installer.ensure_dependency @spec, dep
end
- assert_equal 'a requires b (> 0.0.2)', e.message
+ assert_equal 'a requires b (> 2)', e.message
end
def test_expand_and_validate_gem_dir
@@ -226,7 +229,32 @@ load 'my_exec'
"You may need to remove this file if you broke the test once"
end
- def test_generate_bin_scripts
+ def test_generate_bin_bindir
+ @installer.wrappers = true
+
+ @spec.executables = ["my_exec"]
+ @spec.bindir = '.'
+
+ exec_file = @installer.formatted_program_filename "my_exec"
+ exec_path = File.join util_gem_dir(@spec.version), exec_file
+ File.open exec_path, 'w' do |f|
+ f.puts '#!/usr/bin/ruby'
+ end
+
+ @installer.gem_dir = util_gem_dir
+
+ @installer.generate_bin
+
+ assert_equal true, File.directory?(util_inst_bindir)
+ installed_exec = File.join(util_inst_bindir, "my_exec")
+ assert_equal true, File.exist?(installed_exec)
+ assert_equal(0100755, File.stat(installed_exec).mode) unless win_platform?
+
+ wrapper = File.read installed_exec
+ assert_match %r|generated by RubyGems|, wrapper
+ end
+
+ def test_generate_bin_script
@installer.wrappers = true
util_make_exec
@installer.gem_dir = util_gem_dir
@@ -241,7 +269,36 @@ load 'my_exec'
assert_match %r|generated by RubyGems|, wrapper
end
- def test_generate_bin_scripts_install_dir
+ def test_generate_bin_script_format
+ @installer.format_executable = true
+ @installer.wrappers = true
+ util_make_exec
+ @installer.gem_dir = util_gem_dir
+
+ Gem::Installer.exec_format = 'foo-%s-bar'
+ @installer.generate_bin
+ assert_equal true, File.directory?(util_inst_bindir)
+ installed_exec = File.join util_inst_bindir, 'foo-my_exec-bar'
+ assert_equal true, File.exist?(installed_exec)
+ ensure
+ Gem::Installer.exec_format = nil
+ end
+
+ def test_generate_bin_script_format_disabled
+ @installer.wrappers = true
+ util_make_exec
+ @installer.gem_dir = util_gem_dir
+
+ Gem::Installer.exec_format = 'foo-%s-bar'
+ @installer.generate_bin
+ assert_equal true, File.directory?(util_inst_bindir)
+ installed_exec = File.join util_inst_bindir, 'my_exec'
+ assert_equal true, File.exist?(installed_exec)
+ ensure
+ Gem::Installer.exec_format = nil
+ end
+
+ def test_generate_bin_script_install_dir
@installer.wrappers = true
@spec.executables = ["my_exec"]
@@ -265,13 +322,13 @@ load 'my_exec'
assert_match %r|generated by RubyGems|, wrapper
end
- def test_generate_bin_scripts_no_execs
+ def test_generate_bin_script_no_execs
@installer.wrappers = true
@installer.generate_bin
assert_equal false, File.exist?(util_inst_bindir)
end
- def test_generate_bin_scripts_no_perms
+ def test_generate_bin_script_no_perms
@installer.wrappers = true
util_make_exec
@@ -286,7 +343,30 @@ load 'my_exec'
File.chmod 0700, util_inst_bindir unless $DEBUG
end
- def test_generate_bin_symlinks
+ def test_generate_bin_script_no_shebang
+ @installer.wrappers = true
+ @spec.executables = ["my_exec"]
+
+ gem_dir = File.join @gemhome, 'gems', @spec.full_name
+ gem_bindir = File.join gem_dir, 'bin'
+ FileUtils.mkdir_p gem_bindir
+ File.open File.join(gem_bindir, "my_exec"), 'w' do |f|
+ f.puts "blah blah blah"
+ end
+
+ @installer.generate_bin
+
+ installed_exec = File.join @gemhome, 'bin', 'my_exec'
+ assert_equal true, File.exist?(installed_exec)
+ assert_equal 0100755, File.stat(installed_exec).mode unless win_platform?
+
+ wrapper = File.read installed_exec
+ assert_match %r|generated by RubyGems|, wrapper
+ # HACK some gems don't have #! in their executables, restore 2008/06
+ #assert_no_match %r|generated by RubyGems|, wrapper
+ end
+
+ def test_generate_bin_symlink
return if win_platform? #Windows FS do not support symlinks
@installer.wrappers = false
@@ -301,13 +381,13 @@ load 'my_exec'
File.readlink(installed_exec))
end
- def test_generate_bin_symlinks_no_execs
+ def test_generate_bin_symlink_no_execs
@installer.wrappers = false
@installer.generate_bin
assert_equal false, File.exist?(util_inst_bindir)
end
- def test_generate_bin_symlinks_no_perms
+ def test_generate_bin_symlink_no_perms
@installer.wrappers = false
util_make_exec
@installer.gem_dir = util_gem_dir
@@ -323,7 +403,7 @@ load 'my_exec'
File.chmod 0700, util_inst_bindir unless $DEBUG
end
- def test_generate_bin_symlinks_update_newer
+ def test_generate_bin_symlink_update_newer
return if win_platform? #Windows FS do not support symlinks
@installer.wrappers = false
@@ -338,22 +418,22 @@ load 'my_exec'
@spec = Gem::Specification.new do |s|
s.files = ['lib/code.rb']
s.name = "a"
- s.version = "0.0.3"
+ s.version = "3"
s.summary = "summary"
s.description = "desc"
s.require_path = 'lib'
end
- util_make_exec '0.0.3'
- @installer.gem_dir = File.join util_gem_dir('0.0.3')
+ util_make_exec '3'
+ @installer.gem_dir = File.join util_gem_dir('3')
@installer.generate_bin
installed_exec = File.join(util_inst_bindir, "my_exec")
- assert_equal(File.join(util_gem_bindir('0.0.3'), "my_exec"),
+ assert_equal(File.join(util_gem_bindir('3'), "my_exec"),
File.readlink(installed_exec),
"Ensure symlink moved to latest version")
end
- def test_generate_bin_symlinks_update_older
+ def test_generate_bin_symlink_update_older
return if win_platform? #Windows FS do not support symlinks
@installer.wrappers = false
@@ -368,25 +448,25 @@ load 'my_exec'
spec = Gem::Specification.new do |s|
s.files = ['lib/code.rb']
s.name = "a"
- s.version = "0.0.1"
+ s.version = "1"
s.summary = "summary"
s.description = "desc"
s.require_path = 'lib'
end
- util_make_exec '0.0.1'
- @installer.gem_dir = util_gem_dir('0.0.1')
+ util_make_exec '1'
+ @installer.gem_dir = util_gem_dir('1')
@installer.spec = spec
@installer.generate_bin
installed_exec = File.join(util_inst_bindir, "my_exec")
- assert_equal(File.join(util_gem_dir('0.0.2'), "bin", "my_exec"),
+ assert_equal(File.join(util_gem_dir('2'), "bin", "my_exec"),
File.readlink(installed_exec),
"Ensure symlink not moved")
end
- def test_generate_bin_symlinks_update_remove_wrapper
+ def test_generate_bin_symlink_update_remove_wrapper
return if win_platform? #Windows FS do not support symlinks
@installer.wrappers = true
@@ -400,23 +480,23 @@ load 'my_exec'
@spec = Gem::Specification.new do |s|
s.files = ['lib/code.rb']
s.name = "a"
- s.version = "0.0.3"
+ s.version = "3"
s.summary = "summary"
s.description = "desc"
s.require_path = 'lib'
end
@installer.wrappers = false
- util_make_exec '0.0.3'
- @installer.gem_dir = util_gem_dir '0.0.3'
+ util_make_exec '3'
+ @installer.gem_dir = util_gem_dir '3'
@installer.generate_bin
installed_exec = File.join(util_inst_bindir, "my_exec")
- assert_equal(File.join(util_gem_dir('0.0.3'), "bin", "my_exec"),
+ assert_equal(File.join(util_gem_dir('3'), "bin", "my_exec"),
File.readlink(installed_exec),
"Ensure symlink moved to latest version")
end
- def test_generate_bin_symlinks_win32
+ def test_generate_bin_symlink_win32
old_win_platform = Gem.win_platform?
Gem.win_platform = true
@installer.wrappers = false
@@ -454,6 +534,19 @@ load 'my_exec'
assert_match(/#{default_shebang}/, shebang_line)
end
+ def test_initialize
+ spec = quick_gem 'a' do |s| s.platform = Gem::Platform.new 'mswin32' end
+ gem = File.join @tempdir, "#{spec.full_name}.gem"
+
+ util_build_gem spec
+ FileUtils.mv File.join(@gemhome, 'cache', "#{spec.full_name}.gem"),
+ @tempdir
+
+ installer = Gem::Installer.new gem
+
+ assert_equal File.join(@gemhome, 'gems', spec.full_name), installer.gem_dir
+ end
+
def test_install
util_setup_gem
@@ -518,7 +611,7 @@ load 'my_exec'
installer.install
end
- gem_dir = File.join(@gemhome, 'gems', 'old_ruby_required-0.0.1')
+ gem_dir = File.join(@gemhome, 'gems', 'old_ruby_required-1')
assert File.exist?(gem_dir)
end
@@ -605,8 +698,8 @@ load 'my_exec'
end
def test_install_wrong_rubygems_version
- spec = quick_gem 'old_rubygems_required', '0.0.1' do |s|
- s.required_rubygems_version = '< 0.0.0'
+ spec = quick_gem 'old_rubygems_required', '1' do |s|
+ s.required_rubygems_version = '< 0'
end
util_build_gem spec
@@ -618,21 +711,21 @@ load 'my_exec'
e = assert_raise Gem::InstallError do
@installer.install
end
- assert_equal 'old_rubygems_required requires RubyGems version < 0.0.0',
+ assert_equal 'old_rubygems_required requires RubyGems version < 0',
e.message
end
end
def test_installation_satisfies_dependency_eh
- dep = Gem::Dependency.new 'a', '>= 0.0.2'
+ dep = Gem::Dependency.new 'a', '>= 2'
assert @installer.installation_satisfies_dependency?(dep)
- dep = Gem::Dependency.new 'a', '> 0.0.2'
+ dep = Gem::Dependency.new 'a', '> 2'
assert ! @installer.installation_satisfies_dependency?(dep)
end
def test_shebang
- util_make_exec '0.0.2', "#!/usr/bin/ruby"
+ util_make_exec '2', "#!/usr/bin/ruby"
shebang = @installer.shebang 'my_exec'
@@ -640,7 +733,7 @@ load 'my_exec'
end
def test_shebang_arguments
- util_make_exec '0.0.2', "#!/usr/bin/ruby -ws"
+ util_make_exec '2', "#!/usr/bin/ruby -ws"
shebang = @installer.shebang 'my_exec'
@@ -648,14 +741,14 @@ load 'my_exec'
end
def test_shebang_empty
- util_make_exec '0.0.2', ''
+ util_make_exec '2', ''
shebang = @installer.shebang 'my_exec'
assert_equal "#!#{Gem.ruby}", shebang
end
def test_shebang_env
- util_make_exec '0.0.2', "#!/usr/bin/env ruby"
+ util_make_exec '2', "#!/usr/bin/env ruby"
shebang = @installer.shebang 'my_exec'
@@ -663,7 +756,7 @@ load 'my_exec'
end
def test_shebang_env_arguments
- util_make_exec '0.0.2', "#!/usr/bin/env ruby -ws"
+ util_make_exec '2', "#!/usr/bin/env ruby -ws"
shebang = @installer.shebang 'my_exec'
@@ -671,7 +764,7 @@ load 'my_exec'
end
def test_shebang_env_shebang
- util_make_exec '0.0.2', ''
+ util_make_exec '2', ''
@installer.env_shebang = true
shebang = @installer.shebang 'my_exec'
@@ -679,7 +772,7 @@ load 'my_exec'
end
def test_shebang_nested
- util_make_exec '0.0.2', "#!/opt/local/ruby/bin/ruby"
+ util_make_exec '2', "#!/opt/local/ruby/bin/ruby"
shebang = @installer.shebang 'my_exec'
@@ -687,7 +780,7 @@ load 'my_exec'
end
def test_shebang_nested_arguments
- util_make_exec '0.0.2', "#!/opt/local/ruby/bin/ruby -ws"
+ util_make_exec '2', "#!/opt/local/ruby/bin/ruby -ws"
shebang = @installer.shebang 'my_exec'
@@ -695,7 +788,7 @@ load 'my_exec'
end
def test_shebang_version
- util_make_exec '0.0.2', "#!/usr/bin/ruby18"
+ util_make_exec '2', "#!/usr/bin/ruby18"
shebang = @installer.shebang 'my_exec'
@@ -703,7 +796,7 @@ load 'my_exec'
end
def test_shebang_version_arguments
- util_make_exec '0.0.2', "#!/usr/bin/ruby18 -ws"
+ util_make_exec '2', "#!/usr/bin/ruby18 -ws"
shebang = @installer.shebang 'my_exec'
@@ -711,7 +804,7 @@ load 'my_exec'
end
def test_shebang_version_env
- util_make_exec '0.0.2', "#!/usr/bin/env ruby18"
+ util_make_exec '2', "#!/usr/bin/env ruby18"
shebang = @installer.shebang 'my_exec'
@@ -719,7 +812,7 @@ load 'my_exec'
end
def test_shebang_version_env_arguments
- util_make_exec '0.0.2', "#!/usr/bin/env ruby18 -ws"
+ util_make_exec '2', "#!/usr/bin/env ruby18 -ws"
shebang = @installer.shebang 'my_exec'
@@ -753,7 +846,7 @@ load 'my_exec'
end
def old_ruby_required
- spec = quick_gem 'old_ruby_required', '0.0.1' do |s|
+ spec = quick_gem 'old_ruby_required', '1' do |s|
s.required_ruby_version = '= 1.4.6'
end
@@ -790,4 +883,3 @@ load 'my_exec'
end
-
diff --git a/test/rubygems/test_gem_platform.rb b/test/rubygems/test_gem_platform.rb
index a1462d4dcd..648c2a9f36 100644
--- a/test/rubygems/test_gem_platform.rb
+++ b/test/rubygems/test_gem_platform.rb
@@ -5,6 +5,19 @@ require 'rbconfig'
class TestGemPlatform < RubyGemTestCase
+ def test_self_const_missing
+ consts = [:DARWIN, :LINUX_586, :MSWIN32, :PPC_DARWIN, :WIN32, :X86_LINUX]
+
+ consts.each do |const|
+ e = assert_raise NameError do
+ Gem::Platform.const_missing const
+ end
+
+ assert_equal "#{const} has been removed, use CURRENT instead",
+ e.message
+ end
+ end
+
def test_self_local
util_set_arch 'i686-darwin8.10.1'
@@ -60,6 +73,10 @@ class TestGemPlatform < RubyGemTestCase
'i386-mingw32' => ['x86', 'mingw32', nil],
'i386-mswin32' => ['x86', 'mswin32', nil],
'i386-mswin32_80' => ['x86', 'mswin32', '80'],
+ 'i386-mswin32-80' => ['x86', 'mswin32', '80'],
+ 'x86-mswin32' => ['x86', 'mswin32', nil],
+ 'x86-mswin32_60' => ['x86', 'mswin32', '60'],
+ 'x86-mswin32-60' => ['x86', 'mswin32', '60'],
'i386-netbsdelf' => ['x86', 'netbsdelf', nil],
'i386-openbsd4.0' => ['x86', 'openbsd', '4.0'],
'i386-solaris2.10' => ['x86', 'solaris', '2.10'],
diff --git a/test/rubygems/test_gem_remote_fetcher.rb b/test/rubygems/test_gem_remote_fetcher.rb
index 83865e8033..fd3843851a 100644
--- a/test/rubygems/test_gem_remote_fetcher.rb
+++ b/test/rubygems/test_gem_remote_fetcher.rb
@@ -140,11 +140,12 @@ gems:
raise SocketError
end
+ uri = 'http://gems.example.com/yaml'
e = assert_raise Gem::RemoteFetcher::FetchError do
- fetcher.fetch_size 'http://gems.example.com/yaml'
+ fetcher.fetch_size uri
end
- assert_equal 'SocketError (SocketError)', e.message
+ assert_equal "SocketError (SocketError)\n\tgetting size of #{uri}", e.message
end
def test_no_proxy
@@ -231,6 +232,22 @@ gems:
assert_equal 'EOFError: EOFError reading uri', e.message
end
+ def test_fetch_path_open_uri_http_error
+ fetcher = Gem::RemoteFetcher.new nil
+
+ def fetcher.open_uri_or_path(uri)
+ io = StringIO.new 'went boom'
+ err = OpenURI::HTTPError.new 'error', io
+ raise err
+ end
+
+ e = assert_raise Gem::RemoteFetcher::FetchError do
+ fetcher.fetch_path 'uri'
+ end
+
+ assert_equal "OpenURI::HTTPError: error reading uri\n\twent boom", e.message
+ end
+
def test_fetch_path_socket_error
fetcher = Gem::RemoteFetcher.new nil
diff --git a/test/rubygems/test_gem_remote_installer.rb b/test/rubygems/test_gem_remote_installer.rb
deleted file mode 100644
index 90d94843bd..0000000000
--- a/test/rubygems/test_gem_remote_installer.rb
+++ /dev/null
@@ -1,161 +0,0 @@
-#--
-# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
-# All rights reserved.
-# See LICENSE.txt for permissions.
-#++
-
-require 'test/unit'
-require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
-require 'rubygems/remote_installer'
-
-class MockFetcher
- def initialize(uri, proxy)
- @uri = uri
- @proxy = proxy
- end
-
- def size
- 1000
- end
-
- def source_index
- if @uri =~ /non.existent.url/
- fail Gem::RemoteSourceException,
- "Error fetching remote gem cache: Mock Socket Exception"
- end
- result = {
- 'foo-1.2.3' => Gem::Specification.new do |s|
- s.name = 'foo'
- s.version = "1.2.3"
- s.summary = "This is a cool package"
- end,
- 'foo-tools-2.0.0' => Gem::Specification.new do |s|
- s.name = 'foo-tools'
- s.version = "2.0.0"
- s.summary = "This is an even cooler package"
- end,
- 'foo-2-2.0.0' => Gem::Specification.new do |s|
- s.name = 'foo-2'
- s.version = "2.0.0"
- s.summary = "This is the coolest package evar!~!"
- end,
- }
- result
- end
-
- def fetch_path(path)
- end
-
- def self.finish
- end
-end
-
-class TestGemRemoteInstaller < RubyGemTestCase
-
- def setup
- super
-
- util_setup_fake_fetcher
-
- util_setup_source_info_cache @gem1, @gem4
-
- @installer = Gem::RemoteInstaller.new
- @installer.instance_variable_set("@fetcher_class", MockFetcher)
- end
-
- def teardown
- FileUtils.rm "dest_file" rescue nil
- end
-
- def test_find_gem_to_install
- future_gem = quick_gem @gem1.name, '9.9.9' do |spec|
- spec.required_ruby_version = '> 999.999.999' # HACK
- end
-
- util_setup_source_info_cache @gem1, future_gem
- version = Gem::Version::Requirement.new "> 0.0.0"
- gems = @installer.find_gem_to_install(@gem1.name, version)
-
- assert_equal @gem1.full_name, gems.first.full_name
- end
-
- def test_source_index_hash
- source_hash = @installer.source_index_hash
-
- assert_equal 1, source_hash.size
- assert source_hash.has_key?('http://gems.example.com')
- assert_equal [@gem1, @gem4],
- source_hash['http://gems.example.com'].search(@gem1.name)
- end
-
- def test_specs_n_sources_matching
- version = Gem::Version::Requirement.new "> 0.0.0"
- specs_n_sources = @installer.specs_n_sources_matching @gem1.name, version
-
- gems = specs_n_sources.map { |g,| g.full_name }
-
- assert_equal [@gem1.full_name], gems,
- "Gems with longer names and higher versions must not match"
- end
-
-end
-
-# This test suite has a number of TODOs in the test cases. The
-# TestRemoteInstaller test suite is a reworking of this class from
-# scratch.
-class RemoteInstallerTest #< RubyGemTestCase # HACK disabled
- class RInst < Gem::RemoteInstaller
- include Test::Unit::Assertions
-
- attr_accessor :expected_destination_files
- attr_accessor :expected_bodies
- attr_accessor :caches
- attr_accessor :responses
-
- def source_index_hash
- @caches
- end
-
- def fetch(uri)
- @reponses ||= {}
- @responses[uri]
- end
-
- def write_gem_to_file(body, destination_file)
- expected_destination_file = expected_destination_files.pop
- expected_body = expected_bodies.pop
- assert_equal expected_body, body, "Unexpected body"
- assert_equal expected_destination_file, destination_file, "Unexpected destination file"
- end
-
- def new_installer(gem)
- return MockInstaller.new(gem)
- end
- end
-
- def setup
- Gem.clear_paths
- @remote_installer = Gem::RemoteInstaller.new
- @remote_installer.instance_eval { @fetcher_class = MockFetcher }
- end
-
- SAMPLE_SPEC = Gem::Specification.new do |s|
- s.name = 'foo'
- s.version = "1.2.3"
- s.platform = Gem::Platform::RUBY
- s.summary = "This is a cool package"
- s.files = []
- end
- SAMPLE_CACHE = { 'foo-1.2.3' => SAMPLE_SPEC }
- SAMPLE_CACHE_YAML = SAMPLE_CACHE.to_yaml
-
- FOO_GEM = '' # TODO
- CACHE_DIR = File.join(Gem.dir, 'cache')
-
- def test_install
- result = @remote_installer.install('foo')
- assert_equal [nil], result
- end
-
-end
-
diff --git a/test/rubygems/test_gem_server.rb b/test/rubygems/test_gem_server.rb
index 98c8ba5543..c283e661dc 100644
--- a/test/rubygems/test_gem_server.rb
+++ b/test/rubygems/test_gem_server.rb
@@ -4,6 +4,7 @@ require 'rubygems/server'
require 'stringio'
class Gem::Server
+ attr_accessor :source_index
attr_reader :server
end
@@ -25,6 +26,7 @@ class TestGemServer < RubyGemTestCase
@server.quick @req, @res
+ assert_equal 200, @res.status, @res.body
assert_match %r| \d\d:\d\d:\d\d |, @res['date']
assert_equal 'text/plain', @res['content-type']
assert_equal "a-1", @res.body
@@ -36,6 +38,7 @@ class TestGemServer < RubyGemTestCase
@server.quick @req, @res
+ assert_equal 200, @res.status, @res.body
assert_match %r| \d\d:\d\d:\d\d |, @res['date']
assert_equal 'text/plain', @res['content-type']
assert_equal "a-1", Zlib::Inflate.inflate(@res.body)
@@ -47,6 +50,7 @@ class TestGemServer < RubyGemTestCase
@server.quick @req, @res
+ assert_equal 200, @res.status, @res.body
assert @res['date']
assert_equal 'text/plain', @res['content-type']
yaml = Zlib::Inflate.inflate(@res.body)
@@ -55,15 +59,54 @@ class TestGemServer < RubyGemTestCase
assert_match %r|version: "1"|, yaml
end
+ def test_quick_a_1_mswin32_gemspec_rz
+ a1_p = quick_gem 'a', '1' do |s| s.platform = Gem::Platform.local end
+ si = Gem::SourceIndex.new @a1.full_name => @a1, a1_p.full_name => a1_p
+ @server.source_index = si
+
+ data = StringIO.new "GET /quick/a-1-#{Gem::Platform.local}.gemspec.rz HTTP/1.0\r\n\r\n"
+ @req.parse data
+
+ @server.quick @req, @res
+
+ assert_equal 200, @res.status, @res.body
+ assert @res['date']
+ assert_equal 'text/plain', @res['content-type']
+ yaml = Zlib::Inflate.inflate(@res.body)
+ assert_match %r|Gem::Specification|, yaml
+ assert_match %r|name: a|, yaml
+ assert_match %r|version: "1"|, yaml
+ end
+
+ def test_quick_common_substrings
+ ab1 = quick_gem 'ab', '1'
+ si = Gem::SourceIndex.new @a1.full_name => @a1, ab1.full_name => ab1
+ @server.source_index = si
+
+ data = StringIO.new "GET /quick/a-1.gemspec.rz HTTP/1.0\r\n\r\n"
+ @req.parse data
+
+ @server.quick @req, @res
+
+ assert_equal 200, @res.status, @res.body
+ assert @res['date']
+ assert_equal 'text/plain', @res['content-type']
+ yaml = Zlib::Inflate.inflate @res.body
+ assert_match %r|Gem::Specification|, yaml
+ assert_match %r|name: a$|, yaml
+ assert_match %r|version: "1"|, yaml
+ end
+
def test_quick_z_9_gemspec_rz
data = StringIO.new "GET /quick/z-9.gemspec.rz HTTP/1.0\r\n\r\n"
@req.parse data
@server.quick @req, @res
+ assert_equal 404, @res.status, @res.body
assert_match %r| \d\d:\d\d:\d\d |, @res['date']
assert_equal 'text/plain', @res['content-type']
- assert_equal '', @res.body
+ assert_equal 'No gems found matching "z" "9" nil', @res.body
assert_equal 404, @res.status
end
diff --git a/test/rubygems/test_gem_source_index.rb b/test/rubygems/test_gem_source_index.rb
index befbbe6f67..45f59f2430 100644
--- a/test/rubygems/test_gem_source_index.rb
+++ b/test/rubygems/test_gem_source_index.rb
@@ -178,7 +178,7 @@ class TestGemSourceIndex < RubyGemTestCase
end
def test_latest_specs
- spec = quick_gem @gem1.name, '0.0.1'
+ spec = quick_gem @gem1.name, '1'
@source_index.add_spec spec
expected = [
@@ -223,7 +223,7 @@ class TestGemSourceIndex < RubyGemTestCase
def test_search
assert_equal [@gem1, @gem4], @source_index.search("gem_one")
- assert_equal [@gem1], @source_index.search("gem_one", "= 0.0.2")
+ assert_equal [@gem1], @source_index.search("gem_one", "= 2")
assert_equal [], @source_index.search("bogusstring")
assert_equal [], @source_index.search("gem_one", "= 3.2.1")
diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb
index 69d625ceb6..723e566a24 100644
--- a/test/rubygems/test_gem_specification.rb
+++ b/test/rubygems/test_gem_specification.rb
@@ -47,12 +47,13 @@ end
def setup
super
- @a0_0_1 = quick_gem 'a', '0.0.1' do |s|
+ @a1 = quick_gem 'a', '1' do |s|
s.executable = 'exec'
s.extensions << 'ext/a/extconf.rb'
s.has_rdoc = 'true'
s.test_file = 'test/suite.rb'
s.requirements << 'A working computer'
+ s.rubyforge_project = 'example'
s.add_dependency 'rake', '> 0.4'
s.add_dependency 'jabber4r', '> 0.0.0'
@@ -62,9 +63,14 @@ end
s.files = %w[lib/code.rb]
end
- @a0_0_2 = quick_gem 'a', '0.0.2' do |s|
+ @a2 = quick_gem 'a', '2' do |s|
s.files = %w[lib/code.rb]
end
+
+ FileUtils.mkdir_p File.join(@tempdir, 'bin')
+ File.open File.join(@tempdir, 'bin', 'exec'), 'w' do |fp|
+ fp.puts "#!#{Gem.ruby}"
+ end
end
def test_self_attribute_names
@@ -107,10 +113,10 @@ end
end
def test_self_load
- spec = File.join @gemhome, 'specifications', "#{@a0_0_2.full_name}.gemspec"
+ spec = File.join @gemhome, 'specifications', "#{@a2.full_name}.gemspec"
gs = Gem::Specification.load spec
- assert_equal @a0_0_2, gs
+ assert_equal @a2, gs
end
def test_self_load_legacy_ruby
@@ -119,7 +125,7 @@ end
assert_equal '0.4.0', s.version.to_s
assert_equal true, s.has_rdoc?
assert_equal Gem::Specification::TODAY, s.date
- assert s.required_ruby_version.satisfied_by?(Gem::Version.new('0.0.1'))
+ assert s.required_ruby_version.satisfied_by?(Gem::Version.new('1'))
assert_equal false, s.has_unit_tests?
end
@@ -129,7 +135,7 @@ end
assert_equal '0.4.0', s.version.to_s
assert_equal true, s.has_rdoc?
#assert_equal Date.today, s.date
- #assert s.required_ruby_version.satisfied_by?(Gem::Version.new('0.0.1'))
+ #assert s.required_ruby_version.satisfied_by?(Gem::Version.new('1'))
assert_equal false, s.has_unit_tests?
end
@@ -197,10 +203,10 @@ end
end
def test__dump
- @a0_0_2.platform = Gem::Platform.local
- @a0_0_2.instance_variable_set :@original_platform, 'old_platform'
+ @a2.platform = Gem::Platform.local
+ @a2.instance_variable_set :@original_platform, 'old_platform'
- data = Marshal.dump @a0_0_2
+ data = Marshal.dump @a2
same_spec = Marshal.load data
@@ -208,64 +214,64 @@ end
end
def test_author
- assert_equal 'A User', @a0_0_1.author
+ assert_equal 'A User', @a1.author
end
def test_authors
- assert_equal ['A User'], @a0_0_1.authors
+ assert_equal ['A User'], @a1.authors
end
def test_bindir_equals
- @a0_0_1.bindir = 'apps'
+ @a1.bindir = 'apps'
- assert_equal 'apps', @a0_0_1.bindir
+ assert_equal 'apps', @a1.bindir
end
def test_bindir_equals_nil
- @a0_0_2.bindir = nil
- @a0_0_2.executable = 'app'
+ @a2.bindir = nil
+ @a2.executable = 'app'
- assert_equal nil, @a0_0_2.bindir
- assert_equal %w[lib/code.rb app], @a0_0_2.files
+ assert_equal nil, @a2.bindir
+ assert_equal %w[lib/code.rb app], @a2.files
end
def test_date
- assert_equal Gem::Specification::TODAY, @a0_0_1.date
+ assert_equal Gem::Specification::TODAY, @a1.date
end
def test_date_equals_date
- @a0_0_1.date = Date.new(2003, 9, 17)
- assert_equal Time.local(2003, 9, 17, 0,0,0), @a0_0_1.date
+ @a1.date = Date.new(2003, 9, 17)
+ assert_equal Time.local(2003, 9, 17, 0,0,0), @a1.date
end
def test_date_equals_string
- @a0_0_1.date = '2003-09-17'
- assert_equal Time.local(2003, 9, 17, 0,0,0), @a0_0_1.date
+ @a1.date = '2003-09-17'
+ assert_equal Time.local(2003, 9, 17, 0,0,0), @a1.date
end
def test_date_equals_time
- @a0_0_1.date = Time.local(2003, 9, 17, 0,0,0)
- assert_equal Time.local(2003, 9, 17, 0,0,0), @a0_0_1.date
+ @a1.date = Time.local(2003, 9, 17, 0,0,0)
+ assert_equal Time.local(2003, 9, 17, 0,0,0), @a1.date
end
def test_date_equals_time_local
# HACK PDT
- @a0_0_1.date = Time.local(2003, 9, 17, 19,50,0)
- assert_equal Time.local(2003, 9, 17, 0,0,0), @a0_0_1.date
+ @a1.date = Time.local(2003, 9, 17, 19,50,0)
+ assert_equal Time.local(2003, 9, 17, 0,0,0), @a1.date
end
def test_date_equals_time_utc
# HACK PDT
- @a0_0_1.date = Time.local(2003, 9, 17, 19,50,0)
- assert_equal Time.local(2003, 9, 17, 0,0,0), @a0_0_1.date
+ @a1.date = Time.local(2003, 9, 17, 19,50,0)
+ assert_equal Time.local(2003, 9, 17, 0,0,0), @a1.date
end
def test_default_executable
- assert_equal 'exec', @a0_0_1.default_executable
+ assert_equal 'exec', @a1.default_executable
- @a0_0_1.default_executable = nil
- @a0_0_1.instance_variable_set :@executables, nil
- assert_equal nil, @a0_0_1.default_executable
+ @a1.default_executable = nil
+ @a1.instance_variable_set :@executables, nil
+ assert_equal nil, @a1.default_executable
end
def test_dependencies
@@ -273,11 +279,11 @@ end
jabber = Gem::Dependency.new 'jabber4r', '> 0.0.0'
pqa = Gem::Dependency.new 'pqa', ['> 0.4', '<= 0.6']
- assert_equal [rake, jabber, pqa], @a0_0_1.dependencies
+ assert_equal [rake, jabber, pqa], @a1.dependencies
end
def test_description
- assert_equal 'This is a test description', @a0_0_1.description
+ assert_equal 'This is a test description', @a1.description
end
def test_eql_eh
@@ -290,10 +296,10 @@ end
end
def test_equals2
- assert_equal @a0_0_1, @a0_0_1
- assert_equal @a0_0_1, @a0_0_1.dup
- assert_not_equal @a0_0_1, @a0_0_2
- assert_not_equal @a0_0_1, Object.new
+ assert_equal @a1, @a1
+ assert_equal @a1, @a1.dup
+ assert_not_equal @a1, @a2
+ assert_not_equal @a1, Object.new
end
# The cgikit specification was reported to be causing trouble in at least
@@ -322,42 +328,42 @@ end
end
def test_equals2_default_executable
- spec = @a0_0_1.dup
+ spec = @a1.dup
spec.default_executable = 'xx'
- assert_not_equal @a0_0_1, spec
- assert_not_equal spec, @a0_0_1
+ assert_not_equal @a1, spec
+ assert_not_equal spec, @a1
end
def test_equals2_extensions
- spec = @a0_0_1.dup
+ spec = @a1.dup
spec.extensions = 'xx'
- assert_not_equal @a0_0_1, spec
- assert_not_equal spec, @a0_0_1
+ assert_not_equal @a1, spec
+ assert_not_equal spec, @a1
end
def test_executables
- @a0_0_1.executable = 'app'
- assert_equal %w[app], @a0_0_1.executables
+ @a1.executable = 'app'
+ assert_equal %w[app], @a1.executables
end
def test_executable_equals
- @a0_0_2.executable = 'app'
- assert_equal 'app', @a0_0_2.executable
- assert_equal %w[lib/code.rb bin/app], @a0_0_2.files
+ @a2.executable = 'app'
+ assert_equal 'app', @a2.executable
+ assert_equal %w[lib/code.rb bin/app], @a2.files
end
def test_extensions
- assert_equal ['ext/a/extconf.rb'], @a0_0_1.extensions
+ assert_equal ['ext/a/extconf.rb'], @a1.extensions
end
def test_files
- @a0_0_1.files = %w(files bin/common)
- @a0_0_1.test_files = %w(test_files bin/common)
- @a0_0_1.executables = %w(executables common)
- @a0_0_1.extra_rdoc_files = %w(extra_rdoc_files bin/common)
- @a0_0_1.extensions = %w(extensions bin/common)
+ @a1.files = %w(files bin/common)
+ @a1.test_files = %w(test_files bin/common)
+ @a1.executables = %w(executables common)
+ @a1.extra_rdoc_files = %w(extra_rdoc_files bin/common)
+ @a1.extensions = %w(extensions bin/common)
expected = %w[
bin/common
@@ -367,113 +373,123 @@ end
files
test_files
]
- assert_equal expected, @a0_0_1.files.sort
+ assert_equal expected, @a1.files.sort
end
def test_files_duplicate
- @a0_0_2.files = %w[a b c d b]
- @a0_0_2.extra_rdoc_files = %w[x y z x]
- @a0_0_2.normalize
+ @a2.files = %w[a b c d b]
+ @a2.extra_rdoc_files = %w[x y z x]
+ @a2.normalize
- assert_equal %w[a b c d x y z], @a0_0_2.files
- assert_equal %w[x y z], @a0_0_2.extra_rdoc_files
+ assert_equal %w[a b c d x y z], @a2.files
+ assert_equal %w[x y z], @a2.extra_rdoc_files
end
def test_files_extra_rdoc_files
- @a0_0_2.files = %w[a b c d]
- @a0_0_2.extra_rdoc_files = %w[x y z]
- @a0_0_2.normalize
- assert_equal %w[a b c d x y z], @a0_0_2.files
+ @a2.files = %w[a b c d]
+ @a2.extra_rdoc_files = %w[x y z]
+ @a2.normalize
+ assert_equal %w[a b c d x y z], @a2.files
end
def test_files_non_array
- @a0_0_1.files = "F"
- @a0_0_1.test_files = "TF"
- @a0_0_1.executables = "X"
- @a0_0_1.extra_rdoc_files = "ERF"
- @a0_0_1.extensions = "E"
+ @a1.files = "F"
+ @a1.test_files = "TF"
+ @a1.executables = "X"
+ @a1.extra_rdoc_files = "ERF"
+ @a1.extensions = "E"
- assert_equal %w[E ERF F TF bin/X], @a0_0_1.files.sort
+ assert_equal %w[E ERF F TF bin/X], @a1.files.sort
end
def test_files_non_array_pathological
- @a0_0_1.instance_variable_set :@files, "F"
- @a0_0_1.instance_variable_set :@test_files, "TF"
- @a0_0_1.instance_variable_set :@extra_rdoc_files, "ERF"
- @a0_0_1.instance_variable_set :@extensions, "E"
- @a0_0_1.instance_variable_set :@executables, "X"
+ @a1.instance_variable_set :@files, "F"
+ @a1.instance_variable_set :@test_files, "TF"
+ @a1.instance_variable_set :@extra_rdoc_files, "ERF"
+ @a1.instance_variable_set :@extensions, "E"
+ @a1.instance_variable_set :@executables, "X"
+
+ assert_equal %w[E ERF F TF bin/X], @a1.files.sort
+ assert_kind_of Integer, @a1.hash
+ end
- assert_equal %w[E ERF F TF bin/X], @a0_0_1.files.sort
- assert_kind_of Integer, @a0_0_1.hash
+ def test_full_gem_path
+ assert_equal File.join(@gemhome, 'gems', @a1.full_name),
+ @a1.full_gem_path
+
+ @a1.original_platform = 'mswin32'
+
+ assert_equal File.join(@gemhome, 'gems', @a1.original_name),
+ @a1.full_gem_path
end
def test_full_name
- assert_equal 'a-0.0.1', @a0_0_1.full_name
+ assert_equal 'a-1', @a1.full_name
- @a0_0_1.platform = Gem::Platform.new ['universal', 'darwin', nil]
- assert_equal 'a-0.0.1-universal-darwin', @a0_0_1.full_name
+ @a1.platform = Gem::Platform.new ['universal', 'darwin', nil]
+ assert_equal 'a-1-universal-darwin', @a1.full_name
- @a0_0_1.instance_variable_set :@new_platform, 'mswin32'
- assert_equal 'a-0.0.1-mswin32', @a0_0_1.full_name, 'legacy'
+ @a1.instance_variable_set :@new_platform, 'mswin32'
+ assert_equal 'a-1-mswin32', @a1.full_name, 'legacy'
return if win_platform?
- @a0_0_1.platform = 'current'
- assert_equal 'a-0.0.1-x86-darwin-8', @a0_0_1.full_name
+ @a1.platform = 'current'
+ assert_equal 'a-1-x86-darwin-8', @a1.full_name
end
def test_full_name_windows
test_cases = {
- 'i386-mswin32' => 'a-0.0.1-x86-mswin32-60',
- 'i386-mswin32_80' => 'a-0.0.1-x86-mswin32-80',
- 'i386-mingw32' => 'a-0.0.1-x86-mingw32'
+ 'i386-mswin32' => 'a-1-x86-mswin32-60',
+ 'i386-mswin32_80' => 'a-1-x86-mswin32-80',
+ 'i386-mingw32' => 'a-1-x86-mingw32'
}
test_cases.each do |arch, expected|
util_set_arch arch
- @a0_0_1.platform = 'current'
- assert_equal expected, @a0_0_1.full_name
+ @a1.platform = 'current'
+ assert_equal expected, @a1.full_name
end
end
def test_has_rdoc_eh
- assert_equal true, @a0_0_1.has_rdoc?
+ assert_equal true, @a1.has_rdoc?
end
def test_hash
- assert_equal @a0_0_1.hash, @a0_0_1.hash
- assert_equal @a0_0_1.hash, @a0_0_1.dup.hash
- assert_not_equal @a0_0_1.hash, @a0_0_2.hash
+ assert_equal @a1.hash, @a1.hash
+ assert_equal @a1.hash, @a1.dup.hash
+ assert_not_equal @a1.hash, @a2.hash
end
def test_lib_files
- @a0_0_1.files = %w[lib/foo.rb Rakefile]
+ @a1.files = %w[lib/foo.rb Rakefile]
- assert_equal %w[lib/foo.rb], @a0_0_1.lib_files
+ assert_equal %w[lib/foo.rb], @a1.lib_files
end
def test_name
- assert_equal 'a', @a0_0_1.name
+ assert_equal 'a', @a1.name
end
def test_original_name
- assert_equal 'a-0.0.1', @a0_0_1.full_name
+ assert_equal 'a-1', @a1.full_name
- @a0_0_1.platform = 'i386-linux'
- @a0_0_1.instance_variable_set :@original_platform, 'i386-linux'
- assert_equal 'a-0.0.1-i386-linux', @a0_0_1.original_name
+ @a1.platform = 'i386-linux'
+ @a1.instance_variable_set :@original_platform, 'i386-linux'
+ assert_equal 'a-1-i386-linux', @a1.original_name
end
def test_platform
- assert_equal Gem::Platform::RUBY, @a0_0_1.platform
+ assert_equal Gem::Platform::RUBY, @a1.platform
end
def test_platform_equals
- @a0_0_1.platform = nil
- assert_equal Gem::Platform::RUBY, @a0_0_1.platform
+ @a1.platform = nil
+ assert_equal Gem::Platform::RUBY, @a1.platform
- @a0_0_1.platform = Gem::Platform::RUBY
- assert_equal Gem::Platform::RUBY, @a0_0_1.platform
+ @a1.platform = Gem::Platform::RUBY
+ assert_equal Gem::Platform::RUBY, @a1.platform
test_cases = {
'i386-mswin32' => ['x86', 'mswin32', '60'],
@@ -484,29 +500,35 @@ end
test_cases.each do |arch, expected|
util_set_arch arch
- @a0_0_1.platform = Gem::Platform::CURRENT
- assert_equal Gem::Platform.new(expected), @a0_0_1.platform
+ @a1.platform = Gem::Platform::CURRENT
+ assert_equal Gem::Platform.new(expected), @a1.platform
end
end
+ def test_platform_equals_current
+ @a1.platform = Gem::Platform::CURRENT
+ assert_equal Gem::Platform.local, @a1.platform
+ assert_equal Gem::Platform.local.to_s, @a1.original_platform
+ end
+
def test_platform_equals_legacy
- @a0_0_1.platform = Gem::Platform::WIN32
- assert_equal Gem::Platform::MSWIN32, @a0_0_1.platform
+ @a1.platform = 'mswin32'
+ assert_equal Gem::Platform.new('x86-mswin32'), @a1.platform
- @a0_0_1.platform = Gem::Platform::LINUX_586
- assert_equal Gem::Platform::X86_LINUX, @a0_0_1.platform
+ @a1.platform = 'i586-linux'
+ assert_equal Gem::Platform.new('x86-linux'), @a1.platform
- @a0_0_1.platform = Gem::Platform::DARWIN
- assert_equal Gem::Platform::PPC_DARWIN, @a0_0_1.platform
+ @a1.platform = 'powerpc-darwin'
+ assert_equal Gem::Platform.new('ppc-darwin'), @a1.platform
end
def test_require_paths
- @a0_0_1.require_path = 'lib'
- assert_equal %w[lib], @a0_0_1.require_paths
+ @a1.require_path = 'lib'
+ assert_equal %w[lib], @a1.require_paths
end
def test_requirements
- assert_equal ['A working computer'], @a0_0_1.requirements
+ assert_equal ['A working computer'], @a1.requirements
end
def test_spaceship_name
@@ -539,28 +561,22 @@ end
end
def test_summary
- assert_equal 'this is a summary', @a0_0_1.summary
+ assert_equal 'this is a summary', @a1.summary
end
def test_test_files
- @a0_0_1.test_file = 'test/suite.rb'
- assert_equal ['test/suite.rb'], @a0_0_1.test_files
- end
-
- def test_test_suite_file
- @a0_0_2.test_suite_file = 'test/suite.rb'
- assert_equal ['test/suite.rb'], @a0_0_2.test_files
- # XXX: what about the warning?
+ @a1.test_file = 'test/suite.rb'
+ assert_equal ['test/suite.rb'], @a1.test_files
end
def test_to_ruby
- @a0_0_2.required_rubygems_version = Gem::Requirement.new '> 0'
+ @a2.required_rubygems_version = Gem::Requirement.new '> 0'
- ruby_code = @a0_0_2.to_ruby
+ ruby_code = @a2.to_ruby
expected = "Gem::Specification.new do |s|
s.name = %q{a}
- s.version = \"0.0.2\"
+ s.version = \"2\"
s.specification_version = #{Gem::Specification::CURRENT_SPECIFICATION_VERSION} if s.respond_to? :specification_version=
@@ -582,17 +598,20 @@ end
same_spec = eval ruby_code
- assert_equal @a0_0_2, same_spec
+ assert_equal @a2, same_spec
end
def test_to_ruby_fancy
- @a0_0_1.platform = Gem::Platform::PPC_DARWIN
- ruby_code = @a0_0_1.to_ruby
+ @a1.platform = Gem::Platform.local
+ ruby_code = @a1.to_ruby
+
+ local = Gem::Platform.local
+ expected_platform = "[#{local.cpu.inspect}, #{local.os.inspect}, #{local.version.inspect}]"
expected = "Gem::Specification.new do |s|
s.name = %q{a}
- s.version = \"0.0.1\"
- s.platform = Gem::Platform.new([\"ppc\", \"darwin\", nil])
+ s.version = \"1\"
+ s.platform = Gem::Platform.new(#{expected_platform})
s.specification_version = 2 if s.respond_to? :specification_version=
@@ -609,6 +628,7 @@ end
s.homepage = %q{http://example.com}
s.require_paths = [\"lib\"]
s.requirements = [\"A working computer\"]
+ s.rubyforge_project = %q{example}
s.rubygems_version = %q{#{Gem::RubyGemsVersion}}
s.summary = %q{this is a summary}
s.test_files = [\"test/suite.rb\"]
@@ -623,7 +643,7 @@ end
same_spec = eval ruby_code
- assert_equal @a0_0_1, same_spec
+ assert_equal @a1, same_spec
end
def test_to_ruby_legacy
@@ -635,10 +655,10 @@ end
end
def test_to_ruby_platform
- @a0_0_2.platform = Gem::Platform.local
- @a0_0_2.instance_variable_set :@original_platform, 'old_platform'
+ @a2.platform = Gem::Platform.local
+ @a2.instance_variable_set :@original_platform, 'old_platform'
- ruby_code = @a0_0_2.to_ruby
+ ruby_code = @a2.to_ruby
same_spec = eval ruby_code
@@ -646,28 +666,34 @@ end
end
def test_to_yaml
- yaml_str = @a0_0_1.to_yaml
+ yaml_str = @a1.to_yaml
same_spec = YAML.load(yaml_str)
- assert_equal @a0_0_1, same_spec
+ assert_equal @a1, same_spec
end
def test_to_yaml_fancy
- @a0_0_1.platform = Gem::Platform::PPC_DARWIN
- yaml_str = @a0_0_1.to_yaml
+ @a1.platform = Gem::Platform.local
+ yaml_str = @a1.to_yaml
same_spec = YAML.load(yaml_str)
- assert_equal Gem::Platform::PPC_DARWIN, same_spec.platform
+ assert_equal Gem::Platform.local, same_spec.platform
- assert_equal @a0_0_1, same_spec
+ assert_equal @a1, same_spec
end
- def test_to_yaml_legacy_platform
- @a0_0_1.platform = 'powerpc-darwin7.9.0'
- @a0_0_1.instance_variable_set :@original_platform, 'powerpc-darwin7.9.0'
+ def test_to_yaml_platform_empty_string
+ @a1.instance_variable_set :@original_platform, ''
- yaml_str = @a0_0_1.to_yaml
+ assert_match %r|^platform: ruby$|, @a1.to_yaml
+ end
+
+ def test_to_yaml_platform_legacy
+ @a1.platform = 'powerpc-darwin7.9.0'
+ @a1.instance_variable_set :@original_platform, 'powerpc-darwin7.9.0'
+
+ yaml_str = @a1.to_yaml
same_spec = YAML.load(yaml_str)
@@ -675,8 +701,61 @@ end
assert_equal 'powerpc-darwin7.9.0', same_spec.original_platform
end
+ def test_to_yaml_platform_nil
+ @a1.instance_variable_set :@original_platform, nil
+
+ assert_match %r|^platform: ruby$|, @a1.to_yaml
+ end
+
def test_validate
- assert @a0_0_1.validate
+ Dir.chdir @tempdir do
+ assert @a1.validate
+ end
+ end
+
+ def test_validate_authors
+ Dir.chdir @tempdir do
+ @a1.authors = []
+
+ use_ui @ui do
+ @a1.validate
+ end
+
+ assert_equal "WARNING: no author specified\n", @ui.error, 'error'
+
+ @a1.authors = [Object.new]
+
+ e = assert_raise Gem::InvalidSpecificationException do
+ @a1.validate
+ end
+
+ assert_equal 'authors must be Array of Strings', e.message
+ end
+ end
+
+ def test_validate_autorequire
+ Dir.chdir @tempdir do
+ @a1.autorequire = 'code'
+
+ use_ui @ui do
+ @a1.validate
+ end
+
+ assert_equal "WARNING: deprecated autorequire specified\n",
+ @ui.error, 'error'
+ end
+ end
+
+ def test_validate_email
+ Dir.chdir @tempdir do
+ @a1.email = ''
+
+ use_ui @ui do
+ @a1.validate
+ end
+
+ assert_equal "WARNING: no email specified\n", @ui.error, 'error'
+ end
end
def test_validate_empty
@@ -687,51 +766,104 @@ end
assert_equal 'missing value for attribute name', e.message
end
+ def test_validate_executables
+ FileUtils.mkdir_p File.join(@tempdir, 'bin')
+ File.open File.join(@tempdir, 'bin', 'exec'), 'w' do end
+
+ use_ui @ui do
+ Dir.chdir @tempdir do
+ assert @a1.validate
+ end
+ end
+
+ assert_equal '', @ui.output, 'output'
+ assert_equal "WARNING: bin/exec is missing #! line\n", @ui.error, 'error'
+ end
+
def test_validate_empty_require_paths
- @a0_0_1.require_paths = []
+ @a1.require_paths = []
e = assert_raise Gem::InvalidSpecificationException do
- @a0_0_1.validate
+ @a1.validate
end
assert_equal 'specification must have at least one require_path', e.message
end
- def test_validate_platform_bad
- @a0_0_1.platform = Object.new
- assert_raise Gem::InvalidSpecificationException do @a0_0_1.validate end
+ def test_validate_homepage
+ Dir.chdir @tempdir do
+ @a1.homepage = ''
- @a0_0_1.platform = "my-custom-platform"
- e = assert_raise Gem::InvalidSpecificationException do
- @a0_0_1.validate
+ use_ui @ui do
+ @a1.validate
+ end
+
+ assert_equal "WARNING: no homepage specified\n", @ui.error, 'error'
end
+ end
- assert_equal 'invalid platform "my-custom-platform", see Gem::Platform',
- e.message
+ def test_validate_has_rdoc
+ Dir.chdir @tempdir do
+ @a1.has_rdoc = false
+
+ use_ui @ui do
+ @a1.validate
+ end
+
+ assert_equal "WARNING: RDoc will not be generated (has_rdoc == false)\n",
+ @ui.error, 'error'
+ end
end
def test_validate_platform_legacy
- @a0_0_1.platform = Gem::Platform::WIN32
- assert @a0_0_1.validate
+ Dir.chdir @tempdir do
+ @a1.platform = 'mswin32'
+ assert @a1.validate
+
+ @a1.platform = 'i586-linux'
+ assert @a1.validate
+
+ @a1.platform = 'powerpc-darwin'
+ assert @a1.validate
+ end
+ end
- @a0_0_1.platform = Gem::Platform::LINUX_586
- assert @a0_0_1.validate
+ def test_validate_rubyforge_project
+ Dir.chdir @tempdir do
+ @a1.rubyforge_project = ''
- @a0_0_1.platform = Gem::Platform::DARWIN
- assert @a0_0_1.validate
+ use_ui @ui do
+ @a1.validate
+ end
+
+ assert_equal "WARNING: no rubyforge_project specified\n",
+ @ui.error, 'error'
+ end
end
def test_validate_rubygems_version
- @a0_0_1.rubygems_version = "3"
+ @a1.rubygems_version = "3"
e = assert_raise Gem::InvalidSpecificationException do
- @a0_0_1.validate
+ @a1.validate
end
assert_equal "expected RubyGems version #{Gem::RubyGemsVersion}, was 3",
e.message
end
+ def test_validate_summary
+ Dir.chdir @tempdir do
+ @a1.summary = ''
+
+ use_ui @ui do
+ @a1.validate
+ end
+
+ assert_equal "WARNING: no summary specified\n", @ui.error, 'error'
+ end
+ end
+
def test_version
- assert_equal Gem::Version.new('0.0.1'), @a0_0_1.version
+ assert_equal Gem::Version.new('1'), @a1.version
end
end
diff --git a/test/rubygems/test_gem_version.rb b/test/rubygems/test_gem_version.rb
index 95f37ddd23..99dd49933d 100644
--- a/test/rubygems/test_gem_version.rb
+++ b/test/rubygems/test_gem_version.rb
@@ -55,6 +55,11 @@ class TestGemVersion < RubyGemTestCase
assert_inadequate( "1.0.0.1", "= 1.0")
end
+ def test_bump_trailing_zeros
+ v = Gem::Version.new("5.0.0")
+ assert_equal "5.1", v.bump.to_s
+ end
+
def test_bump
v = Gem::Version.new("5.2.4")
assert_equal "5.3", v.bump.to_s
@@ -65,6 +70,16 @@ class TestGemVersion < RubyGemTestCase
assert_equal "6", v.bump.to_s
end
+ def test_eql_eh
+ v = Gem::Version.new("1.2")
+
+ assert_equal true, v.eql?(@v1_2)
+ assert_equal true, @v1_2.eql?(v)
+
+ assert_equal false, @v1_2.eql?(@v1_3)
+ assert_equal false, @v1_3.eql?(@v1_2)
+ end
+
def test_equals2
v = Gem::Version.new("1.2")
diff --git a/test/rubygems/test_kernel.rb b/test/rubygems/test_kernel.rb
index d7d5eaaee2..e06a78e32a 100644
--- a/test/rubygems/test_kernel.rb
+++ b/test/rubygems/test_kernel.rb
@@ -25,39 +25,39 @@ class TestKernel < RubyGemTestCase
end
def test_gem
- assert gem('a', '= 0.0.1'), "Should load"
- assert $:.any? { |p| %r{a-0.0.1/lib} =~ p }
- assert $:.any? { |p| %r{a-0.0.1/bin} =~ p }
+ assert gem('a', '= 1'), "Should load"
+ assert $:.any? { |p| %r{a-1/lib} =~ p }
+ assert $:.any? { |p| %r{a-1/bin} =~ p }
end
def test_gem_redundent
- assert gem('a', '= 0.0.1'), "Should load"
- assert ! gem('a', '= 0.0.1'), "Should not load"
- assert_equal 1, $:.select { |p| %r{a-0.0.1/lib} =~ p }.size
- assert_equal 1, $:.select { |p| %r{a-0.0.1/bin} =~ p }.size
+ assert gem('a', '= 1'), "Should load"
+ assert ! gem('a', '= 1'), "Should not load"
+ assert_equal 1, $:.select { |p| %r{a-1/lib} =~ p }.size
+ assert_equal 1, $:.select { |p| %r{a-1/bin} =~ p }.size
end
def test_gem_overlapping
- assert gem('a', '= 0.0.1'), "Should load"
- assert ! gem('a', '>= 0.0.1'), "Should not load"
- assert_equal 1, $:.select { |p| %r{a-0.0.1/lib} =~ p }.size
- assert_equal 1, $:.select { |p| %r{a-0.0.1/bin} =~ p }.size
+ assert gem('a', '= 1'), "Should load"
+ assert ! gem('a', '>= 1'), "Should not load"
+ assert_equal 1, $:.select { |p| %r{a-1/lib} =~ p }.size
+ assert_equal 1, $:.select { |p| %r{a-1/bin} =~ p }.size
end
def test_gem_conflicting
- assert gem('a', '= 0.0.1'), "Should load"
+ assert gem('a', '= 1'), "Should load"
ex = assert_raise Gem::Exception do
- gem 'a', '= 0.0.2'
+ gem 'a', '= 2'
end
- assert_match(/activate a \(= 0\.0\.2\)/, ex.message)
- assert_match(/activated a-0\.0\.1/, ex.message)
+ assert_match(/activate a \(= 2\)/, ex.message)
+ assert_match(/activated a-1/, ex.message)
- assert $:.any? { |p| %r{a-0.0.1/lib} =~ p }
- assert $:.any? { |p| %r{a-0.0.1/bin} =~ p }
- assert ! $:.any? { |p| %r{a-0.0.2/lib} =~ p }
- assert ! $:.any? { |p| %r{a-0.0.2/bin} =~ p }
+ assert $:.any? { |p| %r{a-1/lib} =~ p }
+ assert $:.any? { |p| %r{a-1/bin} =~ p }
+ assert ! $:.any? { |p| %r{a-2/lib} =~ p }
+ assert ! $:.any? { |p| %r{a-2/bin} =~ p }
end
end