summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-22 22:46:50 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-22 22:46:50 +0000
commit4c2304f0004e9f1784540f3d36976aad9eab1f68 (patch)
treefe5d7f52b7e01644d0a57316aab03299ed0ee5c8 /test
parent66cc0fa4abde68ae360ba2d2cdf4e44bc833e33a (diff)
* lib/rubygems: Import RubyGems from master as of commit b165260
* test/rubygems: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42124 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/rubygems/test_gem.rb54
-rw-r--r--test/rubygems/test_gem_command_manager.rb44
-rw-r--r--test/rubygems/test_gem_commands_contents_command.rb28
-rw-r--r--test/rubygems/test_gem_commands_help_command.rb2
-rw-r--r--test/rubygems/test_gem_commands_pristine_command.rb4
-rw-r--r--test/rubygems/test_gem_commands_query_command.rb28
-rw-r--r--test/rubygems/test_gem_commands_search_command.rb17
-rw-r--r--test/rubygems/test_gem_commands_uninstall_command.rb33
-rw-r--r--test/rubygems/test_gem_ext_builder.rb58
-rw-r--r--test/rubygems/test_gem_ext_ext_conf_builder.rb41
-rw-r--r--test/rubygems/test_gem_remote_fetcher.rb11
11 files changed, 288 insertions, 32 deletions
diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb
index 6cce66ce58..0ee8d36f8e 100644
--- a/test/rubygems/test_gem.rb
+++ b/test/rubygems/test_gem.rb
@@ -13,8 +13,13 @@ end
class TestGem < Gem::TestCase
+ PLUGINS_LOADED = []
+
def setup
super
+
+ PLUGINS_LOADED.clear
+
common_installer_setup
ENV.delete 'RUBYGEMS_GEMDEPS'
@@ -345,9 +350,7 @@ class TestGem < Gem::TestCase
spec
}
- # HACK should be Gem.refresh
- Gem.searcher = nil
- Gem::Specification.reset
+ Gem.refresh
expected = [
File.expand_path('test/rubygems/sff/discover.rb', @@project_dir),
@@ -361,6 +364,37 @@ class TestGem < Gem::TestCase
assert_equal cwd, $LOAD_PATH.shift
end
+ def test_self_find_latest_files
+ cwd = File.expand_path("test/rubygems", @@project_dir)
+ $LOAD_PATH.unshift cwd
+
+ discover_path = File.join 'lib', 'sff', 'discover.rb'
+
+ _, foo2 = %w(1 2).map { |version|
+ spec = quick_gem 'sff', version do |s|
+ s.files << discover_path
+ end
+
+ write_file(File.join 'gems', spec.full_name, discover_path) do |fp|
+ fp.puts "# #{spec.full_name}"
+ end
+
+ spec
+ }
+
+ Gem.refresh
+
+ expected = [
+ File.expand_path('test/rubygems/sff/discover.rb', @@project_dir),
+ File.join(foo2.full_gem_path, discover_path),
+ ]
+
+ assert_equal expected, Gem.find_latest_files('sff/discover')
+ assert_equal expected, Gem.find_latest_files('sff/**.rb'), '[ruby-core:31730]'
+ ensure
+ assert_equal cwd, $LOAD_PATH.shift
+ end
+
def test_self_latest_spec_for
a1 = quick_spec 'a', 1
a2 = quick_spec 'a', 2
@@ -883,14 +917,20 @@ class TestGem < Gem::TestCase
Dir.chdir @tempdir do
FileUtils.mkdir_p 'lib'
File.open plugin_path, "w" do |fp|
- fp.puts "class TestGem; TEST_SPEC_PLUGIN_LOAD = :loaded; end"
+ fp.puts "class TestGem; PLUGINS_LOADED << 'plugin'; end"
end
- foo = quick_spec 'foo', '1' do |s|
+ foo1 = quick_spec 'foo', '1' do |s|
s.files << plugin_path
end
- install_gem foo
+ install_gem foo1
+
+ foo2 = quick_spec 'foo', '2' do |s|
+ s.files << plugin_path
+ end
+
+ install_gem foo2
end
Gem.searcher = nil
@@ -900,7 +940,7 @@ class TestGem < Gem::TestCase
Gem.load_plugins
- assert_equal :loaded, TEST_SPEC_PLUGIN_LOAD
+ assert_equal %w[plugin], PLUGINS_LOADED
end
def test_load_env_plugins
diff --git a/test/rubygems/test_gem_command_manager.rb b/test/rubygems/test_gem_command_manager.rb
index e201d73275..f6433c5cc3 100644
--- a/test/rubygems/test_gem_command_manager.rb
+++ b/test/rubygems/test_gem_command_manager.rb
@@ -58,7 +58,7 @@ class TestGemCommandManager < Gem::TestCase
use_ui @ui do
assert_raises Gem::MockGemUi::TermError do
- @command_manager.run 'interrupt'
+ @command_manager.run %w[interrupt]
end
assert_equal '', ui.output
assert_equal "ERROR: Interrupted\n", ui.error
@@ -75,7 +75,7 @@ class TestGemCommandManager < Gem::TestCase
@command_manager.register_command :crash
use_ui @ui do
assert_raises Gem::MockGemUi::TermError do
- @command_manager.run 'crash'
+ @command_manager.run %w[crash]
end
assert_equal '', ui.output
err = ui.error.split("\n").first
@@ -89,7 +89,7 @@ class TestGemCommandManager < Gem::TestCase
def test_process_args_bad_arg
use_ui @ui do
assert_raises Gem::MockGemUi::TermError do
- @command_manager.process_args("--bad-arg")
+ @command_manager.process_args %w[--bad-arg]
end
end
@@ -107,7 +107,7 @@ class TestGemCommandManager < Gem::TestCase
end
#check defaults
- @command_manager.process_args("install")
+ @command_manager.process_args %w[install]
assert_equal %w[ri], check_options[:document].sort
assert_equal false, check_options[:force]
assert_equal :both, check_options[:domain]
@@ -118,8 +118,10 @@ class TestGemCommandManager < Gem::TestCase
#check settings
check_options = nil
- @command_manager.process_args(
- "install --force --local --rdoc --install-dir . --version 3.0 --no-wrapper --bindir . ")
+ @command_manager.process_args %w[
+ install --force --local --rdoc --install-dir .
+ --version 3.0 --no-wrapper --bindir .
+ ]
assert_equal %w[rdoc ri], check_options[:document].sort
assert_equal true, check_options[:force]
assert_equal :local, check_options[:domain]
@@ -130,17 +132,17 @@ class TestGemCommandManager < Gem::TestCase
#check remote domain
check_options = nil
- @command_manager.process_args("install --remote")
+ @command_manager.process_args %w[install --remote]
assert_equal :remote, check_options[:domain]
#check both domain
check_options = nil
- @command_manager.process_args("install --both")
+ @command_manager.process_args %w[install --both]
assert_equal :both, check_options[:domain]
#check both domain
check_options = nil
- @command_manager.process_args("install --both")
+ @command_manager.process_args %w[install --both]
assert_equal :both, check_options[:domain]
end
end
@@ -155,12 +157,12 @@ class TestGemCommandManager < Gem::TestCase
end
#check defaults
- @command_manager.process_args("uninstall")
+ @command_manager.process_args %w[uninstall]
assert_equal Gem::Requirement.default, check_options[:version]
#check settings
check_options = nil
- @command_manager.process_args("uninstall foobar --version 3.0")
+ @command_manager.process_args %w[uninstall foobar --version 3.0]
assert_equal "foobar", check_options[:args].first
assert_equal Gem::Requirement.new('3.0'), check_options[:version]
end
@@ -175,12 +177,12 @@ class TestGemCommandManager < Gem::TestCase
end
#check defaults
- @command_manager.process_args("check")
+ @command_manager.process_args %w[check]
assert_equal true, check_options[:alien]
#check settings
check_options = nil
- @command_manager.process_args("check foobar --alien")
+ @command_manager.process_args %w[check foobar --alien]
assert_equal true, check_options[:alien]
end
@@ -194,12 +196,12 @@ class TestGemCommandManager < Gem::TestCase
end
#check defaults
- @command_manager.process_args("build")
+ @command_manager.process_args %w[build]
#NOTE: Currently no defaults
#check settings
check_options = nil
- @command_manager.process_args("build foobar.rb")
+ @command_manager.process_args %w[build foobar.rb]
assert_equal 'foobar.rb', check_options[:args].first
end
@@ -213,26 +215,26 @@ class TestGemCommandManager < Gem::TestCase
end
#check defaults
- @command_manager.process_args("query")
+ @command_manager.process_args %w[query]
assert_equal(//, check_options[:name])
assert_equal :local, check_options[:domain]
assert_equal false, check_options[:details]
#check settings
check_options = nil
- @command_manager.process_args("query --name foobar --local --details")
+ @command_manager.process_args %w[query --name foobar --local --details]
assert_equal(/foobar/i, check_options[:name])
assert_equal :local, check_options[:domain]
assert_equal true, check_options[:details]
#remote domain
check_options = nil
- @command_manager.process_args("query --remote")
+ @command_manager.process_args %w[query --remote]
assert_equal :remote, check_options[:domain]
#both (local/remote) domains
check_options = nil
- @command_manager.process_args("query --both")
+ @command_manager.process_args %w[query --both]
assert_equal :both, check_options[:domain]
end
@@ -246,12 +248,12 @@ class TestGemCommandManager < Gem::TestCase
end
#check defaults
- @command_manager.process_args("update")
+ @command_manager.process_args %w[update]
assert_includes check_options[:document], 'rdoc'
#check settings
check_options = nil
- @command_manager.process_args("update --force --rdoc --install-dir .")
+ @command_manager.process_args %w[update --force --rdoc --install-dir .]
assert_includes check_options[:document], 'ri'
assert_equal true, check_options[:force]
assert_equal Dir.pwd, check_options[:install_dir]
diff --git a/test/rubygems/test_gem_commands_contents_command.rb b/test/rubygems/test_gem_commands_contents_command.rb
index 35c9631959..d87e84fc82 100644
--- a/test/rubygems/test_gem_commands_contents_command.rb
+++ b/test/rubygems/test_gem_commands_contents_command.rb
@@ -91,6 +91,34 @@ class TestGemCommandsContentsCommand < Gem::TestCase
assert_equal "", @ui.error
end
+ def test_execute_missing_single
+ @cmd.options[:args] = %w[foo]
+
+ assert_raises Gem::MockGemUi::TermError do
+ use_ui @ui do
+ @cmd.execute
+ end
+ end
+
+ assert_match "Unable to find gem 'foo'", @ui.output
+ assert_empty @ui.error
+ end
+
+ def test_execute_missing_multiple
+ @cmd.options[:args] = %w[foo bar]
+
+ gem 'foo'
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_match "lib/foo.rb", @ui.output
+ assert_match "Unable to find gem 'bar'", @ui.output
+
+ assert_empty @ui.error
+ end
+
def test_execute_multiple
@cmd.options[:args] = %w[foo bar]
diff --git a/test/rubygems/test_gem_commands_help_command.rb b/test/rubygems/test_gem_commands_help_command.rb
index c3e143f619..3a6f2fa523 100644
--- a/test/rubygems/test_gem_commands_help_command.rb
+++ b/test/rubygems/test_gem_commands_help_command.rb
@@ -18,7 +18,7 @@ class TestGemCommandsHelpCommand < Gem::TestCase
def test_gem_help_bad
util_gem 'bad' do |out, err|
assert_equal('', out)
- assert_match(/Unknown command bad. Try gem help commands\n/, err)
+ assert_match "Unknown command bad", err
end
end
diff --git a/test/rubygems/test_gem_commands_pristine_command.rb b/test/rubygems/test_gem_commands_pristine_command.rb
index c5a2ab3f2f..78c3f85a5b 100644
--- a/test/rubygems/test_gem_commands_pristine_command.rb
+++ b/test/rubygems/test_gem_commands_pristine_command.rb
@@ -104,9 +104,9 @@ class TestGemCommandsPristineCommand < Gem::TestCase
assert_path_exists gem_exec
if win_platform?
- assert_match /\A#!\s*ruby/, File.read(gem_exec)
+ assert_match %r%\A#!\s*ruby%, File.read(gem_exec)
else
- assert_match /\A#!\s*\/usr\/bin\/env ruby/, File.read(gem_exec)
+ assert_match %r%\A#!\s*/usr/bin/env ruby%, File.read(gem_exec)
end
end
diff --git a/test/rubygems/test_gem_commands_query_command.rb b/test/rubygems/test_gem_commands_query_command.rb
index b79d13d270..a7e5e01f09 100644
--- a/test/rubygems/test_gem_commands_query_command.rb
+++ b/test/rubygems/test_gem_commands_query_command.rb
@@ -195,6 +195,34 @@ pl (1)
assert_equal '', @ui.error
end
+ def test_execute_installed_inverse
+ @cmd.handle_options %w[-n a --no-installed]
+
+ e = assert_raises Gem::MockGemUi::TermError do
+ use_ui @ui do
+ @cmd.execute
+ end
+ end
+
+ assert_equal "false\n", @ui.output
+ assert_equal '', @ui.error
+
+ assert_equal 1, e.exit_code
+ end
+
+ def test_execute_installed_inverse_not_installed
+ @cmd.handle_options %w[-n not_installed --no-installed]
+
+ assert_raises Gem::MockGemUi::SystemExitException do
+ use_ui @ui do
+ @cmd.execute
+ end
+ end
+
+ assert_equal "true\n", @ui.output
+ assert_equal '', @ui.error
+ end
+
def test_execute_installed_no_name
@cmd.handle_options %w[--installed]
diff --git a/test/rubygems/test_gem_commands_search_command.rb b/test/rubygems/test_gem_commands_search_command.rb
new file mode 100644
index 0000000000..fb8debc245
--- /dev/null
+++ b/test/rubygems/test_gem_commands_search_command.rb
@@ -0,0 +1,17 @@
+require 'rubygems/test_case'
+require 'rubygems/commands/search_command'
+
+class TestGemCommandsSearchCommand < Gem::TestCase
+
+ def setup
+ super
+
+ @cmd = Gem::Commands::SearchCommand.new
+ end
+
+ def test_initialize
+ assert_equal :remote, @cmd.defaults[:domain]
+ end
+
+end
+
diff --git a/test/rubygems/test_gem_commands_uninstall_command.rb b/test/rubygems/test_gem_commands_uninstall_command.rb
index 844c7b4b97..d6fe3ea5d9 100644
--- a/test/rubygems/test_gem_commands_uninstall_command.rb
+++ b/test/rubygems/test_gem_commands_uninstall_command.rb
@@ -16,6 +16,20 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
@executable = File.join(@gemhome, 'bin', 'executable')
end
+ def test_execute_all_gem_names
+ @cmd.options[:args] = %w[a b]
+ @cmd.options[:all] = true
+
+ assert_raises Gem::MockGemUi::TermError do
+ use_ui @ui do
+ @cmd.execute
+ end
+ end
+
+ assert_equal "ERROR: Gem names and --all may not be used together\n",
+ @ui.error
+ end
+
def test_execute_dependency_order
c = quick_gem 'c' do |spec|
spec.add_dependency 'a'
@@ -43,6 +57,7 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
def test_execute_removes_executable
ui = Gem::MockGemUi.new
+
util_setup_gem ui
build_rake_in do
@@ -175,5 +190,23 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
assert Gem::Specification.find_all_by_name('x').length == 0
end
+ def test_execute_all
+ ui = Gem::MockGemUi.new "y\n"
+
+ util_make_gems
+ util_setup_gem ui
+
+ assert Gem::Specification.find_all_by_name('a').length > 1
+
+ @cmd.options[:all] = true
+ @cmd.options[:args] = []
+
+ use_ui ui do
+ @cmd.execute
+ end
+
+ refute_includes Gem::Specification.all_names, 'a'
+ end
+
end
diff --git a/test/rubygems/test_gem_ext_builder.rb b/test/rubygems/test_gem_ext_builder.rb
new file mode 100644
index 0000000000..14a77b8db3
--- /dev/null
+++ b/test/rubygems/test_gem_ext_builder.rb
@@ -0,0 +1,58 @@
+require 'rubygems/test_case'
+require 'rubygems/ext'
+
+class TestGemExtBuilder < Gem::TestCase
+
+ def setup
+ super
+
+ @ext = File.join @tempdir, 'ext'
+ @dest_path = File.join @tempdir, 'prefix'
+
+ FileUtils.mkdir_p @ext
+ FileUtils.mkdir_p @dest_path
+
+ @orig_DESTDIR = ENV['DESTDIR']
+ end
+
+ def teardown
+ ENV['DESTDIR'] = @orig_DESTDIR
+
+ super
+ end
+
+ def test_class_make
+ ENV['DESTDIR'] = 'destination'
+ results = []
+
+ Dir.chdir @ext do
+ open 'Makefile', 'w' do |io|
+ io.puts <<-MAKEFILE
+all:
+\t@#{Gem.ruby} -e "puts %Q{all: \#{ENV['DESTDIR']}}"
+
+install:
+\t@#{Gem.ruby} -e "puts %Q{install: \#{ENV['DESTDIR']}}"
+ MAKEFILE
+ end
+
+ Gem::Ext::Builder.make @dest_path, results
+ end
+
+ results = results.join "\n"
+
+
+ if RUBY_VERSION > '2.0' then
+ assert_match %r%"DESTDIR=#{ENV['DESTDIR']}"$%, results
+ assert_match %r%"DESTDIR=#{ENV['DESTDIR']}" install$%, results
+ else
+ refute_match %r%"DESTDIR=#{ENV['DESTDIR']}"$%, results
+ refute_match %r%"DESTDIR=#{ENV['DESTDIR']}" install$%, results
+ end
+
+ assert_match %r%^all: destination$%, results
+ assert_match %r%^install: destination$%, results
+ 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 3703e6b63b..33398ac6f3 100644
--- a/test/rubygems/test_gem_ext_ext_conf_builder.rb
+++ b/test/rubygems/test_gem_ext_ext_conf_builder.rb
@@ -27,7 +27,10 @@ class TestGemExtExtConfBuilder < Gem::TestCase
output = []
Dir.chdir @ext do
- Gem::Ext::ExtConfBuilder.build 'extconf.rb', nil, @dest_path, output
+ result =
+ Gem::Ext::ExtConfBuilder.build 'extconf.rb', nil, @dest_path, output
+
+ assert_same result, output
end
assert_match(/^#{Gem.ruby} extconf.rb/, output[0])
@@ -108,6 +111,42 @@ checking for main\(\) in .*?nonexistent/m, error.message)
assert_equal("#{Gem.ruby} extconf.rb", output[0])
end
+ def test_class_build_unconventional
+ 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 <<-'EXTCONF'
+include RbConfig
+
+ruby_exe = "#{CONFIG['RUBY_INSTALL_NAME']}#{CONFIG['EXEEXT']}"
+ruby = File.join CONFIG['bindir'], ruby_exe
+
+open 'Makefile', 'w' do |io|
+ io.write <<-Makefile
+all: ruby
+install: ruby
+
+ruby:
+\t#{ruby} -e0
+
+ Makefile
+end
+ EXTCONF
+ end
+
+ output = []
+
+ Dir.chdir @ext do
+ Gem::Ext::ExtConfBuilder.build 'extconf.rb', nil, @dest_path, output
+ end
+
+ assert_contains_make_command '', output[2]
+ assert_contains_make_command 'install', output[4]
+ assert_empty Dir.glob(File.join(@ext, 'siteconf*.rb'))
+ end
+
def test_class_make
if vc_windows? && !nmake_found?
skip("test_class_make skipped - nmake not found")
diff --git a/test/rubygems/test_gem_remote_fetcher.rb b/test/rubygems/test_gem_remote_fetcher.rb
index 572148f125..fe6da708b6 100644
--- a/test/rubygems/test_gem_remote_fetcher.rb
+++ b/test/rubygems/test_gem_remote_fetcher.rb
@@ -580,6 +580,17 @@ gems:
end
end
+ def test_request_block
+ fetcher = Gem::RemoteFetcher.new nil
+
+ assert_throws :block_called do
+ fetcher.request URI('http://example'), Net::HTTP::Get do |req|
+ assert_kind_of Net::HTTPGenericRequest, req
+ throw :block_called
+ end
+ end
+ end
+
def test_yaml_error_on_size
use_ui @ui do
self.class.enable_yaml = false