aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-06-09 21:38:59 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-06-09 21:38:59 +0000
commit31c94ffeb5f09d09ac2c86fc9e6614e38251a43d (patch)
tree10e44506238c7af3d7c9d822111996731726e38d /test
parenta6afbaeb3be396c0fdea3b9077d9256c59edcfca (diff)
downloadruby-31c94ffeb5f09d09ac2c86fc9e6614e38251a43d.tar.gz
Update to RubyGems 1.3.4 r2223
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/rubygems/foo/discover.rb0
-rw-r--r--test/rubygems/gem_installer_test_case.rb33
-rw-r--r--test/rubygems/gem_package_tar_test_case.rb18
-rw-r--r--test/rubygems/gemutilities.rb122
-rw-r--r--test/rubygems/insure_session.rb2
-rw-r--r--test/rubygems/mockgemui.rb3
-rw-r--r--test/rubygems/rubygems_plugin.rb16
-rw-r--r--test/rubygems/simple_gem.rb46
-rw-r--r--test/rubygems/test_gem.rb212
-rw-r--r--test/rubygems/test_gem_command.rb16
-rw-r--r--test/rubygems/test_gem_command_manager.rb15
-rw-r--r--test/rubygems/test_gem_commands_cert_command.rb2
-rw-r--r--test/rubygems/test_gem_commands_contents_command.rb63
-rw-r--r--test/rubygems/test_gem_commands_environment_command.rb2
-rw-r--r--test/rubygems/test_gem_commands_generate_index_command.rb105
-rw-r--r--test/rubygems/test_gem_commands_install_command.rb107
-rw-r--r--test/rubygems/test_gem_commands_pristine_command.rb6
-rw-r--r--test/rubygems/test_gem_commands_query_command.rb122
-rw-r--r--test/rubygems/test_gem_commands_server_command.rb26
-rw-r--r--test/rubygems/test_gem_commands_sources_command.rb10
-rw-r--r--test/rubygems/test_gem_commands_specification_command.rb44
-rw-r--r--test/rubygems/test_gem_commands_uninstall_command.rb5
-rw-r--r--test/rubygems/test_gem_commands_unpack_command.rb9
-rw-r--r--test/rubygems/test_gem_commands_update_command.rb19
-rw-r--r--test/rubygems/test_gem_dependency.rb73
-rw-r--r--test/rubygems/test_gem_dependency_installer.rb25
-rw-r--r--test/rubygems/test_gem_dependency_list.rb12
-rw-r--r--test/rubygems/test_gem_doc_manager.rb8
-rw-r--r--test/rubygems/test_gem_ext_configure_builder.rb18
-rw-r--r--test/rubygems/test_gem_ext_ext_conf_builder.rb22
-rw-r--r--test/rubygems/test_gem_format.rb2
-rw-r--r--test/rubygems/test_gem_gem_path_searcher.rb2
-rw-r--r--test/rubygems/test_gem_gem_runner.rb11
-rw-r--r--test/rubygems/test_gem_indexer.rb421
-rw-r--r--test/rubygems/test_gem_install_update_options.rb26
-rw-r--r--test/rubygems/test_gem_installer.rb36
-rw-r--r--test/rubygems/test_gem_local_remote_options.rb3
-rw-r--r--test/rubygems/test_gem_package_tar_header.rb6
-rw-r--r--test/rubygems/test_gem_package_tar_input.rb8
-rw-r--r--test/rubygems/test_gem_package_tar_output.rb4
-rw-r--r--test/rubygems/test_gem_package_tar_writer.rb6
-rw-r--r--test/rubygems/test_gem_package_task.rb70
-rw-r--r--test/rubygems/test_gem_platform.rb18
-rw-r--r--test/rubygems/test_gem_remote_fetcher.rb24
-rw-r--r--test/rubygems/test_gem_server.rb10
-rw-r--r--test/rubygems/test_gem_source_index.rb477
-rw-r--r--test/rubygems/test_gem_source_info_cache.rb2
-rw-r--r--test/rubygems/test_gem_spec_fetcher.rb82
-rw-r--r--test/rubygems/test_gem_specification.rb336
-rw-r--r--test/rubygems/test_gem_uninstaller.rb68
-rw-r--r--test/rubygems/test_gem_version.rb110
-rw-r--r--test/rubygems/test_gem_version_option.rb13
-rw-r--r--test/rubygems/test_kernel.rb12
53 files changed, 2138 insertions, 770 deletions
diff --git a/test/rubygems/foo/discover.rb b/test/rubygems/foo/discover.rb
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/test/rubygems/foo/discover.rb
diff --git a/test/rubygems/gem_installer_test_case.rb b/test/rubygems/gem_installer_test_case.rb
index 944ec71435..0f1a1e2e6a 100644
--- a/test/rubygems/gem_installer_test_case.rb
+++ b/test/rubygems/gem_installer_test_case.rb
@@ -1,4 +1,3 @@
-require 'minitest/unit'
require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
require 'rubygems/installer'
@@ -20,17 +19,17 @@ class GemInstallerTestCase < RubyGemTestCase
def setup
super
- @spec = quick_gem "a"
+ @spec = quick_gem 'a'
@gem = File.join @tempdir, "#{@spec.full_name}.gem"
- util_build_gem @spec
- FileUtils.mv File.join(@gemhome, 'cache', "#{@spec.full_name}.gem"),
- @tempdir
+ @installer = util_installer @spec, @gem, @gemhome
- @installer = Gem::Installer.new @gem
- @installer.gem_dir = util_gem_dir
- @installer.gem_home = @gemhome
- @installer.spec = @spec
+ @user_spec = quick_gem 'b'
+ @user_gem = File.join @tempdir, "#{@user_spec.full_name}.gem"
+
+ @user_installer = util_installer @user_spec, @user_gem, Gem.user_dir
+ @user_installer.gem_dir = File.join(Gem.user_dir, 'gems',
+ @user_spec.full_name)
end
def util_gem_bindir(version = '2')
@@ -49,8 +48,7 @@ class GemInstallerTestCase < RubyGemTestCase
@spec.executables = ["my_exec"]
FileUtils.mkdir_p util_gem_bindir(version)
- exec_file = @installer.formatted_program_filename "my_exec"
- exec_path = File.join util_gem_bindir(version), exec_file
+ exec_path = File.join util_gem_bindir(version), "my_exec"
File.open exec_path, 'w' do |f|
f.puts shebang
end
@@ -82,5 +80,18 @@ class GemInstallerTestCase < RubyGemTestCase
@installer = Gem::Installer.new @gem
end
+ def util_installer(spec, gem_path, gem_home)
+ util_build_gem spec
+ FileUtils.mv File.join(@gemhome, 'cache', "#{spec.full_name}.gem"),
+ @tempdir
+
+ installer = Gem::Installer.new gem_path
+ installer.gem_dir = util_gem_dir
+ installer.gem_home = gem_home
+ installer.spec = spec
+
+ installer
+ end
+
end
diff --git a/test/rubygems/gem_package_tar_test_case.rb b/test/rubygems/gem_package_tar_test_case.rb
index 08ee57d66b..8a21df6de2 100644
--- a/test/rubygems/gem_package_tar_test_case.rb
+++ b/test/rubygems/gem_package_tar_test_case.rb
@@ -1,20 +1,6 @@
require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
require 'rubygems/package'
-class File
-
- # straight from setup.rb
- def self.dir?(path)
- # for corrupted windows stat()
- File.directory?((path[-1,1] == '/') ? path : path + '/')
- end
-
- def self.read_b(name)
- File.open(name, "rb") { |f| f.read }
- end
-
-end
-
class TarTestCase < RubyGemTestCase
def ASCIIZ(str, length)
@@ -49,7 +35,7 @@ class TarTestCase < RubyGemTestCase
linkname 100
magic 6
version 2
- uname 32
+ uname 32
gname 32
devmajor 8
devminor 8
@@ -68,7 +54,7 @@ class TarTestCase < RubyGemTestCase
next
end
- assert_equal expected[offset, length], actual[offset, length],
+ assert_equal expected[offset, length], actual[offset, length],
"Field #{name} of the tar header differs."
offset += length
diff --git a/test/rubygems/gemutilities.rb b/test/rubygems/gemutilities.rb
index 02ebb33837..365b9d21f9 100644
--- a/test/rubygems/gemutilities.rb
+++ b/test/rubygems/gemutilities.rb
@@ -8,24 +8,35 @@ at_exit { $SAFE = 1 }
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
-require 'rubygems'
+if RUBY_VERSION > '1.9' then
+ Gem::QuickLoader.load_full_rubygems_library
+else
+ require 'rubygems'
+end
require 'fileutils'
begin
+ gem 'minitest', '>= 1.3.1'
require 'minitest/unit'
-rescue LoadError
- warn "Install minitest gem"
+rescue Gem::LoadError
+ warn "Install minitest gem >= 1.3.1"
raise
end
require 'tmpdir'
require 'uri'
require 'rubygems/package'
require 'rubygems/test_utilities'
+require 'pp'
+
+begin
+ gem 'rdoc'
+rescue Gem::LoadError
+end
+
+require 'rdoc/rdoc'
require File.join(File.expand_path(File.dirname(__FILE__)), 'mockgemui')
module Gem
- @ruby = ENV['RUBY']
-
def self.searcher=(searcher)
MUTEX.synchronize do @searcher = searcher end
end
@@ -64,6 +75,8 @@ class RubyGemTestCase < MiniTest::Unit::TestCase
@latest_usrcache = File.join(@gemhome, ".gem", "latest_user_cache")
@userhome = File.join @tempdir, 'userhome'
+ Gem.ensure_gem_subdirectories @gemhome
+
@orig_ENV_HOME = ENV['HOME']
ENV['HOME'] = @userhome
Gem.instance_variable_set :@user_home, nil
@@ -85,7 +98,7 @@ class RubyGemTestCase < MiniTest::Unit::TestCase
Gem::SpecFetcher.fetcher = nil
@orig_BASERUBY = Gem::ConfigMap[:BASERUBY]
- Gem::ConfigMap[:BASERUBY] = Gem::ConfigMap[:RUBY_INSTALL_NAME]
+ Gem::ConfigMap[:BASERUBY] = Gem::ConfigMap[:ruby_install_name]
@orig_arch = Gem::ConfigMap[:arch]
@@ -160,6 +173,13 @@ class RubyGemTestCase < MiniTest::Unit::TestCase
Gem::Installer.new(gem, :wrappers => true).install
end
+ def mu_pp(obj)
+ s = ''
+ s = PP.pp obj, s
+ s = s.force_encoding(Encoding.default_external) if defined? Encoding
+ s.chomp
+ end
+
def prep_cache_files(lc)
@usr_si ||= Gem::SourceIndex.new
@usr_sice ||= Gem::SourceInfoCacheEntry.new @usr_si, 0
@@ -254,10 +274,8 @@ class RubyGemTestCase < MiniTest::Unit::TestCase
Gem::Builder.new(spec).build
end
- cache_dir = File.join(@gemhome, 'cache')
- FileUtils.mkdir_p cache_dir
FileUtils.mv "#{spec.full_name}.gem",
- File.join(cache_dir, "#{spec.original_name}.gem")
+ File.join(@gemhome, 'cache', "#{spec.original_name}.gem")
end
end
@@ -294,14 +312,30 @@ class RubyGemTestCase < MiniTest::Unit::TestCase
out.string
end
- def util_make_gems
+ def util_make_gems(prerelease = false)
+ @a1 = quick_gem 'a', '1' do |s|
+ s.files = %w[lib/code.rb]
+ s.require_paths = %w[lib]
+ s.date = Gem::Specification::TODAY - 86400
+ s.homepage = 'http://a.example.com'
+ s.email = %w[example@example.com example2@example.com]
+ s.authors = %w[Example Example2]
+ s.description = <<-DESC
+This line is really, really long. So long, in fact, that it is more than eighty characters long! The purpose of this line is for testing wrapping behavior because sometimes people don't wrap their text to eighty characters. Without the wrapping, the text might not look good in the RSS feed.
+
+Also, a list:
+ * An entry that's actually kind of sort
+ * an entry that's really long, which will probably get wrapped funny. That's ok, somebody wasn't thinking straight when they made it more than eighty characters.
+ DESC
+ end
+
init = proc do |s|
s.files = %w[lib/code.rb]
s.require_paths = %w[lib]
end
- @a1 = quick_gem('a', '1', &init)
@a2 = quick_gem('a', '2', &init)
+ @a3a = quick_gem('a', '3.a', &init)
@a_evil9 = quick_gem('a_evil', '9', &init)
@b2 = quick_gem('b', '2', &init)
@c1_2 = quick_gem('c', '1.2', &init)
@@ -312,13 +346,23 @@ class RubyGemTestCase < MiniTest::Unit::TestCase
s.instance_variable_set :@original_platform, 'i386-linux'
end
+ if prerelease
+ @a2_pre = quick_gem('a', '2.a', &init)
+ write_file File.join(*%W[gems #{@a2_pre.original_name} lib code.rb]) do
+ end
+ util_build_gem @a2_pre
+ 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 #{@a3a.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
- [@a1, @a2, @a_evil9, @b2, @c1_2, @pl1].each { |spec| util_build_gem spec }
+ [@a1, @a2, @a3a, @a_evil9, @b2, @c1_2, @pl1].each do |spec|
+ util_build_gem spec
+ end
FileUtils.rm_r File.join(@gemhome, 'gems', @pl1.original_name)
@@ -338,26 +382,28 @@ class RubyGemTestCase < MiniTest::Unit::TestCase
platform
end
- def util_setup_fake_fetcher
+ def util_setup_fake_fetcher(prerelease = false)
require 'zlib'
require 'socket'
require 'rubygems/remote_fetcher'
@fetcher = Gem::FakeFetcher.new
- util_make_gems
+ util_make_gems(prerelease)
- @all_gems = [@a1, @a2, @a_evil9, @b2, @c1_2].sort
+ @all_gems = [@a1, @a2, @a3a, @a_evil9, @b2, @c1_2].sort
@all_gem_names = @all_gems.map { |gem| gem.full_name }
- gem_names = [@a1.full_name, @a2.full_name, @b2.full_name]
+ gem_names = [@a1.full_name, @a2.full_name, @a3a.full_name, @b2.full_name]
@gem_names = gem_names.sort.join("\n")
@source_index = Gem::SourceIndex.new
@source_index.add_spec @a1
@source_index.add_spec @a2
+ @source_index.add_spec @a3a
@source_index.add_spec @a_evil9
@source_index.add_spec @c1_2
+ @source_index.add_spec @a2_pre if prerelease
Gem::RemoteFetcher.fetcher = @fetcher
end
@@ -400,7 +446,13 @@ class RubyGemTestCase < MiniTest::Unit::TestCase
spec_fetcher.latest_specs[@uri] << spec_tuple
end
- si.gems.sort_by { |_,spec| spec }.each do |_, spec|
+ spec_fetcher.prerelease_specs[@uri] = []
+ si.prerelease_specs.sort.each do |spec|
+ spec_tuple = [spec.name, spec.version, spec.original_platform]
+ spec_fetcher.prerelease_specs[@uri] << spec_tuple
+ end
+
+ (si.gems.merge si.prerelease_gems).sort_by { |_,spec| spec }.each do |_, spec|
path = "#{@gem_repo}quick/Marshal.#{Gem.marshal_version}/#{spec.original_name}.gemspec.rz"
data = Marshal.dump spec
data_deflate = Zlib::Deflate.deflate data
@@ -422,6 +474,42 @@ class RubyGemTestCase < MiniTest::Unit::TestCase
Gem.win_platform?
end
+ # Returns whether or not we're on a version of Ruby built with VC++ (or
+ # Borland) versus Cygwin, Mingw, etc.
+ #
+ def self.vc_windows?
+ RUBY_PLATFORM.match('mswin')
+ end
+
+ # Returns whether or not we're on a version of Ruby built with VC++ (or
+ # Borland) versus Cygwin, Mingw, etc.
+ #
+ def vc_windows?
+ RUBY_PLATFORM.match('mswin')
+ end
+
+ # Returns the make command for the current platform. For versions of Ruby
+ # built on MS Windows with VC++ or Borland it will return 'nmake'. On all
+ # other platforms, including Cygwin, it will return 'make'.
+ #
+ def self.make_command
+ vc_windows? ? 'nmake' : 'make'
+ end
+
+ # Returns the make command for the current platform. For versions of Ruby
+ # built on MS Windows with VC++ or Borland it will return 'nmake'. On all
+ # other platforms, including Cygwin, it will return 'make'.
+ #
+ def make_command
+ vc_windows? ? 'nmake' : 'make'
+ end
+
+ # Returns whether or not the nmake command could be found.
+ #
+ def nmake_found?
+ system('nmake /? 1>NUL 2>&1')
+ end
+
# NOTE Allow tests to use a random (but controlled) port number instead of
# a hardcoded one. This helps CI tools when running parallels builds on
# the same builder slave.
diff --git a/test/rubygems/insure_session.rb b/test/rubygems/insure_session.rb
index 4ae706494a..e56f9abcb8 100644
--- a/test/rubygems/insure_session.rb
+++ b/test/rubygems/insure_session.rb
@@ -23,7 +23,7 @@ def install_session
puts
puts "with the appropriate admin privileges."
puts "*****************************************************************"
- puts
+ puts
exit
end
gem 'session'
diff --git a/test/rubygems/mockgemui.rb b/test/rubygems/mockgemui.rb
index 57582ef57d..d5624960df 100644
--- a/test/rubygems/mockgemui.rb
+++ b/test/rubygems/mockgemui.rb
@@ -56,7 +56,8 @@ class MockGemUi < Gem::StreamUI
def terminate_interaction(status=0)
@terminated = true
- raise TermError
+ raise TermError unless status == 0
+ raise Gem::SystemExitException, status
end
end
diff --git a/test/rubygems/rubygems_plugin.rb b/test/rubygems/rubygems_plugin.rb
new file mode 100644
index 0000000000..269c3f10db
--- /dev/null
+++ b/test/rubygems/rubygems_plugin.rb
@@ -0,0 +1,16 @@
+require 'rubygems/command_manager'
+
+class Gem::Commands::InterruptCommand < Gem::Command
+
+ def initialize
+ super('interrupt', 'Raises an Interrupt Exception', {})
+ end
+
+ def execute
+ raise Interrupt, "Interrupt exception"
+ end
+
+end
+
+Gem::CommandManager.instance.register_command :interrupt
+
diff --git a/test/rubygems/simple_gem.rb b/test/rubygems/simple_gem.rb
index 4b6112300e..a6f14bc3c7 100644
--- a/test/rubygems/simple_gem.rb
+++ b/test/rubygems/simple_gem.rb
@@ -5,63 +5,59 @@
#++
SIMPLE_GEM = <<-GEMDATA
- MD5SUM = "954df67d9475aa2f4fbba20aa33649c8"
+ MD5SUM = "e3701f9db765a2358aef94c40ded71c8"
if $0 == __FILE__
require 'optparse'
-
+
options = {}
ARGV.options do |opts|
opts.on_tail("--help", "show this message") {puts opts; exit}
- opts.on('--dir=DIRNAME', "Installation directory for the Gem") {|x|
- options[:directory] = x
- }
- opts.on('--force', "Force Gem to intall, bypassing dependency checks") {|x|
- options[:force] = x
- }
- opts.on('--gen-rdoc', "Generate RDoc documentation for the Gem") {|x|
- options[:gen_rdoc] = x
- }
+ opts.on('--dir=DIRNAME', "Installation directory for the Gem") {|options[:directory]|}
+ opts.on('--force', "Force Gem to intall, bypassing dependency checks") {|options[:force]|}
+ opts.on('--gen-rdoc', "Generate RDoc documentation for the Gem") {|options[:gen_rdoc]|}
opts.parse!
end
- require 'rubygems/installer'
-
- gem = Gem::Installer.new(__FILE__, options).install
+ require 'rubygems'
+ @directory = options[:directory] || Gem.dir
+ @force = options[:force]
+
+ gem = Gem::Installer.new(__FILE__).install(@force, @directory)
if options[:gen_rdoc]
Gem::DocManager.new(gem).generate_rdoc
end
- end
+end
__END__
---- !ruby/object:Gem::Specification
+--- !ruby/object:Gem::Specification
rubygems_version: "1.0"
name: testing
-version: !ruby/object:Gem::Version
+version: !ruby/object:Gem::Version
version: 1.2.3
date: 2004-03-18 22:01:52.859121 -05:00
-platform:
+platform:
summary: This exercise the gem testing stuff.
-require_paths:
+require_paths:
- lib
-files:
+files:
- lib/foo.rb
- lib/test
- lib/test.rb
- lib/test/wow.rb
autorequire: test
test_suite_file: foo
-requirements:
+requirements:
- a computer processor
----
--
+---
+-
size: 109
mode: 420
path: lib/foo.rb
--
+-
size: 0
mode: 420
path: lib/test.rb
--
+-
size: 15
mode: 420
path: lib/test/wow.rb
diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb
index e777527007..3c5eed3a04 100644
--- a/test/rubygems/test_gem.rb
+++ b/test/rubygems/test_gem.rb
@@ -24,6 +24,7 @@ class TestGem < RubyGemTestCase
expected = [
File.join(@gemhome, *%W[gems #{@a1.full_name} lib]),
File.join(@gemhome, *%W[gems #{@a2.full_name} lib]),
+ File.join(@gemhome, *%W[gems #{@a3a.full_name} lib]),
File.join(@gemhome, *%W[gems #{@a_evil9.full_name} lib]),
File.join(@gemhome, *%W[gems #{@b2.full_name} lib]),
File.join(@gemhome, *%W[gems #{@c1_2.full_name} lib]),
@@ -41,6 +42,56 @@ class TestGem < RubyGemTestCase
assert(!Gem.available?("monkeys"))
end
+ def test_self_bin_path_bin_name
+ util_exec_gem
+ assert_equal @abin_path, Gem.bin_path('a', 'abin')
+ end
+
+ def test_self_bin_path_bin_name_version
+ util_exec_gem
+ assert_equal @abin_path, Gem.bin_path('a', 'abin', '4')
+ end
+
+ def test_self_bin_path_name
+ util_exec_gem
+ assert_equal @exec_path, Gem.bin_path('a')
+ end
+
+ def test_self_bin_path_name_version
+ util_exec_gem
+ assert_equal @exec_path, Gem.bin_path('a', nil, '4')
+ end
+
+ def test_self_bin_path_no_default_bin
+ quick_gem 'a', '2' do |s|
+ s.executables = ['exec']
+ end
+ assert_raises(Gem::Exception) do
+ Gem.bin_path('a', '2')
+ end
+ end
+
+ def test_self_bin_path_no_bin_file
+ quick_gem 'a', '1'
+ assert_raises(Gem::Exception) do
+ Gem.bin_path('a', '1')
+ end
+ end
+
+ def test_self_bin_path_with_spaces
+ quick_gem 'sp ace', '3' do |s|
+ s.executables = ['exec']
+ end
+ path = Gem.bin_path('sp ace', 'exec')
+ assert_equal %w(" "), [path[0,1], path[-1,1]], "Path should be escaped"
+ end
+
+ def test_self_bin_path_not_found
+ assert_raises(Gem::GemNotFoundException) do
+ Gem.bin_path('non-existent')
+ end
+ end
+
def test_self_bindir
assert_equal File.join(@gemhome, 'bin'), Gem.bindir
assert_equal File.join(@gemhome, 'bin'), Gem.bindir(Gem.dir)
@@ -111,39 +162,30 @@ class TestGem < RubyGemTestCase
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'
+ orig_RUBY_INSTALL_NAME = Gem::ConfigMap[:ruby_install_name]
+ 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
+ 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'
+ orig_RUBY_INSTALL_NAME = Gem::ConfigMap[:ruby_install_name]
+ 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
+ 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'
+ orig_RUBY_INSTALL_NAME = Gem::ConfigMap[:ruby_install_name]
+ 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
+ Gem::ConfigMap[:ruby_install_name] = orig_RUBY_INSTALL_NAME
end
def test_self_default_sources
@@ -166,7 +208,7 @@ class TestGem < RubyGemTestCase
def test_self_ensure_gem_directories_missing_parents
gemdir = File.join @tempdir, 'a/b/c/gemdir'
FileUtils.rm_rf File.join(@tempdir, 'a') rescue nil
- assert !File.exist?(File.join(@tempdir, 'a')),
+ refute File.exist?(File.join(@tempdir, 'a')),
"manually remove #{File.join @tempdir, 'a'}, tests are broken"
Gem.use_paths gemdir
@@ -179,14 +221,14 @@ class TestGem < RubyGemTestCase
def test_self_ensure_gem_directories_write_protected
gemdir = File.join @tempdir, "egd"
FileUtils.rm_r gemdir rescue nil
- assert !File.exist?(gemdir), "manually remove #{gemdir}, tests are broken"
+ refute File.exist?(gemdir), "manually remove #{gemdir}, tests are broken"
FileUtils.mkdir_p gemdir
FileUtils.chmod 0400, gemdir
Gem.use_paths gemdir
Gem.ensure_gem_subdirectories gemdir
- assert !File.exist?("#{gemdir}/cache")
+ refute File.exist?("#{gemdir}/cache")
ensure
FileUtils.chmod 0600, gemdir
end
@@ -196,14 +238,14 @@ class TestGem < RubyGemTestCase
gemdir = "#{parent}/a/b/c"
FileUtils.rm_r parent rescue nil
- assert !File.exist?(parent), "manually remove #{parent}, tests are broken"
+ refute File.exist?(parent), "manually remove #{parent}, tests are broken"
FileUtils.mkdir_p parent
FileUtils.chmod 0400, parent
Gem.use_paths(gemdir)
Gem.ensure_gem_subdirectories gemdir
- assert !File.exist?("#{gemdir}/cache")
+ refute File.exist?("#{gemdir}/cache")
ensure
FileUtils.chmod 0600, parent
end
@@ -223,18 +265,20 @@ class TestGem < RubyGemTestCase
end
def test_self_find_files
+ discover_path = File.join 'lib', 'foo', 'discover.rb'
+
foo1 = quick_gem 'foo', '1' do |s|
- s.files << 'lib/foo/discover.rb'
+ s.files << discover_path
end
foo2 = quick_gem 'foo', '2' do |s|
- s.files << 'lib/foo/discover.rb'
+ s.files << discover_path
end
- path = File.join 'gems', foo1.full_name, 'lib', 'foo', 'discover.rb'
+ path = File.join 'gems', foo1.full_name, discover_path
write_file(path) { |fp| fp.puts "# #{path}" }
- path = File.join 'gems', foo2.full_name, 'lib', 'foo', 'discover.rb'
+ path = File.join 'gems', foo2.full_name, discover_path
write_file(path) { |fp| fp.puts "# #{path}" }
@fetcher = Gem::FakeFetcher.new
@@ -245,18 +289,19 @@ class TestGem < RubyGemTestCase
Gem.searcher = nil
expected = [
- File.join(foo1.full_gem_path, 'lib', 'foo', 'discover.rb'),
- File.join(foo2.full_gem_path, 'lib', 'foo', 'discover.rb'),
+ File.expand_path('foo/discover.rb', File.dirname(__FILE__)),
+ File.join(foo2.full_gem_path, discover_path),
+ File.join(foo1.full_gem_path, discover_path),
]
- assert_equal expected, Gem.find_files('foo/discover').sort
+ assert_equal expected, Gem.find_files('foo/discover')
end
def test_self_latest_load_paths
util_make_gems
expected = [
- File.join(@gemhome, *%W[gems #{@a2.full_name} lib]),
+ File.join(@gemhome, *%W[gems #{@a3a.full_name} lib]),
File.join(@gemhome, *%W[gems #{@a_evil9.full_name} lib]),
File.join(@gemhome, *%W[gems #{@b2.full_name} lib]),
File.join(@gemhome, *%W[gems #{@c1_2.full_name} lib]),
@@ -298,7 +343,7 @@ class TestGem < RubyGemTestCase
apple_gem_home = File.join @tempdir, 'apple_gem_home'
Gem.const_set :APPLE_GEM_HOME, apple_gem_home
- assert Gem.path.include?(apple_gem_home)
+ assert_includes Gem.path, apple_gem_home
ensure
Gem.send :remove_const, :APPLE_GEM_HOME
end
@@ -309,7 +354,7 @@ class TestGem < RubyGemTestCase
apple_gem_home = File.join @tempdir, 'apple_gem_home'
Gem.const_set :APPLE_GEM_HOME, apple_gem_home
- assert !Gem.path.include?(apple_gem_home)
+ refute Gem.path.include?(apple_gem_home)
ensure
Gem.send :remove_const, :APPLE_GEM_HOME
end
@@ -400,17 +445,17 @@ class TestGem < RubyGemTestCase
def test_self_refresh
util_make_gems
- a1_spec = File.join @gemhome, "specifications", "#{@a1.full_name}.gemspec"
+ a1_spec = File.join @gemhome, "specifications", "#{@a1.full_name}.gemspec"
FileUtils.mv a1_spec, @tempdir
- assert !Gem.source_index.gems.include?(@a1.full_name)
+ refute Gem.source_index.gems.include?(@a1.full_name)
FileUtils.mv File.join(@tempdir, "#{@a1.full_name}.gemspec"), a1_spec
Gem.refresh
- assert Gem.source_index.gems.include?(@a1.full_name)
+ assert_includes Gem.source_index.gems, @a1.full_name
assert_equal nil, Gem.instance_variable_get(:@searcher)
end
@@ -463,11 +508,28 @@ class TestGem < RubyGemTestCase
Gem::ConfigMap[:EXEEXT] = orig_exe_ext
end
- def test_self_ruby_version
- version = RUBY_VERSION.dup
- version << ".#{RUBY_PATCHLEVEL}" if defined? RUBY_PATCHLEVEL
+ def test_self_ruby_version_1_8_5
+ util_set_RUBY_VERSION '1.8.5'
- assert_equal Gem::Version.new(version), Gem.ruby_version
+ assert_equal Gem::Version.new('1.8.5'), Gem.ruby_version
+ ensure
+ util_restore_RUBY_VERSION
+ end
+
+ def test_self_ruby_version_1_8_6p287
+ util_set_RUBY_VERSION '1.8.6', 287
+
+ assert_equal Gem::Version.new('1.8.6.287'), Gem.ruby_version
+ ensure
+ util_restore_RUBY_VERSION
+ end
+
+ def test_self_ruby_version_1_9_2dev_r23493
+ util_set_RUBY_VERSION '1.9.2', -1, 23493
+
+ assert_equal Gem::Version.new('1.9.2.dev.23493'), Gem.ruby_version
+ ensure
+ util_restore_RUBY_VERSION
end
def test_self_searcher
@@ -478,13 +540,12 @@ class TestGem < RubyGemTestCase
other = File.join @tempdir, 'other'
path = [@userhome, other].join File::PATH_SEPARATOR
Gem.send :set_paths, path
- path = Gem.path
- assert_equal path[0], @userhome
- assert_equal path[1], other
+ assert_equal [@userhome, other, @gemhome], Gem.path
end
def test_self_set_paths_nonexistent_home
+ ENV['GEM_HOME'] = @gemhome
Gem.clear_paths
other = File.join @tempdir, 'other'
@@ -493,7 +554,7 @@ class TestGem < RubyGemTestCase
Gem.send :set_paths, other
- refute File.exist?(File.join(other, 'gems'))
+ assert_equal [other, @gemhome], Gem.path
end
def test_self_source_index
@@ -538,6 +599,28 @@ class TestGem < RubyGemTestCase
end
end
+ def test_self_user_home_user_drive_and_path
+ Gem.clear_paths
+
+ # safe-keep env variables
+ orig_home, orig_user_profile = ENV['HOME'], ENV['USERPROFILE']
+ orig_user_drive, orig_user_path = ENV['HOMEDRIVE'], ENV['HOMEPATH']
+
+ # prepare the environment
+ ENV.delete('HOME')
+ ENV.delete('USERPROFILE')
+ ENV['HOMEDRIVE'] = 'Z:'
+ ENV['HOMEPATH'] = '\\Users\\RubyUser'
+
+ assert_equal "Z:\\Users\\RubyUser", Gem.user_home
+
+ ensure
+ ENV['HOME'] = orig_home
+ ENV['USERPROFILE'] = orig_user_profile
+ ENV['USERDRIVE'] = orig_user_drive
+ ENV['USERPATH'] = orig_user_path
+ end if '1.9' > RUBY_VERSION
+
def util_ensure_gem_dirs
Gem.ensure_gem_subdirectories @gemhome
@additional.each do |dir|
@@ -545,5 +628,46 @@ class TestGem < RubyGemTestCase
end
end
+ def util_exec_gem
+ spec, _ = quick_gem 'a', '4' do |s|
+ s.default_executable = 'exec'
+ s.executables = ['exec', 'abin']
+ end
+
+ @exec_path = File.join spec.full_gem_path, spec.bindir, 'exec'
+ @abin_path = File.join spec.full_gem_path, spec.bindir, 'abin'
+ end
+
+ def util_set_RUBY_VERSION(version, patchlevel = nil, revision = nil)
+ if Gem.instance_variables.include? :@ruby_version or
+ Gem.instance_variables.include? '@ruby_version' then
+ Gem.send :remove_instance_variable, :@ruby_version
+ end
+
+ @RUBY_VERSION = RUBY_VERSION
+ @RUBY_PATCHLEVEL = RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL)
+ @RUBY_REVISION = RUBY_REVISION if defined?(RUBY_REVISION)
+
+ Object.send :remove_const, :RUBY_VERSION
+ Object.send :remove_const, :RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL)
+ Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION)
+
+ Object.const_set :RUBY_VERSION, version
+ Object.const_set :RUBY_PATCHLEVEL, patchlevel if patchlevel
+ Object.const_set :RUBY_REVISION, revision if revision
+ end
+
+ def util_restore_RUBY_VERSION
+ Object.send :remove_const, :RUBY_VERSION
+ Object.send :remove_const, :RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL)
+ Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION)
+
+ Object.const_set :RUBY_VERSION, @RUBY_VERSION
+ Object.const_set :RUBY_PATCHLEVEL, @RUBY_PATCHLEVEL if
+ defined?(@RUBY_PATCHLEVEL)
+ Object.const_set :RUBY_REVISION, @RUBY_REVISION if
+ defined?(@RUBY_REVISION)
+ end
+
end
diff --git a/test/rubygems/test_gem_command.rb b/test/rubygems/test_gem_command.rb
index ff63804a4a..7a48c842b8 100644
--- a/test/rubygems/test_gem_command.rb
+++ b/test/rubygems/test_gem_command.rb
@@ -55,16 +55,6 @@ class TestGemCommand < RubyGemTestCase
assert_equal [], h
end
- def test_add_option_overlapping_common_and_local_options
- @cmd.add_option('-x', '--zip', 'BAD!') do end
- @cmd.add_option('-z', '--exe', 'BAD!') do end
- @cmd.add_option('-x', '--exe', 'BAD!') do end
-
- assert_match %r|-x, --exe|, @cmd.parser.to_s
- refute_match %r|-z, --exe|, @cmd.parser.to_s
- refute_match %r|-x, --zip|, @cmd.parser.to_s
- end
-
def test_basic_accessors
assert_equal "doit", @cmd.command
assert_equal "gem doit", @cmd.program_name
@@ -182,9 +172,9 @@ class TestGemCommand < RubyGemTestCase
assert @cmd.handles?(['--help', 'command'])
assert @cmd.handles?(['-f', 'filename'])
assert @cmd.handles?(['--file=filename'])
- assert ! @cmd.handles?(['-z'])
- assert ! @cmd.handles?(['-f'])
- assert ! @cmd.handles?(['--toothpaste'])
+ refute @cmd.handles?(['-z'])
+ refute @cmd.handles?(['-f'])
+ refute @cmd.handles?(['--toothpaste'])
args = ['-h', 'command']
@cmd.handles?(args)
diff --git a/test/rubygems/test_gem_command_manager.rb b/test/rubygems/test_gem_command_manager.rb
index bcfe65b359..40ca857353 100644
--- a/test/rubygems/test_gem_command_manager.rb
+++ b/test/rubygems/test_gem_command_manager.rb
@@ -7,29 +7,16 @@
require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
require 'rubygems/command_manager'
-class InterruptCommand < Gem::Command
-
- def initialize
- super('interrupt', 'Raises an Interrupt Exception', {})
- end
-
- def execute
- raise Interrupt, "Interrupt exception"
- end
-
-end
-
class TestGemCommandManager < RubyGemTestCase
def setup
super
- @command_manager = Gem::CommandManager.new
+ @command_manager = Gem::CommandManager.instance
end
def test_run_interrupt
use_ui @ui do
- @command_manager.register_command :interrupt
assert_raises MockGemUi::TermError do
@command_manager.run 'interrupt'
end
diff --git a/test/rubygems/test_gem_commands_cert_command.rb b/test/rubygems/test_gem_commands_cert_command.rb
index 749fe62198..43124f2c40 100644
--- a/test/rubygems/test_gem_commands_cert_command.rb
+++ b/test/rubygems/test_gem_commands_cert_command.rb
@@ -105,7 +105,7 @@ class TestGemCommandsCertCommand < RubyGemTestCase
assert_equal "Removed '/CN=rubygems/DC=example/DC=com'\n", @ui.output
assert_equal '', @ui.error
- assert !File.exist?(@cert_file_name)
+ refute File.exist?(@cert_file_name)
end
def test_execute_sign
diff --git a/test/rubygems/test_gem_commands_contents_command.rb b/test/rubygems/test_gem_commands_contents_command.rb
index b891094ed8..a40be4e3fb 100644
--- a/test/rubygems/test_gem_commands_contents_command.rb
+++ b/test/rubygems/test_gem_commands_contents_command.rb
@@ -24,6 +24,27 @@ class TestGemCommandsContentsCommand < RubyGemTestCase
assert_equal "", @ui.error
end
+ def test_execute_all
+ @cmd.options[:all] = true
+
+ quick_gem 'foo' do |gem|
+ gem.files = %w[lib/foo.rb Rakefile]
+ end
+
+ quick_gem 'bar' do |gem|
+ gem.files = %w[lib/bar.rb Rakefile]
+ end
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_match %r|lib/foo\.rb|, @ui.output
+ assert_match %r|lib/bar\.rb|, @ui.output
+ assert_match %r|Rakefile|, @ui.output
+ assert_equal "", @ui.error
+ end
+
def test_execute_bad_gem
@cmd.options[:args] = %w[foo]
@@ -75,6 +96,48 @@ class TestGemCommandsContentsCommand < RubyGemTestCase
assert_equal "", @ui.error
end
+ def test_execute_multiple
+ @cmd.options[:args] = %w[foo bar]
+ quick_gem 'foo' do |gem|
+ gem.files = %w[lib/foo.rb Rakefile]
+ end
+
+ quick_gem 'bar' do |gem|
+ gem.files = %w[lib/bar.rb Rakefile]
+ end
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_match %r|lib/foo\.rb|, @ui.output
+ assert_match %r|lib/bar\.rb|, @ui.output
+ assert_match %r|Rakefile|, @ui.output
+ assert_equal "", @ui.error
+ end
+
+ def test_execute_no_prefix
+ @cmd.options[:args] = %w[foo]
+ @cmd.options[:prefix] = false
+
+ quick_gem 'foo' do |gem|
+ gem.files = %w[lib/foo.rb Rakefile]
+ end
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ expected = <<-EOF
+lib/foo.rb
+Rakefile
+ EOF
+
+ assert_equal expected, @ui.output
+
+ assert_equal "", @ui.error
+ end
+
def test_handle_options
assert_equal false, @cmd.options[:lib_only]
assert_equal [], @cmd.options[:specdirs]
diff --git a/test/rubygems/test_gem_commands_environment_command.rb b/test/rubygems/test_gem_commands_environment_command.rb
index 7f80b3e1a3..0640543f52 100644
--- a/test/rubygems/test_gem_commands_environment_command.rb
+++ b/test/rubygems/test_gem_commands_environment_command.rb
@@ -24,7 +24,7 @@ class TestGemCommandsEnvironmentCommand < RubyGemTestCase
assert_match %r|INSTALLATION DIRECTORY: #{Regexp.escape @gemhome}|,
@ui.output
assert_match %r|RUBYGEMS PREFIX: |, @ui.output
- assert_match %r|RUBY EXECUTABLE:.*#{Gem::ConfigMap[:RUBY_INSTALL_NAME]}|,
+ assert_match %r|RUBY EXECUTABLE:.*#{Gem::ConfigMap[:ruby_install_name]}|,
@ui.output
assert_match %r|EXECUTABLE DIRECTORY:|, @ui.output
assert_match %r|RUBYGEMS PLATFORMS:|, @ui.output
diff --git a/test/rubygems/test_gem_commands_generate_index_command.rb b/test/rubygems/test_gem_commands_generate_index_command.rb
index d886fc5e2c..d038bd6d5e 100644
--- a/test/rubygems/test_gem_commands_generate_index_command.rb
+++ b/test/rubygems/test_gem_commands_generate_index_command.rb
@@ -1,4 +1,3 @@
-require 'minitest/unit'
require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
require 'rubygems/indexer'
require 'rubygems/commands/generate_index_command'
@@ -28,5 +27,109 @@ class TestGemCommandsGenerateIndexCommand < RubyGemTestCase
assert File.exist?(quick_index_rz), quick_index_rz
end
+ def test_execute_rss_update
+ @cmd.options[:update] = true
+ @cmd.options[:rss_host] = 'example.com'
+ @cmd.options[:rss_gems_host] = 'gems.example.com'
+
+ use_ui @ui do
+ assert_raises MockGemUi::TermError do
+ @cmd.execute
+ end
+ end
+
+ assert_equal "ERROR: --update not compatible with RSS generation\n",
+ @ui.error
+ assert_empty @ui.output
+ end
+
+ def test_handle_options_directory
+ return if win_platform?
+ refute_equal '/nonexistent', @cmd.options[:directory]
+
+ @cmd.handle_options %w[--directory /nonexistent]
+
+ assert_equal '/nonexistent', @cmd.options[:directory]
+ end
+
+ def test_handle_options_directory_windows
+ return unless win_platform?
+
+ refute_equal '/nonexistent', @cmd.options[:directory]
+
+ @cmd.handle_options %w[--directory C:/nonexistent]
+
+ assert_equal 'C:/nonexistent', @cmd.options[:directory]
+ end
+
+ def test_handle_options_invalid
+ e = assert_raises OptionParser::InvalidOption do
+ @cmd.handle_options %w[--no-modern --no-legacy]
+ end
+
+ assert_equal 'invalid option: --no-legacy no indicies will be built',
+ e.message
+
+ @cmd = Gem::Commands::GenerateIndexCommand.new
+ e = assert_raises OptionParser::InvalidOption do
+ @cmd.handle_options %w[--no-legacy --no-modern]
+ end
+
+ assert_equal 'invalid option: --no-modern no indicies will be built',
+ e.message
+ end
+
+ def test_handle_options_legacy
+ @cmd.handle_options %w[--legacy]
+
+ assert @cmd.options[:build_legacy]
+ assert @cmd.options[:build_modern], ':build_modern not set'
+ end
+
+ def test_handle_options_modern
+ @cmd.handle_options %w[--modern]
+
+ assert @cmd.options[:build_legacy]
+ assert @cmd.options[:build_modern], ':build_modern not set'
+ end
+
+ def test_handle_options_no_legacy
+ @cmd.handle_options %w[--no-legacy]
+
+ refute @cmd.options[:build_legacy]
+ assert @cmd.options[:build_modern]
+ end
+
+ def test_handle_options_no_modern
+ @cmd.handle_options %w[--no-modern]
+
+ assert @cmd.options[:build_legacy]
+ refute @cmd.options[:build_modern]
+ end
+
+ def test_handle_options_rss_gems_host
+ @cmd.handle_options %w[--rss-gems-host gems.example.com]
+
+ assert_equal 'gems.example.com', @cmd.options[:rss_gems_host]
+ end
+
+ def test_handle_options_rss_host
+ @cmd.handle_options %w[--rss-host example.com]
+
+ assert_equal 'example.com', @cmd.options[:rss_host]
+ end
+
+ def test_handle_options_rss_title
+ @cmd.handle_options %w[--rss-title Example\ Gems]
+
+ assert_equal 'Example Gems', @cmd.options[:rss_title]
+ end
+
+ def test_handle_options_update
+ @cmd.handle_options %w[--update]
+
+ assert @cmd.options[:update]
+ end
+
end if ''.respond_to? :to_xs
diff --git a/test/rubygems/test_gem_commands_install_command.rb b/test/rubygems/test_gem_commands_install_command.rb
index 97fefbf859..d9ee8098a5 100644
--- a/test/rubygems/test_gem_commands_install_command.rb
+++ b/test/rubygems/test_gem_commands_install_command.rb
@@ -11,6 +11,52 @@ class TestGemCommandsInstallCommand < RubyGemTestCase
@cmd.options[:generate_ri] = false
end
+ def test_execute_exclude_prerelease
+ util_setup_fake_fetcher(:prerelease)
+ util_setup_spec_fetcher @a2, @a2_pre
+
+ @fetcher.data["#{@gem_repo}gems/#{@a2.full_name}.gem"] =
+ read_binary(File.join(@gemhome, 'cache', "#{@a2.full_name}.gem"))
+ @fetcher.data["#{@gem_repo}gems/#{@a2_pre.full_name}.gem"] =
+ read_binary(File.join(@gemhome, 'cache', "#{@a2_pre.full_name}.gem"))
+
+ @cmd.options[:args] = [@a2.name]
+
+ use_ui @ui do
+ e = assert_raises Gem::SystemExitException do
+ @cmd.execute
+ end
+ assert_equal 0, e.exit_code, @ui.error
+ end
+
+ assert_match(/Successfully installed #{@a2.full_name}$/, @ui.output)
+ refute_match(/Successfully installed #{@a2_pre.full_name}$/, @ui.output)
+ end
+
+ def test_execute_explicit_version_includes_prerelease
+ util_setup_fake_fetcher(:prerelease)
+ util_setup_spec_fetcher @a2, @a2_pre
+
+ @fetcher.data["#{@gem_repo}gems/#{@a2.full_name}.gem"] =
+ read_binary(File.join(@gemhome, 'cache', "#{@a2.full_name}.gem"))
+ @fetcher.data["#{@gem_repo}gems/#{@a2_pre.full_name}.gem"] =
+ read_binary(File.join(@gemhome, 'cache', "#{@a2_pre.full_name}.gem"))
+
+ @cmd.handle_options [@a2_pre.name, '--version', @a2_pre.version.to_s]
+ assert @cmd.options[:prerelease]
+ assert @cmd.options[:version].satisfied_by?(@a2_pre.version)
+
+ use_ui @ui do
+ e = assert_raises Gem::SystemExitException do
+ @cmd.execute
+ end
+ assert_equal 0, e.exit_code, @ui.error
+ end
+
+ refute_match(/Successfully installed #{@a2.full_name}$/, @ui.output)
+ assert_match(/Successfully installed #{@a2_pre.full_name}$/, @ui.output)
+ end
+
def test_execute_include_dependencies
@cmd.options[:include_dependencies] = true
@cmd.options[:args] = []
@@ -57,6 +103,34 @@ class TestGemCommandsInstallCommand < RubyGemTestCase
assert out.empty?, out.inspect
end
+ def test_no_user_install
+ skip 'skipped on MS Windows (chmod has no effect)' if win_platform?
+
+ util_setup_fake_fetcher
+ @cmd.options[:user_install] = false
+
+ FileUtils.mv File.join(@gemhome, 'cache', "#{@a2.full_name}.gem"),
+ File.join(@tempdir)
+
+ @cmd.options[:args] = [@a2.name]
+
+ use_ui @ui do
+ orig_dir = Dir.pwd
+ begin
+ File.chmod 0755, @userhome
+ File.chmod 0555, @gemhome
+
+ Dir.chdir @tempdir
+ assert_raises Gem::FilePermissionError do
+ @cmd.execute
+ end
+ ensure
+ Dir.chdir orig_dir
+ File.chmod 0755, @gemhome
+ end
+ end
+ end
+
def test_execute_local_missing
util_setup_fake_fetcher
@cmd.options[:domain] = :local
@@ -100,6 +174,29 @@ class TestGemCommandsInstallCommand < RubyGemTestCase
@ui.error
end
+ def test_execute_prerelease
+ util_setup_fake_fetcher(:prerelease)
+ util_setup_spec_fetcher @a2, @a2_pre
+
+ @fetcher.data["#{@gem_repo}gems/#{@a2.full_name}.gem"] =
+ read_binary(File.join(@gemhome, 'cache', "#{@a2.full_name}.gem"))
+ @fetcher.data["#{@gem_repo}gems/#{@a2_pre.full_name}.gem"] =
+ read_binary(File.join(@gemhome, 'cache', "#{@a2_pre.full_name}.gem"))
+
+ @cmd.options[:prerelease] = true
+ @cmd.options[:args] = [@a2_pre.name]
+
+ use_ui @ui do
+ e = assert_raises Gem::SystemExitException do
+ @cmd.execute
+ end
+ assert_equal 0, e.exit_code, @ui.error
+ end
+
+ refute_match(/Successfully installed #{@a2.full_name}$/, @ui.output)
+ assert_match(/Successfully installed #{@a2_pre.full_name}$/, @ui.output)
+ end
+
def test_execute_remote
@cmd.options[:generate_rdoc] = true
@cmd.options[:generate_ri] = true
@@ -112,17 +209,10 @@ class TestGemCommandsInstallCommand < RubyGemTestCase
@cmd.options[:args] = [@a2.name]
- err = ""
- class << err
- alias write <<
- end
use_ui @ui do
e = assert_raises Gem::SystemExitException do
- stderr, $stderr = $stderr, err
- begin
+ capture_io do
@cmd.execute
- ensure
- $stderr = stderr
end
end
assert_equal 0, e.exit_code
@@ -136,7 +226,6 @@ class TestGemCommandsInstallCommand < RubyGemTestCase
assert_equal "Installing RDoc documentation for #{@a2.full_name}...",
out.shift
assert out.empty?, out.inspect
- assert_match /^Updating class cache with \d+ classes/, err
end
def test_execute_two
diff --git a/test/rubygems/test_gem_commands_pristine_command.rb b/test/rubygems/test_gem_commands_pristine_command.rb
index 307cba7b7f..54b3d77594 100644
--- a/test/rubygems/test_gem_commands_pristine_command.rb
+++ b/test/rubygems/test_gem_commands_pristine_command.rb
@@ -35,7 +35,7 @@ class TestGemCommandsPristineCommand < RubyGemTestCase
assert_equal "Restoring gem(s) to pristine condition...", out.shift
assert_equal "Restored #{a.full_name}", out.shift
- assert out.empty?, out.inspect
+ assert_empty out, out.inspect
end
def test_execute_all
@@ -63,7 +63,7 @@ class TestGemCommandsPristineCommand < RubyGemTestCase
assert_equal "Restoring gem(s) to pristine condition...", out.shift
assert_equal "Restored #{a.full_name}", out.shift
- assert out.empty?, out.inspect
+ assert_empty out, out.inspect
end
def test_execute_missing_cache_gem
@@ -86,7 +86,7 @@ class TestGemCommandsPristineCommand < RubyGemTestCase
out = @ui.output.split "\n"
assert_equal "Restoring gem\(s\) to pristine condition...", out.shift
- assert out.empty?, out.inspect
+ assert_empty out, out.inspect
assert_equal "ERROR: Cached gem for #{a.full_name} not found, use `gem install` to restore\n",
@ui.error
diff --git a/test/rubygems/test_gem_commands_query_command.rb b/test/rubygems/test_gem_commands_query_command.rb
index 785a08cd6c..228d0b3946 100644
--- a/test/rubygems/test_gem_commands_query_command.rb
+++ b/test/rubygems/test_gem_commands_query_command.rb
@@ -10,7 +10,7 @@ class TestGemCommandsQueryCommand < RubyGemTestCase
util_setup_fake_fetcher
- @si = util_setup_spec_fetcher @a1, @a2, @pl1
+ @si = util_setup_spec_fetcher @a1, @a2, @pl1, @a3a
@fetcher.data["#{@gem_repo}Marshal.#{Gem.marshal_version}"] = proc do
raise Gem::RemoteFetcher::FetchError
@@ -85,6 +85,51 @@ a (2)
This is a lot of text.
pl (1)
+ Platform: i386-linux
+ Author: A User
+ Homepage: http://example.com
+
+ this is a summary
+ EOF
+
+ assert_equal expected, @ui.output
+ assert_equal '', @ui.error
+ end
+
+ def test_execute_details_platform
+ @a1.platform = 'x86-linux'
+
+ @a2.summary = 'This is a lot of text. ' * 4
+ @a2.authors = ['Abraham Lincoln', 'Hirohito']
+ @a2.homepage = 'http://a.example.com/'
+ @a2.rubyforge_project = 'rubygems'
+ @a2.platform = 'universal-darwin'
+
+ @si = util_setup_spec_fetcher @a1, @a2, @pl1
+
+ @cmd.handle_options %w[-r -d]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ expected = <<-EOF
+
+*** REMOTE GEMS ***
+
+a (2, 1)
+ Platforms:
+ 1: x86-linux
+ 2: universal-darwin
+ Authors: Abraham Lincoln, Hirohito
+ Rubyforge: http://rubyforge.org/projects/rubygems
+ Homepage: http://a.example.com/
+
+ This is a lot of text. This is a lot of text. This is a lot of text.
+ This is a lot of text.
+
+pl (1)
+ Platform: i386-linux
Author: A User
Homepage: http://example.com
@@ -207,11 +252,30 @@ RubyGems will revert to legacy indexes degrading performance.
assert_equal expected, @ui.error
end
+ def test_execute_legacy_prerelease
+ Gem::SpecFetcher.fetcher = nil
+ si = util_setup_source_info_cache @a1, @a2, @pl1
+
+ @fetcher.data["#{@gem_repo}yaml"] = YAML.dump si
+ @fetcher.data["#{@gem_repo}Marshal.#{Gem.marshal_version}"] =
+ si.dump
+
+ @fetcher.data.delete "#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"
+
+ @cmd.handle_options %w[-r --prerelease]
+
+ e = assert_raises Gem::OperationNotSupportedError do
+ @cmd.execute
+ end
+
+ assert_equal 'Prereleases not supported on legacy repositories', e.message
+ end
+
def test_execute_local_details
- @a2.summary = 'This is a lot of text. ' * 4
- @a2.authors = ['Abraham Lincoln', 'Hirohito']
- @a2.homepage = 'http://a.example.com/'
- @a2.rubyforge_project = 'rubygems'
+ @a3a.summary = 'This is a lot of text. ' * 4
+ @a3a.authors = ['Abraham Lincoln', 'Hirohito']
+ @a3a.homepage = 'http://a.example.com/'
+ @a3a.rubyforge_project = 'rubygems'
@cmd.handle_options %w[--local --details]
@@ -223,10 +287,11 @@ RubyGems will revert to legacy indexes degrading performance.
*** LOCAL GEMS ***
-a (2, 1)
+a (3.a, 2, 1)
Author: A User
Homepage: http://example.com
- Installed at (2): #{@gemhome}
+ Installed at (3.a): #{@gemhome}
+ (2): #{@gemhome}
(1): #{@gemhome}
this is a summary
@@ -253,6 +318,7 @@ c (1.2)
this is a summary
pl (1)
+ Platform: i386-linux
Author: A User
Homepage: http://example.com
Installed at: #{@gemhome}
@@ -274,7 +340,7 @@ pl (1)
end
expected = <<-EOF
-a (2, 1)
+a (3.a, 2, 1)
a_evil (9)
b (2)
c (1.2)
@@ -322,5 +388,45 @@ pl (1)
assert_equal '', @ui.error
end
+ def test_execute_prerelease
+ @cmd.handle_options %w[-r --prerelease]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ expected = <<-EOF
+
+*** REMOTE GEMS ***
+
+a (3.a)
+ EOF
+
+ assert_equal expected, @ui.output
+ assert_equal '', @ui.error
+ end
+
+ def test_execute_prerelease_local
+ @cmd.handle_options %w[-l --prerelease]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ expected = <<-EOF
+
+*** LOCAL GEMS ***
+
+a (3.a, 2, 1)
+a_evil (9)
+b (2)
+c (1.2)
+pl (1)
+ EOF
+
+ assert_equal expected, @ui.output
+ assert_equal "WARNING: prereleases are always shown locally\n", @ui.error
+ end
+
end
diff --git a/test/rubygems/test_gem_commands_server_command.rb b/test/rubygems/test_gem_commands_server_command.rb
index 93d5a6ed47..64ecbeb1f0 100644
--- a/test/rubygems/test_gem_commands_server_command.rb
+++ b/test/rubygems/test_gem_commands_server_command.rb
@@ -22,5 +22,31 @@ class TestGemCommandsServerCommand < RubyGemTestCase
assert_equal File.expand_path('/nonexistent'), @cmd.options[:gemdir]
assert_equal 9999, @cmd.options[:port]
end
+
+ def test_handle_options_port
+ @cmd.send :handle_options, %w[-p 0]
+ assert_equal 0, @cmd.options[:port]
+
+ @cmd.send :handle_options, %w[-p 65535]
+ assert_equal 65535, @cmd.options[:port]
+
+ @cmd.send :handle_options, %w[-p http]
+ assert_equal 80, @cmd.options[:port]
+
+ e = assert_raises OptionParser::InvalidArgument do
+ @cmd.send :handle_options, %w[-p nonexistent]
+ end
+
+ assert_equal 'invalid argument: -p nonexistent: no such named service',
+ e.message
+
+ e = assert_raises OptionParser::InvalidArgument do
+ @cmd.send :handle_options, %w[-p 65536]
+ end
+
+ assert_equal 'invalid argument: -p 65536: not a port number',
+ e.message
+ end
+
end
diff --git a/test/rubygems/test_gem_commands_sources_command.rb b/test/rubygems/test_gem_commands_sources_command.rb
index 75babee39d..d58b35e740 100644
--- a/test/rubygems/test_gem_commands_sources_command.rb
+++ b/test/rubygems/test_gem_commands_sources_command.rb
@@ -11,6 +11,10 @@ class TestGemCommandsSourcesCommand < RubyGemTestCase
@new_repo = "http://beta-gems.example.com"
end
+ def test_initialize_proxy
+ assert @cmd.handles?(['--http-proxy', 'http://proxy.example.com'])
+ end
+
def test_execute
util_setup_spec_fetcher
@cmd.handle_options []
@@ -175,12 +179,12 @@ Will cause RubyGems to revert to legacy indexes, degrading performance.
assert_equal expected, @ui.output
assert_equal '', @ui.error
- assert !File.exist?(cache.system_cache_file),
+ refute File.exist?(cache.system_cache_file),
'system cache file'
- assert !File.exist?(cache.latest_system_cache_file),
+ refute File.exist?(cache.latest_system_cache_file),
'latest system cache file'
- assert !File.exist?(fetcher.dir), 'cache dir removed'
+ refute File.exist?(fetcher.dir), 'cache dir removed'
end
def test_execute_remove
diff --git a/test/rubygems/test_gem_commands_specification_command.rb b/test/rubygems/test_gem_commands_specification_command.rb
index c2379595c7..3f936a64ea 100644
--- a/test/rubygems/test_gem_commands_specification_command.rb
+++ b/test/rubygems/test_gem_commands_specification_command.rb
@@ -70,6 +70,34 @@ class TestGemCommandsSpecificationCommand < RubyGemTestCase
assert_equal '', @ui.error
end
+ def test_execute_field
+ foo = quick_gem 'foo'
+ Gem.source_index.add_spec foo
+
+ @cmd.options[:args] = %w[foo name]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_equal "--- foo\n\n", @ui.output
+ end
+
+ def test_execute_marshal
+ foo = quick_gem 'foo'
+ Gem.source_index.add_spec foo
+
+ @cmd.options[:args] = %w[foo]
+ @cmd.options[:format] = :marshal
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_equal foo, Marshal.load(@ui.output)
+ assert_equal '', @ui.error
+ end
+
def test_execute_remote
foo = quick_gem 'foo'
@@ -92,5 +120,21 @@ class TestGemCommandsSpecificationCommand < RubyGemTestCase
assert_match %r|name: foo|, @ui.output
end
+ def test_execute_ruby
+ foo = quick_gem 'foo'
+ Gem.source_index.add_spec foo
+
+ @cmd.options[:args] = %w[foo]
+ @cmd.options[:format] = :ruby
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_match %r|Gem::Specification.new|, @ui.output
+ assert_match %r|s.name = %q\{foo\}|, @ui.output
+ assert_equal '', @ui.error
+ end
+
end
diff --git a/test/rubygems/test_gem_commands_uninstall_command.rb b/test/rubygems/test_gem_commands_uninstall_command.rb
index cded63f447..b1b7a56868 100644
--- a/test/rubygems/test_gem_commands_uninstall_command.rb
+++ b/test/rubygems/test_gem_commands_uninstall_command.rb
@@ -53,9 +53,10 @@ class TestGemCommandsUninstallCommand < GemInstallerTestCase
end
end
- assert_match(/\AUnknown gem foo >= 0$/, e.message)
+ assert_match(/\Acannot uninstall, check `gem list -d foo`$/, e.message)
output = @ui.output.split "\n"
- assert output.empty?, "UI output should be empty after an uninstall error"
+ assert_empty output, "UI output should be empty after an uninstall error"
end
+
end
diff --git a/test/rubygems/test_gem_commands_unpack_command.rb b/test/rubygems/test_gem_commands_unpack_command.rb
index 6dac927757..6e53acbc54 100644
--- a/test/rubygems/test_gem_commands_unpack_command.rb
+++ b/test/rubygems/test_gem_commands_unpack_command.rb
@@ -14,7 +14,7 @@ class TestGemCommandsUnpackCommand < RubyGemTestCase
def test_execute
util_make_gems
- @cmd.options[:args] = %w[a]
+ @cmd.options[:args] = %w[a b]
use_ui @ui do
Dir.chdir @tempdir do
@@ -22,7 +22,8 @@ class TestGemCommandsUnpackCommand < RubyGemTestCase
end
end
- assert File.exist?(File.join(@tempdir, 'a-2'))
+ assert File.exist?(File.join(@tempdir, 'a-3.a')), 'a should be installed'
+ assert File.exist?(File.join(@tempdir, 'b-2')), 'b should be installed'
end
def test_execute_gem_path
@@ -43,7 +44,7 @@ class TestGemCommandsUnpackCommand < RubyGemTestCase
end
end
- assert File.exist?(File.join(@tempdir, 'a-2'))
+ assert File.exist?(File.join(@tempdir, 'a-3.a'))
end
def test_execute_gem_path_missing
@@ -80,7 +81,7 @@ class TestGemCommandsUnpackCommand < RubyGemTestCase
end
end
- assert File.exist?(File.join(@tempdir, target, 'a-2'))
+ assert File.exist?(File.join(@tempdir, target, 'a-3.a'))
end
def test_execute_exact_match
diff --git a/test/rubygems/test_gem_commands_update_command.rb b/test/rubygems/test_gem_commands_update_command.rb
index 77727fe6db..4d7592a4c0 100644
--- a/test/rubygems/test_gem_commands_update_command.rb
+++ b/test/rubygems/test_gem_commands_update_command.rb
@@ -8,6 +8,9 @@ class TestGemCommandsUpdateCommand < RubyGemTestCase
@cmd = Gem::Commands::UpdateCommand.new
+ @cmd.options[:generate_rdoc] = false
+ @cmd.options[:generate_ri] = false
+
util_setup_fake_fetcher
@a1_path = File.join @gemhome, 'cache', "#{@a1.full_name}.gem"
@@ -27,6 +30,8 @@ class TestGemCommandsUpdateCommand < RubyGemTestCase
Gem::Installer.new(@a1_path).install
@cmd.options[:args] = []
+ @cmd.options[:generate_rdoc] = true
+ @cmd.options[:generate_ri] = true
use_ui @ui do
@cmd.execute
@@ -37,8 +42,10 @@ class TestGemCommandsUpdateCommand < RubyGemTestCase
assert_equal "Updating #{@a2.name}", out.shift
assert_equal "Successfully installed #{@a2.full_name}", out.shift
assert_equal "Gems updated: #{@a2.name}", out.shift
+ assert_equal "Installing ri documentation for a-2...", out.shift
+ assert_equal "Installing RDoc documentation for a-2...", out.shift
- assert out.empty?, out.inspect
+ assert_empty out
end
# before:
@@ -101,7 +108,7 @@ class TestGemCommandsUpdateCommand < RubyGemTestCase
assert_equal "Gems updated: #{@c2.name}, #{@b2.name}, #{@a2.name}",
out.shift
- assert out.empty?, out.inspect
+ assert_empty out
end
def test_execute_named
@@ -121,7 +128,7 @@ class TestGemCommandsUpdateCommand < RubyGemTestCase
assert_equal "Successfully installed #{@a2.full_name}", out.shift
assert_equal "Gems updated: #{@a2.name}", out.shift
- assert out.empty?, out.inspect
+ assert_empty out
end
def test_execute_named_up_to_date
@@ -139,7 +146,7 @@ class TestGemCommandsUpdateCommand < RubyGemTestCase
assert_equal "Updating installed gems", out.shift
assert_equal "Nothing to update", out.shift
- assert out.empty?, out.inspect
+ assert_empty out
end
def test_execute_up_to_date
@@ -157,8 +164,6 @@ class TestGemCommandsUpdateCommand < RubyGemTestCase
assert_equal "Updating installed gems", out.shift
assert_equal "Nothing to update", out.shift
- assert out.empty?, out.inspect
+ assert_empty out
end
-
end
-
diff --git a/test/rubygems/test_gem_dependency.rb b/test/rubygems/test_gem_dependency.rb
index 5b409fa1a8..7b8c7bb45d 100644
--- a/test/rubygems/test_gem_dependency.rb
+++ b/test/rubygems/test_gem_dependency.rb
@@ -20,6 +20,10 @@ class TestGemDependency < RubyGemTestCase
@r1_0 = Gem::Requirement.new ['> 1.0']
end
+ def dep(name, version)
+ Gem::Dependency.new name, version
+ end
+
def test_initialize
assert_equal "pkg", @pkg1_0.name
assert_equal @r1_0, @pkg1_0.version_requirements
@@ -96,10 +100,6 @@ class TestGemDependency < RubyGemTestCase
end
def test_equals_tilde
- def dep(name, version)
- Gem::Dependency.new name, version
- end
-
a0 = dep 'a', '0'
a1 = dep 'a', '1'
b0 = dep 'b', '0'
@@ -108,14 +108,64 @@ class TestGemDependency < RubyGemTestCase
pa0r = dep(/a/, '>= 0')
pab0r = dep(/a|b/, '>= 0')
- assert((a0 =~ a0), 'match self')
- assert((pa0 =~ a0), 'match version exact')
- assert((pa0 =~ a1), 'match version')
- assert((pa0r =~ a0), 'match regex simple')
- assert((pab0r =~ a0), 'match regex complex')
+ assert_match a0, a0, 'match self'
+ assert_match pa0, a0, 'match version exact'
+ assert_match pa0, a1, 'match version'
+ assert_match pa0r, a0, 'match regex simple'
+ assert_match pab0r, a0, 'match regex complex'
+
+ refute_match pa0r, b0, 'fail match regex'
+ refute_match pa0r, Object.new, 'fail match Object'
+ end
+
+ def test_equals_tilde_escape
+ a1 = Gem::Dependency.new 'a', '1'
+
+ pab1 = Gem::Dependency.new 'a|b', '>= 1'
+ pab1r = Gem::Dependency.new(/a|b/, '>= 1')
+
+ refute_match pab1, a1, 'escaped'
+ assert_match pab1r, a1, 'exact regexp'
+ end
+
+ def test_equals_tilde_object
+ a0 = Object.new
+
+ def a0.name() 'a' end
+ def a0.version() '0' end
+
+ pa0 = Gem::Dependency.new 'a', '>= 0'
+
+ assert_match pa0, a0, 'match version exact'
+ end
+
+ def test_equals_tilde_spec
+ def spec(name, version)
+ Gem::Specification.new do |spec|
+ spec.name = name
+ spec.version = version
+ end
+ end
+
+ a0 = spec 'a', '0'
+ a1 = spec 'a', '1'
+ b0 = spec 'b', '0'
+
+ pa0 = dep 'a', '>= 0'
+ pa0r = dep(/a/, '>= 0')
+ pab0r = dep(/a|b/, '>= 0')
+
+ assert_match pa0, a0, 'match version exact'
+ assert_match pa0, a1, 'match version'
- assert(!(pa0r =~ b0), 'fail match regex')
- assert(!(pa0r =~ Object.new), 'fail match Object')
+ assert_match pa0r, a0, 'match regex simple'
+ assert_match pa0r, a1, 'match regex simple'
+
+ assert_match pab0r, a0, 'match regex complex'
+ assert_match pab0r, b0, 'match regex complex'
+
+ refute_match pa0r, b0, 'fail match regex'
+ refute_match pa0r, Object.new, 'fail match Object'
end
def test_hash
@@ -135,5 +185,6 @@ class TestGemDependency < RubyGemTestCase
refute_equal(runtime.hash, development.hash)
end
+
end
diff --git a/test/rubygems/test_gem_dependency_installer.rb b/test/rubygems/test_gem_dependency_installer.rb
index cf7e569714..2fea37adcc 100644
--- a/test/rubygems/test_gem_dependency_installer.rb
+++ b/test/rubygems/test_gem_dependency_installer.rb
@@ -13,8 +13,10 @@ class TestGemDependencyInstaller < RubyGemTestCase
write_file File.join('gems', 'a-1', 'bin', 'a_bin') do |fp|
fp.puts "#!/usr/bin/ruby"
end
+
@a1, @a1_gem = util_gem 'a', '1' do |s| s.executables << 'a_bin' end
@aa1, @aa1_gem = util_gem 'aa', '1'
+ @a1_pre, @a1_pre_gem = util_gem 'a', '1.a'
@b1, @b1_gem = util_gem 'b', '1' do |s|
s.add_dependency 'a'
@@ -44,8 +46,8 @@ class TestGemDependencyInstaller < RubyGemTestCase
@fetcher = Gem::FakeFetcher.new
Gem::RemoteFetcher.fetcher = @fetcher
- si = util_setup_spec_fetcher @a1, @b1, @d1, @d2, @x1_m, @x1_o, @w1, @y1,
- @y1_1_p, @z1
+ si = util_setup_spec_fetcher(@a1, @a1_pre, @b1, @d1, @d2, @x1_m, @x1_o, @w1, @y1,
+ @y1_1_p, @z1)
util_clear_gems
end
@@ -257,7 +259,7 @@ class TestGemDependencyInstaller < RubyGemTestCase
inst.install 'a'
end
- assert_match %r|\A#!/\S+/env #{Gem::ConfigMap[:RUBY_INSTALL_NAME]}\n|,
+ assert_match %r|\A#!/\S+/env #{Gem::ConfigMap[:ruby_install_name]}\n|,
File.read(File.join(@gemhome, 'bin', 'a_bin'))
end
@@ -356,13 +358,15 @@ class TestGemDependencyInstaller < RubyGemTestCase
FileUtils.mv @b1_gem, @tempdir
inst = nil
- Gem.source_index.gems.delete @a1.full_name
+ Gem.source_index.remove_spec @a1.full_name
+ Gem.source_index.remove_spec @a1_pre.full_name
Dir.chdir @tempdir do
e = assert_raises Gem::InstallError do
inst = Gem::DependencyInstaller.new :domain => :local
inst.install 'b'
end
+
assert_equal 'b requires a (>= 0, runtime)', e.message
end
@@ -632,5 +636,16 @@ class TestGemDependencyInstaller < RubyGemTestCase
assert_equal %w[d-1 e-1], inst.gems_to_install.map { |s| s.full_name }
end
-end
+ def test_prerelease_uses_pre_index
+ installer = Gem::DependencyInstaller.new
+ pre_installer = Gem::DependencyInstaller.new(:prerelease => true)
+ dependency = Gem::Dependency.new('a', Gem::Requirement.default)
+ releases = installer.find_gems_with_sources(dependency).map{ |gems, *| gems }
+ prereleases = pre_installer.find_gems_with_sources(dependency).map{ |gems, *| gems }
+
+ assert releases.select{ |s| s.name == 'a' and s.version.to_s == '1' }.first
+ assert releases.select{ |s| s.name == 'a' and s.version.to_s == '1.a' }.empty?
+ assert_equal [@a1_pre], prereleases
+ end
+end
diff --git a/test/rubygems/test_gem_dependency_list.rb b/test/rubygems/test_gem_dependency_list.rb
index a10a1a4b2c..ddceb35256 100644
--- a/test/rubygems/test_gem_dependency_list.rb
+++ b/test/rubygems/test_gem_dependency_list.rb
@@ -105,7 +105,7 @@ class TestGemDependencyList < RubyGemTestCase
@deplist.add @b2
- assert ! @deplist.ok?, 'unsatisfied dependency'
+ refute @deplist.ok?, 'unsatisfied dependency'
@deplist.add @a1
@@ -144,7 +144,7 @@ class TestGemDependencyList < RubyGemTestCase
@deplist.add @b2
- assert ! @deplist.ok_to_remove?("a-1")
+ refute @deplist.ok_to_remove?("a-1")
@deplist.add @a2
@@ -161,7 +161,7 @@ class TestGemDependencyList < RubyGemTestCase
@deplist.remove_by_name("a-1")
- assert ! @deplist.ok_to_remove?("a-2")
+ refute @deplist.ok_to_remove?("a-2")
end
def test_remove_by_name
@@ -169,7 +169,7 @@ class TestGemDependencyList < RubyGemTestCase
@deplist.remove_by_name "a-1"
- assert ! @deplist.ok?
+ refute @deplist.ok?
end
def test_tsort_each_node
@@ -181,7 +181,7 @@ class TestGemDependencyList < RubyGemTestCase
assert_equal order.shift, node.full_name
end
- assert order.empty?
+ assert_empty order
end
def test_tsort_each_child
@@ -193,7 +193,7 @@ class TestGemDependencyList < RubyGemTestCase
assert_equal order.shift, node.full_name
end
- assert order.empty?
+ assert_empty order
end
# d1 -> b1 -> a1
diff --git a/test/rubygems/test_gem_doc_manager.rb b/test/rubygems/test_gem_doc_manager.rb
index f519ce7cd4..bcedb87b56 100644
--- a/test/rubygems/test_gem_doc_manager.rb
+++ b/test/rubygems/test_gem_doc_manager.rb
@@ -18,7 +18,13 @@ class TestGemDocManager < RubyGemTestCase
def test_uninstall_doc_unwritable
orig_mode = File.stat(@spec.installation_path).mode
- File.chmod 0, @spec.installation_path
+
+ # File.chmod has no effect on MS Windows directories (it needs ACL).
+ if win_platform?
+ skip("test_uninstall_doc_unwritable skipped on MS Windows")
+ else
+ File.chmod(0, @spec.installation_path)
+ end
assert_raises Gem::FilePermissionError do
@manager.uninstall_doc
diff --git a/test/rubygems/test_gem_ext_configure_builder.rb b/test/rubygems/test_gem_ext_configure_builder.rb
index 304fc8e3f7..8f8525f5fd 100644
--- a/test/rubygems/test_gem_ext_configure_builder.rb
+++ b/test/rubygems/test_gem_ext_configure_builder.rb
@@ -16,7 +16,7 @@ class TestGemExtConfigureBuilder < RubyGemTestCase
end
def test_self_build
- return if RUBY_PLATFORM =~ /mswin/ # HACK
+ skip("test_self_build skipped on MS Windows (VC++)") if vc_windows?
File.open File.join(@ext, './configure'), 'w' do |configure|
configure.puts "#!/bin/sh\necho \"#{@makefile_body}\" > Makefile"
@@ -37,7 +37,7 @@ class TestGemExtConfigureBuilder < RubyGemTestCase
end
def test_self_build_fail
- return if RUBY_PLATFORM =~ /mswin/ # HACK
+ skip("test_self_build_fail skipped on MS Windows (VC++)") if vc_windows?
output = []
error = assert_raises Gem::InstallError do
@@ -63,6 +63,10 @@ class TestGemExtConfigureBuilder < RubyGemTestCase
end
def test_self_build_has_makefile
+ if vc_windows? && !nmake_found?
+ skip("test_self_build_has_makefile skipped - nmake not found")
+ end
+
File.open File.join(@ext, 'Makefile'), 'w' do |makefile|
makefile.puts @makefile_body
end
@@ -72,14 +76,8 @@ class TestGemExtConfigureBuilder < RubyGemTestCase
Gem::Ext::ConfigureBuilder.build nil, nil, @dest_path, output
end
- case RUBY_PLATFORM
- when /mswin/ then
- assert_equal 'nmake', output[0]
- assert_equal 'nmake install', output[2]
- else
- assert_equal 'make', output[0]
- assert_equal 'make install', output[2]
- end
+ assert_equal make_command, output[0]
+ assert_equal "#{make_command} install", output[2]
end
end
diff --git a/test/rubygems/test_gem_ext_ext_conf_builder.rb b/test/rubygems/test_gem_ext_ext_conf_builder.rb
index d178c1f737..e815a6555f 100644
--- a/test/rubygems/test_gem_ext_ext_conf_builder.rb
+++ b/test/rubygems/test_gem_ext_ext_conf_builder.rb
@@ -14,6 +14,10 @@ class TestGemExtExtConfBuilder < RubyGemTestCase
end
def test_class_build
+ if vc_windows? && !nmake_found?
+ skip("test_class_build skipped - nmake not found")
+ end
+
File.open File.join(@ext, 'extconf.rb'), 'w' do |extconf|
extconf.puts "require 'mkmf'\ncreate_makefile 'foo'"
end
@@ -46,6 +50,10 @@ class TestGemExtExtConfBuilder < RubyGemTestCase
end
def test_class_build_extconf_fail
+ if vc_windows? && !nmake_found?
+ skip("test_class_build_extconf_fail skipped - nmake not found")
+ end
+
File.open File.join(@ext, 'extconf.rb'), 'w' do |extconf|
extconf.puts "require 'mkmf'"
extconf.puts "have_library 'nonexistent' or abort 'need libnonexistent'"
@@ -69,6 +77,10 @@ checking for main\(\) in .*?nonexistent/m, error.message)
end
def test_class_make
+ if vc_windows? && !nmake_found?
+ skip("test_class_make skipped - nmake not found")
+ end
+
output = []
makefile_path = File.join(@ext, 'Makefile')
File.open makefile_path, 'w' do |makefile|
@@ -82,14 +94,8 @@ checking for main\(\) in .*?nonexistent/m, error.message)
Gem::Ext::ExtConfBuilder.make @ext, output
end
- case RUBY_PLATFORM
- when /mswin/ then
- assert_equal 'nmake', output[0]
- assert_equal 'nmake install', output[2]
- else
- assert_equal 'make', output[0]
- assert_equal 'make install', output[2]
- end
+ assert_equal make_command, output[0]
+ assert_equal "#{make_command} install", output[2]
edited_makefile = <<-EOF
RUBYARCHDIR = #{@ext}$(target_prefix)
diff --git a/test/rubygems/test_gem_format.rb b/test/rubygems/test_gem_format.rb
index 4d8a38a062..d09ab6ce19 100644
--- a/test/rubygems/test_gem_format.rb
+++ b/test/rubygems/test_gem_format.rb
@@ -21,7 +21,7 @@ class TestGemFormat < RubyGemTestCase
gems = Dir[File.join(@gemhome, 'cache', '*.gem')]
- names = [@a1, @a2, @a_evil9, @b2, @c1_2, @pl1].map do |spec|
+ names = [@a1, @a2, @a3a, @a_evil9, @b2, @c1_2, @pl1].map do |spec|
spec.original_name
end
diff --git a/test/rubygems/test_gem_gem_path_searcher.rb b/test/rubygems/test_gem_gem_path_searcher.rb
index d69de4d22a..5737c0b226 100644
--- a/test/rubygems/test_gem_gem_path_searcher.rb
+++ b/test/rubygems/test_gem_gem_path_searcher.rb
@@ -51,7 +51,7 @@ class TestGemGemPathSearcher < RubyGemTestCase
end
def test_matching_file_eh
- assert !@gps.matching_file?(@foo1, 'bar')
+ refute @gps.matching_file?(@foo1, 'bar')
assert @gps.matching_file?(@foo1, 'foo')
end
diff --git a/test/rubygems/test_gem_gem_runner.rb b/test/rubygems/test_gem_gem_runner.rb
index 2b4889e015..24a45e4281 100644
--- a/test/rubygems/test_gem_gem_runner.rb
+++ b/test/rubygems/test_gem_gem_runner.rb
@@ -30,5 +30,16 @@ class TestGemGemRunner < RubyGemTestCase
assert_equal %w[--all], Gem::DocManager.configured_args
end
+ def test_build_args__are_handled
+ Gem.clear_paths
+
+ gr = Gem::GemRunner.new
+ assert_raises(Gem::SystemExitException) do
+ gr.run(%W[--help -- --build_arg1 --build_arg2])
+ end
+
+ assert_equal %w[--build_arg1 --build_arg2], Gem::Command.build_args
+ end
+
end
diff --git a/test/rubygems/test_gem_indexer.rb b/test/rubygems/test_gem_indexer.rb
index b1932c7335..a48acbbfe6 100644
--- a/test/rubygems/test_gem_indexer.rb
+++ b/test/rubygems/test_gem_indexer.rb
@@ -19,21 +19,45 @@ class TestGemIndexer < RubyGemTestCase
util_make_gems
- @d2_0 = quick_gem 'd', '2.0'
+ @d2_0 = quick_gem 'd', '2.0' do |s|
+ s.date = Gem::Specification::TODAY - 86400 * 3
+ end
util_build_gem @d2_0
+ @d2_0_a = quick_gem 'd', '2.0.a'
+ util_build_gem @d2_0_a
+
+ @d2_0_b = quick_gem 'd', '2.0.b'
+ util_build_gem @d2_0_b
+
gems = File.join(@tempdir, 'gems')
FileUtils.mkdir_p gems
cache_gems = File.join @gemhome, 'cache', '*.gem'
FileUtils.mv Dir[cache_gems], gems
- @indexer = Gem::Indexer.new @tempdir
+ @indexer = Gem::Indexer.new @tempdir, :rss_title => 'ExampleForge gems',
+ :rss_host => 'example.com',
+ :rss_gems_host => 'gems.example.com'
end
def test_initialize
assert_equal @tempdir, @indexer.dest_directory
assert_equal File.join(Dir.tmpdir, "gem_generate_index_#{$$}"),
@indexer.directory
+
+ indexer = Gem::Indexer.new @tempdir
+ assert indexer.build_legacy
+ assert indexer.build_modern
+
+ indexer = Gem::Indexer.new @tempdir, :build_legacy => false,
+ :build_modern => true
+ refute indexer.build_legacy
+ assert indexer.build_modern
+
+ indexer = Gem::Indexer.new @tempdir, :build_legacy => true,
+ :build_modern => false
+ assert indexer.build_legacy
+ refute indexer.build_modern
end
def test_build_indicies
@@ -137,6 +161,296 @@ pl-1-i386-linux
assert_indexed @tempdir, "latest_specs.#{@marshal_version}"
assert_indexed @tempdir, "latest_specs.#{@marshal_version}.gz"
+
+ expected = <<-EOF
+<?xml version="1.0"?>
+<rss version="2.0">
+ <channel>
+ <title>ExampleForge gems</title>
+ <link>http://example.com</link>
+ <description>Recently released gems from http://example.com</description>
+ <generator>RubyGems v#{Gem::RubyGemsVersion}</generator>
+ <docs>http://cyber.law.harvard.edu/rss/rss.html</docs>
+ <item>
+ <title>a-2</title>
+ <description>
+&lt;pre&gt;This is a test description&lt;/pre&gt;
+ </description>
+ <author>example@example.com (A User)</author>
+ <guid>a-2</guid>
+ <enclosure url="http://gems.example.com/gems/a-2.gem"
+ length="3072" type="application/octet-stream" />
+ <pubDate>#{Gem::Specification::TODAY.rfc2822}</pubDate>
+ <link>http://example.com</link>
+ </item>
+ <item>
+ <title>a_evil-9</title>
+ <description>
+&lt;pre&gt;This is a test description&lt;/pre&gt;
+ </description>
+ <author>example@example.com (A User)</author>
+ <guid>a_evil-9</guid>
+ <enclosure url="http://gems.example.com/gems/a_evil-9.gem"
+ length="3072" type="application/octet-stream" />
+ <pubDate>#{Gem::Specification::TODAY.rfc2822}</pubDate>
+ <link>http://example.com</link>
+ </item>
+ <item>
+ <title>b-2</title>
+ <description>
+&lt;pre&gt;This is a test description&lt;/pre&gt;
+ </description>
+ <author>example@example.com (A User)</author>
+ <guid>b-2</guid>
+ <enclosure url="http://gems.example.com/gems/b-2.gem"
+ length="3072" type="application/octet-stream" />
+ <pubDate>#{Gem::Specification::TODAY.rfc2822}</pubDate>
+ <link>http://example.com</link>
+ </item>
+ <item>
+ <title>c-1.2</title>
+ <description>
+&lt;pre&gt;This is a test description&lt;/pre&gt;
+ </description>
+ <author>example@example.com (A User)</author>
+ <guid>c-1.2</guid>
+ <enclosure url="http://gems.example.com/gems/c-1.2.gem"
+ length="3072" type="application/octet-stream" />
+ <pubDate>#{Gem::Specification::TODAY.rfc2822}</pubDate>
+ <link>http://example.com</link>
+ </item>
+ <item>
+ <title>pl-1-x86-linux</title>
+ <description>
+&lt;pre&gt;This is a test description&lt;/pre&gt;
+ </description>
+ <author>example@example.com (A User)</author>
+ <guid>pl-1-x86-linux</guid>
+ <enclosure url="http://gems.example.com/gems/pl-1-x86-linux.gem"
+ length="3072" type="application/octet-stream" />
+ <pubDate>#{Gem::Specification::TODAY.rfc2822}</pubDate>
+ <link>http://example.com</link>
+ </item>
+ <item>
+ <title>a-1</title>
+ <description>
+&lt;pre&gt;This line is really, really long. So long, in fact, that it is more than
+eighty characters long! The purpose of this line is for testing wrapping
+behavior because sometimes people don't wrap their text to eighty characters.
+Without the wrapping, the text might not look good in the RSS feed.
+
+Also, a list:
+ * An entry that's actually kind of sort
+ * an entry that's really long, which will probably get wrapped funny.
+That's ok, somebody wasn't thinking straight when they made it more than
+eighty characters.&lt;/pre&gt;
+ </description>
+ <author>example@example.com (Example), example2@example.com (Example2)</author>
+ <guid>a-1</guid>
+ <enclosure url="http://gems.example.com/gems/a-1.gem"
+ length="3584" type="application/octet-stream" />
+ <pubDate>#{(Gem::Specification::TODAY - 86400).rfc2822}</pubDate>
+ <link>http://a.example.com</link>
+ </item>
+ </channel>
+</rss>
+ EOF
+
+ gems_rss = File.read File.join(@tempdir, 'index.rss')
+
+ assert_equal expected, gems_rss
+ end
+
+ def test_generate_index_legacy
+ @indexer.build_modern = false
+ @indexer.build_legacy = true
+
+ use_ui @ui do
+ @indexer.generate_index
+ end
+
+ assert_indexed @tempdir, 'yaml'
+ assert_indexed @tempdir, 'yaml.Z'
+ assert_indexed @tempdir, "Marshal.#{@marshal_version}"
+ assert_indexed @tempdir, "Marshal.#{@marshal_version}.Z"
+
+ quickdir = File.join @tempdir, 'quick'
+ marshal_quickdir = File.join quickdir, "Marshal.#{@marshal_version}"
+
+ assert File.directory?(quickdir)
+ assert File.directory?(marshal_quickdir)
+
+ assert_indexed quickdir, "index"
+ assert_indexed quickdir, "index.rz"
+
+ assert_indexed quickdir, "latest_index"
+ assert_indexed quickdir, "latest_index.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"
+ refute_indexed quickdir, "#{@pl1.full_name}.gemspec.rz"
+
+ assert_indexed marshal_quickdir, "#{@a1.full_name}.gemspec.rz"
+ assert_indexed marshal_quickdir, "#{@a2.full_name}.gemspec.rz"
+
+ refute_indexed quickdir, "#{@c1_2.full_name}.gemspec"
+ refute_indexed marshal_quickdir, "#{@c1_2.full_name}.gemspec"
+
+ refute_indexed @tempdir, "specs.#{@marshal_version}"
+ refute_indexed @tempdir, "specs.#{@marshal_version}.gz"
+
+ refute_indexed @tempdir, "latest_specs.#{@marshal_version}"
+ refute_indexed @tempdir, "latest_specs.#{@marshal_version}.gz"
+ end
+
+ def test_generate_index_legacy_back_to_back
+ @indexer.build_modern = true
+ @indexer.build_legacy = true
+
+ use_ui @ui do
+ @indexer.generate_index
+ end
+
+ @indexer = Gem::Indexer.new @tempdir
+ @indexer.build_modern = false
+ @indexer.build_legacy = true
+
+ use_ui @ui do
+ @indexer.generate_index
+ end
+
+ assert_indexed @tempdir, 'yaml'
+ assert_indexed @tempdir, 'yaml.Z'
+ assert_indexed @tempdir, "Marshal.#{@marshal_version}"
+ assert_indexed @tempdir, "Marshal.#{@marshal_version}.Z"
+
+ quickdir = File.join @tempdir, 'quick'
+ marshal_quickdir = File.join quickdir, "Marshal.#{@marshal_version}"
+
+ assert File.directory?(quickdir)
+ assert File.directory?(marshal_quickdir)
+
+ assert_indexed quickdir, "index"
+ assert_indexed quickdir, "index.rz"
+
+ assert_indexed quickdir, "latest_index"
+ assert_indexed quickdir, "latest_index.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"
+
+ assert_indexed marshal_quickdir, "#{@a1.full_name}.gemspec.rz"
+ assert_indexed marshal_quickdir, "#{@a2.full_name}.gemspec.rz"
+
+ assert_indexed @tempdir, "specs.#{@marshal_version}"
+ assert_indexed @tempdir, "specs.#{@marshal_version}.gz"
+
+ assert_indexed @tempdir, "latest_specs.#{@marshal_version}"
+ assert_indexed @tempdir, "latest_specs.#{@marshal_version}.gz"
+ end
+
+ def test_generate_index_modern
+ @indexer.build_modern = true
+ @indexer.build_legacy = false
+
+ use_ui @ui do
+ @indexer.generate_index
+ end
+
+ refute_indexed @tempdir, 'yaml'
+ refute_indexed @tempdir, 'yaml.Z'
+ refute_indexed @tempdir, "Marshal.#{@marshal_version}"
+ refute_indexed @tempdir, "Marshal.#{@marshal_version}.Z"
+
+ quickdir = File.join @tempdir, 'quick'
+ marshal_quickdir = File.join quickdir, "Marshal.#{@marshal_version}"
+
+ assert File.directory?(quickdir), 'quickdir should be directory'
+ assert File.directory?(marshal_quickdir)
+
+ refute_indexed quickdir, "index"
+ refute_indexed quickdir, "index.rz"
+
+ refute_indexed quickdir, "latest_index"
+ refute_indexed quickdir, "latest_index.rz"
+
+ refute_indexed quickdir, "#{@a1.full_name}.gemspec.rz"
+ refute_indexed quickdir, "#{@a2.full_name}.gemspec.rz"
+ refute_indexed quickdir, "#{@b2.full_name}.gemspec.rz"
+ refute_indexed quickdir, "#{@c1_2.full_name}.gemspec.rz"
+
+ refute_indexed quickdir, "#{@pl1.original_name}.gemspec.rz"
+ refute_indexed quickdir, "#{@pl1.full_name}.gemspec.rz"
+
+ assert_indexed marshal_quickdir, "#{@a1.full_name}.gemspec.rz"
+ assert_indexed marshal_quickdir, "#{@a2.full_name}.gemspec.rz"
+
+ refute_indexed quickdir, "#{@c1_2.full_name}.gemspec"
+ refute_indexed marshal_quickdir, "#{@c1_2.full_name}.gemspec"
+
+ assert_indexed @tempdir, "specs.#{@marshal_version}"
+ assert_indexed @tempdir, "specs.#{@marshal_version}.gz"
+
+ assert_indexed @tempdir, "latest_specs.#{@marshal_version}"
+ assert_indexed @tempdir, "latest_specs.#{@marshal_version}.gz"
+ end
+
+ def test_generate_index_modern_back_to_back
+ @indexer.build_modern = true
+ @indexer.build_legacy = true
+
+ use_ui @ui do
+ @indexer.generate_index
+ end
+
+ @indexer = Gem::Indexer.new @tempdir
+ @indexer.build_modern = true
+ @indexer.build_legacy = false
+
+ use_ui @ui do
+ @indexer.generate_index
+ end
+
+ assert_indexed @tempdir, 'yaml'
+ assert_indexed @tempdir, 'yaml.Z'
+ assert_indexed @tempdir, "Marshal.#{@marshal_version}"
+ assert_indexed @tempdir, "Marshal.#{@marshal_version}.Z"
+
+ quickdir = File.join @tempdir, 'quick'
+ marshal_quickdir = File.join quickdir, "Marshal.#{@marshal_version}"
+
+ assert File.directory?(quickdir)
+ assert File.directory?(marshal_quickdir)
+
+ assert_indexed quickdir, "index"
+ assert_indexed quickdir, "index.rz"
+
+ assert_indexed quickdir, "latest_index"
+ assert_indexed quickdir, "latest_index.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"
+
+ assert_indexed marshal_quickdir, "#{@a1.full_name}.gemspec.rz"
+ assert_indexed marshal_quickdir, "#{@a2.full_name}.gemspec.rz"
+
+ assert_indexed @tempdir, "specs.#{@marshal_version}"
+ assert_indexed @tempdir, "specs.#{@marshal_version}.gz"
+
+ assert_indexed @tempdir, "latest_specs.#{@marshal_version}"
+ assert_indexed @tempdir, "latest_specs.#{@marshal_version}.gz"
end
def test_generate_index_ui
@@ -144,25 +458,25 @@ pl-1-i386-linux
@indexer.generate_index
end
- expected = <<-EOF
-Loading 7 gems from #{@tempdir}
-.......
-Loaded all gems
-Generating quick index gemspecs for 7 gems
-.......
-Complete
-Generating specs index
-Generating latest specs index
-Generating quick index
-Generating latest index
-Generating Marshal master index
-Generating YAML master index for 7 gems (this may take a while)
-.......
-Complete
-Compressing indicies
- EOF
+ assert_match %r%^Loading 10 gems from #{Regexp.escape @tempdir}$%,
+ @ui.output
+ assert_match %r%^\.\.\.\.\.\.\.\.\.\.$%, @ui.output
+ assert_match %r%^Loaded all gems$%, @ui.output
+ assert_match %r%^Generating Marshal quick index gemspecs for 7 gems$%,
+ @ui.output
+ assert_match %r%^Generating YAML quick index gemspecs for 7 gems$%,
+ @ui.output
+ assert_match %r%^Complete$%, @ui.output
+ assert_match %r%^Generating specs index$%, @ui.output
+ assert_match %r%^Generating latest specs index$%, @ui.output
+ assert_match %r%^Generating quick index$%, @ui.output
+ assert_match %r%^Generating latest index$%, @ui.output
+ assert_match %r%^Generating prerelease specs index$%, @ui.output
+ assert_match %r%^Generating Marshal master index$%, @ui.output
+ assert_match %r%^Generating YAML master index for 7 gems \(this may take a while\)$%, @ui.output
+ assert_match %r%^Complete$%, @ui.output
+ assert_match %r%^Compressing indicies$%, @ui.output
- assert_equal expected, @ui.output
assert_equal '', @ui.error
end
@@ -248,6 +562,71 @@ Compressing indicies
'identical platforms not identical'
end
+ def test_generate_index_prerelease_specs
+ use_ui @ui do
+ @indexer.generate_index
+ end
+
+ prerelease_specs_path = File.join @tempdir, "prerelease_specs.#{@marshal_version}"
+
+ prerelease_specs_dump = Gem.read_binary prerelease_specs_path
+ prerelease_specs = Marshal.load prerelease_specs_dump
+
+ assert_equal [['a', Gem::Version.new('3.a'), 'ruby'],
+ ['d', Gem::Version.new('2.0.a'), 'ruby'],
+ ['d', Gem::Version.new('2.0.b'), 'ruby']],
+ prerelease_specs
+ end
+
+ def test_update_index
+ use_ui @ui do
+ @indexer.generate_index
+ end
+
+ quickdir = File.join @tempdir, 'quick'
+ marshal_quickdir = File.join quickdir, "Marshal.#{@marshal_version}"
+
+ assert File.directory?(quickdir)
+ assert File.directory?(marshal_quickdir)
+
+ @d2_1 = quick_gem 'd', '2.1'
+ util_build_gem @d2_1
+ @d2_1_tuple = [@d2_1.name, @d2_1.version, @d2_1.original_platform]
+
+ @d2_1_a = quick_gem 'd', '2.2.a'
+ util_build_gem @d2_1_a
+ @d2_1_a_tuple = [@d2_1_a.name, @d2_1_a.version, @d2_1_a.original_platform]
+
+ gems = File.join @tempdir, 'gems'
+ FileUtils.mv File.join(@gemhome, 'cache', "#{@d2_1.full_name}.gem"), gems
+ FileUtils.mv File.join(@gemhome, 'cache', "#{@d2_1_a.full_name}.gem"), gems
+
+ use_ui @ui do
+ @indexer.update_index
+ end
+
+ assert_indexed marshal_quickdir, "#{@d2_1.full_name}.gemspec.rz"
+
+ specs_index = Marshal.load Gem.read_binary(@indexer.dest_specs_index)
+
+ assert_includes specs_index, @d2_1_tuple
+ refute_includes specs_index, @d2_1_a_tuple
+
+ latest_specs_index = Marshal.load \
+ Gem.read_binary(@indexer.dest_latest_specs_index)
+
+ assert_includes latest_specs_index, @d2_1_tuple
+ assert_includes latest_specs_index,
+ [@d2_0.name, @d2_0.version, @d2_0.original_platform]
+ refute_includes latest_specs_index, @d2_1_a_tuple
+
+ pre_specs_index = Marshal.load \
+ Gem.read_binary(@indexer.dest_prerelease_specs_index)
+
+ assert_includes pre_specs_index, @d2_1_a_tuple
+ refute_includes pre_specs_index, @d2_1_tuple
+ end
+
def assert_indexed(dir, name)
file = File.join dir, name
assert File.exist?(file), "#{file} does not exist"
@@ -255,7 +634,7 @@ Compressing indicies
def refute_indexed(dir, name)
file = File.join dir, name
- assert !File.exist?(file), "#{file} exists"
+ refute File.exist?(file), "#{file} exists"
end
end if ''.respond_to? :to_xs
diff --git a/test/rubygems/test_gem_install_update_options.rb b/test/rubygems/test_gem_install_update_options.rb
index 8610a79cdf..fb77678d0d 100644
--- a/test/rubygems/test_gem_install_update_options.rb
+++ b/test/rubygems/test_gem_install_update_options.rb
@@ -1,4 +1,3 @@
-require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
require File.join(File.expand_path(File.dirname(__FILE__)),
'gem_installer_test_case')
require 'rubygems/install_update_options'
@@ -21,6 +20,11 @@ class TestGemInstallUpdateOptions < GemInstallerTestCase
assert @cmd.handles?(args)
end
+ def test_prerelease
+ @cmd.handle_options %w[--prerelease]
+ assert_equal true, @cmd.options[:prerelease]
+ end
+
def test_security_policy
@cmd.handle_options %w[-P HighSecurity]
@@ -38,6 +42,8 @@ class TestGemInstallUpdateOptions < GemInstallerTestCase
def test_user_install_enabled
@cmd.handle_options %w[--user-install]
+ assert @cmd.options[:user_install]
+
@installer = Gem::Installer.new @gem, @cmd.options
@installer.install
assert File.exist?(File.join(Gem.user_dir, 'gems'))
@@ -46,15 +52,23 @@ class TestGemInstallUpdateOptions < GemInstallerTestCase
end
def test_user_install_disabled_read_only
- @cmd.handle_options %w[--no-user-install]
+ if win_platform?
+ skip('test_user_install_disabled_read_only test skipped on MS Windows')
+ else
+ @cmd.handle_options %w[--no-user-install]
- File.chmod 0755, @userhome
- FileUtils.chmod 0000, @gemhome
+ refute @cmd.options[:user_install]
- assert_raises(Gem::FilePermissionError) do
- @installer = Gem::Installer.new @gem, @cmd.options
+ File.chmod 0755, @userhome
+ FileUtils.chmod 0000, @gemhome
+
+ assert_raises(Gem::FilePermissionError) do
+ @installer = Gem::Installer.new @gem, @cmd.options
+ end
end
ensure
FileUtils.chmod 0755, @gemhome
end
+
end
+
diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb
index 0d677d6d71..00f22e403d 100644
--- a/test/rubygems/test_gem_installer.rb
+++ b/test/rubygems/test_gem_installer.rb
@@ -31,7 +31,7 @@ if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
end
gem 'a', version
-load 'my_exec'
+load Gem.bin_path('a', 'my_exec', version)
EOF
wrapper = @installer.app_script_text 'my_exec'
@@ -46,7 +46,7 @@ load 'my_exec'
assert_equal '', @ui.output
assert_equal '', @ui.error
- assert !File.exist?('gem_make.out')
+ refute File.exist?('gem_make.out')
end
def test_build_extensions_extconf_bad
@@ -288,12 +288,16 @@ load 'my_exec'
util_make_exec
Dir.mkdir util_inst_bindir
- File.chmod 0000, util_inst_bindir
- assert_raises Gem::FilePermissionError do
- @installer.generate_bin
- end
+ if win_platform?
+ skip('test_generate_bin_script_no_perms skipped on MS Windows')
+ else
+ File.chmod 0000, util_inst_bindir
+ assert_raises Gem::FilePermissionError do
+ @installer.generate_bin
+ end
+ end
ensure
File.chmod 0700, util_inst_bindir unless $DEBUG
end
@@ -373,12 +377,16 @@ load 'my_exec'
@installer.gem_dir = util_gem_dir
Dir.mkdir util_inst_bindir
- File.chmod 0000, util_inst_bindir
- assert_raises Gem::FilePermissionError do
- @installer.generate_bin
- end
+ if win_platform?
+ skip('test_generate_bin_symlink_no_perms skipped on MS Windows')
+ else
+ File.chmod 0000, util_inst_bindir
+ assert_raises Gem::FilePermissionError do
+ @installer.generate_bin
+ end
+ end
ensure
File.chmod 0700, util_inst_bindir unless $DEBUG
end
@@ -535,7 +543,7 @@ load 'my_exec'
cache_file = File.join @gemhome, 'cache', "#{@spec.full_name}.gem"
Gem.pre_install do |installer|
- assert !File.exist?(cache_file), 'cache file should not exist yet'
+ refute File.exist?(cache_file), 'cache file should not exist yet'
end
Gem.post_install do |installer|
@@ -771,7 +779,7 @@ load 'my_exec'
assert @installer.installation_satisfies_dependency?(dep)
dep = Gem::Dependency.new 'a', '> 2'
- assert ! @installer.installation_satisfies_dependency?(dep)
+ refute @installer.installation_satisfies_dependency?(dep)
end
def test_shebang
@@ -818,7 +826,7 @@ load 'my_exec'
@installer.env_shebang = true
shebang = @installer.shebang 'my_exec'
- assert_equal "#!/usr/bin/env #{Gem::ConfigMap[:RUBY_INSTALL_NAME]}", shebang
+ assert_equal "#!/usr/bin/env #{Gem::ConfigMap[:ruby_install_name]}", shebang
end
def test_shebang_nested
@@ -884,7 +892,7 @@ load 'my_exec'
spec_dir = File.join @gemhome, 'specifications'
spec_file = File.join spec_dir, "#{@spec.full_name}.gemspec"
FileUtils.rm spec_file
- assert !File.exist?(spec_file)
+ refute File.exist?(spec_file)
@installer.spec = @spec
@installer.gem_home = @gemhome
diff --git a/test/rubygems/test_gem_local_remote_options.rb b/test/rubygems/test_gem_local_remote_options.rb
index e920972fd9..3dd390ecfd 100644
--- a/test/rubygems/test_gem_local_remote_options.rb
+++ b/test/rubygems/test_gem_local_remote_options.rb
@@ -60,8 +60,9 @@ class TestGemLocalRemoteOptions < RubyGemTestCase
s1 = URI.parse 'http://more-gems.example.com/'
s2 = URI.parse 'http://even-more-gems.example.com/'
s3 = URI.parse 'http://other-gems.example.com/some_subdir'
+ s4 = URI.parse 'http://more-gems.example.com/' # Intentional duplicate
- @cmd.handle_options %W[--source #{s1} --source #{s2} --source #{s3}]
+ @cmd.handle_options %W[--source #{s1} --source #{s2} --source #{s3} --source #{s4}]
assert_equal [s1.to_s, s2.to_s, "#{s3}/"], Gem.sources
end
diff --git a/test/rubygems/test_gem_package_tar_header.rb b/test/rubygems/test_gem_package_tar_header.rb
index 9b7708dca8..5ad1a793b5 100644
--- a/test/rubygems/test_gem_package_tar_header.rb
+++ b/test/rubygems/test_gem_package_tar_header.rb
@@ -58,7 +58,7 @@ class TestGemPackageTarHeader < TarTestCase
assert_equal 'user', @tar_header.uname, 'uname'
assert_equal '00', @tar_header.version, 'version'
- assert !@tar_header.empty?, 'empty'
+ refute_empty @tar_header, 'empty'
end
def test_initialize_bad
@@ -80,13 +80,13 @@ class TestGemPackageTarHeader < TarTestCase
end
def test_empty_eh
- assert !@tar_header.empty?
+ refute_empty @tar_header
@tar_header = Gem::Package::TarHeader.new :name => 'x', :prefix => '',
:mode => 0, :size => 0,
:empty => true
- assert @tar_header.empty?
+ assert_empty @tar_header
end
def test_equals2
diff --git a/test/rubygems/test_gem_package_tar_input.rb b/test/rubygems/test_gem_package_tar_input.rb
index 5e6fb2badd..8f8a193876 100644
--- a/test/rubygems/test_gem_package_tar_input.rb
+++ b/test/rubygems/test_gem_package_tar_input.rb
@@ -48,7 +48,7 @@ class TestGemPackageTarInput < TarTestCase
meta = @spec.to_yaml
f.write tar_file_header("metadata", "", 0644, meta.size)
- f.write meta + "\0" * (1024 - meta.size)
+ f.write meta + "\0" * (1024 - meta.size)
f.write "\0" * 1024
end
@@ -92,8 +92,8 @@ class TestGemPackageTarInput < TarTestCase
tar_input.extract_entry @tempdir, entry
name = File.join @tempdir, entry.header.name
- if entry.directory?
- assert File.dir?(name)
+ if entry.directory? then
+ assert File.directory?(name)
else
assert File.file?(name)
assert_equal @entry_sizes[i], File.stat(name).size
@@ -111,7 +111,7 @@ class TestGemPackageTarInput < TarTestCase
@entry_files.each_with_index do |x, i|
assert File.file?(x)
- assert_equal @entry_contents[i], File.read_b(x)
+ assert_equal @entry_contents[i], Gem.read_binary(x)
end
end
diff --git a/test/rubygems/test_gem_package_tar_output.rb b/test/rubygems/test_gem_package_tar_output.rb
index 06dbb1a4da..31f02c67a6 100644
--- a/test/rubygems/test_gem_package_tar_output.rb
+++ b/test/rubygems/test_gem_package_tar_output.rb
@@ -49,7 +49,7 @@ class TestGemPackageTarOutput < TarTestCase
gz = Zlib::GzipReader.new StringIO.new(data)
assert_equal "This is some metadata\n", gz.read
- assert files.empty?
+ assert_empty files
ensure
gz.close if gz
end
@@ -82,7 +82,7 @@ class TestGemPackageTarOutput < TarTestCase
name, data = files.shift
assert_equal 'metadata.gz.sig', name
- assert files.empty?
+ assert_empty files
end
end
diff --git a/test/rubygems/test_gem_package_tar_writer.rb b/test/rubygems/test_gem_package_tar_writer.rb
index 5f3e7efb6f..4c2b475bf1 100644
--- a/test/rubygems/test_gem_package_tar_writer.rb
+++ b/test/rubygems/test_gem_package_tar_writer.rb
@@ -46,7 +46,7 @@ class TestTarWriter < TarTestCase
def test_add_file_simple_padding
@tar_writer.add_file_simple 'x', 0, 100
- assert_headers_equal tar_file_header('x', '', 0, 100),
+ assert_headers_equal tar_file_header('x', '', 0, 100),
@io.string[0, 512]
assert_equal "\0" * 512, @io.string[512, 512]
@@ -61,7 +61,7 @@ class TestTarWriter < TarTestCase
end
def test_add_file_simple_size
- assert_raises Gem::Package::TarWriter::FileOverflow do
+ assert_raises Gem::Package::TarWriter::FileOverflow do
@tar_writer.add_file_simple("lib/foo/bar", 0, 10) do |io|
io.write "1" * 11
end
@@ -69,7 +69,7 @@ class TestTarWriter < TarTestCase
end
def test_add_file_unseekable
- assert_raises Gem::Package::NonSeekableIO do
+ assert_raises Gem::Package::NonSeekableIO do
Gem::Package::TarWriter.new(Object.new).add_file 'x', 0
end
end
diff --git a/test/rubygems/test_gem_package_task.rb b/test/rubygems/test_gem_package_task.rb
new file mode 100644
index 0000000000..aed4f05b83
--- /dev/null
+++ b/test/rubygems/test_gem_package_task.rb
@@ -0,0 +1,70 @@
+# Copyright (c) 2003, 2004 Jim Weirich, 2009 Eric Hodel
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems'
+require 'rubygems/package_task'
+
+class TestGemPackageTask < MiniTest::Unit::TestCase
+
+ def test_gem_package
+ gem = Gem::Specification.new do |g|
+ g.name = "pkgr"
+ g.version = "1.2.3"
+ g.files = Rake::FileList["x"].resolve
+ end
+ pkg = Gem::PackageTask.new(gem) do |p|
+ p.package_files << "y"
+ end
+ assert_equal ["x", "y"], pkg.package_files
+ assert_equal "pkgr-1.2.3.gem", pkg.gem_file
+ end
+
+ def test_gem_package_with_current_platform
+ gem = Gem::Specification.new do |g|
+ g.name = "pkgr"
+ g.version = "1.2.3"
+ g.files = Rake::FileList["x"].resolve
+ g.platform = Gem::Platform::CURRENT
+ end
+ pkg = Gem::PackageTask.new(gem) do |p|
+ p.package_files << "y"
+ end
+ assert_equal ["x", "y"], pkg.package_files
+ assert_match(/^pkgr-1\.2\.3-(\S+)\.gem$/, pkg.gem_file)
+ end
+
+ def test_gem_package_with_ruby_platform
+ gem = Gem::Specification.new do |g|
+ g.name = "pkgr"
+ g.version = "1.2.3"
+ g.files = Rake::FileList["x"].resolve
+ g.platform = Gem::Platform::RUBY
+ end
+ pkg = Gem::PackageTask.new(gem) do |p|
+ p.package_files << "y"
+ end
+ assert_equal ["x", "y"], pkg.package_files
+ assert_equal "pkgr-1.2.3.gem", pkg.gem_file
+ end
+
+end
+
diff --git a/test/rubygems/test_gem_platform.rb b/test/rubygems/test_gem_platform.rb
index e71fcd5c5d..aa23533a39 100644
--- a/test/rubygems/test_gem_platform.rb
+++ b/test/rubygems/test_gem_platform.rb
@@ -133,6 +133,12 @@ class TestGemPlatform < RubyGemTestCase
assert_equal '1', platform.version
end
+ def test_empty
+ platform = Gem::Platform.new 'cpu-other_platform1'
+ assert_respond_to platform, :empty?
+ assert_equal false, platform.empty?
+ end
+
def test_to_s
if win_platform? then
assert_equal 'x86-mswin32-60', Gem::Platform.local.to_s
@@ -155,8 +161,8 @@ class TestGemPlatform < RubyGemTestCase
other = Gem::Platform.new %w[cpu other_platform 1]
assert(my === my)
- assert !(other === my)
- assert !(my === other)
+ refute(other === my)
+ refute(my === other)
end
def test_equals3_cpu
@@ -167,10 +173,10 @@ class TestGemPlatform < RubyGemTestCase
util_set_arch 'powerpc-darwin8'
assert((ppc_darwin8 === Gem::Platform.local), 'powerpc =~ universal')
assert((uni_darwin8 === Gem::Platform.local), 'powerpc =~ universal')
- assert !(x86_darwin8 === Gem::Platform.local), 'powerpc =~ universal'
+ refute((x86_darwin8 === Gem::Platform.local), 'powerpc =~ universal')
util_set_arch 'i686-darwin8'
- assert !(ppc_darwin8 === Gem::Platform.local), 'powerpc =~ universal'
+ refute((ppc_darwin8 === Gem::Platform.local), 'powerpc =~ universal')
assert((uni_darwin8 === Gem::Platform.local), 'x86 =~ universal')
assert((x86_darwin8 === Gem::Platform.local), 'powerpc =~ universal')
@@ -191,8 +197,8 @@ class TestGemPlatform < RubyGemTestCase
assert((x86_darwin === Gem::Platform.local), 'x86_darwin === x86_darwin8')
assert((x86_darwin8 === Gem::Platform.local), 'x86_darwin8 === x86_darwin8')
- assert !(x86_darwin7 === Gem::Platform.local), 'x86_darwin7 === x86_darwin8'
- assert !(x86_darwin9 === Gem::Platform.local), 'x86_darwin9 === x86_darwin8'
+ refute((x86_darwin7 === Gem::Platform.local), 'x86_darwin7 === x86_darwin8')
+ refute((x86_darwin9 === Gem::Platform.local), 'x86_darwin9 === x86_darwin8')
end
def test_equals_tilde
diff --git a/test/rubygems/test_gem_remote_fetcher.rb b/test/rubygems/test_gem_remote_fetcher.rb
index 3f135ba046..465443c901 100644
--- a/test/rubygems/test_gem_remote_fetcher.rb
+++ b/test/rubygems/test_gem_remote_fetcher.rb
@@ -151,7 +151,7 @@ gems:
fetcher.fetch_size 'gems.example.com/yaml'
end
- assert_equal 'uri is not an HTTP URI', e.message
+ assert_equal 'uri scheme is invalid', e.message
end
def test_fetch_size_socket_error
@@ -237,6 +237,21 @@ gems:
inst.download(@a1, local_path)
end
+ def test_download_local_space
+ space_path = File.join @tempdir, 'space path'
+ FileUtils.mkdir space_path
+ FileUtils.mv @a1_gem, space_path
+ local_path = File.join space_path, "#{@a1.full_name}.gem"
+ inst = nil
+
+ Dir.chdir @tempdir do
+ inst = Gem::RemoteFetcher.fetcher
+ end
+
+ assert_equal File.join(@gemhome, 'cache', "#{@a1.full_name}.gem"),
+ inst.download(@a1, local_path)
+ end
+
def test_download_install_dir
a1_data = nil
File.open @a1_gem, 'rb' do |fp|
@@ -463,6 +478,13 @@ gems:
assert_equal nil, fetcher.fetch_path(URI.parse(@gem_repo), Time.at(0))
end
+ def test_get_proxy_from_env_auto_normalizes
+ fetcher = Gem::RemoteFetcher.new(nil)
+ ENV['HTTP_PROXY'] = 'fakeurl:12345'
+
+ assert_equal('http://fakeurl:12345', fetcher.get_proxy_from_env.to_s)
+ end
+
def test_get_proxy_from_env_empty
orig_env_HTTP_PROXY = ENV['HTTP_PROXY']
orig_env_http_proxy = ENV['http_proxy']
diff --git a/test/rubygems/test_gem_server.rb b/test/rubygems/test_gem_server.rb
index 866a9e3c97..d929c04c07 100644
--- a/test/rubygems/test_gem_server.rb
+++ b/test/rubygems/test_gem_server.rb
@@ -222,6 +222,16 @@ class TestGemServer < RubyGemTestCase
assert_equal Gem::Platform.local, spec.platform
end
+ def test_rdoc
+ data = StringIO.new "GET /rdoc?q=a HTTP/1.0\r\n\r\n"
+ @req.parse data
+
+ @server.rdoc @req, @res
+
+ assert_equal 200, @res.status, @res.body
+ assert_match %r|No documentation found|, @res.body
+ assert_equal 'text/html', @res['content-type']
+ end
def test_root
data = StringIO.new "GET / HTTP/1.0\r\n\r\n"
diff --git a/test/rubygems/test_gem_source_index.rb b/test/rubygems/test_gem_source_index.rb
index 977f2c2b59..0983089cd9 100644
--- a/test/rubygems/test_gem_source_index.rb
+++ b/test/rubygems/test_gem_source_index.rb
@@ -208,269 +208,6 @@ WARNING: Invalid .gemspec format in '#{spec_file}'
assert_equal @fetcher, @source_index.fetcher
end
- def test_fetch_bulk_index_compressed
- util_setup_bulk_fetch true
-
- use_ui @ui do
- fetched_index = @source_index.fetch_bulk_index @uri
- assert_equal [@a1.full_name, @a2.full_name, @a_evil9.full_name,
- @c1_2.full_name].sort,
- fetched_index.gems.map { |n,s| n }.sort
- end
-
- paths = @fetcher.paths
-
- assert_equal "#{@gem_repo}Marshal.#{@marshal_version}.Z", paths.shift
-
- assert paths.empty?, paths.join(', ')
- end
-
- def test_fetch_bulk_index_error
- @fetcher.data["#{@gem_repo}Marshal.#{@marshal_version}.Z"] = proc { raise SocketError }
- @fetcher.data["#{@gem_repo}Marshal.#{@marshal_version}"] = proc { raise SocketError }
- @fetcher.data["#{@gem_repo}yaml.Z"] = proc { raise SocketError }
- @fetcher.data["#{@gem_repo}yaml"] = proc { raise SocketError }
-
- e = assert_raises Gem::RemoteSourceException do
- use_ui @ui do
- @source_index.fetch_bulk_index @uri
- end
- end
-
- paths = @fetcher.paths
-
- assert_equal "#{@gem_repo}Marshal.#{@marshal_version}.Z", paths.shift
- assert_equal "#{@gem_repo}Marshal.#{@marshal_version}", paths.shift
- assert_equal "#{@gem_repo}yaml.Z", paths.shift
- assert_equal "#{@gem_repo}yaml", paths.shift
-
- assert paths.empty?, paths.join(', ')
-
- assert_equal 'Error fetching remote gem cache: SocketError',
- e.message
- end
-
- def test_fetch_bulk_index_fallback
- @fetcher.data["#{@gem_repo}Marshal.#{@marshal_version}.Z"] =
- proc { raise SocketError }
- @fetcher.data["#{@gem_repo}Marshal.#{@marshal_version}"] =
- proc { raise SocketError }
- @fetcher.data["#{@gem_repo}yaml.Z"] = proc { raise SocketError }
- @fetcher.data["#{@gem_repo}yaml"] = @source_index.to_yaml
-
- use_ui @ui do
- fetched_index = @source_index.fetch_bulk_index @uri
- assert_equal [@a1.full_name, @a2.full_name, @a_evil9.full_name,
- @c1_2.full_name].sort,
- fetched_index.gems.map { |n,s| n }.sort
- end
-
- paths = @fetcher.paths
-
- assert_equal "#{@gem_repo}Marshal.#{@marshal_version}.Z", paths.shift
- assert_equal "#{@gem_repo}Marshal.#{@marshal_version}", paths.shift
- assert_equal "#{@gem_repo}yaml.Z", paths.shift
- assert_equal "#{@gem_repo}yaml", paths.shift
-
- assert paths.empty?, paths.join(', ')
- end
-
- def test_fetch_bulk_index_marshal_mismatch
- marshal = @source_index.dump
- marshal[0] = (Marshal::MAJOR_VERSION - 1).chr
-
- @fetcher.data["#{@gem_repo}Marshal.#{@marshal_version}"] = marshal
- @fetcher.data["#{@gem_repo}yaml"] = @source_index.to_yaml
-
- use_ui @ui do
- fetched_index = @source_index.fetch_bulk_index @uri
- assert_equal [@a1.full_name, @a2.full_name, @a_evil9.full_name,
- @c1_2.full_name].sort,
- fetched_index.gems.map { |n,s| n }.sort
- end
-
- paths = @fetcher.paths
-
- assert_equal "#{@gem_repo}Marshal.#{@marshal_version}.Z", paths.shift
- assert_equal "#{@gem_repo}Marshal.#{@marshal_version}", paths.shift
- assert_equal "#{@gem_repo}yaml.Z", paths.shift
- assert_equal "#{@gem_repo}yaml", paths.shift
-
- assert paths.empty?, paths.join(', ')
- end
-
- def test_fetch_bulk_index_uncompressed
- util_setup_bulk_fetch false
- use_ui @ui do
- fetched_index = @source_index.fetch_bulk_index @uri
- assert_equal [@a1.full_name, @a2.full_name, @a_evil9.full_name,
- @c1_2.full_name].sort,
- fetched_index.gems.map { |n,s| n }.sort
- end
-
- paths = @fetcher.paths
-
- assert_equal "#{@gem_repo}Marshal.#{@marshal_version}.Z", paths.shift
- assert_equal "#{@gem_repo}Marshal.#{@marshal_version}", paths.shift
-
- assert paths.empty?, paths.join(', ')
- end
-
- def test_fetch_quick_index
- index = util_zip @gem_names
- latest_index = util_zip [@a2.full_name, @b2.full_name].join("\n")
-
- @fetcher.data["#{@gem_repo}quick/index.rz"] = index
- @fetcher.data["#{@gem_repo}quick/latest_index.rz"] = latest_index
-
- quick_index = @source_index.fetch_quick_index @uri, false
- assert_equal [@a2.full_name, @b2.full_name].sort,
- quick_index.sort
-
- paths = @fetcher.paths
-
- assert_equal "#{@gem_repo}quick/latest_index.rz", paths.shift
-
- assert paths.empty?, paths.join(', ')
- end
-
- def test_fetch_quick_index_all
- index = util_zip @gem_names
- latest_index = util_zip [@a2.full_name, @b2.full_name].join("\n")
-
- @fetcher.data["#{@gem_repo}quick/index.rz"] = index
- @fetcher.data["#{@gem_repo}quick/latest_index.rz"] = latest_index
-
- quick_index = @source_index.fetch_quick_index @uri, true
- assert_equal [@a1.full_name, @a2.full_name, @b2.full_name].sort,
- quick_index.sort
-
- paths = @fetcher.paths
-
- assert_equal "#{@gem_repo}quick/index.rz", paths.shift
-
- assert paths.empty?, paths.join(', ')
- end
-
- def test_fetch_quick_index_error
- @fetcher.data["#{@gem_repo}quick/index.rz"] =
- proc { raise Exception }
-
- e = assert_raises Gem::OperationNotSupportedError do
- @source_index.fetch_quick_index @uri, true
- end
-
- assert_equal 'No quick index found: Exception', e.message
-
- paths = @fetcher.paths
-
- assert_equal "#{@gem_repo}quick/index.rz", paths.shift
-
- assert paths.empty?, paths.join(', ')
- end
-
- def test_fetch_quick_index_fallback
- index = util_zip @gem_names
-
- @fetcher.data["#{@gem_repo}quick/index.rz"] = index
-
- quick_index = @source_index.fetch_quick_index @uri, false
- assert_equal @gem_names.split, quick_index.sort
-
- paths = @fetcher.paths
-
- assert_equal "#{@gem_repo}quick/latest_index.rz", paths.shift
- assert_equal "#{@gem_repo}quick/index.rz", paths.shift
-
- assert paths.empty?, paths.join(', ')
- end
-
- def test_fetch_quick_index_subdir
- latest_index = util_zip [@a2.full_name, @b2.full_name].join("\n")
- repo = URI.parse "#{@gem_repo}~nobody/mirror/"
-
- @fetcher.data["#{repo}quick/latest_index.rz"] = latest_index
-
- quick_index = @source_index.fetch_quick_index repo, false
- assert_equal [@a2.full_name, @b2.full_name].sort,
- quick_index.sort
-
- paths = @fetcher.paths
-
- assert_equal "#{repo}quick/latest_index.rz", paths.shift
-
- assert paths.empty?, paths.join(', ')
- end
-
- def test_fetch_single_spec
- a1_spec_url = "#{@gem_repo}quick/Marshal.#{Gem.marshal_version}/#{@a1.full_name}.gemspec.rz"
- @fetcher.data[a1_spec_url] = util_zip Marshal.dump(@a1)
-
- spec = @source_index.send :fetch_single_spec, URI.parse(@gem_repo),
- @a1.full_name
-
- assert_equal @a1.full_name, spec.full_name
-
- paths = @fetcher.paths
-
- assert_equal a1_spec_url, paths.shift
-
- assert paths.empty?, paths.join(', ')
- end
-
- def test_fetch_single_spec_subdir
- repo = URI.parse "#{@gem_repo}~nobody/mirror/"
-
- a1_spec_url = "#{repo}quick/Marshal.#{Gem.marshal_version}/#{@a1.full_name}.gemspec.rz"
- @fetcher.data[a1_spec_url] = util_zip Marshal.dump(@a1)
-
- spec = @source_index.send :fetch_single_spec, repo, @a1.full_name
-
- assert_equal @a1.full_name, spec.full_name
-
- paths = @fetcher.paths
-
- assert_equal a1_spec_url, paths.shift
-
- assert paths.empty?, paths.join(', ')
- end
-
- def test_fetch_single_spec_yaml
- a1_spec_url = "#{@gem_repo}quick/#{@a1.full_name}.gemspec.rz"
- @fetcher.data[a1_spec_url] = util_zip @a1.to_yaml
-
- repo = URI.parse @gem_repo
-
- spec = @source_index.send :fetch_single_spec, repo, @a1.full_name
-
- assert_equal @a1.full_name, spec.full_name
-
- paths = @fetcher.paths
-
- assert_equal "#{@gem_repo}quick/Marshal.#{Gem.marshal_version}/#{@a1.full_name}.gemspec.rz", paths.shift
- assert_equal a1_spec_url, paths.shift
-
- assert paths.empty?, paths.join(', ')
- end
-
- def test_fetch_single_spec_yaml_subdir
- repo = URI.parse "#{@gem_repo}~nobody/mirror/"
-
- a1_spec_url = "#{repo}quick/#{@a1.full_name}.gemspec.rz"
- @fetcher.data[a1_spec_url] = util_zip @a1.to_yaml
-
- spec = @source_index.send :fetch_single_spec, repo, @a1.full_name
-
- assert_equal @a1.full_name, spec.full_name
-
- paths = @fetcher.paths
-
- assert_equal "#{repo}quick/Marshal.#{Gem.marshal_version}/#{@a1.full_name}.gemspec.rz", paths.shift
- assert_equal a1_spec_url, paths.shift
-
- assert paths.empty?, paths.join(', ')
- end
-
def test_find_missing
missing = @source_index.find_missing [@b2.full_name]
assert_equal [@b2.full_name], missing
@@ -485,7 +222,7 @@ WARNING: Invalid .gemspec format in '#{spec_file}'
end
def test_find_name
- assert_equal [@a1, @a2], @source_index.find_name('a')
+ assert_equal [@a1, @a2, @a3a], @source_index.find_name('a')
assert_equal [@a2], @source_index.find_name('a', '= 2')
assert_equal [], @source_index.find_name('bogusstring')
assert_equal [], @source_index.find_name('a', '= 3')
@@ -593,14 +330,25 @@ WARNING: Invalid .gemspec format in '#{spec_file}'
assert_equal [updated_platform.name], @source_index.outdated
end
+ def test_prerelease_specs_kept_in_right_place
+ gem_a1_alpha = quick_gem 'abba', '1.a'
+ @source_index.add_spec gem_a1_alpha
+
+ refute @source_index.latest_specs.include?(gem_a1_alpha)
+ assert_nil @source_index.specification(gem_a1_alpha.full_name)
+ assert @source_index.prerelease_specs.include?(gem_a1_alpha)
+
+ # TODO: don't think this tests writing prerelease index to disk
+ end
+
def test_refresh_bang
- a1_spec = File.join @gemhome, "specifications", "#{@a1.full_name}.gemspec"
+ a1_spec = File.join @gemhome, "specifications", "#{@a1.full_name}.gemspec"
FileUtils.mv a1_spec, @tempdir
source_index = Gem::SourceIndex.from_installed_gems
- assert !source_index.gems.include?(@a1.full_name)
+ refute source_index.gems.include?(@a1.full_name)
FileUtils.mv File.join(@tempdir, "#{@a1.full_name}.gemspec"), a1_spec
@@ -640,13 +388,28 @@ WARNING: Invalid .gemspec format in '#{spec_file}'
assert_equal gems, @source_index.gems.map { |n,s| n }.sort
end
+ def test_remove_spec
+ deleted = @source_index.remove_spec 'a-1'
+
+ assert_equal %w[a-2 a-3.a a_evil-9 c-1.2],
+ @source_index.all_gems.values.map { |s| s.full_name }.sort
+
+ deleted = @source_index.remove_spec 'a-3.a'
+
+ assert_equal %w[a-2 a_evil-9 c-1.2],
+ @source_index.all_gems.values.map { |s| s.full_name }.sort
+ end
+
def test_search
requirement = Gem::Requirement.create '= 9'
with_version = Gem::Dependency.new(/^a/, requirement)
assert_equal [@a_evil9], @source_index.search(with_version)
with_default = Gem::Dependency.new(/^a/, Gem::Requirement.default)
- assert_equal [@a1, @a2, @a_evil9], @source_index.search(with_default)
+ assert_equal [@a1, @a2, @a3a, @a_evil9], @source_index.search(with_default)
+
+ c1_1_dep = Gem::Dependency.new 'c', '~> 1.1'
+ assert_equal [@c1_2], @source_index.search(c1_1_dep)
end
def test_search_platform
@@ -692,186 +455,6 @@ WARNING: Invalid .gemspec format in '#{spec_file}'
assert_equal 'some text', @source_index.unzip(input)
end
- def test_update_bulk
- util_setup_bulk_fetch true
-
- @source_index.gems.replace({})
- assert_equal [], @source_index.gems.keys.sort
-
- use_ui @ui do
- @source_index.update @uri, true
-
- assert_equal [@a1.full_name, @a2.full_name, @a_evil9.full_name,
- @c1_2.full_name],
- @source_index.gems.keys.sort
- end
-
- paths = @fetcher.paths
-
- assert_equal "#{@gem_repo}quick/index.rz", paths.shift
- assert_equal "#{@gem_repo}Marshal.#{@marshal_version}.Z", paths.shift
-
- assert paths.empty?, paths.join(', ')
- end
-
- def test_update_incremental
- old_gem_conf = Gem.configuration
- Gem.configuration = Gem::ConfigFile.new([])
-
- latest_names = [@a2, @a_evil9, @b2, @c1_2].map { |s| s.full_name }
- latest_index = util_zip latest_names.join("\n")
- @fetcher.data["#{@gem_repo}quick/latest_index.rz"] = latest_index
-
- marshal_uri = File.join @gem_repo, "quick", "Marshal.#{@marshal_version}",
- "#{@b2.full_name}.gemspec.rz"
- @fetcher.data[marshal_uri] = util_zip Marshal.dump(@b2)
-
- use_ui @ui do
- @source_index.update @uri, false
-
- assert_equal latest_names, @source_index.gems.keys.sort
- end
-
- paths = @fetcher.paths
- assert_equal "#{@gem_repo}quick/latest_index.rz", paths.shift
- assert_equal marshal_uri, paths.shift
-
- assert paths.empty?, paths.join(', ')
- ensure
- Gem.configuration = old_gem_conf
- end
-
- def test_update_incremental_all
- old_gem_conf = Gem.configuration
- Gem.configuration = Gem::ConfigFile.new([])
-
- quick_index = util_zip @all_gem_names.join("\n")
- @fetcher.data["#{@gem_repo}quick/index.rz"] = quick_index
-
- marshal_uri = File.join @gem_repo, "quick", "Marshal.#{@marshal_version}",
- "#{@b2.full_name}.gemspec.rz"
- @fetcher.data[marshal_uri] = util_zip Marshal.dump(@b2)
-
- use_ui @ui do
- @source_index.update @uri, true
-
- assert_equal @all_gem_names, @source_index.gems.keys.sort
- end
-
- paths = @fetcher.paths
- assert_equal "#{@gem_repo}quick/index.rz", paths.shift
- assert_equal marshal_uri, paths.shift
-
- assert paths.empty?, paths.join(', ')
- ensure
- Gem.configuration = old_gem_conf
- end
-
- def test_update_incremental_fallback
- old_gem_conf = Gem.configuration
- Gem.configuration = Gem::ConfigFile.new([])
-
- quick_index = util_zip @all_gem_names.join("\n")
- @fetcher.data["#{@gem_repo}quick/index.rz"] = quick_index
-
- marshal_uri = File.join @gem_repo, "quick", "Marshal.#{@marshal_version}",
- "#{@b2.full_name}.gemspec.rz"
-
- yaml_uri = "#{@gem_repo}quick/#{@b2.full_name}.gemspec.rz"
- @fetcher.data[yaml_uri] = util_zip @b2.to_yaml
-
- use_ui @ui do
- @source_index.update @uri, true
-
- assert_equal @all_gem_names, @source_index.gems.keys.sort
- end
-
- paths = @fetcher.paths
- assert_equal "#{@gem_repo}quick/index.rz", paths.shift
- assert_equal marshal_uri, paths.shift
- assert_equal yaml_uri, paths.shift
-
- assert paths.empty?, paths.join(', ')
- ensure
- Gem.configuration = old_gem_conf
- end
-
- def test_update_incremental_marshal_mismatch
- old_gem_conf = Gem.configuration
- Gem.configuration = Gem::ConfigFile.new([])
-
- quick_index = util_zip @all_gem_names.join("\n")
- @fetcher.data["#{@gem_repo}quick/index.rz"] = quick_index
-
- marshal_uri = File.join @gem_repo, "quick", "Marshal.#{@marshal_version}",
- "#{@b2.full_name}.gemspec.rz"
- marshal_data = Marshal.dump(@b2)
- marshal_data[0] = (Marshal::MAJOR_VERSION - 1).chr
- @fetcher.data[marshal_uri] = util_zip marshal_data
-
- yaml_uri = "#{@gem_repo}quick/#{@b2.full_name}.gemspec.rz"
- @fetcher.data[yaml_uri] = util_zip @b2.to_yaml
-
- use_ui @ui do
- @source_index.update @uri, true
-
- assert_equal @all_gem_names, @source_index.gems.keys.sort
- end
-
- paths = @fetcher.paths
- assert_equal "#{@gem_repo}quick/index.rz", paths.shift
- assert_equal marshal_uri, paths.shift
- assert_equal yaml_uri, paths.shift
-
- assert paths.empty?, paths.join(', ')
- ensure
- Gem.configuration = old_gem_conf
- end
-
- def test_update_subdir
- @gem_repo = @gem_repo + 'subdir/'
-
- util_setup_bulk_fetch true
-
- @source_index.gems.replace({})
- assert_equal [], @source_index.gems.keys.sort
-
- uri = @uri.to_s + 'subdir/'
-
- use_ui @ui do
- @source_index.update uri, true
-
- assert_equal [@a1.full_name, @a2.full_name, @a_evil9.full_name,
- @c1_2.full_name],
- @source_index.gems.keys.sort
- end
-
- paths = @fetcher.paths
-
- assert_equal "#{@gem_repo}quick/index.rz", paths.shift
- assert_equal "#{@gem_repo}Marshal.#{@marshal_version}.Z", paths.shift
-
- assert paths.empty?, paths.join(', ')
- end
-
- def test_update_with_missing
- marshal_uri = File.join @gem_repo, "quick", "Marshal.#{@marshal_version}",
- "#{@c1_2.full_name}.gemspec.rz"
- dumped = Marshal.dump @c1_2
- @fetcher.data[marshal_uri] = util_zip(dumped)
-
- use_ui @ui do
- @source_index.update_with_missing @uri, [@c1_2.full_name]
- end
-
- spec = @source_index.specification(@c1_2.full_name)
- # We don't care about the equality of undumped attributes
- @c1_2.files = spec.files
- @c1_2.loaded_from = spec.loaded_from
-
- assert_equal @c1_2, spec
- end
-
def util_setup_bulk_fetch(compressed)
source_index = @source_index.dump
diff --git a/test/rubygems/test_gem_source_info_cache.rb b/test/rubygems/test_gem_source_info_cache.rb
index 2a4ee6922a..237c1efea8 100644
--- a/test/rubygems/test_gem_source_info_cache.rb
+++ b/test/rubygems/test_gem_source_info_cache.rb
@@ -294,7 +294,7 @@ class TestGemSourceInfoCache < RubyGemTestCase
gem_names = @sic.search(//, false, true).map { |spec| spec.full_name }
- assert_equal %w[a-1 a-2 a_evil-9 c-1.2], gem_names
+ assert_equal %w[a-1 a-2 a-3.a a_evil-9 c-1.2], gem_names
end
def test_search_dependency
diff --git a/test/rubygems/test_gem_spec_fetcher.rb b/test/rubygems/test_gem_spec_fetcher.rb
index 774785be08..972289f233 100644
--- a/test/rubygems/test_gem_spec_fetcher.rb
+++ b/test/rubygems/test_gem_spec_fetcher.rb
@@ -10,22 +10,31 @@ class TestGemSpecFetcher < RubyGemTestCase
util_setup_fake_fetcher
+ @a_pre = quick_gem 'a', '1.a'
@source_index.add_spec @pl1
+ @source_index.add_spec @a_pre
@specs = @source_index.gems.sort.map do |name, spec|
[spec.name, spec.version, spec.original_platform]
end.sort
- @fetcher.data["#{@gem_repo}specs.#{Gem.marshal_version}.gz"] =
- util_gzip(Marshal.dump(@specs))
-
@latest_specs = @source_index.latest_specs.sort.map do |spec|
[spec.name, spec.version, spec.original_platform]
end
+ @prerelease_specs = @source_index.prerelease_gems.sort.map do |name, spec|
+ [spec.name, spec.version, spec.original_platform]
+ end.sort
+
+ @fetcher.data["#{@gem_repo}specs.#{Gem.marshal_version}.gz"] =
+ util_gzip(Marshal.dump(@specs))
+
@fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] =
util_gzip(Marshal.dump(@latest_specs))
+ @fetcher.data["#{@gem_repo}prerelease_specs.#{Gem.marshal_version}.gz"] =
+ util_gzip(Marshal.dump(@prerelease_specs))
+
@sf = Gem::SpecFetcher.new
end
@@ -34,6 +43,8 @@ class TestGemSpecFetcher < RubyGemTestCase
util_zip(Marshal.dump(@a1))
@fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a2.full_name}.gemspec.rz"] =
util_zip(Marshal.dump(@a2))
+ @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a_pre.full_name}.gemspec.rz"] =
+ util_zip(Marshal.dump(@a_pre))
dep = Gem::Dependency.new 'a', 1
specs_and_sources = @sf.fetch dep, true
@@ -54,6 +65,8 @@ class TestGemSpecFetcher < RubyGemTestCase
util_zip(Marshal.dump(@a1))
@fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a2.full_name}.gemspec.rz"] =
util_zip(Marshal.dump(@a2))
+ @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a_pre.full_name}.gemspec.rz"] =
+ util_zip(Marshal.dump(@a_pre))
dep = Gem::Dependency.new 'a', 1
specs_and_sources = @sf.fetch dep
@@ -65,6 +78,24 @@ class TestGemSpecFetcher < RubyGemTestCase
assert_equal [[@a2.full_name, @gem_repo]], spec_names
end
+ def test_fetch_prerelease
+ @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a1.full_name}.gemspec.rz"] =
+ util_zip(Marshal.dump(@a1))
+ @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a2.full_name}.gemspec.rz"] =
+ util_zip(Marshal.dump(@a2))
+ @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a_pre.full_name}.gemspec.rz"] =
+ util_zip(Marshal.dump(@a_pre))
+
+ dep = Gem::Dependency.new 'a', '1.a'
+ specs_and_sources = @sf.fetch dep, false, true, true
+
+ spec_names = specs_and_sources.map do |spec, source_uri|
+ [spec.full_name, source_uri]
+ end
+
+ assert_equal [[@a_pre.full_name, @gem_repo]], spec_names
+ end
+
def test_fetch_legacy_repo
@fetcher.data.delete "#{@gem_repo}specs.#{Gem.marshal_version}.gz"
@fetcher.data["#{@gem_repo}yaml"] = ''
@@ -186,6 +217,17 @@ RubyGems will revert to legacy indexes degrading performance.
assert_equal expected, specs
end
+ def test_find_matching_prerelease
+ dep = Gem::Dependency.new 'a', '1.a'
+ specs = @sf.find_matching dep, false, true, true
+
+ expected = [
+ [['a', Gem::Version.new('1.a'), Gem::Platform::RUBY], @gem_repo],
+ ]
+
+ assert_equal expected, specs
+ end
+
def test_find_matching_platform
util_set_arch 'i386-linux'
@@ -237,7 +279,7 @@ RubyGems will revert to legacy indexes degrading performance.
def test_list_cache
specs = @sf.list
- assert !specs[@uri].empty?
+ refute specs[@uri].empty?
@fetcher.data["#{@gem_repo}/latest_specs.#{Gem.marshal_version}.gz"] = nil
@@ -249,7 +291,7 @@ RubyGems will revert to legacy indexes degrading performance.
def test_list_cache_all
specs = @sf.list true
- assert !specs[@uri].empty?
+ refute specs[@uri].empty?
@fetcher.data["#{@gem_repo}/specs.#{Gem.marshal_version}.gz"] = nil
@@ -268,6 +310,12 @@ RubyGems will revert to legacy indexes degrading performance.
assert_equal [@specs], specs.values, 'specs file not loaded'
end
+ def test_list_prerelease
+ specs = @sf.list false, true
+
+ assert_equal @prerelease_specs, specs[@uri].sort
+ end
+
def test_load_specs
specs = @sf.load_specs @uri, 'specs'
@@ -308,5 +356,29 @@ RubyGems will revert to legacy indexes degrading performance.
assert_equal @latest_specs, latest_specs
end
+ def test_load_specs_cached_empty
+ @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] =
+ proc do
+ @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] =
+ util_gzip(Marshal.dump(@latest_specs))
+
+ nil
+ end
+
+ cache_dir = File.join Gem.user_home, '.gem', 'specs', 'gems.example.com%80'
+
+ FileUtils.mkdir_p cache_dir
+
+ cache_file = File.join cache_dir, "latest_specs.#{Gem.marshal_version}"
+
+ open cache_file, 'wb' do |io|
+ io.write Marshal.dump(@latest_specs)[0, 10]
+ end
+
+ latest_specs = @sf.load_specs @uri, 'latest_specs'
+
+ assert_equal @latest_specs, latest_specs
+ end
+
end
diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb
index 79093ff3a5..e18b0f73ef 100644
--- a/test/rubygems/test_gem_specification.rb
+++ b/test/rubygems/test_gem_specification.rb
@@ -53,6 +53,7 @@ end
s.test_file = 'test/suite.rb'
s.requirements << 'A working computer'
s.rubyforge_project = 'example'
+ s.license = 'MIT'
s.add_dependency 'rake', '> 0.4'
s.add_dependency 'jabber4r', '> 0.0.0'
@@ -91,6 +92,7 @@ end
files
has_rdoc
homepage
+ licenses
name
platform
post_install_message
@@ -195,8 +197,8 @@ end
assert_equal [], spec.requirements
assert_equal [], spec.dependencies
assert_equal 'bin', spec.bindir
- assert_equal false, spec.has_rdoc
- assert_equal false, spec.has_rdoc?
+ assert_equal true, spec.has_rdoc
+ assert_equal true, spec.has_rdoc?
assert_equal '>= 0', spec.required_ruby_version.to_s
assert_equal '>= 0', spec.required_rubygems_version.to_s
end
@@ -216,6 +218,80 @@ end
assert_equal "1.3.5", spec.version.to_s
end
+ def test_initialize_copy
+ spec = Gem::Specification.new do |s|
+ s.name = "blah"
+ s.version = "1.3.5"
+ s.summary = 'summary'
+ s.description = 'description'
+ s.authors = 'author a', 'author b'
+ s.licenses = 'BSD'
+ s.files = 'lib/file.rb'
+ s.test_files = 'test/file.rb'
+ s.rdoc_options = '--foo'
+ s.extra_rdoc_files = 'README.txt'
+ s.executables = 'exec'
+ s.extensions = 'ext/extconf.rb'
+ s.requirements = 'requirement'
+ s.add_dependency 'some_gem'
+ end
+
+ new_spec = spec.dup
+
+ assert_equal "blah", spec.name
+ assert_same spec.name, new_spec.name
+
+ assert_equal "1.3.5", spec.version.to_s
+ assert_same spec.version, new_spec.version
+
+ assert_equal Gem::Platform::RUBY, spec.platform
+ assert_same spec.platform, new_spec.platform
+
+ assert_equal 'summary', spec.summary
+ assert_same spec.summary, new_spec.summary
+
+ assert_equal %w[lib/file.rb test/file.rb bin/exec README.txt
+ ext/extconf.rb],
+ spec.files
+ refute_same spec.files, new_spec.files, 'files'
+
+ assert_equal %w[test/file.rb], spec.test_files
+ refute_same spec.test_files, new_spec.test_files, 'test_files'
+
+ assert_equal %w[--foo], spec.rdoc_options
+ refute_same spec.rdoc_options, new_spec.rdoc_options, 'rdoc_options'
+
+ assert_equal %w[README.txt], spec.extra_rdoc_files
+ refute_same spec.extra_rdoc_files, new_spec.extra_rdoc_files,
+ 'extra_rdoc_files'
+
+ assert_equal %w[exec], spec.executables
+ refute_same spec.executables, new_spec.executables, 'executables'
+
+ assert_equal %w[ext/extconf.rb], spec.extensions
+ refute_same spec.extensions, new_spec.extensions, 'extensions'
+
+ assert_equal %w[requirement], spec.requirements
+ refute_same spec.requirements, new_spec.requirements, 'requirements'
+
+ assert_equal [Gem::Dependency.new('some_gem', Gem::Requirement.default)],
+ spec.dependencies
+ refute_same spec.dependencies, new_spec.dependencies, 'dependencies'
+
+ assert_equal 'bin', spec.bindir
+ assert_same spec.bindir, new_spec.bindir
+
+ assert_equal true, spec.has_rdoc
+ assert_same spec.has_rdoc, new_spec.has_rdoc
+
+ assert_equal '>= 0', spec.required_ruby_version.to_s
+ assert_same spec.required_ruby_version, new_spec.required_ruby_version
+
+ assert_equal '>= 0', spec.required_rubygems_version.to_s
+ assert_same spec.required_rubygems_version,
+ new_spec.required_rubygems_version
+ end
+
def test__dump
@a2.platform = Gem::Platform.local
@a2.instance_variable_set :@original_platform, 'old_platform'
@@ -355,7 +431,7 @@ end
s.homepage = %q{http://www.spice-of-life.net/download/cgikit/}
s.autorequire = %q{cgikit}
s.bindir = nil
- s.has_rdoc = nil
+ s.has_rdoc = true
s.required_ruby_version = nil
s.platform = nil
s.files = ["lib/cgikit", "lib/cgikit.rb", "lib/cgikit/components", "..."]
@@ -490,7 +566,7 @@ end
'i386-mswin32_80' => 'a-1-x86-mswin32-80',
'i386-mingw32' => 'a-1-x86-mingw32'
}
-
+
test_cases.each do |arch, expected|
util_set_arch arch
@a1.platform = 'current'
@@ -502,18 +578,49 @@ end
assert @a1.has_rdoc?
end
+ def test_has_rdoc_equals
+
+ use_ui @ui do
+ @a1.has_rdoc = false
+ end
+
+ assert_equal '', @ui.output
+
+ assert_equal true, @a1.has_rdoc
+ end
+
def test_hash
assert_equal @a1.hash, @a1.hash
assert_equal @a1.hash, @a1.dup.hash
refute_equal @a1.hash, @a2.hash
end
+ def test_installation_path
+ assert_equal @gemhome, @a1.installation_path
+
+ @a1.instance_variable_set :@loaded_from, nil
+
+ e = assert_raises Gem::Exception do
+ @a1.installation_path
+ end
+
+ assert_equal 'spec a-1 is not from an installed gem', e.message
+ end
+
def test_lib_files
@a1.files = %w[lib/foo.rb Rakefile]
assert_equal %w[lib/foo.rb], @a1.lib_files
end
+ def test_license
+ assert_equal 'MIT', @a1.license
+ end
+
+ def test_licenses
+ assert_equal ['MIT'], @a1.licenses
+ end
+
def test_name
assert_equal 'a', @a1.name
end
@@ -568,6 +675,12 @@ end
assert_equal Gem::Platform.new('ppc-darwin'), @a1.platform
end
+ def test_prerelease_spec_adds_required_rubygems_version
+ @prerelease = quick_gem('tardis', '2.2.0.a')
+ refute @prerelease.required_rubygems_version.satisfied_by?(Gem::Version.new('1.3.1'))
+ assert @prerelease.required_rubygems_version.satisfied_by?(Gem::Version.new('1.4.0'))
+ end
+
def test_require_paths
@a1.require_path = 'lib'
assert_equal %w[lib], @a1.require_paths
@@ -646,7 +759,6 @@ Gem::Specification.new do |s|
s.description = %q{This is a test description}
s.email = %q{example@example.com}
s.files = [\"lib/code.rb\"]
- s.has_rdoc = true
s.homepage = %q{http://example.com}
s.require_paths = [\"lib\"]
s.rubygems_version = %q{#{Gem::RubyGemsVersion}}
@@ -698,8 +810,8 @@ Gem::Specification.new do |s|
s.executables = [\"exec\"]
s.extensions = [\"ext/a/extconf.rb\"]
s.files = [\"lib/code.rb\", \"test/suite.rb\", \"bin/exec\", \"ext/a/extconf.rb\"]
- s.has_rdoc = %q{true}
s.homepage = %q{http://example.com}
+ s.licenses = [\"MIT\"]
s.require_paths = [\"lib\"]
s.requirements = [\"A working computer\"]
s.rubyforge_project = %q{example}
@@ -709,7 +821,7 @@ Gem::Specification.new do |s|
if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
- s.specification_version = 2
+ s.specification_version = 3
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<rake>, [\"> 0.4\"])
@@ -797,12 +909,16 @@ end
end
def test_validate
+ util_setup_validate
+
Dir.chdir @tempdir do
assert @a1.validate
end
end
def test_validate_authors
+ util_setup_validate
+
Dir.chdir @tempdir do
@a1.authors = []
@@ -819,10 +935,28 @@ end
end
assert_equal 'authors must be Array of Strings', e.message
+
+ @a1.authors = ['FIXME (who is writing this software)']
+
+ e = assert_raises Gem::InvalidSpecificationException do
+ @a1.validate
+ end
+
+ assert_equal '"FIXME" or "TODO" is not an author', e.message
+
+ @a1.authors = ['TODO (who is writing this software)']
+
+ e = assert_raises Gem::InvalidSpecificationException do
+ @a1.validate
+ end
+
+ assert_equal '"FIXME" or "TODO" is not an author', e.message
end
end
def test_validate_autorequire
+ util_setup_validate
+
Dir.chdir @tempdir do
@a1.autorequire = 'code'
@@ -835,7 +969,50 @@ end
end
end
+ def test_validate_description
+ util_setup_validate
+
+ Dir.chdir @tempdir do
+ @a1.description = ''
+
+ use_ui @ui do
+ @a1.validate
+ end
+
+ assert_equal "WARNING: no description specified\n", @ui.error, 'error'
+
+ @ui = MockGemUi.new
+ @a1.summary = 'this is my summary'
+ @a1.description = @a1.summary
+
+ use_ui @ui do
+ @a1.validate
+ end
+
+ assert_equal "WARNING: description and summary are identical\n",
+ @ui.error, 'error'
+
+ @a1.description = 'FIXME (describe your package)'
+
+ e = assert_raises Gem::InvalidSpecificationException do
+ @a1.validate
+ end
+
+ assert_equal '"FIXME" or "TODO" is not a description', e.message
+
+ @a1.description = 'TODO (describe your package)'
+
+ e = assert_raises Gem::InvalidSpecificationException do
+ @a1.validate
+ end
+
+ assert_equal '"FIXME" or "TODO" is not a description', e.message
+ end
+ end
+
def test_validate_email
+ util_setup_validate
+
Dir.chdir @tempdir do
@a1.email = ''
@@ -844,10 +1021,28 @@ end
end
assert_equal "WARNING: no email specified\n", @ui.error, 'error'
+
+ @a1.email = 'FIXME (your e-mail)'
+
+ e = assert_raises Gem::InvalidSpecificationException do
+ @a1.validate
+ end
+
+ assert_equal '"FIXME" or "TODO" is not an email address', e.message
+
+ @a1.email = 'TODO (your e-mail)'
+
+ e = assert_raises Gem::InvalidSpecificationException do
+ @a1.validate
+ end
+
+ assert_equal '"FIXME" or "TODO" is not an email address', e.message
end
end
def test_validate_empty
+ util_setup_validate
+
e = assert_raises Gem::InvalidSpecificationException do
Gem::Specification.new.validate
end
@@ -856,8 +1051,11 @@ end
end
def test_validate_executables
+ util_setup_validate
+
FileUtils.mkdir_p File.join(@tempdir, 'bin')
File.open File.join(@tempdir, 'bin', 'exec'), 'w' do end
+ FileUtils.mkdir_p File.join(@tempdir, 'exec')
use_ui @ui do
Dir.chdir @tempdir do
@@ -865,45 +1063,94 @@ end
end
end
+ assert_equal %w[exec], @a1.executables
+
assert_equal '', @ui.output, 'output'
assert_equal "WARNING: bin/exec is missing #! line\n", @ui.error, 'error'
end
def test_validate_empty_require_paths
- @a1.require_paths = []
- e = assert_raises Gem::InvalidSpecificationException do
- @a1.validate
+ if win_platform? then
+ skip 'test_validate_empty_require_paths skipped on MS Windows (symlink)'
+ else
+ util_setup_validate
+
+ @a1.require_paths = []
+ e = assert_raises Gem::InvalidSpecificationException do
+ @a1.validate
+ end
+
+ assert_equal 'specification must have at least one require_path',
+ e.message
end
+ end
- assert_equal 'specification must have at least one require_path', e.message
+ def test_validate_files
+ skip 'test_validate_files skipped on MS Windows (symlink)' if win_platform?
+ util_setup_validate
+
+ @a1.files += ['lib', 'lib2']
+
+ Dir.chdir @tempdir do
+ FileUtils.ln_s '/root/path', 'lib2' unless vc_windows?
+
+ e = assert_raises Gem::InvalidSpecificationException do
+ @a1.validate
+ end
+
+ assert_equal '["lib2"] are not files', e.message
+ end
+
+ assert_equal %w[lib/code.rb test/suite.rb bin/exec ext/a/extconf.rb lib2],
+ @a1.files
end
def test_validate_homepage
+ util_setup_validate
+
Dir.chdir @tempdir do
- @a1.homepage = ''
+ @a1.homepage = nil
use_ui @ui do
@a1.validate
end
assert_equal "WARNING: no homepage specified\n", @ui.error, 'error'
- end
- end
- def test_validate_has_rdoc
- Dir.chdir @tempdir do
- @a1.has_rdoc = false
+ @ui = MockGemUi.new
+
+ @a1.homepage = ''
use_ui @ui do
@a1.validate
end
- assert_equal "WARNING: RDoc will not be generated (has_rdoc == false)\n",
- @ui.error, 'error'
+ assert_equal "WARNING: no homepage specified\n", @ui.error, 'error'
+
+ @a1.homepage = 'over at my cool site'
+
+ e = assert_raises Gem::InvalidSpecificationException do
+ @a1.validate
+ end
+
+ assert_equal '"over at my cool site" is not a URI', e.message
end
end
+ def test_validate_name
+ util_setup_validate
+
+ e = assert_raises Gem::InvalidSpecificationException do
+ @a1.name = :json
+ @a1.validate
+ end
+
+ assert_equal 'invalid value for attribute name: ":json"', e.message
+ end
+
def test_validate_platform_legacy
+ util_setup_validate
+
Dir.chdir @tempdir do
@a1.platform = 'mswin32'
assert @a1.validate
@@ -917,6 +1164,8 @@ end
end
def test_validate_rubyforge_project
+ util_setup_validate
+
Dir.chdir @tempdir do
@a1.rubyforge_project = ''
@@ -930,6 +1179,8 @@ end
end
def test_validate_rubygems_version
+ util_setup_validate
+
@a1.rubygems_version = "3"
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
@@ -939,7 +1190,26 @@ end
e.message
end
+ def test_validate_specification_version
+ util_setup_validate
+
+ Dir.chdir @tempdir do
+ @a1.specification_version = '1.0'
+
+ e = assert_raises Gem::InvalidSpecificationException do
+ use_ui @ui do
+ @a1.validate
+ end
+ end
+
+ err = 'specification_version must be a Fixnum (did you mean version?)'
+ assert_equal err, e.message
+ end
+ end
+
def test_validate_summary
+ util_setup_validate
+
Dir.chdir @tempdir do
@a1.summary = ''
@@ -948,6 +1218,22 @@ end
end
assert_equal "WARNING: no summary specified\n", @ui.error, 'error'
+
+ @a1.summary = 'FIXME (describe your package)'
+
+ e = assert_raises Gem::InvalidSpecificationException do
+ @a1.validate
+ end
+
+ assert_equal '"FIXME" or "TODO" is not a summary', e.message
+
+ @a1.summary = 'TODO (describe your package)'
+
+ e = assert_raises Gem::InvalidSpecificationException do
+ @a1.validate
+ end
+
+ assert_equal '"FIXME" or "TODO" is not a summary', e.message
end
end
@@ -955,5 +1241,17 @@ end
assert_equal Gem::Version.new('1'), @a1.version
end
+ def util_setup_validate
+ Dir.chdir @tempdir do
+ FileUtils.mkdir_p File.join('ext', 'a')
+ FileUtils.mkdir_p 'lib'
+ FileUtils.mkdir_p 'test'
+
+ FileUtils.touch File.join('ext', 'a', 'extconf.rb')
+ FileUtils.touch File.join('lib', 'code.rb')
+ FileUtils.touch File.join('test', 'suite.rb')
+ end
+ end
+
end
diff --git a/test/rubygems/test_gem_uninstaller.rb b/test/rubygems/test_gem_uninstaller.rb
index bb90f5cc5f..2b026e9c4c 100644
--- a/test/rubygems/test_gem_uninstaller.rb
+++ b/test/rubygems/test_gem_uninstaller.rb
@@ -10,9 +10,28 @@ class TestGemUninstaller < GemInstallerTestCase
ui = MockGemUi.new
util_setup_gem ui
+ @user_spec.executables = ["my_exec"]
+
+ # HACK util_make_exec
+ user_bin_dir = File.join Gem.user_dir, 'gems', @user_spec.full_name, 'bin'
+ FileUtils.mkdir_p user_bin_dir
+ exec_path = File.join user_bin_dir, "my_exec"
+ File.open exec_path, 'w' do |f|
+ f.puts "#!/usr/bin/ruby"
+ end
+
+ user_bin_dir = File.join Gem.user_dir, 'bin'
+ FileUtils.mkdir_p user_bin_dir
+ exec_path = File.join user_bin_dir, "my_exec"
+ File.open exec_path, 'w' do |f|
+ f.puts "#!/usr/bin/ruby"
+ end
+
build_rake_in do
use_ui ui do
@installer.install
+ @user_installer.install
+ Gem::Uninstaller.new(@user_spec.name, :executables => false).uninstall
end
end
end
@@ -47,10 +66,23 @@ class TestGemUninstaller < GemInstallerTestCase
assert_equal false, File.exist?(File.join(@gemhome, 'bin', 'executable'))
end
+ def test_remove_executables_user
+ uninstaller = Gem::Uninstaller.new nil, :executables => true
+
+ use_ui @ui do
+ uninstaller.remove_executables @user_spec
+ end
+
+ exec_path = File.join Gem.user_dir, 'bin', 'my_exec'
+ assert_equal false, File.exist?(exec_path), 'removed exec from bin dir'
+
+ assert_equal "Removing my_exec\n", @ui.output
+ end
+
def test_path_ok_eh
uninstaller = Gem::Uninstaller.new nil
- assert_equal true, uninstaller.path_ok?(@spec)
+ assert_equal true, uninstaller.path_ok?(@gemhome, @spec)
end
def test_path_ok_eh_legacy
@@ -59,7 +91,13 @@ class TestGemUninstaller < GemInstallerTestCase
@spec.loaded_from.gsub! @spec.full_name, '\&-legacy'
@spec.platform = 'legacy'
- assert_equal true, uninstaller.path_ok?(@spec)
+ assert_equal true, uninstaller.path_ok?(@gemhome, @spec)
+ end
+
+ def test_path_ok_eh_user
+ uninstaller = Gem::Uninstaller.new nil
+
+ assert_equal true, uninstaller.path_ok?(Gem.user_dir, @user_spec)
end
def test_uninstall
@@ -72,12 +110,34 @@ class TestGemUninstaller < GemInstallerTestCase
end
Gem.post_uninstall do
- assert !File.exist?(gem_dir), 'gem_dir should not exist'
+ refute File.exist?(gem_dir), 'gem_dir should not exist'
+ end
+
+ uninstaller.uninstall
+
+ refute File.exist?(gem_dir)
+
+ assert_same uninstaller, @pre_uninstall_hook_arg
+ assert_same uninstaller, @post_uninstall_hook_arg
+ end
+
+ def test_uninstall_user
+ uninstaller = Gem::Uninstaller.new @user_spec.name, :executables => true,
+ :user_install => true
+
+ gem_dir = File.join Gem.user_dir, 'gems', @user_spec.full_name
+
+ Gem.pre_uninstall do
+ assert File.exist?(gem_dir), 'gem_dir should exist'
+ end
+
+ Gem.post_uninstall do
+ refute File.exist?(gem_dir), 'gem_dir should not exist'
end
uninstaller.uninstall
- assert !File.exist?(gem_dir)
+ refute File.exist?(gem_dir)
assert_same uninstaller, @pre_uninstall_hook_arg
assert_same uninstaller, @post_uninstall_hook_arg
diff --git a/test/rubygems/test_gem_version.rb b/test/rubygems/test_gem_version.rb
index 4f5f79eaad..d87245f92b 100644
--- a/test/rubygems/test_gem_version.rb
+++ b/test/rubygems/test_gem_version.rb
@@ -12,9 +12,13 @@ class TestGemVersion < RubyGemTestCase
def setup
super
+ version = Object.new
+ def version.to_s() '1.4.0' end
+
@v1_0 = Gem::Version.new '1.0'
@v1_2 = Gem::Version.new '1.2'
@v1_3 = Gem::Version.new '1.3'
+ @v1_4_0 = Gem::Version.new version
end
def test_class_create
@@ -64,6 +68,11 @@ class TestGemVersion < RubyGemTestCase
assert_equal "5.3", v.bump.to_s
end
+ def test_bump_alpha
+ v = Gem::Version.new("5.2.4.a")
+ assert_equal "5.3", v.bump.to_s
+ end
+
def test_bump_one_level
v = Gem::Version.new("5")
assert_equal "6", v.bump.to_s
@@ -83,6 +92,20 @@ class TestGemVersion < RubyGemTestCase
assert_equal false, @v1_3.eql?(@v1_2)
end
+ def test_eql_eh4
+ v1_4 = Gem::Version.new '1.4'
+ v1_4_0 = Gem::Version.new "1.4.0"
+
+ assert_equal true, v1_4_0.eql?(@v1_4_0)
+ assert_equal true, @v1_4_0.eql?(v1_4_0)
+
+ assert_equal false, v1_4.eql?(@v1_4_0)
+ assert_equal false, @v1_4_0.eql?(v1_4)
+
+ assert_equal false, @v1_4_0.eql?(@v1_3)
+ assert_equal false, @v1_3.eql?(@v1_4_0)
+ end
+
def test_equals2
v = Gem::Version.new("1.2")
@@ -96,12 +119,17 @@ class TestGemVersion < RubyGemTestCase
def test_hash
v1_2 = Gem::Version.new "1.2"
v1_2_0 = Gem::Version.new "1.2.0"
+ v1_4_0 = Gem::Version.new "1.4.0"
assert_equal v1_2.hash, @v1_2.hash
refute_equal v1_2_0.hash, @v1_2.hash
+ assert_equal v1_4_0.hash, @v1_4_0.hash
+
refute_equal @v1_2.hash, @v1_3.hash
+
+ refute_equal @v1_2.hash, @v1_4_0.hash
end
def test_illformed_requirements
@@ -113,9 +141,12 @@ class TestGemVersion < RubyGemTestCase
end
def test_normalize
- assert_equal [1], Gem::Version.new("1").to_ints
- assert_equal [1], Gem::Version.new("1.0").to_ints
- assert_equal [1, 1], Gem::Version.new("1.1").to_ints
+ assert_equal [0], Gem::Version.new("").normalize.map { |part| part.value }
+ assert_equal [0], Gem::Version.new("0").normalize.map { |part| part.value }
+ assert_equal [1], Gem::Version.new("1").normalize.map { |part| part.value }
+ assert_equal [1], Gem::Version.new("1.0").normalize.map { |part| part.value }
+ assert_equal [1, 1], Gem::Version.new("1.1").normalize.map { |part| part.value }
+ assert_equal [1, 1, "a"], Gem::Version.new("1.1.a").normalize.map { |part| part.value }
end
def test_ok
@@ -139,9 +170,41 @@ class TestGemVersion < RubyGemTestCase
assert_adequate( "", "< 0.1")
assert_adequate( " ", "< 0.1 ")
assert_adequate( "", " < 0.1")
+ assert_adequate( " ", "> 0.a ")
+ assert_adequate( "", " > 0.a")
assert_adequate( "0", "=")
assert_adequate( "0", ">=")
assert_adequate( "0", "<=")
+ assert_adequate( "3.1", "< 3.2.rc1")
+ assert_adequate( "3.2.0", "> 3.2.0.rc1")
+ assert_adequate( "3.2.0.rc2", "> 3.2.0.rc1")
+ assert_adequate( "3.0.rc2", "< 3.0")
+ assert_adequate( "3.0.rc2", "< 3.0.0")
+ assert_adequate( "3.0.rc2", "< 3.0.1")
+ end
+
+ def test_parse_parts_from_version_string
+ assert_equal [], part_values(Gem::Version.new("").parse_parts_from_version_string)
+ assert_equal [1], part_values(Gem::Version.new("1").parse_parts_from_version_string)
+ assert_equal [1, 0], part_values(Gem::Version.new("1.0").parse_parts_from_version_string)
+ assert_equal [1, 0, "a"], part_values(Gem::Version.new("1.0.a").parse_parts_from_version_string)
+ end
+
+ def test_prerelease
+ assert Gem::Version.new('1.2.0.a').prerelease?
+ assert Gem::Version.new('2.9.b').prerelease?
+ assert Gem::Version.new('22.1.50.0.d').prerelease?
+
+ refute Gem::Version.new('1.2.0').prerelease?
+ refute Gem::Version.new('2.9').prerelease?
+ refute Gem::Version.new('22.1.50.0').prerelease?
+ end
+
+ def test_release
+ assert_equal Gem::Version.new('1.2.0'), Gem::Version.new('1.2.0.a').release
+ assert_equal Gem::Version.new('1.1'), Gem::Version.new('1.1.rc10').release
+ assert_equal Gem::Version.new('1.9.3'), Gem::Version.new('1.9.3.alpha.5').release
+ assert_equal Gem::Version.new('1.9.3'), Gem::Version.new('1.9.3').release
end
def test_satisfied_by_eh_boxed
@@ -156,6 +219,11 @@ class TestGemVersion < RubyGemTestCase
assert_adequate( "1.4.5", "~> 1.4.4")
assert_inadequate("1.5", "~> 1.4.4")
assert_inadequate("2.0", "~> 1.4.4")
+
+ assert_inadequate("1.1.pre", "~> 1.0.0")
+ assert_adequate( "1.1.pre", "~> 1.1")
+ assert_inadequate("2.0.a", "~> 1.0")
+ assert_adequate( "2.0.a", "~> 2.0")
end
def test_satisfied_by_eh_multiple
@@ -169,7 +237,12 @@ class TestGemVersion < RubyGemTestCase
end
def test_spaceship
+ assert_equal 0, Gem::Version.new('1.0') <=> Gem::Version.new('1.0.0')
+ assert_equal 1, Gem::Version.new('1.0') <=> Gem::Version.new('1.0.a')
assert_equal 1, Gem::Version.new('1.8.2') <=> Gem::Version.new('0.0.0')
+ assert_equal 1, Gem::Version.new('1.8.2') <=> Gem::Version.new('1.8.2.a')
+ assert_equal 1, Gem::Version.new('1.8.2.b') <=> Gem::Version.new('1.8.2.a')
+ assert_equal 0, Gem::Version.new('') <=> Gem::Version.new('0')
end
def test_boxed
@@ -201,7 +274,7 @@ class TestGemVersion < RubyGemTestCase
def assert_inadequate(version, requirement)
ver = Gem::Version.new(version)
req = Gem::Version::Requirement.new(requirement)
- assert ! req.satisfied_by?(ver),
+ refute req.satisfied_by?(ver),
"Version #{version} should not be adequate for Requirement #{requirement}"
end
@@ -210,5 +283,34 @@ class TestGemVersion < RubyGemTestCase
assert_equal @v1_0.version, actual.version
end
+ def part_values(*parts)
+ parts.flatten.map { |part| part.value }
+ end
+end
+
+class TestGemVersionPart < RubyGemTestCase
+ def test_initialize
+ assert_equal 1, Gem::Version::Part.new(1).value
+ assert_equal 1, Gem::Version::Part.new("1").value
+ assert_equal "a", Gem::Version::Part.new("a").value
+ end
+
+ def test_spaceship
+ assert_equal(-1, Gem::Version::Part.new(1) <=> Gem::Version::Part.new(2))
+ assert_equal( 0, Gem::Version::Part.new(2) <=> Gem::Version::Part.new(2))
+ assert_equal( 1, Gem::Version::Part.new(2) <=> Gem::Version::Part.new(1))
+
+ assert_equal(-1, Gem::Version::Part.new("a") <=> Gem::Version::Part.new("b"))
+ assert_equal( 0, Gem::Version::Part.new("b") <=> Gem::Version::Part.new("b"))
+ assert_equal( 1, Gem::Version::Part.new("b") <=> Gem::Version::Part.new("a"))
+
+ assert_equal(-1, Gem::Version::Part.new("a") <=> Gem::Version::Part.new(1))
+ assert_equal( 1, Gem::Version::Part.new(1) <=> Gem::Version::Part.new("a"))
+ end
+
+ def test_succ
+ assert_equal 2, Gem::Version::Part.new(1).succ.value
+ assert_equal "b", Gem::Version::Part.new("a").succ.value
+ end
end
diff --git a/test/rubygems/test_gem_version_option.rb b/test/rubygems/test_gem_version_option.rb
index 3fda36ed68..1a47e9ce15 100644
--- a/test/rubygems/test_gem_version_option.rb
+++ b/test/rubygems/test_gem_version_option.rb
@@ -23,6 +23,19 @@ class TestGemVersionOption < RubyGemTestCase
assert @cmd.handles?(%w[--version >1])
end
+ def test_enables_prerelease
+ @cmd.add_version_option
+
+ @cmd.handle_options %w[mygem -v 0.2.0.a]
+ assert @cmd.options[:prerelease]
+
+ @cmd.handle_options %w[mygem -v 0.2.0]
+ refute @cmd.options[:prerelease]
+
+ @cmd.handle_options %w[mygem]
+ refute @cmd.options[:prerelease]
+ end
+
def test_platform_option
@cmd.add_platform_option
diff --git a/test/rubygems/test_kernel.rb b/test/rubygems/test_kernel.rb
index ae594be65c..9dd63b85d7 100644
--- a/test/rubygems/test_kernel.rb
+++ b/test/rubygems/test_kernel.rb
@@ -31,14 +31,14 @@ class TestKernel < RubyGemTestCase
def test_gem_redundent
assert gem('a', '= 1'), "Should load"
- assert ! gem('a', '= 1'), "Should not load"
+ refute 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', '= 1'), "Should load"
- assert ! gem('a', '>= 1'), "Should not load"
+ refute 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
@@ -46,17 +46,19 @@ class TestKernel < RubyGemTestCase
def test_gem_conflicting
assert gem('a', '= 1'), "Should load"
- ex = assert_raises Gem::Exception do
+ ex = assert_raises Gem::LoadError do
gem 'a', '= 2'
end
assert_match(/activate a \(= 2, runtime\)/, ex.message)
assert_match(/activated a-1/, ex.message)
+ assert_equal 'a', ex.name
+ assert_equal Gem::Requirement.new('= 2'), ex.version_requirement
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 }
+ refute $:.any? { |p| %r{a-2/lib} =~ p }
+ refute $:.any? { |p| %r{a-2/bin} =~ p }
end
end