summaryrefslogtreecommitdiff
path: root/win32
AgeCommit message (Expand)Author
2002-04-19* win32/Makefile.sub: add -DNT to $CFLAGS instead of $CPPFLAGS.usa
2002-04-19* win32/win32.c: include <mswsock.h> on __MINGW32__.eban
2002-04-12* win32/Makefile.sub: use missing/acosh.c.usa
2002-03-29* win32/README.win32: follow recent changes.usa
2002-03-28* win32/Makefile.sub (config.status): reflect user defined $CC inusa
2002-03-26* win32/mkexports.rb: support VC++.NET.usa
2002-03-20* win32/Makefile.sub (config.status): fix install path (prefix).usa
2002-03-20* win32/config.status.in: no longer used.nobu
2002-03-20* win32/Makefile.sub (config.status): and use recent autoconf format.nobu
2002-03-20* win32/Makefile.sub: made variables configurable.nobu
2002-03-15* win32/win32.c (StartSockets): remove duplicated lines.nobu
2002-02-22* win32/config.status.in: set LIBRUBY_SO.usa
2002-01-10* win32/resource.rb: Modify copyright in resource script.usa
2001-11-26 * win32/win32.c (mypopen): fixed that mypclose() didn't really closeusa
2001-11-14 * hash.c (ruby_setenv): remove USE_WIN32_RTL_ENV block since it'susa
2001-11-13 * win32/win32.c (waitpid): fix wait count.usa
2001-11-13 * win32/win32.c (mypopen): return error status instead of callingusa
2001-11-13 * hash.c (envix): use GET_ENVIRON and FREE_ENVIRON to get environmentusa
2001-11-09* win32/config.status.in: make CFLAGS same as Makefile's one.usa
2001-10-30 * win32/mkexports.rb: follow the change of rb_io_puts().usa
2001-09-25* win32/win32.c (isInternalCmd): check return value of NtMakeCmdVector (Tiete...usa
2001-08-24* dln.c (dln_strerror): fix a bug that sometimes made null message onusa
2001-08-15* win32/win32.c (NtCmdGlob): avoid VC++ warning.usa
2001-08-07* win32/win32.h: fix problems with BC++ (ruby-bugs#PR161).usa
2001-06-09* ext/extmk.rb.in: Use -F and -T for mswin32 because cl.exe doesn't support -...usa
2001-05-30* win32/dir.h: re-add.usa
2001-05-30* ruby.c (proc_options): unexpected SecurityError happens when -T4.matz
2001-05-13* win32/resource.rb: Modify copyright in resource script.usa
2001-05-12* win32/win32.c (kill): add support of signal 9 on mswin32/mingw32.usa
2001-05-06forgot some checkins.matz
2001-05-02* win32/config.h.in: add SIZEOF___INT64 definition.usa
2001-04-14* win32/config.status.in: no longer use missing/alloca.c.usa
2001-04-01* win32/win32.c: use ruby's opendir on mingw32.eban
2001-03-28* win32/Makefile.sub: disable global optimization.eban
2001-03-21* win32/win32.c (isUNCRoot): multibyte character support.eban
2001-03-21* win32/win32.c (win32_stat): WinNT/2k "//host/share" support.eban
2001-03-21rb_iglob -> rb_globieban
2001-03-20* win32/dir.h: replace missing/dir.h .usa
2001-03-20* win32/win32.c (win32_stat): UNC support.eban
2001-03-19* dir.c (glob_helper): replace lstat() by stat() to follow symlinkmatz
2001-03-05* win32/win32.c (gettimeofday): use GetLocalTime() instead of ftime()eban
2001-02-24* win32/win32.c (myrename): fix error handling.eban
2001-02-17* win32/win32.c: fasten file I/O on mswin32/mingw32.usa
2001-02-09* win32/win32.c (win32_stat): replace stat for enable when pathnameusa
2001-02-08* parse.y (parse_quotedwords): %w should allow parenthesis escape.matz
2001-01-17* win32/config.status.in: remove DEFS definition.eban
2001-01-14*** empty log message ***usa
2001-01-11NORETURN, INLINEeban
2001-01-10NORETURNeban
2001-01-10setres[ug]id, NORETURNeban
ble summary='file diffstat' width='100%'> -rw-r--r--trunk/test/rubygems/test_gem_commands_fetch_command.rb55
-rw-r--r--trunk/test/rubygems/test_gem_commands_generate_index_command.rb32
-rw-r--r--trunk/test/rubygems/test_gem_commands_install_command.rb166
-rw-r--r--trunk/test/rubygems/test_gem_commands_mirror_command.rb61
-rw-r--r--trunk/test/rubygems/test_gem_commands_outdated_command.rb43
-rw-r--r--trunk/test/rubygems/test_gem_commands_pristine_command.rb109
-rw-r--r--trunk/test/rubygems/test_gem_commands_query_command.rb288
-rw-r--r--trunk/test/rubygems/test_gem_commands_server_command.rb27
-rw-r--r--trunk/test/rubygems/test_gem_commands_sources_command.rb275
-rw-r--r--trunk/test/rubygems/test_gem_commands_specification_command.rb97
-rw-r--r--trunk/test/rubygems/test_gem_commands_stale_command.rb39
-rw-r--r--trunk/test/rubygems/test_gem_commands_unpack_command.rb115
-rw-r--r--trunk/test/rubygems/test_gem_commands_update_command.rb165
-rw-r--r--trunk/test/rubygems/test_gem_config_file.rb276
-rw-r--r--trunk/test/rubygems/test_gem_dependency.rb140
-rw-r--r--trunk/test/rubygems/test_gem_dependency_installer.rb637
-rw-r--r--trunk/test/rubygems/test_gem_dependency_list.rb212
-rwxr-xr-xtrunk/test/rubygems/test_gem_digest.rb44
-rw-r--r--trunk/test/rubygems/test_gem_doc_manager.rb32
-rw-r--r--trunk/test/rubygems/test_gem_ext_configure_builder.rb86
-rw-r--r--trunk/test/rubygems/test_gem_ext_ext_conf_builder.rb122
-rw-r--r--trunk/test/rubygems/test_gem_ext_rake_builder.rb76
-rw-r--r--trunk/test/rubygems/test_gem_format.rb69
-rw-r--r--trunk/test/rubygems/test_gem_gem_path_searcher.rb60
-rw-r--r--trunk/test/rubygems/test_gem_gem_runner.rb35
-rw-r--r--trunk/test/rubygems/test_gem_indexer.rb263
-rw-r--r--trunk/test/rubygems/test_gem_install_update_options.rb61
-rw-r--r--trunk/test/rubygems/test_gem_installer.rb868
-rw-r--r--trunk/test/rubygems/test_gem_local_remote_options.rb85
-rw-r--r--trunk/test/rubygems/test_gem_package_tar_header.rb137
-rw-r--r--trunk/test/rubygems/test_gem_package_tar_input.rb119
-rw-r--r--trunk/test/rubygems/test_gem_package_tar_output.rb104
-rw-r--r--trunk/test/rubygems/test_gem_package_tar_reader.rb53
-rw-r--r--trunk/test/rubygems/test_gem_package_tar_reader_entry.rb116
-rw-r--r--trunk/test/rubygems/test_gem_package_tar_writer.rb151
-rw-r--r--trunk/test/rubygems/test_gem_platform.rb259
-rw-r--r--trunk/test/rubygems/test_gem_remote_fetcher.rb692
-rw-r--r--trunk/test/rubygems/test_gem_requirement.rb223
-rw-r--r--trunk/test/rubygems/test_gem_server.rb301
-rw-r--r--trunk/test/rubygems/test_gem_source_index.rb834
-rw-r--r--trunk/test/rubygems/test_gem_source_info_cache.rb448
-rw-r--r--trunk/test/rubygems/test_gem_source_info_cache_entry.rb79
-rw-r--r--trunk/test/rubygems/test_gem_spec_fetcher.rb303
-rw-r--r--trunk/test/rubygems/test_gem_specification.rb954
-rw-r--r--trunk/test/rubygems/test_gem_stream_ui.rb117
-rw-r--r--trunk/test/rubygems/test_gem_uninstaller.rb66
-rw-r--r--trunk/test/rubygems/test_gem_validator.rb70
-rw-r--r--trunk/test/rubygems/test_gem_version.rb215
-rw-r--r--trunk/test/rubygems/test_gem_version_option.rb77
-rw-r--r--trunk/test/rubygems/test_kernel.rb65
74 files changed, 12556 insertions, 0 deletions
diff --git a/trunk/test/rubygems/bogussources.rb b/trunk/test/rubygems/bogussources.rb
new file mode 100644
index 0000000000..008e3a1de5
--- /dev/null
+++ b/trunk/test/rubygems/bogussources.rb
@@ -0,0 +1,8 @@
+#--
+# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
+# All rights reserved.
+# See LICENSE.txt for permissions.
+#++
+
+require 'rubygems'
+Gem.use_paths("test/mock/gems")
diff --git a/trunk/test/rubygems/data/gem-private_key.pem b/trunk/test/rubygems/data/gem-private_key.pem
new file mode 100644
index 0000000000..3e4be4cd9a
--- /dev/null
+++ b/trunk/test/rubygems/data/gem-private_key.pem
@@ -0,0 +1,27 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIIEpQIBAAKCAQEAz0tTOtsJuHDKAEXrQx0f6DUEzBEUTSLR1fk0iEHsY9rDCQxm
+sw5Bf2UnVhdD03B4/XzIK+pat2CMQc37/vLIBuVgS7g/fzatGiM0m5rAHtycr0XU
+8Ek6zjx4iSv70OLjybY+/utHCEc838awGDMCFR21jYxgATPVwqAIyasvwbKh/Vhw
+uErFPqT9G8BKTHsaX+H+ADIRH001OmWkjB6EyjF05114kNMa0+2C7daV9hoBL3md
+hCt6zOGcapl/9LkGxhcNEUB/So16V1ZQldg9macGyWktyNTSfctlF+f8okAmicG3
+XIwaW8UTmjFCmvDs/h1R/uKpe2IOHz87n29d2QIDAQABAoIBAQCR6n/nyg+JmTtX
+/d+hGns/RTLfQpZ7xarXZ9gmoeD4WSE42VXhbIOGXXnXDAFecKl6Jb/xycGZm4if
+OZPM3rEWyZeDNWrc7WvkHiwF7GSYVMqmRg2iJqoSSla+mAtl+pBFiNfHMW6K0Tp0
+erOyFRW+L2+A9/MMZaRun6AP9URkn0jz2kwmMFf+6szmzVn6fPFzZDRI+hEeaDmi
+LBzSrfrddrIBX+xGEoBj6RmfnKBCSUVSSxOauYjd4mVjVYxvMH4SV1hXDUS5GPl5
+MbCiBb7bpNIg/8ljMoRrQiqk0XwwS7MaCqPtMhUtpSmC/zSjAfmoN7AOc/Xh69cQ
+OCMNZH9BAoGBAPBlsuuU6fg0gVTKDdR12jHx03uRRt8/nPxHnpJkZCIh9XKh1LtY
+bkumi9HZpp3mzDiaGg/rwfCwNckKx8NLhICLgkric6ClrKftxTu6C8tBAb5YDi6u
+74KYnV8lMY/unzBtIloPgM3uluS292POmrWZpKwhvHLD71MewzMor5HFAoGBANy/
+mwsBs8i3Gzk8Twjq8effhPpE7kpxhC7bhwmjX3q41EjQWDT8M6xb1P9dRSsCIebi
+kqP1yhl27dJpA8r5WqE/z89xhBvObAGRv41eXxOI0LaH2k5lJQrUeSC+51dy+BEB
+T3GXD4C5ezZHQ8Wz/oL73uikrfhD+AqOZT2YbMEFAoGBAJvWEWpOGm3f+4bvhI+Z
+5lxCG4oa3wqRvj58XvsfQRovUWGCLtlTtgwsZq8enLf3iaOXohV4Czzvva4Z4u1i
+4v5BcbEBo1scixRBOn5BWKvl9C9j/a2dkX3jWQD4p2xaj69gz8f6DNFyPTb+tNhq
+cjgO5YUASZ1MDrSfWIKteULRAoGAZkZv8x2KyofrmQ0UITGZerDYz4t4TA1kDMGx
+QwnqhtVzpXjCJWpkFotFmDsCfPaz9mErR8PtKvcrIL1/AF+fWe5Sve3+I1P0PpXk
+hf8fVdGhwbAXuRKrouTmagGI9b9Sp65PvHUcvasyJufFwqeuV8mScX87CzeSiHGI
+/ozMdnECgYEAq4+losrhe0DEmiC9zVPvwRXjbSixDsSJxHfOcqIsZqhUgBiZ4TJD
+SrkuukrMZib6BAD+PtCJS1TBbJyyvL3QecizhHSIh3ZnT0HnaRPatLEYmU65+3kE
+kTqL4ik92bJnnWowy677sydl1lzBJDVa9ZlTs7BFSd8y/0DZaUxGg2I=
+-----END RSA PRIVATE KEY-----
diff --git a/trunk/test/rubygems/data/gem-public_cert.pem b/trunk/test/rubygems/data/gem-public_cert.pem
new file mode 100644
index 0000000000..885bf7f369
--- /dev/null
+++ b/trunk/test/rubygems/data/gem-public_cert.pem
@@ -0,0 +1,20 @@
+-----BEGIN CERTIFICATE-----
+MIIDNjCCAh6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBBMREwDwYDVQQDDAhydWJ5
+Z2VtczEXMBUGCgmSJomT8ixkARkWB2V4YW1wbGUxEzARBgoJkiaJk/IsZAEZFgNj
+b20wHhcNMDcwODAyMDMyNTQyWhcNMDgwODAxMDMyNTQyWjBBMREwDwYDVQQDDAhy
+dWJ5Z2VtczEXMBUGCgmSJomT8ixkARkWB2V4YW1wbGUxEzARBgoJkiaJk/IsZAEZ
+FgNjb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDPS1M62wm4cMoA
+RetDHR/oNQTMERRNItHV+TSIQexj2sMJDGazDkF/ZSdWF0PTcHj9fMgr6lq3YIxB
+zfv+8sgG5WBLuD9/Nq0aIzSbmsAe3JyvRdTwSTrOPHiJK/vQ4uPJtj7+60cIRzzf
+xrAYMwIVHbWNjGABM9XCoAjJqy/BsqH9WHC4SsU+pP0bwEpMexpf4f4AMhEfTTU6
+ZaSMHoTKMXTnXXiQ0xrT7YLt1pX2GgEveZ2EK3rM4ZxqmX/0uQbGFw0RQH9KjXpX
+VlCV2D2ZpwbJaS3I1NJ9y2UX5/yiQCaJwbdcjBpbxROaMUKa8Oz+HVH+4ql7Yg4f
+Pzufb13ZAgMBAAGjOTA3MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQW
+BBRYTAoj4cn8CWZMHFnHGQgoO5jyFTANBgkqhkiG9w0BAQUFAAOCAQEATRrJC05l
+dOmx67Sy3bU+AVXkOr7B9nn2Myqo9uSIAncPoElN6aHr/Q8wOOjtok4r0JcHPe1e
+eotDCZUE1Jkl13Tpv26rOfOOUHtGlyAIAtpsUGOraaJkSut4WKLr1/KckyAAEtgP
+c13A0s0mEiWFRuYxIdEi54561pTT2qQBE/DUPGoYD5rUg9XYAlSovMMwG99Oca7L
+cI6vCymr1bzzddExoywBNOy0fbBT62I3ICBGbH5yOVVKVmlxeo2Zp10FCj0kDrnq
+OuMJSDr5I2XPYqoC+W4YSbwn55o2jGIUX1lOq2Hvj4tFgSxlnJZn0tUhBfR3gSOn
+IFnrqu8PlZsLFw==
+-----END CERTIFICATE-----
diff --git a/trunk/test/rubygems/fake_certlib/openssl.rb b/trunk/test/rubygems/fake_certlib/openssl.rb
new file mode 100644
index 0000000000..948110f078
--- /dev/null
+++ b/trunk/test/rubygems/fake_certlib/openssl.rb
@@ -0,0 +1,7 @@
+#--
+# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
+# All rights reserved.
+# See LICENSE.txt for permissions.
+#++
+
+fail LoadError, "no such file to load -- openssl"
diff --git a/trunk/test/rubygems/functional.rb b/trunk/test/rubygems/functional.rb
new file mode 100644
index 0000000000..4838167324
--- /dev/null
+++ b/trunk/test/rubygems/functional.rb
@@ -0,0 +1,95 @@
+#!/usr/bin/env ruby
+#--
+# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
+# All rights reserved.
+# See LICENSE.txt for permissions.
+#++
+
+require 'test/unit'
+require 'rubygems'
+require 'test/insure_session'
+require 'rubygems/format'
+require 'rubygems/command_manager'
+
+class FunctionalTest < Test::Unit::TestCase
+ def setup
+ @gem_path = File.expand_path("bin/gem")
+ lib_path = File.expand_path("lib")
+ @ruby_options = "-I#{lib_path} -I."
+ @verbose = false
+ end
+
+ def test_gem_help_options
+ gem_nossl 'help options'
+ assert_match(/Usage:/, @out, @err)
+ assert_status
+ end
+
+ def test_gem_help_commands
+ gem_nossl 'help commands'
+ assert_match(/gem install/, @out)
+ assert_status
+ end
+
+ def test_gem_no_args_shows_help
+ gem_nossl
+ assert_match(/Usage:/, @out)
+ assert_status 1
+ end
+
+ # This test is disabled because of the insanely long time it takes
+ # to time out.
+ def xtest_bogus_source_hoses_up_remote_install_but_gem_command_gives_decent_error_message
+ @ruby_options << " -rtest/bogussources"
+ gem_nossl "install asdf --remote"
+ assert_match(/error/im, @err)
+ assert_status 1
+ end
+
+ def test_all_command_helps
+ mgr = Gem::CommandManager.new
+ mgr.command_names.each do |cmdname|
+ gem_nossl "help #{cmdname}"
+ assert_match(/Usage: gem #{cmdname}/, @out,
+ "should see help for #{cmdname}")
+ end
+ end
+
+ # :section: Help Methods
+
+ # Run a gem command without the SSL library.
+ def gem_nossl(options="")
+ old_options = @ruby_options.dup
+ @ruby_options << " -Itest/fake_certlib"
+ gem(options)
+ ensure
+ @ruby_options = old_options
+ end
+
+ # Run a gem command with the SSL library.
+ def gem_withssl(options="")
+ gem(options)
+ end
+
+ # Run a gem command for the functional test.
+ def gem(options="")
+ shell = Session::Shell.new
+ options = options + " --config-file missing_file" if options !~ /--config-file/
+ command = "#{Gem.ruby} #{@ruby_options} #{@gem_path} #{options}"
+ puts "\n\nCOMMAND: [#{command}]" if @verbose
+ @out, @err = shell.execute command
+ @status = shell.exit_status
+ puts "STATUS: [#{@status}]" if @verbose
+ puts "OUTPUT: [#{@out}]" if @verbose
+ puts "ERROR: [#{@err}]" if @verbose
+ puts "PWD: [#{Dir.pwd}]" if @verbose
+ shell.close
+ end
+
+ private
+
+ def assert_status(expected_status=0)
+ assert_equal expected_status, @status
+ end
+
+end
diff --git a/trunk/test/rubygems/gem_installer_test_case.rb b/trunk/test/rubygems/gem_installer_test_case.rb
new file mode 100644
index 0000000000..0d684eb1eb
--- /dev/null
+++ b/trunk/test/rubygems/gem_installer_test_case.rb
@@ -0,0 +1,86 @@
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/installer'
+
+class Gem::Installer
+ attr_accessor :gem_dir
+
+ attr_writer :format
+ attr_writer :gem_home
+ attr_writer :env_shebang
+ attr_writer :ignore_dependencies
+ attr_writer :format_executable
+ attr_writer :security_policy
+ attr_writer :spec
+ attr_writer :wrappers
+end
+
+class GemInstallerTestCase < RubyGemTestCase
+
+ def setup
+ super
+
+ @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 = Gem::Installer.new @gem
+ @installer.gem_dir = util_gem_dir
+ @installer.gem_home = @gemhome
+ @installer.spec = @spec
+ end
+
+ def util_gem_bindir(version = '2')
+ File.join util_gem_dir(version), "bin"
+ end
+
+ def util_gem_dir(version = '2')
+ File.join @gemhome, "gems", "a-#{version}" # HACK
+ end
+
+ def util_inst_bindir
+ File.join @gemhome, "bin"
+ end
+
+ def util_make_exec(version = '2', shebang = "#!/usr/bin/ruby")
+ @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
+ File.open exec_path, 'w' do |f|
+ f.puts shebang
+ end
+ end
+
+ def util_setup_gem(ui = @ui) # HACK fix use_ui to make this automatic
+ @spec.files = File.join('lib', 'code.rb')
+ @spec.executables << 'executable'
+ @spec.extensions << File.join('ext', 'a', 'mkrf_conf.rb')
+
+ Dir.chdir @tempdir do
+ FileUtils.mkdir_p 'bin'
+ FileUtils.mkdir_p 'lib'
+ FileUtils.mkdir_p File.join('ext', 'a')
+ File.open File.join('bin', 'executable'), 'w' do |f| f.puts '1' end
+ File.open File.join('lib', 'code.rb'), 'w' do |f| f.puts '1' end
+ File.open File.join('ext', 'a', 'mkrf_conf.rb'), 'w' do |f|
+ f << <<-EOF
+ File.open 'Rakefile', 'w' do |rf| rf.puts "task :default" end
+ EOF
+ end
+
+ use_ui ui do
+ FileUtils.rm @gem
+ Gem::Builder.new(@spec).build
+ end
+ end
+
+ @installer = Gem::Installer.new @gem
+ end
+
+end
+
diff --git a/trunk/test/rubygems/gem_package_tar_test_case.rb b/trunk/test/rubygems/gem_package_tar_test_case.rb
new file mode 100644
index 0000000000..756b30ef27
--- /dev/null
+++ b/trunk/test/rubygems/gem_package_tar_test_case.rb
@@ -0,0 +1,146 @@
+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)
+ str + "\0" * (length - str.length)
+ end
+
+ def SP(s)
+ s + " "
+ end
+
+ def SP_Z(s)
+ s + " \0"
+ end
+
+ def Z(s)
+ s + "\0"
+ end
+
+ def assert_headers_equal(expected, actual)
+ expected = expected.to_s unless String === expected
+ actual = actual.to_s unless String === actual
+
+ fields = %w[
+ name 100
+ mode 8
+ uid 8
+ gid 8
+ size 12
+ mtime 12
+ checksum 8
+ typeflag 1
+ linkname 100
+ magic 6
+ version 2
+ uname 32
+ gname 32
+ devmajor 8
+ devminor 8
+ prefix 155
+ ]
+
+ offset = 0
+
+ until fields.empty? do
+ name = fields.shift
+ length = fields.shift.to_i
+
+ if name == "checksum" then
+ chksum_off = offset
+ offset += length
+ next
+ end
+
+ assert_equal expected[offset, length], actual[offset, length],
+ "Field #{name} of the tar header differs."
+
+ offset += length
+ end
+
+ assert_equal expected[chksum_off, 8], actual[chksum_off, 8]
+ end
+
+ def calc_checksum(header)
+ sum = header.unpack("C*").inject{|s,a| s + a}
+ SP(Z(to_oct(sum, 6)))
+ end
+
+ def header(type, fname, dname, length, mode, checksum = nil)
+ checksum ||= " " * 8
+
+ arr = [ # struct tarfile_entry_posix
+ ASCIIZ(fname, 100), # char name[100]; ASCII + (Z unless filled)
+ Z(to_oct(mode, 7)), # char mode[8]; 0 padded, octal null
+ Z(to_oct(0, 7)), # char uid[8]; ditto
+ Z(to_oct(0, 7)), # char gid[8]; ditto
+ Z(to_oct(length, 11)), # char size[12]; 0 padded, octal, null
+ Z(to_oct(0, 11)), # char mtime[12]; 0 padded, octal, null
+ checksum, # char checksum[8]; 0 padded, octal, null, space
+ type, # char typeflag[1]; file: "0" dir: "5"
+ "\0" * 100, # char linkname[100]; ASCII + (Z unless filled)
+ "ustar\0", # char magic[6]; "ustar\0"
+ "00", # char version[2]; "00"
+ ASCIIZ("wheel", 32), # char uname[32]; ASCIIZ
+ ASCIIZ("wheel", 32), # char gname[32]; ASCIIZ
+ Z(to_oct(0, 7)), # char devmajor[8]; 0 padded, octal, null
+ Z(to_oct(0, 7)), # char devminor[8]; 0 padded, octal, null
+ ASCIIZ(dname, 155) # char prefix[155]; ASCII + (Z unless filled)
+ ]
+
+ format = "C100C8C8C8C12C12C8CC100C6C2C32C32C8C8C155"
+ h = if RUBY_VERSION >= "1.9" then
+ arr.join
+ else
+ arr = arr.join("").split(//).map{|x| x[0]}
+ arr.pack format
+ end
+ ret = h + "\0" * (512 - h.size)
+ assert_equal(512, ret.size)
+ ret
+ end
+
+ def tar_dir_header(name, prefix, mode)
+ h = header("5", name, prefix, 0, mode)
+ checksum = calc_checksum(h)
+ header("5", name, prefix, 0, mode, checksum)
+ end
+
+ def tar_file_header(fname, dname, mode, length)
+ h = header("0", fname, dname, length, mode)
+ checksum = calc_checksum(h)
+ header("0", fname, dname, length, mode, checksum)
+ end
+
+ def to_oct(n, pad_size)
+ "%0#{pad_size}o" % n
+ end
+
+ def util_entry(tar)
+ io = TempIO.new tar
+ header = Gem::Package::TarHeader.from io
+ entry = Gem::Package::TarReader::Entry.new header, io
+ end
+
+ def util_dir_entry
+ util_entry tar_dir_header("foo", "bar", 0)
+ end
+
+end
+
diff --git a/trunk/test/rubygems/gemutilities.rb b/trunk/test/rubygems/gemutilities.rb
new file mode 100644
index 0000000000..0ab2c5272c
--- /dev/null
+++ b/trunk/test/rubygems/gemutilities.rb
@@ -0,0 +1,441 @@
+#!/usr/bin/env ruby
+#--
+# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
+# All rights reserved.
+# See LICENSE.txt for permissions.
+#++
+
+at_exit { $SAFE = 1 }
+
+$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
+
+require 'fileutils'
+require 'test/unit'
+require 'tmpdir'
+require 'uri'
+require 'rubygems/package'
+require 'rubygems/test_utilities'
+
+require File.join(File.expand_path(File.dirname(__FILE__)), 'mockgemui')
+
+module Gem
+ def self.source_index=(si)
+ @@source_index = si
+ end
+
+ def self.win_platform=(val)
+ @@win_platform = val
+ end
+
+ module DefaultUserInteraction
+ @ui = MockGemUi.new
+ end
+end
+
+class RubyGemTestCase < Test::Unit::TestCase
+
+ include Gem::DefaultUserInteraction
+
+ undef_method :default_test if instance_methods.include? 'default_test' or
+ instance_methods.include? :default_test
+
+ def setup
+ super
+
+ @ui = MockGemUi.new
+ tmpdir = nil
+ Dir.chdir Dir.tmpdir do tmpdir = Dir.pwd end # HACK OSX /private/tmp
+ @tempdir = File.join tmpdir, "test_rubygems_#{$$}"
+ @tempdir.untaint
+ @gemhome = File.join @tempdir, "gemhome"
+ @gemcache = File.join(@gemhome, "source_cache")
+ @usrcache = File.join(@gemhome, ".gem", "user_cache")
+ @latest_usrcache = File.join(@gemhome, ".gem", "latest_user_cache")
+ @userhome = File.join @tempdir, 'userhome'
+
+ ENV['HOME'] = @userhome
+ Gem.instance_variable_set :@user_home, nil
+
+ FileUtils.mkdir_p @gemhome
+ FileUtils.mkdir_p @userhome
+
+ ENV['GEMCACHE'] = @usrcache
+ Gem.use_paths(@gemhome)
+ Gem.loaded_specs.clear
+
+ Gem.configuration.verbose = true
+ Gem.configuration.update_sources = true
+
+ @gem_repo = "http://gems.example.com/"
+ @uri = URI.parse @gem_repo
+ Gem.sources.replace [@gem_repo]
+
+ Gem::SpecFetcher.fetcher = nil
+
+ @orig_BASERUBY = Gem::ConfigMap[:BASERUBY]
+ Gem::ConfigMap[:BASERUBY] = Gem::ConfigMap[:RUBY_INSTALL_NAME]
+
+ @orig_arch = Gem::ConfigMap[:arch]
+
+ if win_platform?
+ util_set_arch 'i386-mswin32'
+ else
+ util_set_arch 'i686-darwin8.10.1'
+ end
+
+ @marshal_version = "#{Marshal::MAJOR_VERSION}.#{Marshal::MINOR_VERSION}"
+
+ @private_key = File.expand_path File.join(File.dirname(__FILE__),
+ 'private_key.pem')
+ @public_cert = File.expand_path File.join(File.dirname(__FILE__),
+ 'public_cert.pem')
+ end
+
+ def teardown
+ Gem::ConfigMap[:BASERUBY] = @orig_BASERUBY
+ Gem::ConfigMap[:arch] = @orig_arch
+
+ if defined? Gem::RemoteFetcher then
+ Gem::RemoteFetcher.fetcher = nil
+ end
+
+ FileUtils.rm_rf @tempdir
+
+ ENV.delete 'GEMCACHE'
+ ENV.delete 'GEM_HOME'
+ ENV.delete 'GEM_PATH'
+
+ Gem.clear_paths
+ end
+
+ def install_gem gem
+ require 'rubygems/installer'
+
+ use_ui MockGemUi.new do
+ Dir.chdir @tempdir do
+ Gem::Builder.new(gem).build
+ end
+ end
+
+ gem = File.join(@tempdir, "#{gem.full_name}.gem").untaint
+ Gem::Installer.new(gem, :wrappers => true).install
+ end
+
+ def prep_cache_files(lc)
+ @usr_si ||= Gem::SourceIndex.new
+ @usr_sice ||= Gem::SourceInfoCacheEntry.new @usr_si, 0
+
+ @sys_si ||= Gem::SourceIndex.new
+ @sys_sice ||= Gem::SourceInfoCacheEntry.new @sys_si, 0
+
+ latest_si = Gem::SourceIndex.new
+ latest_si.add_specs(*@sys_si.latest_specs)
+ latest_sys_sice = Gem::SourceInfoCacheEntry.new latest_si, 0
+
+ latest_si = Gem::SourceIndex.new
+ latest_si.add_specs(*@usr_si.latest_specs)
+ latest_usr_sice = Gem::SourceInfoCacheEntry.new latest_si, 0
+
+ [ [lc.system_cache_file, @sys_sice],
+ [lc.latest_system_cache_file, latest_sys_sice],
+ [lc.user_cache_file, @usr_sice],
+ [lc.latest_user_cache_file, latest_usr_sice],
+ ].each do |filename, data|
+ FileUtils.mkdir_p File.dirname(filename).untaint
+
+ open filename.dup.untaint, 'wb' do |f|
+ f.write Marshal.dump({ @gem_repo => data })
+ end
+ end
+ end
+
+ def read_cache(path)
+ open path.dup.untaint, 'rb' do |io|
+ Marshal.load io.read
+ end
+ end
+
+ def read_binary(path)
+ Gem.read_binary path
+ end
+
+ def write_file(path)
+ path = File.join(@gemhome, path)
+ dir = File.dirname path
+ FileUtils.mkdir_p dir
+
+ open path, 'wb' do |io|
+ yield io
+ end
+
+ path
+ end
+
+ def quick_gem(gemname, version='2')
+ require 'rubygems/specification'
+
+ spec = Gem::Specification.new do |s|
+ s.platform = Gem::Platform::RUBY
+ s.name = gemname
+ s.version = version
+ s.author = 'A User'
+ s.email = 'example@example.com'
+ s.homepage = 'http://example.com'
+ s.has_rdoc = true
+ s.summary = "this is a summary"
+ s.description = "This is a test description"
+
+ yield(s) if block_given?
+ end
+
+ path = File.join "specifications", "#{spec.full_name}.gemspec"
+ written_path = write_file path do |io|
+ io.write(spec.to_ruby)
+ end
+
+ spec.loaded_from = written_path
+
+ Gem.source_index.add_spec spec
+
+ return spec
+ end
+
+ def util_build_gem(spec)
+ dir = File.join(@gemhome, 'gems', spec.full_name)
+ FileUtils.mkdir_p dir
+
+ Dir.chdir dir do
+ spec.files.each do |file|
+ next if File.exist? file
+ FileUtils.mkdir_p File.dirname(file)
+ File.open file, 'w' do |fp| fp.puts "# #{file}" end
+ end
+
+ use_ui MockGemUi.new do
+ Gem::Builder.new(spec).build
+ end
+
+ FileUtils.mv "#{spec.full_name}.gem",
+ File.join(@gemhome, 'cache', "#{spec.original_name}.gem")
+ end
+ end
+
+ def util_clear_gems
+ FileUtils.rm_r File.join(@gemhome, 'gems')
+ FileUtils.rm_r File.join(@gemhome, 'specifications')
+ Gem.source_index.refresh!
+ end
+
+ def util_gem(name, version, &block)
+ spec = quick_gem(name, version, &block)
+
+ util_build_gem spec
+
+ cache_file = File.join @tempdir, 'gems', "#{spec.original_name}.gem"
+ FileUtils.mv File.join(@gemhome, 'cache', "#{spec.original_name}.gem"),
+ cache_file
+ FileUtils.rm File.join(@gemhome, 'specifications',
+ "#{spec.full_name}.gemspec")
+
+ spec.loaded_from = nil
+ spec.loaded = false
+
+ [spec, cache_file]
+ end
+
+ def util_gzip(data)
+ out = StringIO.new
+
+ Zlib::GzipWriter.wrap out do |io|
+ io.write data
+ end
+
+ out.string
+ end
+
+ def util_make_gems
+ 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)
+ @a_evil9 = quick_gem('a_evil', '9', &init)
+ @b2 = quick_gem('b', '2', &init)
+ @c1_2 = quick_gem('c', '1.2', &init)
+ @pl1 = quick_gem 'pl', '1' do |s| # l for legacy
+ s.files = %w[lib/code.rb]
+ s.require_paths = %w[lib]
+ s.platform = Gem::Platform.new 'i386-linux'
+ s.instance_variable_set :@original_platform, 'i386-linux'
+ end
+
+ write_file File.join(*%W[gems #{@a1.original_name} lib code.rb]) do end
+ write_file File.join(*%W[gems #{@a2.original_name} lib code.rb]) do end
+ write_file File.join(*%W[gems #{@b2.original_name} lib code.rb]) do end
+ write_file File.join(*%W[gems #{@c1_2.original_name} lib code.rb]) do end
+ write_file File.join(*%W[gems #{@pl1.original_name} lib code.rb]) do end
+
+ [@a1, @a2, @a_evil9, @b2, @c1_2, @pl1].each { |spec| util_build_gem spec }
+
+ FileUtils.rm_r File.join(@gemhome, 'gems', @pl1.original_name)
+
+ Gem.source_index = nil
+ end
+
+ ##
+ # Set the platform to +arch+
+
+ def util_set_arch(arch)
+ Gem::ConfigMap[:arch] = arch
+ platform = Gem::Platform.new arch
+
+ Gem.instance_variable_set :@platforms, nil
+ Gem::Platform.instance_variable_set :@local, nil
+
+ platform
+ end
+
+ def util_setup_fake_fetcher
+ require 'zlib'
+ require 'socket'
+ require 'rubygems/remote_fetcher'
+
+ @fetcher = Gem::FakeFetcher.new
+
+ util_make_gems
+
+ @all_gems = [@a1, @a2, @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 = gem_names.sort.join("\n")
+
+ @source_index = Gem::SourceIndex.new
+ @source_index.add_spec @a1
+ @source_index.add_spec @a2
+ @source_index.add_spec @a_evil9
+ @source_index.add_spec @c1_2
+
+ Gem::RemoteFetcher.fetcher = @fetcher
+ end
+
+ def util_setup_source_info_cache(*specs)
+ require 'rubygems/source_info_cache'
+ require 'rubygems/source_info_cache_entry'
+
+ specs = Hash[*specs.map { |spec| [spec.full_name, spec] }.flatten]
+ si = Gem::SourceIndex.new specs
+
+ sice = Gem::SourceInfoCacheEntry.new si, 0
+ sic = Gem::SourceInfoCache.new
+
+ sic.set_cache_data( { @gem_repo => sice } )
+ sic.update
+ sic.write_cache
+ sic.reset_cache_data
+
+ Gem::SourceInfoCache.instance_variable_set :@cache, sic
+
+ si
+ end
+
+ def util_setup_spec_fetcher(*specs)
+ specs = Hash[*specs.map { |spec| [spec.full_name, spec] }.flatten]
+ si = Gem::SourceIndex.new specs
+
+ spec_fetcher = Gem::SpecFetcher.fetcher
+
+ spec_fetcher.specs[@uri] = []
+ si.gems.sort_by { |_, spec| spec }.each do |_, spec|
+ spec_tuple = [spec.name, spec.version, spec.original_platform]
+ spec_fetcher.specs[@uri] << spec_tuple
+ end
+
+ spec_fetcher.latest_specs[@uri] = []
+ si.latest_specs.sort.each do |spec|
+ spec_tuple = [spec.name, spec.version, spec.original_platform]
+ spec_fetcher.latest_specs[@uri] << spec_tuple
+ end
+
+ si.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
+ @fetcher.data[path] = data_deflate
+ end
+
+ si
+ end
+
+ def util_zip(data)
+ Zlib::Deflate.deflate data
+ end
+
+ def self.win_platform?
+ Gem.win_platform?
+ end
+
+ def win_platform?
+ Gem.win_platform?
+ 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.
+ def self.process_based_port
+ @@process_based_port ||= 8000 + $$ % 1000
+ end
+
+ def process_based_port
+ self.class.process_based_port
+ end
+
+ def build_rake_in
+ gem_ruby = Gem.ruby
+ ruby = @@ruby
+ Gem.module_eval {@ruby = ruby}
+ env_rake = ENV["rake"]
+ ENV["rake"] = @@rake
+ yield @@rake
+ ensure
+ Gem.module_eval {@ruby = gem_ruby}
+ if env_rake
+ ENV["rake"] = env_rake
+ else
+ ENV.delete("rake")
+ end
+ end
+
+ def self.rubybin
+ if ruby = ENV["RUBY"]
+ return ruby
+ end
+ ruby = "ruby"
+ rubyexe = ruby+".exe"
+ 3.times do
+ if File.exist? ruby and File.executable? ruby and !File.directory? ruby
+ return File.expand_path(ruby)
+ end
+ if File.exist? rubyexe and File.executable? rubyexe
+ return File.expand_path(rubyexe)
+ end
+ ruby = File.join("..", ruby)
+ end
+ begin
+ require "rbconfig"
+ File.join(
+ RbConfig::CONFIG["bindir"],
+ RbConfig::CONFIG["ruby_install_name"] + RbConfig::CONFIG["EXEEXT"]
+ )
+ rescue LoadError
+ "ruby"
+ end
+ end
+
+ @@ruby = rubybin
+ @@rake = ENV["rake"] || (@@ruby + " " + File.expand_path("../../../bin/rake", __FILE__))
+
+end
+
diff --git a/trunk/test/rubygems/insure_session.rb b/trunk/test/rubygems/insure_session.rb
new file mode 100644
index 0000000000..e56f9abcb8
--- /dev/null
+++ b/trunk/test/rubygems/insure_session.rb
@@ -0,0 +1,51 @@
+#!/usr/bin/env ruby
+#--
+# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
+# All rights reserved.
+# See LICENSE.txt for permissions.
+#++
+
+
+require 'rubygems'
+
+def install_session
+ path_to_gem = File.join("redist", "session.gem")
+ begin
+ Gem::Installer.new(path_to_gem).install
+ rescue Errno::EACCES => ex
+ puts
+ puts "*****************************************************************"
+ puts "Unable to install Gem 'Session'."
+ puts "Reason: #{ex.message}"
+ puts "Try running:"
+ puts
+ puts " gem -Li #{path_to_gem}"
+ puts
+ puts "with the appropriate admin privileges."
+ puts "*****************************************************************"
+ puts
+ exit
+ end
+ gem 'session'
+end
+
+begin
+ require 'session'
+rescue LoadError => e
+ puts
+ puts "Required Gem 'Session' missing."
+ puts "We can attempt to install from the RubyGems Distribution,"
+ puts "but installation may require admin privileges on your system."
+ puts
+ print "Install now from RubyGems distribution? [Yn]"
+ answer = gets
+ if(answer =~ /^y/i || answer =~ /^[^a-zA-Z0-9]$/) then
+ install_session
+ puts
+ puts "Retry running the functional tests."
+ exit(0)
+ else
+ puts "Test cancelled...quitting"
+ exit(1)
+ end
+end
diff --git a/trunk/test/rubygems/mockgemui.rb b/trunk/test/rubygems/mockgemui.rb
new file mode 100644
index 0000000000..95a95fbf98
--- /dev/null
+++ b/trunk/test/rubygems/mockgemui.rb
@@ -0,0 +1,43 @@
+#!/usr/bin/env ruby
+#--
+# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
+# All rights reserved.
+# See LICENSE.txt for permissions.
+#++
+
+
+require 'stringio'
+require 'rubygems/user_interaction'
+
+class MockGemUi < Gem::StreamUI
+ class TermError < RuntimeError; end
+
+ def initialize(input="")
+ super(StringIO.new(input), StringIO.new, StringIO.new)
+ @terminated = false
+ end
+
+ def input
+ @ins.string
+ end
+
+ def output
+ @outs.string
+ end
+
+ def error
+ @errs.string
+ end
+
+ def terminated?
+ @terminated
+ end
+
+ def terminate_interaction(status=0)
+ @terminated = true
+
+ raise TermError
+ end
+
+end
+
diff --git a/trunk/test/rubygems/private_key.pem b/trunk/test/rubygems/private_key.pem
new file mode 100644
index 0000000000..95b3dc76d8
--- /dev/null
+++ b/trunk/test/rubygems/private_key.pem
@@ -0,0 +1,27 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIIEpAIBAAKCAQEAm24C6xixiAxO+i1f3L8XRMwrmLkt6BvT60mZ7g8HsklH3af7
+KNHA6vo/G6sujs2UsNO4HY8BTEneiVOXXWQlcsJ+Z5wEPlIu4zFueAmLefx+n9lE
+ulNIUDoyUenKX4spoMRnX8k4lXL05ho/6JFq0JdDY2DmAaQ4vvTz5mh9kZiybtHQ
+fzcpbA51uY+sjdQRCPDHyUUfh0SmWJlLYMwcBdVeCiGUPBLi+iP5x1btO4uiJK6Q
+IMaV1H3SUCYtKGQKl7qwFd8k8ZBcHYOtmK61tupg3vqWQc0em6SxPj5lws8+1MVK
+twBNIDx24jF4ntxBRNKMZ7FN5SHbobAgDYkPAQIDAQABAoIBAGQilgK8X/PUajVH
+clEXU3hhSV0VQHwfIYKeYms6h6zXBVPKW0dLC0zXeDztJgueasMZQ67XaPCrTpGO
+px/l2zJ6F1HM8/bqn4aDXDY9f/xRLYryQRMBgL8fHzgitNylHWaT4j2Vt7yg2SI9
+mxrMRNKqASJPVR+Nm3l6+n9gpjVb99wEucWplPPHI6KhXLYPZOqSwt+zaH5roz3k
+UQmMs0Bs4hF1SzVl0n+KNoXHOwswVrmBWXgWvm2OhnwY2e26jfejc8toJc/ShAJ7
+C9exnrdimcgEKbd22Sum4G00CDYhcrG5LHHqkgwifcAEVctrvBZBZHGgpxlO8a8U
+eF2Vr7kCgYEAykdrBlzp7Fn9xzUInBQ3NXTTYAq51lpuJdmHQmPuTSY0buoHkd9f
+xbUCZ2qR9QAesrx4hI0qGLetc8IOKDoWx2rPepCCvO3Kx61o1SB5fAvBue03qVoq
+HqACX3Uk24Em8zAz9xuP13ETH/wU7sUbUxRHMCre6ZDmlxn4g5l+Nl8CgYEAxLVl
+22yBx0dfRr3UsHY9rxll2gIlnfnYfiJzq8wetzt/TfztRV5ILz7FyWqL5d7IoqkA
+fT2V4HAasRJASnKohwJe7z5M/H2ExwkGNFvY+jefb2CoUl5WouK9AlhbqBk3zmHi
+sY5GqQkAp/kHMntEin+sErJw6mkgAGdser3a9p8CgYEAqi31w++tunRnxw4+RRnY
+7Pdx0k6T1NxV6TAe1ONAHNY0rM/mOHqml65W7GzDiU1lhlh8SIB/VzZJDqfHw15D
+xdh94A7uf0bMILwrA4wDyTIW9Xa3Kpq57vQNqwPiU25QN69pOM+Ob+IpBfLOJafc
++kOINOUMj5Kh/aQS6Zzci58CgYEAk24dlFKEBjbRCvU2FrfYTYcsljPru7ZJc2gg
+588J6m0WYf5CWy5pzbcviGFpzvSlzXv7GOLylQ+QgcxbETFUbDPzsT4xd0AgJwj1
+dIKuYgMUZOa94VZBer2TydEtiRS1heJJhKhM/1329u4nXceTvHYqIq1JAfeee48I
+eAoZtaMCgYBz1FjWFQnMTD5nmyPEEZneoBPAR5+9jwOps+IYOoHtazoMFszzd0qo
+JZW3Ihn9KRrVSxfFApKS/ZwjiZ+tJUk7DE/v/0l0sszefY7s8b0pL1lpeZSoL71e
+QoG1WLXUiDV3BRlmyOAF1h3p12KRTLgwubN51ajECwcs3QwE+ZT8Gg==
+-----END RSA PRIVATE KEY-----
diff --git a/trunk/test/rubygems/public_cert.pem b/trunk/test/rubygems/public_cert.pem
new file mode 100644
index 0000000000..9b7c3d8e98
--- /dev/null
+++ b/trunk/test/rubygems/public_cert.pem
@@ -0,0 +1,20 @@
+-----BEGIN CERTIFICATE-----
+MIIDNjCCAh6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBBMRAwDgYDVQQDDAdkcmJy
+YWluMRgwFgYKCZImiZPyLGQBGRYIc2VnbWVudDcxEzARBgoJkiaJk/IsZAEZFgNu
+ZXQwHhcNMDcxMjIxMDIwNDE0WhcNMDgxMjIwMDIwNDE0WjBBMRAwDgYDVQQDDAdk
+cmJyYWluMRgwFgYKCZImiZPyLGQBGRYIc2VnbWVudDcxEzARBgoJkiaJk/IsZAEZ
+FgNuZXQwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCbbgLrGLGIDE76
+LV/cvxdEzCuYuS3oG9PrSZnuDweySUfdp/so0cDq+j8bqy6OzZSw07gdjwFMSd6J
+U5ddZCVywn5nnAQ+Ui7jMW54CYt5/H6f2US6U0hQOjJR6cpfiymgxGdfyTiVcvTm
+Gj/okWrQl0NjYOYBpDi+9PPmaH2RmLJu0dB/NylsDnW5j6yN1BEI8MfJRR+HRKZY
+mUtgzBwF1V4KIZQ8EuL6I/nHVu07i6IkrpAgxpXUfdJQJi0oZAqXurAV3yTxkFwd
+g62YrrW26mDe+pZBzR6bpLE+PmXCzz7UxUq3AE0gPHbiMXie3EFE0oxnsU3lIduh
+sCANiQ8BAgMBAAGjOTA3MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQW
+BBS5k4Z75VSpdM0AclG2UvzFA/VW5DANBgkqhkiG9w0BAQUFAAOCAQEAHagT4lfX
+kP/hDaiwGct7XPuVGbrOsKRVD59FF5kETBxEc9UQ1clKWngf8JoVuEoKD774dW19
+bU0GOVWO+J6FMmT/Cp7nuFJ79egMf/gy4gfUfQMuvfcr6DvZUPIs9P/TlK59iMYF
+DIOQ3DxdF3rMzztNUCizN4taVscEsjCcgW6WkUJnGdqlu3OHWpQxZBJkBTjPCoc6
+UW6on70SFPmAy/5Cq0OJNGEWBfgD9q7rrs/X8GGwUWqXb85RXnUVi/P8Up75E0ag
+14jEc90kN+C7oI/AGCBN0j6JnEtYIEJZibjjDJTSMWlUKKkj30kq7hlUC2CepJ4v
+x52qPcexcYZR7w==
+-----END CERTIFICATE-----
diff --git a/trunk/test/rubygems/simple_gem.rb b/trunk/test/rubygems/simple_gem.rb
new file mode 100644
index 0000000000..a6f14bc3c7
--- /dev/null
+++ b/trunk/test/rubygems/simple_gem.rb
@@ -0,0 +1,72 @@
+#--
+# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
+# All rights reserved.
+# See LICENSE.txt for permissions.
+#++
+
+ SIMPLE_GEM = <<-GEMDATA
+ 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") {|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'
+ @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__
+--- !ruby/object:Gem::Specification
+rubygems_version: "1.0"
+name: testing
+version: !ruby/object:Gem::Version
+ version: 1.2.3
+date: 2004-03-18 22:01:52.859121 -05:00
+platform:
+summary: This exercise the gem testing stuff.
+require_paths:
+ - lib
+files:
+ - lib/foo.rb
+ - lib/test
+ - lib/test.rb
+ - lib/test/wow.rb
+autorequire: test
+test_suite_file: foo
+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
+---
+eJwVjDEKgDAUQ/eeIpsKguhY3ARPoHMp9quF0mL7e39/h5DwQpLpqz4TOqbC
+U42eO6WuYEvBntIhECuaaX1KqXXLmy2kAEc32szExK+PjyBAlpTZyK0N/Twu
+g1CKTjX9BGAj1w==
+---
+eJwDAAAAAAE=
+---
+eJwrKC0pVlAvzy9XyE3MU+cCACwiBP4=
+ GEMDATA
diff --git a/trunk/test/rubygems/test_config.rb b/trunk/test/rubygems/test_config.rb
new file mode 100644
index 0000000000..0568996c4a
--- /dev/null
+++ b/trunk/test/rubygems/test_config.rb
@@ -0,0 +1,21 @@
+#!/usr/bin/env ruby
+#--
+# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
+# All rights reserved.
+# See LICENSE.txt for permissions.
+#++
+
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rbconfig'
+require 'rubygems'
+
+class TestConfig < RubyGemTestCase
+
+ def test_datadir
+ datadir = Config::CONFIG['datadir']
+ assert_equal "#{datadir}/xyz", Config.datadir('xyz')
+ end
+
+end
+
diff --git a/trunk/test/rubygems/test_gem.rb b/trunk/test/rubygems/test_gem.rb
new file mode 100644
index 0000000000..c26eeb573d
--- /dev/null
+++ b/trunk/test/rubygems/test_gem.rb
@@ -0,0 +1,449 @@
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems'
+require 'rubygems/gem_openssl'
+require 'rubygems/installer'
+require 'pathname'
+require 'tmpdir'
+
+class TestGem < RubyGemTestCase
+
+ def setup
+ super
+
+ @additional = %w[a b].map { |d| File.join @tempdir, d }
+ @default_dir_re = %r|/[Rr]uby/[Gg]ems/[0-9.]+|
+ end
+
+ def test_self_all_load_paths
+ util_make_gems
+
+ expected = [
+ File.join(@gemhome, *%W[gems #{@a1.full_name} lib]),
+ File.join(@gemhome, *%W[gems #{@a2.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]),
+ File.join(@gemhome, *%W[gems #{@pl1.full_name} lib]),
+ ]
+
+ assert_equal expected, Gem.all_load_paths.sort
+ end
+
+ def test_self_available?
+ util_make_gems
+ assert(Gem.available?("a"))
+ assert(Gem.available?("a", "1"))
+ assert(Gem.available?("a", ">1"))
+ assert(!Gem.available?("monkeys"))
+ end
+
+ def test_self_bindir
+ assert_equal File.join(@gemhome, 'bin'), Gem.bindir
+ assert_equal File.join(@gemhome, 'bin'), Gem.bindir(Gem.dir)
+ assert_equal File.join(@gemhome, 'bin'), Gem.bindir(Pathname.new(Gem.dir))
+ end
+
+ def test_self_bindir_default_dir
+ default = Gem.default_dir
+ bindir = (defined? RUBY_FRAMEWORK_VERSION) ? '/usr/bin' : Config::CONFIG['bindir']
+ assert_equal bindir, Gem.bindir(default)
+ assert_equal bindir, Gem.bindir(Pathname.new(default))
+ end
+
+ def test_self_clear_paths
+ Gem.dir
+ Gem.path
+ searcher = Gem.searcher
+ source_index = Gem.source_index
+
+ Gem.clear_paths
+
+ assert_equal nil, Gem.instance_variable_get(:@gem_home)
+ assert_equal nil, Gem.instance_variable_get(:@gem_path)
+ assert_not_equal searcher, Gem.searcher
+ assert_not_equal source_index.object_id, Gem.source_index.object_id
+ end
+
+ def test_self_configuration
+ expected = Gem::ConfigFile.new []
+ Gem.configuration = nil
+
+ assert_equal expected, Gem.configuration
+ end
+
+ def test_self_datadir
+ foo = nil
+
+ Dir.chdir @tempdir do
+ FileUtils.mkdir_p 'data'
+ File.open File.join('data', 'foo.txt'), 'w' do |fp|
+ fp.puts 'blah'
+ end
+
+ foo = quick_gem 'foo' do |s| s.files = %w[data/foo.txt] end
+ install_gem foo
+ end
+
+ Gem.source_index = nil
+
+ gem 'foo'
+
+ expected = File.join @gemhome, 'gems', foo.full_name, 'data', 'foo'
+
+ assert_equal expected, Gem.datadir('foo')
+ end
+
+ def test_self_datadir_nonexistent_package
+ assert_nil Gem.datadir('xyzzy')
+ end
+
+ def test_self_default_dir
+ assert_match @default_dir_re, Gem.default_dir
+ end
+
+ def test_self_default_exec_format
+ orig_BASERUBY = Gem::ConfigMap[:BASERUBY]
+ orig_RUBY_INSTALL_NAME = Gem::ConfigMap[:RUBY_INSTALL_NAME]
+ Gem::ConfigMap[:BASERUBY] = 'ruby'
+ Gem::ConfigMap[:RUBY_INSTALL_NAME] = 'ruby'
+
+ assert_equal '%s', Gem.default_exec_format
+ ensure
+ Gem::ConfigMap[:BASERUBY] = orig_BASERUBY
+ Gem::ConfigMap[:RUBY_INSTALL_NAME] = orig_RUBY_INSTALL_NAME
+ end
+
+ def test_self_default_exec_format_18
+ orig_BASERUBY = Gem::ConfigMap[:BASERUBY]
+ orig_RUBY_INSTALL_NAME = Gem::ConfigMap[:RUBY_INSTALL_NAME]
+ Gem::ConfigMap[:BASERUBY] = 'ruby'
+ Gem::ConfigMap[:RUBY_INSTALL_NAME] = 'ruby18'
+
+ assert_equal '%s18', Gem.default_exec_format
+ ensure
+ Gem::ConfigMap[:BASERUBY] = orig_BASERUBY
+ Gem::ConfigMap[:RUBY_INSTALL_NAME] = orig_RUBY_INSTALL_NAME
+ end
+
+ def test_self_default_exec_format_jruby
+ orig_BASERUBY = Gem::ConfigMap[:BASERUBY]
+ orig_RUBY_INSTALL_NAME = Gem::ConfigMap[:RUBY_INSTALL_NAME]
+ Gem::ConfigMap[:BASERUBY] = 'ruby'
+ Gem::ConfigMap[:RUBY_INSTALL_NAME] = 'jruby'
+
+ assert_equal 'j%s', Gem.default_exec_format
+ ensure
+ Gem::ConfigMap[:BASERUBY] = orig_BASERUBY
+ Gem::ConfigMap[:RUBY_INSTALL_NAME] = orig_RUBY_INSTALL_NAME
+ end
+
+ def test_self_default_sources
+ assert_equal %w[http://gems.rubyforge.org/], Gem.default_sources
+ end
+
+ def test_self_dir
+ assert_equal @gemhome, Gem.dir
+
+ Gem::DIRECTORIES.each do |filename|
+ assert File.directory?(File.join(Gem.dir, filename)),
+ "expected #{filename} to exist"
+ end
+ end
+
+ def test_self_ensure_gem_directories
+ FileUtils.rm_r @gemhome
+ Gem.use_paths @gemhome
+
+ Gem.ensure_gem_subdirectories @gemhome
+
+ assert File.directory?(File.join(@gemhome, "cache"))
+ end
+
+ 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')),
+ "manually remove #{File.join @tempdir, 'a'}, tests are broken"
+ Gem.use_paths gemdir
+
+ Gem.ensure_gem_subdirectories gemdir
+
+ assert File.directory?("#{gemdir}/cache")
+ end
+
+ unless win_platform? then # only for FS that support write protection
+ 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"
+ FileUtils.mkdir_p gemdir
+ FileUtils.chmod 0400, gemdir
+ Gem.use_paths gemdir
+
+ Gem.ensure_gem_subdirectories gemdir
+
+ assert !File.exist?("#{gemdir}/cache")
+ ensure
+ FileUtils.chmod 0600, gemdir
+ end
+
+ def test_self_ensure_gem_directories_write_protected_parents
+ parent = File.join(@tempdir, "egd")
+ gemdir = "#{parent}/a/b/c"
+
+ FileUtils.rm_r parent rescue nil
+ assert !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")
+ ensure
+ FileUtils.chmod 0600, parent
+ end
+ end
+
+ def test_ensure_ssl_available
+ orig_Gem_ssl_available = Gem.ssl_available?
+
+ Gem.ssl_available = true
+ assert_nothing_raised do Gem.ensure_ssl_available end
+
+ Gem.ssl_available = false
+ e = assert_raise Gem::Exception do Gem.ensure_ssl_available end
+ assert_equal 'SSL is not installed on this system', e.message
+ ensure
+ Gem.ssl_available = orig_Gem_ssl_available
+ 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 #{@a_evil9.full_name} lib]),
+ File.join(@gemhome, *%W[gems #{@b2.full_name} lib]),
+ File.join(@gemhome, *%W[gems #{@c1_2.full_name} lib]),
+ File.join(@gemhome, *%W[gems #{@pl1.full_name} lib]),
+ ]
+
+ assert_equal expected, Gem.latest_load_paths.sort
+ end
+
+ def test_self_loaded_specs
+ foo = quick_gem 'foo'
+ install_gem foo
+ Gem.source_index = nil
+
+ Gem.activate 'foo'
+
+ assert_equal true, Gem.loaded_specs.keys.include?('foo')
+ end
+
+ def test_self_path
+ assert_equal [Gem.dir], Gem.path
+ end
+
+ def test_self_path_default
+ if defined? APPLE_GEM_HOME
+ orig_APPLE_GEM_HOME = APPLE_GEM_HOME
+ Object.send :remove_const, :APPLE_GEM_HOME
+ end
+ Gem.instance_variable_set :@gem_path, nil
+
+ assert_equal [Gem.default_path, Gem.dir].flatten, Gem.path
+ ensure
+ Object.const_set :APPLE_GEM_HOME, orig_APPLE_GEM_HOME
+ end
+
+ unless win_platform?
+ def test_self_path_APPLE_GEM_HOME
+ Gem.clear_paths
+ Dir.mktmpdir("apple_gem_home") {|d|
+ Gem.const_set :APPLE_GEM_HOME, d
+ assert Gem.path.include?(d)
+ }
+ ensure
+ Gem.send :remove_const, :APPLE_GEM_HOME
+ end
+
+ def test_self_path_APPLE_GEM_HOME_GEM_PATH
+ Gem.clear_paths
+ ENV['GEM_PATH'] = @gemhome
+ Gem.const_set :APPLE_GEM_HOME, '/tmp/apple_gem_home'
+
+ assert !Gem.path.include?('/tmp/apple_gem_home')
+ ensure
+ Gem.send :remove_const, :APPLE_GEM_HOME
+ end
+ end
+
+ def test_self_path_ENV_PATH
+ Gem.send :set_paths, nil
+ path_count = Gem.path.size
+ Gem.clear_paths
+
+ ENV['GEM_PATH'] = @additional.join(File::PATH_SEPARATOR)
+
+ assert_equal @additional, Gem.path[0,2]
+
+ assert_equal path_count + @additional.size, Gem.path.size,
+ "extra path components: #{Gem.path[2..-1].inspect}"
+ assert_match Gem.dir, Gem.path.last
+ end
+
+ def test_self_path_duplicate
+ Gem.clear_paths
+ util_ensure_gem_dirs
+ dirs = @additional + [@gemhome] + [File.join(@tempdir, 'a')]
+
+ ENV['GEM_HOME'] = @gemhome
+ ENV['GEM_PATH'] = dirs.join File::PATH_SEPARATOR
+
+ assert_equal @gemhome, Gem.dir
+
+ paths = [Gem.dir]
+ assert_equal @additional + paths, Gem.path
+ end
+
+ def test_self_path_overlap
+ Gem.clear_paths
+
+ util_ensure_gem_dirs
+ ENV['GEM_HOME'] = @gemhome
+ ENV['GEM_PATH'] = @additional.join(File::PATH_SEPARATOR)
+
+ assert_equal @gemhome, Gem.dir
+
+ paths = [Gem.dir]
+ assert_equal @additional + paths, Gem.path
+ end
+
+ def test_self_platforms
+ assert_equal [Gem::Platform::RUBY, Gem::Platform.local], Gem.platforms
+ end
+
+ def test_self_prefix
+ file_name = File.expand_path __FILE__
+
+ prefix = File.dirname File.dirname(file_name)
+ prefix = File.dirname prefix if File.basename(prefix) == 'test'
+
+ assert_equal prefix, Gem.prefix
+ end
+
+ def test_self_prefix_libdir
+ orig_libdir = Gem::ConfigMap[:libdir]
+
+ file_name = File.expand_path __FILE__
+ prefix = File.dirname File.dirname(file_name)
+ prefix = File.dirname prefix if File.basename(prefix) == 'test'
+
+ Gem::ConfigMap[:libdir] = prefix
+
+ assert_nil Gem.prefix
+ ensure
+ Gem::ConfigMap[:libdir] = orig_libdir
+ end
+
+ def test_self_prefix_sitelibdir
+ orig_sitelibdir = Gem::ConfigMap[:sitelibdir]
+
+ file_name = File.expand_path __FILE__
+ prefix = File.dirname File.dirname(file_name)
+ prefix = File.dirname prefix if File.basename(prefix) == 'test'
+
+ Gem::ConfigMap[:sitelibdir] = prefix
+
+ assert_nil Gem.prefix
+ ensure
+ Gem::ConfigMap[:sitelibdir] = orig_sitelibdir
+ end
+
+ def test_self_refresh
+ util_make_gems
+
+ a1_spec = File.join @gemhome, "specifications", "#{@a1.full_name}.gemspec"
+
+ FileUtils.mv a1_spec, @tempdir
+
+ assert !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_equal nil, Gem.instance_variable_get(:@searcher)
+ end
+
+ def test_self_required_location
+ util_make_gems
+
+ assert_equal File.join(@tempdir, *%w[gemhome gems c-1.2 lib code.rb]),
+ Gem.required_location("c", "code.rb")
+ assert_equal File.join(@tempdir, *%w[gemhome gems a-1 lib code.rb]),
+ Gem.required_location("a", "code.rb", "< 2")
+ assert_equal File.join(@tempdir, *%w[gemhome gems a-2 lib code.rb]),
+ Gem.required_location("a", "code.rb", "= 2")
+ end
+
+ def test_self_ruby_version
+ version = RUBY_VERSION.dup
+ version << ".#{RUBY_PATCHLEVEL}" if defined? RUBY_PATCHLEVEL
+
+ assert_equal Gem::Version.new(version), Gem.ruby_version
+ end
+
+ def test_self_searcher
+ assert_kind_of Gem::GemPathSearcher, Gem.searcher
+ end
+
+ def test_self_source_index
+ assert_kind_of Gem::SourceIndex, Gem.source_index
+ end
+
+ def test_self_sources
+ assert_equal %w[http://gems.example.com/], Gem.sources
+ end
+
+ def test_ssl_available_eh
+ orig_Gem_ssl_available = Gem.ssl_available?
+
+ Gem.ssl_available = true
+ assert_equal true, Gem.ssl_available?
+
+ Gem.ssl_available = false
+ assert_equal false, Gem.ssl_available?
+ ensure
+ Gem.ssl_available = orig_Gem_ssl_available
+ end
+
+ def test_self_use_paths
+ util_ensure_gem_dirs
+
+ Gem.use_paths @gemhome, @additional
+
+ assert_equal @gemhome, Gem.dir
+ assert_equal @additional + [Gem.dir], Gem.path
+ end
+
+ def test_self_user_home
+ if ENV['HOME'] then
+ assert_equal ENV['HOME'], Gem.user_home
+ else
+ assert true, 'count this test'
+ end
+ end
+
+ def util_ensure_gem_dirs
+ Gem.ensure_gem_subdirectories @gemhome
+ @additional.each do |dir|
+ Gem.ensure_gem_subdirectories @gemhome
+ end
+ end
+
+end
+
diff --git a/trunk/test/rubygems/test_gem_builder.rb b/trunk/test/rubygems/test_gem_builder.rb
new file mode 100644
index 0000000000..31a0d71880
--- /dev/null
+++ b/trunk/test/rubygems/test_gem_builder.rb
@@ -0,0 +1,34 @@
+#--
+# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
+# All rights reserved.
+# See LICENSE.txt for permissions.
+#++
+
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/builder'
+
+class TestGemBuilder < RubyGemTestCase
+
+ def test_build
+ builder = Gem::Builder.new quick_gem('a')
+
+ use_ui @ui do
+ Dir.chdir @tempdir do
+ builder.build
+ end
+ end
+
+ assert_match %r|Successfully built RubyGem\n Name: a|, @ui.output
+ end
+
+ def test_build_validates
+ builder = Gem::Builder.new Gem::Specification.new
+
+ assert_raises Gem::InvalidSpecificationException do
+ builder.build
+ end
+ end
+
+end
+
diff --git a/trunk/test/rubygems/test_gem_command.rb b/trunk/test/rubygems/test_gem_command.rb
new file mode 100644
index 0000000000..9ed57b3692
--- /dev/null
+++ b/trunk/test/rubygems/test_gem_command.rb
@@ -0,0 +1,196 @@
+#!/usr/bin/env ruby
+#--
+# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
+# All rights reserved.
+# See LICENSE.txt for permissions.
+#++
+
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/command'
+
+class Gem::Command
+ public :parser
+end
+
+class TestGemCommand < RubyGemTestCase
+
+ def setup
+ super
+
+ @xopt = nil
+
+ Gem::Command.common_options.clear
+ Gem::Command.common_options << [
+ ['-x', '--exe', 'Execute'], lambda do |*a|
+ @xopt = true
+ end
+ ]
+
+ @cmd_name = 'doit'
+ @cmd = Gem::Command.new @cmd_name, 'summary'
+ end
+
+ def test_self_add_specific_extra_args
+ added_args = %w[--all]
+ @cmd.add_option '--all' do |v,o| end
+
+ Gem::Command.add_specific_extra_args @cmd_name, added_args
+
+ assert_equal added_args, Gem::Command.specific_extra_args(@cmd_name)
+
+ h = @cmd.add_extra_args []
+
+ assert_equal added_args, h
+ end
+
+ def test_self_add_specific_extra_args_unknown
+ added_args = %w[--definitely_not_there]
+
+ Gem::Command.add_specific_extra_args @cmd_name, added_args
+
+ assert_equal added_args, Gem::Command.specific_extra_args(@cmd_name)
+
+ h = @cmd.add_extra_args []
+
+ 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, --zip|, @cmd.parser.to_s
+ assert_match %r|-z, --exe|, @cmd.parser.to_s
+ assert_no_match %r|-x, --exe|, @cmd.parser.to_s
+ end
+
+ def test_basic_accessors
+ assert_equal "doit", @cmd.command
+ assert_equal "gem doit", @cmd.program_name
+ assert_equal "summary", @cmd.summary
+ end
+
+ def test_common_option_in_class
+ assert Array === Gem::Command.common_options
+ end
+
+ def test_defaults
+ @cmd.add_option('-h', '--help [COMMAND]', 'Get help on COMMAND') do |value, options|
+ options[:help] = value
+ end
+
+ @cmd.defaults = { :help => true }
+
+ @cmd.when_invoked do |options|
+ assert options[:help], "Help options should default true"
+ end
+
+ use_ui @ui do
+ @cmd.invoke
+ end
+
+ assert_match %r|Usage: gem doit|, @ui.output
+ end
+
+ def test_invoke
+ done = false
+ @cmd.when_invoked { done = true }
+
+ use_ui @ui do
+ @cmd.invoke
+ end
+
+ assert done
+ end
+
+ def test_invode_with_bad_options
+ use_ui @ui do
+ @cmd.when_invoked do true end
+
+ ex = assert_raise(OptionParser::InvalidOption) do
+ @cmd.invoke('-zzz')
+ end
+
+ assert_match(/invalid option:/, ex.message)
+ end
+ end
+
+ def test_invoke_with_common_options
+ @cmd.when_invoked do true end
+
+ use_ui @ui do
+ @cmd.invoke "-x"
+ end
+
+ assert @xopt, "Should have done xopt"
+ end
+
+ # Returning false from the command handler invokes the usage output.
+ def test_invoke_with_help
+ done = false
+
+ use_ui @ui do
+ @cmd.add_option('-h', '--help [COMMAND]', 'Get help on COMMAND') do |value, options|
+ options[:help] = true
+ done = true
+ end
+
+ @cmd.invoke('--help')
+
+ assert done
+ end
+
+ assert_match(/Usage/, @ui.output)
+ assert_match(/gem doit/, @ui.output)
+ assert_match(/\[options\]/, @ui.output)
+ assert_match(/-h/, @ui.output)
+ assert_match(/--help \[COMMAND\]/, @ui.output)
+ assert_match(/Get help on COMMAND/, @ui.output)
+ assert_match(/-x/, @ui.output)
+ assert_match(/--exe/, @ui.output)
+ assert_match(/Execute/, @ui.output)
+ assert_match(/Common Options:/, @ui.output)
+ end
+
+ def test_invoke_with_options
+ @cmd.add_option('-h', '--help [COMMAND]', 'Get help on COMMAND') do |value, options|
+ options[:help] = true
+ end
+
+ @cmd.when_invoked do |opts|
+ assert opts[:help]
+ end
+
+ use_ui @ui do
+ @cmd.invoke '-h'
+ end
+
+ assert_match %r|Usage: gem doit|, @ui.output
+ end
+
+ def test_option_recognition
+ @cmd.add_option('-h', '--help [COMMAND]', 'Get help on COMMAND') do |value, options|
+ options[:help] = true
+ end
+ @cmd.add_option('-f', '--file FILE', 'File option') do |value, options|
+ options[:help] = true
+ end
+ assert @cmd.handles?(['-x'])
+ assert @cmd.handles?(['-h'])
+ assert @cmd.handles?(['-h', 'command'])
+ 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'])
+
+ args = ['-h', 'command']
+ @cmd.handles?(args)
+ assert_equal ['-h', 'command'], args
+ end
+
+end
+
diff --git a/trunk/test/rubygems/test_gem_command_manager.rb b/trunk/test/rubygems/test_gem_command_manager.rb
new file mode 100644
index 0000000000..ee58e89844
--- /dev/null
+++ b/trunk/test/rubygems/test_gem_command_manager.rb
@@ -0,0 +1,213 @@
+#--
+# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
+# All rights reserved.
+# See LICENSE.txt for permissions.
+#++
+
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/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
+ end
+
+ def test_run_interrupt
+ use_ui @ui do
+ @command_manager.register_command :interrupt
+ assert_raises MockGemUi::TermError do
+ @command_manager.run 'interrupt'
+ end
+ assert_equal '', ui.output
+ assert_equal "ERROR: Interrupted\n", ui.error
+ end
+ end
+
+ def test_process_args_bad_arg
+ use_ui @ui do
+ assert_raises(MockGemUi::TermError) {
+ @command_manager.process_args("--bad-arg")
+ }
+ end
+
+ assert_match(/invalid option: --bad-arg/i, @ui.error)
+ end
+
+ def test_process_args_install
+ #capture all install options
+ use_ui @ui do
+ check_options = nil
+ @command_manager['install'].when_invoked do |options|
+ check_options = options
+ true
+ end
+
+ #check defaults
+ @command_manager.process_args("install")
+ assert_equal false, check_options[:test]
+ assert_equal true, check_options[:generate_rdoc]
+ assert_equal false, check_options[:force]
+ assert_equal :both, check_options[:domain]
+ assert_equal true, check_options[:wrappers]
+ assert_equal Gem::Requirement.default, check_options[:version]
+ assert_equal nil, check_options[:install_dir]
+ assert_equal nil, check_options[:bin_dir]
+
+ #check settings
+ check_options = nil
+ @command_manager.process_args(
+ "install --force --test --local --rdoc --install-dir . --version 3.0 --no-wrapper --bindir . ")
+ assert_equal true, check_options[:test]
+ assert_equal true, check_options[:generate_rdoc]
+ assert_equal true, check_options[:force]
+ assert_equal :local, check_options[:domain]
+ assert_equal false, check_options[:wrappers]
+ assert_equal Gem::Requirement.new('3.0'), check_options[:version]
+ assert_equal Dir.pwd, check_options[:install_dir]
+ assert_equal Dir.pwd, check_options[:bin_dir]
+
+ #check remote domain
+ check_options = nil
+ @command_manager.process_args("install --remote")
+ assert_equal :remote, check_options[:domain]
+
+ #check both domain
+ check_options = nil
+ @command_manager.process_args("install --both")
+ assert_equal :both, check_options[:domain]
+
+ #check both domain
+ check_options = nil
+ @command_manager.process_args("install --both")
+ assert_equal :both, check_options[:domain]
+ end
+ end
+
+ def test_process_args_uninstall
+ #capture all uninstall options
+ check_options = nil
+ @command_manager['uninstall'].when_invoked do |options|
+ check_options = options
+ true
+ end
+
+ #check defaults
+ @command_manager.process_args("uninstall")
+ assert_equal Gem::Requirement.default, check_options[:version]
+
+ #check settings
+ check_options = nil
+ @command_manager.process_args("uninstall foobar --version 3.0")
+ assert_equal "foobar", check_options[:args].first
+ assert_equal Gem::Requirement.new('3.0'), check_options[:version]
+ end
+
+ def test_process_args_check
+ #capture all check options
+ check_options = nil
+ @command_manager['check'].when_invoked do |options|
+ check_options = options
+ true
+ end
+
+ #check defaults
+ @command_manager.process_args("check")
+ assert_equal false, check_options[:verify]
+ assert_equal false, check_options[:alien]
+
+ #check settings
+ check_options = nil
+ @command_manager.process_args("check --verify foobar --alien")
+ assert_equal "foobar", check_options[:verify]
+ assert_equal true, check_options[:alien]
+ end
+
+ def test_process_args_build
+ #capture all build options
+ check_options = nil
+ @command_manager['build'].when_invoked do |options|
+ check_options = options
+ true
+ end
+
+ #check defaults
+ @command_manager.process_args("build")
+ #NOTE: Currently no defaults
+
+ #check settings
+ check_options = nil
+ @command_manager.process_args("build foobar.rb")
+ assert_equal 'foobar.rb', check_options[:args].first
+ end
+
+ def test_process_args_query
+ #capture all query options
+ check_options = nil
+ @command_manager['query'].when_invoked do |options|
+ check_options = options
+ true
+ end
+
+ #check defaults
+ @command_manager.process_args("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")
+ 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")
+ assert_equal :remote, check_options[:domain]
+
+ #both (local/remote) domains
+ check_options = nil
+ @command_manager.process_args("query --both")
+ assert_equal :both, check_options[:domain]
+ end
+
+ def test_process_args_update
+ #capture all update options
+ check_options = nil
+ @command_manager['update'].when_invoked do |options|
+ check_options = options
+ true
+ end
+
+ #check defaults
+ @command_manager.process_args("update")
+ assert_equal true, check_options[:generate_rdoc]
+
+ #check settings
+ check_options = nil
+ @command_manager.process_args("update --force --test --rdoc --install-dir .")
+ assert_equal true, check_options[:test]
+ assert_equal true, check_options[:generate_rdoc]
+ assert_equal true, check_options[:force]
+ assert_equal Dir.pwd, check_options[:install_dir]
+ end
+
+end
+
diff --git a/trunk/test/rubygems/test_gem_commands_build_command.rb b/trunk/test/rubygems/test_gem_commands_build_command.rb
new file mode 100644
index 0000000000..a49b6777bd
--- /dev/null
+++ b/trunk/test/rubygems/test_gem_commands_build_command.rb
@@ -0,0 +1,75 @@
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/commands/build_command'
+require 'rubygems/format'
+
+class TestGemCommandsBuildCommand < RubyGemTestCase
+
+ def setup
+ super
+
+ @gem = quick_gem 'some_gem' do |s|
+ s.rubyforge_project = 'example'
+ end
+
+ @cmd = Gem::Commands::BuildCommand.new
+ end
+
+ def test_execute
+ gemspec_file = File.join(@tempdir, "#{@gem.full_name}.gemspec")
+
+ File.open gemspec_file, 'w' do |gs|
+ gs.write @gem.to_ruby
+ end
+
+ util_test_build_gem @gem, gemspec_file
+ end
+
+ def test_execute_yaml
+ gemspec_file = File.join(@tempdir, "#{@gem.full_name}.gemspec")
+
+ File.open gemspec_file, 'w' do |gs|
+ gs.write @gem.to_yaml
+ end
+
+ util_test_build_gem @gem, gemspec_file
+ end
+
+ def test_execute_bad_gem
+ @cmd.options[:args] = %w[some_gem]
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_equal '', @ui.output
+ assert_equal "ERROR: Gemspec file not found: some_gem\n", @ui.error
+ end
+
+ def util_test_build_gem(gem, gemspec_file)
+ @cmd.options[:args] = [gemspec_file]
+
+ use_ui @ui do
+ Dir.chdir @tempdir do
+ @cmd.execute
+ end
+ end
+
+ output = @ui.output.split "\n"
+ assert_equal " Successfully built RubyGem", output.shift
+ assert_equal " Name: some_gem", output.shift
+ assert_equal " Version: 2", output.shift
+ assert_equal " File: some_gem-2.gem", output.shift
+ assert_equal [], output
+ assert_equal '', @ui.error
+
+ gem_file = File.join @tempdir, "#{gem.full_name}.gem"
+ assert File.exist?(gem_file)
+
+ spec = Gem::Format.from_file_by_path(gem_file).spec
+
+ assert_equal "some_gem", spec.name
+ assert_equal "this is a summary", spec.summary
+ end
+
+end
+
diff --git a/trunk/test/rubygems/test_gem_commands_cert_command.rb b/trunk/test/rubygems/test_gem_commands_cert_command.rb
new file mode 100644
index 0000000000..79e3e72158
--- /dev/null
+++ b/trunk/test/rubygems/test_gem_commands_cert_command.rb
@@ -0,0 +1,126 @@
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+
+require 'rubygems/commands/cert_command'
+
+unless defined? OpenSSL then
+ warn "`gem cert` tests are being skipped, module OpenSSL not found"
+end
+
+class TestGemCommandsCertCommand < RubyGemTestCase
+
+ def setup
+ super
+
+ @orig_security_trust_dir = Gem::Security::OPT[:trust_dir]
+ Gem::Security::OPT[:trust_dir] = @tempdir
+
+ @cmd = Gem::Commands::CertCommand.new
+
+ root = File.expand_path(File.dirname(__FILE__))
+
+ FileUtils.cp File.join(root, 'data', 'gem-private_key.pem'), @tempdir
+ FileUtils.cp File.join(root, 'data', 'gem-public_cert.pem'), @tempdir
+
+ @cert_file_name = File.join @tempdir, 'gem-public_cert.pem'
+ @pkey_file_name = File.join @tempdir, 'gem-private_key.pem'
+ end
+
+ def teardown
+ Gem::Security::OPT[:trust_dir] = @orig_security_trust_dir
+
+ super
+ end
+
+ def test_execute_add
+ use_ui @ui do
+ @cmd.send :handle_options, %W[--add #{@cert_file_name}]
+ end
+
+ assert_equal "Added '/CN=rubygems/DC=example/DC=com'\n", @ui.output
+ assert_equal '', @ui.error
+ end
+
+ def test_execute_build
+ FileUtils.rm @cert_file_name
+ FileUtils.rm @pkey_file_name
+
+ use_ui @ui do
+ Dir.chdir @tempdir do
+ @cmd.send :handle_options, %W[--build nobody@example.com]
+ end
+ end
+
+ output = @ui.output.split "\n"
+
+ assert_equal 'Public Cert: gem-public_cert.pem', output.shift
+ assert_equal 'Private Key: gem-private_key.pem', output.shift
+ assert_equal 'Don\'t forget to move the key file to somewhere private...',
+ output.shift
+ assert_equal [], output
+
+ assert_equal '', @ui.error
+
+ assert File.exist?(File.join(@tempdir, 'gem-private_key.pem'))
+ assert File.exist?(File.join(@tempdir, 'gem-public_cert.pem'))
+ end
+
+ def test_execute_certificate
+ use_ui @ui do
+ @cmd.send :handle_options, %W[--certificate #{@cert_file_name}]
+ end
+
+ assert_equal '', @ui.output
+ assert_equal '', @ui.error
+
+ assert_equal File.read(@cert_file_name),
+ Gem::Security::OPT[:issuer_cert].to_s
+ end
+
+ def test_execute_list
+ use_ui @ui do
+ @cmd.send :handle_options, %W[--list]
+ end
+
+ assert_equal "/CN=rubygems/DC=example/DC=com\n", @ui.output
+ assert_equal '', @ui.error
+ end
+
+ def test_execute_private_key
+ use_ui @ui do
+ @cmd.send :handle_options, %W[--private-key #{@pkey_file_name}]
+ end
+
+ assert_equal '', @ui.output
+ assert_equal '', @ui.error
+
+ assert_equal File.read(@pkey_file_name),
+ Gem::Security::OPT[:issuer_key].to_s
+ end
+
+ def test_execute_remove
+ use_ui @ui do
+ @cmd.send :handle_options, %W[--remove rubygems]
+ end
+
+ assert_equal "Removed '/CN=rubygems/DC=example/DC=com'\n", @ui.output
+ assert_equal '', @ui.error
+
+ assert !File.exist?(@cert_file_name)
+ end
+
+ def test_execute_sign
+ use_ui @ui do
+ @cmd.send :handle_options, %W[
+ -K #{@pkey_file_name} -C #{@cert_file_name} --sign #{@cert_file_name}
+ ]
+ end
+
+ assert_equal '', @ui.output
+ assert_equal '', @ui.error
+
+ # HACK this test sucks
+ end
+
+end if defined? OpenSSL
+
diff --git a/trunk/test/rubygems/test_gem_commands_check_command.rb b/trunk/test/rubygems/test_gem_commands_check_command.rb
new file mode 100644
index 0000000000..eea7cc5cfa
--- /dev/null
+++ b/trunk/test/rubygems/test_gem_commands_check_command.rb
@@ -0,0 +1,25 @@
+#--
+# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
+# All rights reserved.
+# See LICENSE.txt for permissions.
+#++
+
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/commands/check_command'
+
+class TestGemCommandsCheckCommand < RubyGemTestCase
+
+ def setup
+ super
+
+ @cmd = Gem::Commands::CheckCommand.new
+ end
+
+ def test_initialize
+ assert_equal "check", @cmd.command
+ assert_equal "gem check", @cmd.program_name
+ assert_match(/Check/, @cmd.summary)
+ end
+
+end
diff --git a/trunk/test/rubygems/test_gem_commands_contents_command.rb b/trunk/test/rubygems/test_gem_commands_contents_command.rb
new file mode 100644
index 0000000000..cdb89673da
--- /dev/null
+++ b/trunk/test/rubygems/test_gem_commands_contents_command.rb
@@ -0,0 +1,92 @@
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/commands/contents_command'
+
+class TestGemCommandsContentsCommand < RubyGemTestCase
+
+ def setup
+ super
+
+ @cmd = Gem::Commands::ContentsCommand.new
+ end
+
+ def test_execute
+ @cmd.options[:args] = %w[foo]
+ quick_gem 'foo' do |gem|
+ gem.files = %w[lib/foo.rb Rakefile]
+ end
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_match %r|lib/foo\.rb|, @ui.output
+ assert_match %r|Rakefile|, @ui.output
+ assert_equal "", @ui.error
+ end
+
+ def test_execute_bad_gem
+ @cmd.options[:args] = %w[foo]
+
+ assert_raise MockGemUi::TermError do
+ use_ui @ui do
+ @cmd.execute
+ end
+ end
+
+ assert_match %r|Unable to find gem 'foo' in default gem paths|, @ui.output
+ assert_match %r|Directories searched:|, @ui.output
+ assert_equal "", @ui.error
+ end
+
+ def test_execute_exact_match
+ @cmd.options[:args] = %w[foo]
+ quick_gem 'foo' do |gem|
+ gem.files = %w[lib/foo.rb Rakefile]
+ end
+
+ quick_gem 'foo_bar' do |gem|
+ gem.files = %w[lib/foo_bar.rb Rakefile]
+ end
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_match %r|lib/foo\.rb|, @ui.output
+ assert_match %r|Rakefile|, @ui.output
+ assert_equal "", @ui.error
+ end
+
+ def test_execute_lib_only
+ @cmd.options[:args] = %w[foo]
+ @cmd.options[:lib_only] = true
+
+ quick_gem 'foo' do |gem|
+ gem.files = %w[lib/foo.rb Rakefile]
+ end
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_match %r|lib/foo\.rb|, @ui.output
+ assert_no_match %r|Rakefile|, @ui.output
+
+ assert_equal "", @ui.error
+ end
+
+ def test_handle_options
+ assert_equal false, @cmd.options[:lib_only]
+ assert_equal [], @cmd.options[:specdirs]
+ assert_equal nil, @cmd.options[:version]
+
+ @cmd.send :handle_options, %w[-l -s foo --version 0.0.2]
+
+ assert_equal true, @cmd.options[:lib_only]
+ assert_equal %w[foo], @cmd.options[:specdirs]
+ assert_equal Gem::Requirement.new('0.0.2'), @cmd.options[:version]
+ end
+
+end
+
diff --git a/trunk/test/rubygems/test_gem_commands_dependency_command.rb b/trunk/test/rubygems/test_gem_commands_dependency_command.rb
new file mode 100644
index 0000000000..e143110a71
--- /dev/null
+++ b/trunk/test/rubygems/test_gem_commands_dependency_command.rb
@@ -0,0 +1,227 @@
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/commands/dependency_command'
+
+class TestGemCommandsDependencyCommand < RubyGemTestCase
+
+ def setup
+ super
+
+ @cmd = Gem::Commands::DependencyCommand.new
+ @cmd.options[:domain] = :local
+
+ util_setup_fake_fetcher
+ end
+
+ def test_execute
+ quick_gem 'foo' do |gem|
+ gem.add_dependency 'bar', '> 1'
+ end
+
+ Gem.source_index = nil
+
+ @cmd.options[:args] = %w[foo]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_equal "Gem foo-2\n bar (> 1, runtime)\n\n", @ui.output
+ assert_equal '', @ui.error
+ end
+
+ def test_execute_no_args
+ Gem.source_index = nil
+
+ @cmd.options[:args] = []
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ expected = <<-EOF
+Gem a-1
+
+Gem a-2
+
+Gem a_evil-9
+
+Gem b-2
+
+Gem c-1.2
+
+Gem pl-1-x86-linux
+
+ EOF
+
+ assert_equal expected, @ui.output
+ assert_equal '', @ui.error
+ end
+
+ def test_execute_no_match
+ @cmd.options[:args] = %w[foo]
+
+ assert_raise MockGemUi::TermError do
+ use_ui @ui do
+ @cmd.execute
+ end
+ end
+
+ assert_equal "No gems found matching foo (>= 0)\n", @ui.output
+ assert_equal '', @ui.error
+ end
+
+ def test_execute_pipe_format
+ quick_gem 'foo' do |gem|
+ gem.add_dependency 'bar', '> 1'
+ end
+
+ @cmd.options[:args] = %w[foo]
+ @cmd.options[:pipe_format] = true
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_equal "bar --version '> 1'\n", @ui.output
+ assert_equal '', @ui.error
+ end
+
+ def test_execute_regexp
+ Gem.source_index = nil
+
+ @cmd.options[:args] = %w[/[ab]/]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ expected = <<-EOF
+Gem a-1
+
+Gem a-2
+
+Gem a_evil-9
+
+Gem b-2
+
+ EOF
+
+ assert_equal expected, @ui.output
+ assert_equal '', @ui.error
+ end
+
+ def test_execute_reverse
+ quick_gem 'foo' do |gem|
+ gem.add_dependency 'bar', '> 1'
+ end
+
+ quick_gem 'baz' do |gem|
+ gem.add_dependency 'foo'
+ end
+
+ Gem.source_index = nil
+
+ @cmd.options[:args] = %w[foo]
+ @cmd.options[:reverse_dependencies] = true
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ expected = <<-EOF
+Gem foo-2
+ bar (> 1, runtime)
+ Used by
+ baz-2 (foo (>= 0, runtime))
+
+ EOF
+
+ assert_equal expected, @ui.output
+ assert_equal '', @ui.error
+ end
+
+ def test_execute_reverse_remote
+ @cmd.options[:args] = %w[foo]
+ @cmd.options[:reverse_dependencies] = true
+ @cmd.options[:domain] = :remote
+
+ assert_raise MockGemUi::TermError do
+ use_ui @ui do
+ @cmd.execute
+ end
+ end
+
+ expected = <<-EOF
+ERROR: Only reverse dependencies for local gems are supported.
+ EOF
+
+ assert_equal '', @ui.output
+ assert_equal expected, @ui.error
+ end
+
+ def test_execute_remote
+ foo = quick_gem 'foo' do |gem|
+ gem.add_dependency 'bar', '> 1'
+ end
+
+ @fetcher = Gem::FakeFetcher.new
+ Gem::RemoteFetcher.fetcher = @fetcher
+
+ util_setup_spec_fetcher foo
+
+ FileUtils.rm File.join(@gemhome, 'specifications',
+ "#{foo.full_name}.gemspec")
+
+ @cmd.options[:args] = %w[foo]
+ @cmd.options[:domain] = :remote
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_equal "Gem foo-2\n bar (> 1, runtime)\n\n", @ui.output
+ assert_equal '', @ui.error
+ end
+
+ def test_execute_remote_legacy
+ foo = quick_gem 'foo' do |gem|
+ gem.add_dependency 'bar', '> 1'
+ end
+
+ @fetcher = Gem::FakeFetcher.new
+ Gem::RemoteFetcher.fetcher = @fetcher
+
+ Gem::SpecFetcher.fetcher = nil
+ si = util_setup_source_info_cache foo
+
+ @fetcher.data["#{@gem_repo}yaml"] = YAML.dump si
+ @fetcher.data["#{@gem_repo}Marshal.#{Gem.marshal_version}"] =
+ si.dump
+
+ @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] = nil
+
+ FileUtils.rm File.join(@gemhome, 'specifications',
+ "#{foo.full_name}.gemspec")
+
+ @cmd.options[:args] = %w[foo]
+ @cmd.options[:domain] = :remote
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_equal "Gem foo-2\n bar (> 1, runtime)\n\n", @ui.output
+
+ expected = <<-EOF
+WARNING: RubyGems 1.2+ index not found for:
+\t#{@gem_repo}
+
+RubyGems will revert to legacy indexes degrading performance.
+ EOF
+
+ assert_equal expected, @ui.error
+ end
+
+end
+
diff --git a/trunk/test/rubygems/test_gem_commands_environment_command.rb b/trunk/test/rubygems/test_gem_commands_environment_command.rb
new file mode 100644
index 0000000000..78246b0301
--- /dev/null
+++ b/trunk/test/rubygems/test_gem_commands_environment_command.rb
@@ -0,0 +1,134 @@
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/commands/environment_command'
+
+class TestGemCommandsEnvironmentCommand < RubyGemTestCase
+
+ def setup
+ super
+
+ @cmd = Gem::Commands::EnvironmentCommand.new
+ end
+
+ def test_execute
+ orig_sources = Gem.sources.dup
+ Gem.sources.replace %w[http://gems.example.com]
+
+ @cmd.send :handle_options, %w[]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_match %r|RUBYGEMS VERSION: (\d\.)+\d|, @ui.output
+ assert_match %r|RUBY VERSION: \d\.\d\.\d \(.*\) \[.*\]|, @ui.output
+ 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]}|,
+ @ui.output
+ assert_match %r|EXECUTABLE DIRECTORY:|, @ui.output
+ assert_match %r|RUBYGEMS PLATFORMS:|, @ui.output
+ assert_match %r|- #{Gem::Platform.local}|, @ui.output
+ assert_match %r|GEM PATHS:|, @ui.output
+ assert_match %r|- #{Regexp.escape @gemhome}|, @ui.output
+ assert_match %r|GEM CONFIGURATION:|, @ui.output
+ assert_match %r|:verbose => |, @ui.output
+ assert_match %r|REMOTE SOURCES:|, @ui.output
+ assert_equal '', @ui.error
+
+ ensure
+ Gem.sources.replace orig_sources
+ end
+
+ def test_execute_gemdir
+ @cmd.send :handle_options, %w[gemdir]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_equal "#{@gemhome}\n", @ui.output
+ assert_equal '', @ui.error
+ end
+
+ def test_execute_gempath
+ @cmd.send :handle_options, %w[gempath]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_equal "#{@gemhome}\n", @ui.output
+ assert_equal '', @ui.error
+ end
+
+ def test_execute_gempath_multiple
+ Gem.clear_paths
+ path = [@gemhome, "#{@gemhome}2"].join File::PATH_SEPARATOR
+ ENV['GEM_PATH'] = path
+
+ @cmd.send :handle_options, %w[gempath]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_equal "#{Gem.path.join File::PATH_SEPARATOR}\n", @ui.output
+ assert_equal '', @ui.error
+ end
+
+ def test_execute_packageversion
+ @cmd.send :handle_options, %w[packageversion]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_equal "#{Gem::RubyGemsPackageVersion}\n", @ui.output
+ assert_equal '', @ui.error
+ end
+
+ def test_execute_remotesources
+ orig_sources = Gem.sources.dup
+ Gem.sources.replace %w[http://gems.example.com]
+
+ @cmd.send :handle_options, %w[remotesources]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_equal "http://gems.example.com\n", @ui.output
+ assert_equal '', @ui.error
+
+ ensure
+ Gem.sources.replace orig_sources
+ end
+
+ def test_execute_unknown
+ @cmd.send :handle_options, %w[unknown]
+
+ assert_raise Gem::CommandLineError do
+ use_ui @ui do
+ @cmd.execute
+ end
+ end
+
+ assert_equal '', @ui.output
+ assert_equal '', @ui.error
+ end
+
+ def test_execute_version
+ @cmd.send :handle_options, %w[version]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_equal "#{Gem::RubyGemsVersion}\n", @ui.output
+ assert_equal '', @ui.error
+ end
+
+end
+
diff --git a/trunk/test/rubygems/test_gem_commands_fetch_command.rb b/trunk/test/rubygems/test_gem_commands_fetch_command.rb
new file mode 100644
index 0000000000..eaa13595b7
--- /dev/null
+++ b/trunk/test/rubygems/test_gem_commands_fetch_command.rb
@@ -0,0 +1,55 @@
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/package'
+require 'rubygems/security'
+require 'rubygems/commands/fetch_command'
+
+class TestGemCommandsFetchCommand < RubyGemTestCase
+
+ def setup
+ super
+
+ @cmd = Gem::Commands::FetchCommand.new
+ end
+
+ def test_execute
+ util_setup_fake_fetcher
+ util_setup_spec_fetcher @a2
+
+ @fetcher.data["#{@gem_repo}gems/#{@a2.full_name}.gem"] =
+ File.read(File.join(@gemhome, 'cache', "#{@a2.full_name}.gem"))
+
+ @cmd.options[:args] = [@a2.name]
+
+ use_ui @ui do
+ Dir.chdir @tempdir do
+ @cmd.execute
+ end
+ end
+
+ assert File.exist?(File.join(@tempdir, "#{@a2.full_name}.gem")),
+ "#{@a2.full_name} fetched"
+ end
+
+ def test_execute_legacy
+ util_setup_fake_fetcher
+ util_setup_source_info_cache @a2
+
+ @fetcher.data["#{@gem_repo}yaml"] = ''
+ @fetcher.data["#{@gem_repo}gems/#{@a2.full_name}.gem"] =
+ File.read(File.join(@gemhome, 'cache', "#{@a2.full_name}.gem"))
+
+ @cmd.options[:args] = [@a2.name]
+
+ use_ui @ui do
+ Dir.chdir @tempdir do
+ @cmd.execute
+ end
+ end
+
+ assert File.exist?(File.join(@tempdir, "#{@a2.full_name}.gem")),
+ "#{@a2.full_name} fetched"
+ end
+
+end
+
diff --git a/trunk/test/rubygems/test_gem_commands_generate_index_command.rb b/trunk/test/rubygems/test_gem_commands_generate_index_command.rb
new file mode 100644
index 0000000000..548197841b
--- /dev/null
+++ b/trunk/test/rubygems/test_gem_commands_generate_index_command.rb
@@ -0,0 +1,32 @@
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/indexer'
+require 'rubygems/commands/generate_index_command'
+
+class TestGemCommandsGenerateIndexCommand < RubyGemTestCase
+
+ def setup
+ super
+
+ @cmd = Gem::Commands::GenerateIndexCommand.new
+ @cmd.options[:directory] = @gemhome
+ end
+
+ def test_execute
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ yaml = File.join @gemhome, 'yaml'
+ yaml_z = File.join @gemhome, 'yaml.Z'
+ quick_index = File.join @gemhome, 'quick', 'index'
+ quick_index_rz = File.join @gemhome, 'quick', 'index.rz'
+
+ assert File.exist?(yaml), yaml
+ assert File.exist?(yaml_z), yaml_z
+ assert File.exist?(quick_index), quick_index
+ assert File.exist?(quick_index_rz), quick_index_rz
+ end
+
+end if ''.respond_to? :to_xs
+
diff --git a/trunk/test/rubygems/test_gem_commands_install_command.rb b/trunk/test/rubygems/test_gem_commands_install_command.rb
new file mode 100644
index 0000000000..ef04072b93
--- /dev/null
+++ b/trunk/test/rubygems/test_gem_commands_install_command.rb
@@ -0,0 +1,166 @@
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/commands/install_command'
+
+class TestGemCommandsInstallCommand < RubyGemTestCase
+
+ def setup
+ super
+
+ @cmd = Gem::Commands::InstallCommand.new
+ @cmd.options[:generate_rdoc] = false
+ @cmd.options[:generate_ri] = false
+ end
+
+ def test_execute_include_dependencies
+ @cmd.options[:include_dependencies] = true
+ @cmd.options[:args] = []
+
+ assert_raise Gem::CommandLineError do
+ use_ui @ui do
+ @cmd.execute
+ end
+ end
+
+ output = @ui.output.split "\n"
+ assert_equal "INFO: `gem install -y` is now default and will be removed",
+ output.shift
+ assert_equal "INFO: use --ignore-dependencies to install only the gems you list",
+ output.shift
+ assert output.empty?, output.inspect
+ end
+
+ def test_execute_local
+ util_setup_fake_fetcher
+ @cmd.options[:domain] = :local
+
+ 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
+ Dir.chdir @tempdir
+ e = assert_raises Gem::SystemExitException do
+ @cmd.execute
+ end
+ assert_equal 0, e.exit_code
+ ensure
+ Dir.chdir orig_dir
+ end
+ end
+
+ out = @ui.output.split "\n"
+ assert_equal "Successfully installed #{@a2.full_name}", out.shift
+ assert_equal "1 gem installed", out.shift
+ assert out.empty?, out.inspect
+ end
+
+ def test_execute_local_missing
+ util_setup_fake_fetcher
+ @cmd.options[:domain] = :local
+
+ @cmd.options[:args] = %w[no_such_gem]
+
+ use_ui @ui do
+ e = assert_raises Gem::SystemExitException do
+ @cmd.execute
+ end
+ assert_equal 2, e.exit_code
+ end
+
+ # HACK no repository was checked
+ assert_equal "ERROR: could not find gem no_such_gem locally or in a repository\n",
+ @ui.error
+ end
+
+ def test_execute_no_gem
+ @cmd.options[:args] = %w[]
+
+ assert_raise Gem::CommandLineError do
+ @cmd.execute
+ end
+ end
+
+ def test_execute_nonexistent
+ util_setup_fake_fetcher
+ util_setup_spec_fetcher
+
+ @cmd.options[:args] = %w[nonexistent]
+
+ use_ui @ui do
+ e = assert_raises Gem::SystemExitException do
+ @cmd.execute
+ end
+ assert_equal 2, e.exit_code
+ end
+
+ assert_equal "ERROR: could not find gem nonexistent locally or in a repository\n",
+ @ui.error
+ end
+
+ def test_execute_remote
+ @cmd.options[:generate_rdoc] = true
+ @cmd.options[:generate_ri] = true
+
+ util_setup_fake_fetcher
+ util_setup_spec_fetcher @a2
+
+ @fetcher.data["#{@gem_repo}gems/#{@a2.full_name}.gem"] =
+ read_binary(File.join(@gemhome, 'cache', "#{@a2.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
+ end
+
+ out = @ui.output.split "\n"
+ assert_equal "Successfully installed #{@a2.full_name}", out.shift
+ assert_equal "1 gem installed", out.shift
+ assert_equal "Installing ri documentation for #{@a2.full_name}...",
+ out.shift
+ assert_equal "Installing RDoc documentation for #{@a2.full_name}...",
+ out.shift
+ assert out.empty?, out.inspect
+ end
+
+ def test_execute_two
+ util_setup_fake_fetcher
+ @cmd.options[:domain] = :local
+
+ FileUtils.mv File.join(@gemhome, 'cache', "#{@a2.full_name}.gem"),
+ File.join(@tempdir)
+
+ FileUtils.mv File.join(@gemhome, 'cache', "#{@b2.full_name}.gem"),
+ File.join(@tempdir)
+
+ @cmd.options[:args] = [@a2.name, @b2.name]
+
+ use_ui @ui do
+ orig_dir = Dir.pwd
+ begin
+ Dir.chdir @tempdir
+ e = assert_raises Gem::SystemExitException do
+ @cmd.execute
+ end
+ assert_equal 0, e.exit_code
+ ensure
+ Dir.chdir orig_dir
+ end
+ end
+
+ out = @ui.output.split "\n"
+ assert_equal "Successfully installed #{@a2.full_name}", out.shift
+ assert_equal "Successfully installed #{@b2.full_name}", out.shift
+ assert_equal "2 gems installed", out.shift
+ assert out.empty?, out.inspect
+ end
+
+end
+
diff --git a/trunk/test/rubygems/test_gem_commands_mirror_command.rb b/trunk/test/rubygems/test_gem_commands_mirror_command.rb
new file mode 100644
index 0000000000..359ba5481e
--- /dev/null
+++ b/trunk/test/rubygems/test_gem_commands_mirror_command.rb
@@ -0,0 +1,61 @@
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/indexer'
+require 'rubygems/commands/mirror_command'
+
+class TestGemCommandsMirrorCommand < RubyGemTestCase
+
+ def setup
+ super
+
+ @cmd = Gem::Commands::MirrorCommand.new
+ end
+
+ def test_execute
+ util_make_gems
+
+ gems_dir = File.join @tempdir, 'gems'
+ mirror = File.join @tempdir, 'mirror'
+
+ FileUtils.mkdir_p gems_dir
+ FileUtils.mkdir_p mirror
+
+ Dir[File.join(@gemhome, 'cache', '*.gem')].each do |gem|
+ FileUtils.mv gem, gems_dir
+ end
+
+ use_ui @ui do
+ Gem::Indexer.new(@tempdir).generate_index
+ end
+
+ orig_HOME = ENV['HOME']
+ ENV['HOME'] = @tempdir
+ Gem.instance_variable_set :@user_home, nil
+
+ File.open File.join(Gem.user_home, '.gemmirrorrc'), 'w' do |fp|
+ fp.puts "---"
+ # tempdir could be a drive+path (under windows)
+ if @tempdir.match(/[a-z]:/i)
+ fp.puts "- from: file:///#{@tempdir}"
+ else
+ fp.puts "- from: file://#{@tempdir}"
+ end
+ fp.puts " to: #{mirror}"
+ end
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert File.exist?(File.join(mirror, 'gems', "#{@a1.full_name}.gem"))
+ assert File.exist?(File.join(mirror, 'gems', "#{@a2.full_name}.gem"))
+ assert File.exist?(File.join(mirror, 'gems', "#{@b2.full_name}.gem"))
+ assert File.exist?(File.join(mirror, 'gems', "#{@c1_2.full_name}.gem"))
+ assert File.exist?(File.join(mirror, "Marshal.#{@marshal_version}"))
+ ensure
+ orig_HOME.nil? ? ENV.delete('HOME') : ENV['HOME'] = orig_HOME
+ Gem.instance_variable_set :@user_home, nil
+ end
+
+end if ''.respond_to? :to_xs
+
diff --git a/trunk/test/rubygems/test_gem_commands_outdated_command.rb b/trunk/test/rubygems/test_gem_commands_outdated_command.rb
new file mode 100644
index 0000000000..a6668c01fc
--- /dev/null
+++ b/trunk/test/rubygems/test_gem_commands_outdated_command.rb
@@ -0,0 +1,43 @@
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/commands/outdated_command'
+
+class TestGemCommandsOutdatedCommand < RubyGemTestCase
+
+ def setup
+ super
+
+ @cmd = Gem::Commands::OutdatedCommand.new
+ end
+
+ def test_initialize
+ assert @cmd.handles?(%W[--platform #{Gem::Platform.local}])
+ end
+
+ def test_execute
+ local_01 = quick_gem 'foo', '0.1'
+ local_02 = quick_gem 'foo', '0.2'
+ remote_10 = quick_gem 'foo', '1.0'
+ remote_20 = quick_gem 'foo', '2.0'
+
+ remote_spec_file = File.join @gemhome, 'specifications',
+ remote_10.full_name + ".gemspec"
+ FileUtils.rm remote_spec_file
+
+ remote_spec_file = File.join @gemhome, 'specifications',
+ remote_20.full_name + ".gemspec"
+ FileUtils.rm remote_spec_file
+
+ @fetcher = Gem::FakeFetcher.new
+ Gem::RemoteFetcher.fetcher = @fetcher
+
+ util_setup_spec_fetcher remote_10, remote_20
+
+ use_ui @ui do @cmd.execute end
+
+ assert_equal "foo (0.2 < 2.0)\n", @ui.output
+ assert_equal "", @ui.error
+ end
+
+end
+
diff --git a/trunk/test/rubygems/test_gem_commands_pristine_command.rb b/trunk/test/rubygems/test_gem_commands_pristine_command.rb
new file mode 100644
index 0000000000..d5d2d7f339
--- /dev/null
+++ b/trunk/test/rubygems/test_gem_commands_pristine_command.rb
@@ -0,0 +1,109 @@
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/commands/pristine_command'
+
+class TestGemCommandsPristineCommand < RubyGemTestCase
+
+ def setup
+ super
+ @cmd = Gem::Commands::PristineCommand.new
+ end
+
+ def test_execute
+ a = quick_gem 'a' do |s| s.executables = %w[foo] end
+ FileUtils.mkdir_p File.join(@tempdir, 'bin')
+ File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp|
+ fp.puts "#!/usr/bin/ruby"
+ end
+
+ install_gem a
+
+ foo_path = File.join @gemhome, 'gems', a.full_name, 'bin', 'foo'
+
+ File.open foo_path, 'w' do |io|
+ io.puts 'I changed it!'
+ end
+
+ @cmd.options[:args] = %w[a]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_equal "#!/usr/bin/ruby\n", File.read(foo_path), foo_path
+
+ out = @ui.output.split "\n"
+
+ assert_equal "Restoring gem(s) to pristine condition...", out.shift
+ assert_equal "Restored #{a.full_name}", out.shift
+ assert out.empty?, out.inspect
+ end
+
+ def test_execute_all
+ a = quick_gem 'a' do |s| s.executables = %w[foo] end
+ FileUtils.mkdir_p File.join(@tempdir, 'bin')
+ File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp|
+ fp.puts "#!/usr/bin/ruby"
+ end
+
+ install_gem a
+
+ gem_bin = File.join @gemhome, 'gems', a.full_name, 'bin', 'foo'
+
+ FileUtils.rm gem_bin
+
+ @cmd.handle_options %w[--all]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert File.exist?(gem_bin)
+
+ out = @ui.output.split "\n"
+
+ assert_equal "Restoring gem(s) to pristine condition...", out.shift
+ assert_equal "Restored #{a.full_name}", out.shift
+ assert out.empty?, out.inspect
+ end
+
+ def test_execute_missing_cache_gem
+ a = quick_gem 'a' do |s| s.executables = %w[foo] end
+ FileUtils.mkdir_p File.join(@tempdir, 'bin')
+ File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp|
+ fp.puts "#!/usr/bin/ruby"
+ end
+
+ install_gem a
+
+ FileUtils.rm File.join(@gemhome, 'cache', "#{a.full_name}.gem")
+
+ @cmd.options[:args] = %w[a]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ out = @ui.output.split "\n"
+
+ assert_equal "Restoring gem\(s\) to pristine condition...", out.shift
+ assert out.empty?, out.inspect
+
+ assert_equal "ERROR: Cached gem for #{a.full_name} not found, use `gem install` to restore\n",
+ @ui.error
+ end
+
+ def test_execute_no_gem
+ @cmd.options[:args] = %w[]
+
+ e = assert_raise Gem::CommandLineError do
+ use_ui @ui do
+ @cmd.execute
+ end
+ end
+
+ assert_match %r|specify a gem name|, e.message
+ end
+
+end
+
diff --git a/trunk/test/rubygems/test_gem_commands_query_command.rb b/trunk/test/rubygems/test_gem_commands_query_command.rb
new file mode 100644
index 0000000000..1b65fc7633
--- /dev/null
+++ b/trunk/test/rubygems/test_gem_commands_query_command.rb
@@ -0,0 +1,288 @@
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/commands/query_command'
+
+class TestGemCommandsQueryCommand < RubyGemTestCase
+
+ def setup
+ super
+
+ @cmd = Gem::Commands::QueryCommand.new
+
+ util_setup_fake_fetcher
+
+ @si = util_setup_spec_fetcher @a1, @a2, @pl1
+
+ @fetcher.data["#{@gem_repo}Marshal.#{Gem.marshal_version}"] = proc do
+ raise Gem::RemoteFetcher::FetchError
+ end
+ end
+
+ def test_execute
+ @cmd.handle_options %w[-r]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ expected = <<-EOF
+
+*** REMOTE GEMS ***
+
+a (2)
+pl (1)
+ EOF
+
+ assert_equal expected, @ui.output
+ assert_equal '', @ui.error
+ end
+
+ def test_execute_all
+ a1_name = @a1.full_name
+ a2_name = @a2.full_name
+
+ @cmd.handle_options %w[-r --all]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ expected = <<-EOF
+
+*** REMOTE GEMS ***
+
+a (2, 1)
+pl (1)
+ EOF
+
+ assert_equal expected, @ui.output
+ assert_equal '', @ui.error
+ end
+
+ def test_execute_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'
+
+ @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)
+ 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)
+ 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_installed
+ @cmd.handle_options %w[-n c --installed]
+
+ e = assert_raise Gem::SystemExitException do
+ use_ui @ui do
+ @cmd.execute
+ end
+ end
+
+ assert_equal 0, e.exit_code
+
+ assert_equal "true\n", @ui.output
+
+ assert_equal '', @ui.error
+ end
+
+ def test_execute_installed_no_name
+ @cmd.handle_options %w[--installed]
+
+ e = assert_raise Gem::SystemExitException do
+ use_ui @ui do
+ @cmd.execute
+ end
+ end
+
+ assert_equal '', @ui.output
+ assert_equal "ERROR: You must specify a gem name\n", @ui.error
+
+ assert_equal 4, e.exit_code
+ end
+
+ def test_execute_installed_not_installed
+ @cmd.handle_options %w[-n not_installed --installed]
+
+ e = assert_raise Gem::SystemExitException 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_version
+ @cmd.handle_options %w[-n c --installed --version 1.2]
+
+ e = assert_raise Gem::SystemExitException do
+ use_ui @ui do
+ @cmd.execute
+ end
+ end
+
+ assert_equal "true\n", @ui.output
+ assert_equal '', @ui.error
+
+ assert_equal 0, e.exit_code
+ end
+
+ def test_execute_installed_version_not_installed
+ @cmd.handle_options %w[-n c --installed --version 2]
+
+ e = assert_raise Gem::SystemExitException 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_legacy
+ 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["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] = nil
+
+ @cmd.handle_options %w[-r]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ expected = <<-EOF
+
+*** REMOTE GEMS ***
+
+a (2)
+pl (1)
+ EOF
+
+ assert_equal expected, @ui.output
+
+ expected = <<-EOF
+WARNING: RubyGems 1.2+ index not found for:
+\t#{@gem_repo}
+
+RubyGems will revert to legacy indexes degrading performance.
+ EOF
+
+ assert_equal expected, @ui.error
+ 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'
+
+ @cmd.handle_options %w[--local --details]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ expected = <<-EOF
+
+*** LOCAL GEMS ***
+
+a (2, 1)
+ Author: A User
+ Homepage: http://example.com
+ Installed at (2): #{@gemhome}
+ (1): #{@gemhome}
+
+ this is a summary
+
+a_evil (9)
+ Author: A User
+ Homepage: http://example.com
+ Installed at: #{@gemhome}
+
+ this is a summary
+
+b (2)
+ Author: A User
+ Homepage: http://example.com
+ Installed at: #{@gemhome}
+
+ this is a summary
+
+c (1.2)
+ Author: A User
+ Homepage: http://example.com
+ Installed at: #{@gemhome}
+
+ this is a summary
+
+pl (1)
+ Author: A User
+ Homepage: http://example.com
+ Installed at: #{@gemhome}
+
+ this is a summary
+ EOF
+
+ assert_equal expected, @ui.output
+ assert_equal '', @ui.error
+ end
+
+ def test_execute_no_versions
+ @cmd.handle_options %w[-r --no-versions]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ expected = <<-EOF
+
+*** REMOTE GEMS ***
+
+a
+pl
+ EOF
+
+ assert_equal expected, @ui.output
+ assert_equal '', @ui.error
+ end
+
+end
+
diff --git a/trunk/test/rubygems/test_gem_commands_server_command.rb b/trunk/test/rubygems/test_gem_commands_server_command.rb
new file mode 100644
index 0000000000..2985b036d8
--- /dev/null
+++ b/trunk/test/rubygems/test_gem_commands_server_command.rb
@@ -0,0 +1,27 @@
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/commands/server_command'
+
+class TestGemCommandsServerCommand < RubyGemTestCase
+
+ def setup
+ super
+
+ @cmd = Gem::Commands::ServerCommand.new
+ end
+
+ def test_handle_options
+ @cmd.send :handle_options, %w[-p 8808 --no-daemon]
+
+ assert_equal false, @cmd.options[:daemon]
+ assert_equal @gemhome, @cmd.options[:gemdir]
+ assert_equal 8808, @cmd.options[:port]
+
+ @cmd.send :handle_options, %w[-p 9999 -d /nonexistent --daemon]
+
+ assert_equal true, @cmd.options[:daemon]
+ assert_equal File.expand_path('/nonexistent'), @cmd.options[:gemdir]
+ assert_equal 9999, @cmd.options[:port]
+ end
+end
+
diff --git a/trunk/test/rubygems/test_gem_commands_sources_command.rb b/trunk/test/rubygems/test_gem_commands_sources_command.rb
new file mode 100644
index 0000000000..623c732e50
--- /dev/null
+++ b/trunk/test/rubygems/test_gem_commands_sources_command.rb
@@ -0,0 +1,275 @@
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/commands/sources_command'
+
+class TestGemCommandsSourcesCommand < RubyGemTestCase
+
+ def setup
+ super
+
+ @cmd = Gem::Commands::SourcesCommand.new
+
+ @new_repo = "http://beta-gems.example.com"
+ end
+
+ def test_execute
+ util_setup_spec_fetcher
+ @cmd.handle_options []
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ expected = <<-EOF
+*** CURRENT SOURCES ***
+
+#{@gem_repo}
+ EOF
+
+ assert_equal expected, @ui.output
+ assert_equal '', @ui.error
+ end
+
+ def test_execute_add
+ util_setup_fake_fetcher
+
+ si = Gem::SourceIndex.new
+ si.add_spec @a1
+
+ specs = si.map do |_, spec|
+ [spec.name, spec.version, spec.original_platform]
+ end
+
+ specs_dump_gz = StringIO.new
+ Zlib::GzipWriter.wrap specs_dump_gz do |io|
+ Marshal.dump specs, io
+ end
+
+ @fetcher.data["#{@new_repo}/specs.#{@marshal_version}.gz"] =
+ specs_dump_gz.string
+
+ @cmd.handle_options %W[--add #{@new_repo}]
+
+ util_setup_spec_fetcher
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_equal [@gem_repo, @new_repo], Gem.sources
+
+ expected = <<-EOF
+#{@new_repo} added to sources
+ EOF
+
+ assert_equal expected, @ui.output
+ assert_equal '', @ui.error
+ end
+
+ def test_execute_add_nonexistent_source
+ util_setup_fake_fetcher
+
+ uri = "http://beta-gems.example.com/specs.#{@marshal_version}.gz"
+ @fetcher.data[uri] = proc do
+ raise Gem::RemoteFetcher::FetchError.new('it died', uri)
+ end
+
+ Gem::RemoteFetcher.fetcher = @fetcher
+
+ @cmd.handle_options %w[--add http://beta-gems.example.com]
+
+ util_setup_spec_fetcher
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ expected = <<-EOF
+Error fetching http://beta-gems.example.com:
+\tit died (#{uri})
+ EOF
+
+ assert_equal expected, @ui.output
+ assert_equal '', @ui.error
+ end
+
+ def test_execute_add_bad_uri
+ @cmd.handle_options %w[--add beta-gems.example.com]
+
+ util_setup_spec_fetcher
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_equal [@gem_repo], Gem.sources
+
+ expected = <<-EOF
+beta-gems.example.com is not a URI
+ EOF
+
+ assert_equal expected, @ui.output
+ assert_equal '', @ui.error
+ end
+
+ def test_execute_add_legacy
+ util_setup_fake_fetcher
+ util_setup_source_info_cache
+
+ si = Gem::SourceIndex.new
+ si.add_spec @a1
+
+ @fetcher.data["#{@new_repo}/yaml"] = ''
+
+ @cmd.handle_options %W[--add #{@new_repo}]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_equal [@gem_repo], Gem.sources
+
+ expected = <<-EOF
+WARNING: RubyGems 1.2+ index not found for:
+\t#{@new_repo}
+
+Will cause RubyGems to revert to legacy indexes, degrading performance.
+ EOF
+
+ assert_equal "#{@new_repo} added to sources\n", @ui.output
+ assert_equal expected, @ui.error
+ end
+
+ def test_execute_clear_all
+ @cmd.handle_options %w[--clear-all]
+
+ util_setup_source_info_cache
+
+ cache = Gem::SourceInfoCache.cache
+ cache.update
+ cache.write_cache
+
+ assert File.exist?(cache.system_cache_file),
+ 'system cache file'
+ assert File.exist?(cache.latest_system_cache_file),
+ 'latest system cache file'
+
+ util_setup_spec_fetcher
+
+ fetcher = Gem::SpecFetcher.fetcher
+
+ # HACK figure out how to force directory creation via fetcher
+ #assert File.directory?(fetcher.dir), 'cache dir exists'
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ expected = <<-EOF
+*** Removed specs cache ***
+*** Removed user source cache ***
+*** Removed latest user source cache ***
+*** Removed system source cache ***
+*** Removed latest system source cache ***
+ EOF
+
+ assert_equal expected, @ui.output
+ assert_equal '', @ui.error
+
+ assert !File.exist?(cache.system_cache_file),
+ 'system cache file'
+ assert !File.exist?(cache.latest_system_cache_file),
+ 'latest system cache file'
+
+ assert !File.exist?(fetcher.dir), 'cache dir removed'
+ end
+
+ def test_execute_remove
+ @cmd.handle_options %W[--remove #{@gem_repo}]
+
+ util_setup_spec_fetcher
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ expected = "#{@gem_repo} removed from sources\n"
+
+ assert_equal expected, @ui.output
+ assert_equal '', @ui.error
+ end
+
+ def test_execute_remove_no_network
+ @cmd.handle_options %W[--remove #{@gem_repo}]
+
+ util_setup_fake_fetcher
+
+ @fetcher.data["#{@gem_repo}Marshal.#{Gem.marshal_version}"] = proc do
+ raise Gem::RemoteFetcher::FetchError
+ end
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ expected = "#{@gem_repo} removed from sources\n"
+
+ assert_equal expected, @ui.output
+ assert_equal '', @ui.error
+ end
+
+ def test_execute_update
+ @cmd.handle_options %w[--update]
+
+ util_setup_fake_fetcher
+ source_index = util_setup_spec_fetcher @a1
+
+ specs = source_index.map do |name, spec|
+ [spec.name, spec.version, spec.original_platform]
+ end
+
+ @fetcher.data["#{@gem_repo}specs.#{Gem.marshal_version}.gz"] =
+ util_gzip Marshal.dump(specs)
+
+ latest_specs = source_index.latest_specs.map do |spec|
+ [spec.name, spec.version, spec.original_platform]
+ end
+
+ @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] =
+ util_gzip Marshal.dump(latest_specs)
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_equal "source cache successfully updated\n", @ui.output
+ assert_equal '', @ui.error
+ end
+
+ def test_execute_update_legacy
+ @cmd.handle_options %w[--update]
+
+ util_setup_fake_fetcher
+ util_setup_source_info_cache
+ Gem::SourceInfoCache.reset
+
+ si = Gem::SourceIndex.new
+ si.add_spec @a1
+ @fetcher.data["#{@gem_repo}yaml"] = YAML.dump si
+ @fetcher.data["#{@gem_repo}Marshal.#{@marshal_version}"] = si.dump
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ expected = <<-EOF
+Bulk updating Gem source index for: #{@gem_repo}
+source cache successfully updated
+ EOF
+
+ assert_equal expected, @ui.output
+ assert_equal '', @ui.error
+ end
+
+end
+
diff --git a/trunk/test/rubygems/test_gem_commands_specification_command.rb b/trunk/test/rubygems/test_gem_commands_specification_command.rb
new file mode 100644
index 0000000000..7ac0429f32
--- /dev/null
+++ b/trunk/test/rubygems/test_gem_commands_specification_command.rb
@@ -0,0 +1,97 @@
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/commands/specification_command'
+
+class TestGemCommandsSpecificationCommand < RubyGemTestCase
+
+ def setup
+ super
+
+ @cmd = Gem::Commands::SpecificationCommand.new
+ end
+
+ def test_execute
+ foo = quick_gem 'foo'
+ Gem.source_index.add_spec foo
+
+ @cmd.options[:args] = %w[foo]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_match %r|Gem::Specification|, @ui.output
+ assert_match %r|name: foo|, @ui.output
+ assert_equal '', @ui.error
+ end
+
+ def test_execute_all
+ foo1 = quick_gem 'foo', '0.0.1'
+ foo2 = quick_gem 'foo', '0.0.2'
+
+ @cmd.options[:args] = %w[foo]
+ @cmd.options[:all] = true
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_match %r|Gem::Specification|, @ui.output
+ assert_match %r|name: foo|, @ui.output
+ assert_match %r|version: 0.0.1|, @ui.output
+ assert_match %r|version: 0.0.2|, @ui.output
+ assert_equal '', @ui.error
+ end
+
+ def test_execute_bad_name
+ @cmd.options[:args] = %w[foo]
+
+ assert_raise MockGemUi::TermError do
+ use_ui @ui do
+ @cmd.execute
+ end
+ end
+
+ assert_equal '', @ui.output
+ assert_equal "ERROR: Unknown gem 'foo'\n", @ui.error
+ end
+
+ def test_execute_exact_match
+ foo = quick_gem 'foo'
+ foo_bar = quick_gem 'foo_bar'
+
+ @cmd.options[:args] = %w[foo]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_match %r|Gem::Specification|, @ui.output
+ assert_match %r|name: foo|, @ui.output
+ assert_equal '', @ui.error
+ end
+
+ def test_execute_remote
+ foo = quick_gem 'foo'
+
+ @fetcher = Gem::FakeFetcher.new
+ Gem::RemoteFetcher.fetcher = @fetcher
+
+ util_setup_spec_fetcher foo
+
+ FileUtils.rm File.join(@gemhome, 'specifications',
+ "#{foo.full_name}.gemspec")
+
+ @cmd.options[:args] = %w[foo]
+ @cmd.options[:domain] = :remote
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_match %r|\A--- !ruby/object:Gem::Specification|, @ui.output
+ assert_match %r|name: foo|, @ui.output
+ end
+
+end
+
diff --git a/trunk/test/rubygems/test_gem_commands_stale_command.rb b/trunk/test/rubygems/test_gem_commands_stale_command.rb
new file mode 100644
index 0000000000..6f66c854a5
--- /dev/null
+++ b/trunk/test/rubygems/test_gem_commands_stale_command.rb
@@ -0,0 +1,39 @@
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/commands/stale_command'
+
+class TestGemCommandsStaleCommand < RubyGemTestCase
+
+ def setup
+ super
+ @cmd = Gem::Commands::StaleCommand.new
+ end
+
+ def test_execute_sorts
+ files = %w[lib/foo_bar.rb Rakefile]
+ foo_bar = quick_gem 'foo_bar' do |gem|
+ gem.files = files
+ end
+ bar_baz = quick_gem 'bar_baz' do |gem|
+ gem.files = files
+ end
+
+ files.each do |file|
+ filename = bar_baz.full_gem_path + "/#{file}"
+ FileUtils.mkdir_p(File.dirname(filename))
+ FileUtils.touch(filename, :mtime => Time.now)
+
+ filename = foo_bar.full_gem_path + "/#{file}"
+ FileUtils.mkdir_p(File.dirname(filename))
+ FileUtils.touch(filename, :mtime => Time.now - 86400)
+ end
+
+ use_ui @ui do
+ @cmd.execute
+ end
+ lines = @ui.output.split("\n")
+ assert_equal("#{foo_bar.name}-#{foo_bar.version}", lines[0].split.first)
+ assert_equal("#{bar_baz.name}-#{bar_baz.version}", lines[1].split.first)
+ end
+
+end
diff --git a/trunk/test/rubygems/test_gem_commands_unpack_command.rb b/trunk/test/rubygems/test_gem_commands_unpack_command.rb
new file mode 100644
index 0000000000..3a62a914a4
--- /dev/null
+++ b/trunk/test/rubygems/test_gem_commands_unpack_command.rb
@@ -0,0 +1,115 @@
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/commands/unpack_command'
+
+class TestGemCommandsUnpackCommand < RubyGemTestCase
+
+ def setup
+ super
+
+ Dir.chdir @tempdir do
+ @cmd = Gem::Commands::UnpackCommand.new
+ end
+ end
+
+ def test_execute
+ util_make_gems
+
+ @cmd.options[:args] = %w[a]
+
+ use_ui @ui do
+ Dir.chdir @tempdir do
+ @cmd.execute
+ end
+ end
+
+ assert File.exist?(File.join(@tempdir, 'a-2'))
+ end
+
+ def test_execute_gem_path
+ util_make_gems
+
+ Gem.clear_paths
+
+ gemhome2 = File.join @tempdir, 'gemhome2'
+
+ Gem.send :set_paths, [gemhome2, @gemhome].join(File::PATH_SEPARATOR)
+ Gem.send :set_home, gemhome2
+
+ @cmd.options[:args] = %w[a]
+
+ use_ui @ui do
+ Dir.chdir @tempdir do
+ @cmd.execute
+ end
+ end
+
+ assert File.exist?(File.join(@tempdir, 'a-2'))
+ end
+
+ def test_execute_gem_path_missing
+ util_make_gems
+
+ Gem.clear_paths
+
+ gemhome2 = File.join @tempdir, 'gemhome2'
+
+ Gem.send :set_paths, [gemhome2, @gemhome].join(File::PATH_SEPARATOR)
+ Gem.send :set_home, gemhome2
+
+ @cmd.options[:args] = %w[z]
+
+ use_ui @ui do
+ Dir.chdir @tempdir do
+ @cmd.execute
+ end
+ end
+
+ assert_equal '', @ui.output
+ end
+
+ def test_execute_with_target_option
+ util_make_gems
+
+ target = 'with_target'
+ @cmd.options[:args] = %w[a]
+ @cmd.options[:target] = target
+
+ use_ui @ui do
+ Dir.chdir @tempdir do
+ @cmd.execute
+ end
+ end
+
+ assert File.exist?(File.join(@tempdir, target, 'a-2'))
+ end
+
+ def test_execute_exact_match
+ foo_spec = quick_gem 'foo'
+ foo_bar_spec = quick_gem 'foo_bar'
+
+ use_ui @ui do
+ Dir.chdir @tempdir do
+ Gem::Builder.new(foo_spec).build
+ Gem::Builder.new(foo_bar_spec).build
+ end
+ end
+
+ foo_path = File.join(@tempdir, "#{foo_spec.full_name}.gem")
+ foo_bar_path = File.join(@tempdir, "#{foo_bar_spec.full_name}.gem")
+ Gem::Installer.new(foo_path).install
+ Gem::Installer.new(foo_bar_path).install
+
+ @cmd.options[:args] = %w[foo]
+
+ use_ui @ui do
+ Dir.chdir @tempdir do
+ @cmd.execute
+ end
+ end
+
+ assert File.exist?(File.join(@tempdir, foo_spec.full_name))
+ end
+
+end
+
diff --git a/trunk/test/rubygems/test_gem_commands_update_command.rb b/trunk/test/rubygems/test_gem_commands_update_command.rb
new file mode 100644
index 0000000000..11da1f8a83
--- /dev/null
+++ b/trunk/test/rubygems/test_gem_commands_update_command.rb
@@ -0,0 +1,165 @@
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/commands/update_command'
+
+class TestGemCommandsUpdateCommand < RubyGemTestCase
+
+ def setup
+ super
+
+ @cmd = Gem::Commands::UpdateCommand.new
+
+ util_setup_fake_fetcher
+
+ @a1_path = File.join @gemhome, 'cache', "#{@a1.full_name}.gem"
+ @a2_path = File.join @gemhome, 'cache', "#{@a2.full_name}.gem"
+
+ util_setup_spec_fetcher @a1, @a2
+
+ @fetcher.data["#{@gem_repo}gems/#{@a1.full_name}.gem"] =
+ read_binary @a1_path
+ @fetcher.data["#{@gem_repo}gems/#{@a2.full_name}.gem"] =
+ read_binary @a2_path
+ end
+
+ def test_execute
+ util_clear_gems
+
+ Gem::Installer.new(@a1_path).install
+
+ @cmd.options[:args] = []
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ out = @ui.output.split "\n"
+ assert_equal "Updating installed gems", out.shift
+ 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 out.empty?, out.inspect
+ end
+
+ # before:
+ # a1 -> c1.2
+ # after:
+ # a2 -> b2 # new dependency
+ # a2 -> c2
+
+ def test_execute_dependencies
+ @a1.add_dependency 'c', '1.2'
+
+ @c2 = quick_gem 'c', '2' do |s|
+ s.files = %w[lib/code.rb]
+ s.require_paths = %w[lib]
+ end
+
+ @a2.add_dependency 'c', '2'
+ @a2.add_dependency 'b', '2'
+
+ @b2_path = File.join @gemhome, 'cache', "#{@b2.full_name}.gem"
+ @c1_2_path = File.join @gemhome, 'cache', "#{@c1_2.full_name}.gem"
+ @c2_path = File.join @gemhome, 'cache', "#{@c2.full_name}.gem"
+
+ @source_index = Gem::SourceIndex.new
+ @source_index.add_spec @a1
+ @source_index.add_spec @a2
+ @source_index.add_spec @b2
+ @source_index.add_spec @c1_2
+ @source_index.add_spec @c2
+
+ util_build_gem @a1
+ util_build_gem @a2
+ util_build_gem @c2
+
+ @fetcher.data["#{@gem_repo}gems/#{@a1.full_name}.gem"] = read_binary @a1_path
+ @fetcher.data["#{@gem_repo}gems/#{@a2.full_name}.gem"] = read_binary @a2_path
+ @fetcher.data["#{@gem_repo}gems/#{@b2.full_name}.gem"] = read_binary @b2_path
+ @fetcher.data["#{@gem_repo}gems/#{@c1_2.full_name}.gem"] =
+ read_binary @c1_2_path
+ @fetcher.data["#{@gem_repo}gems/#{@c2.full_name}.gem"] = read_binary @c2_path
+
+ util_setup_spec_fetcher @a1, @a2, @b2, @c1_2, @c2
+ util_clear_gems
+
+ Gem::Installer.new(@c1_2_path).install
+ Gem::Installer.new(@a1_path).install
+
+ @cmd.options[:args] = []
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ out = @ui.output.split "\n"
+ assert_equal "Updating installed gems", out.shift
+ assert_equal "Updating #{@a2.name}", out.shift
+ assert_equal "Successfully installed #{@c2.full_name}", out.shift
+ assert_equal "Successfully installed #{@b2.full_name}", out.shift
+ assert_equal "Successfully installed #{@a2.full_name}", out.shift
+ assert_equal "Gems updated: #{@c2.name}, #{@b2.name}, #{@a2.name}",
+ out.shift
+
+ assert out.empty?, out.inspect
+ end
+
+ def test_execute_named
+ util_clear_gems
+
+ Gem::Installer.new(@a1_path).install
+
+ @cmd.options[:args] = [@a1.name]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ out = @ui.output.split "\n"
+ assert_equal "Updating installed gems", out.shift
+ 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 out.empty?, out.inspect
+ end
+
+ def test_execute_named_up_to_date
+ util_clear_gems
+
+ Gem::Installer.new(@a2_path).install
+
+ @cmd.options[:args] = [@a2.name]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ out = @ui.output.split "\n"
+ assert_equal "Updating installed gems", out.shift
+ assert_equal "Nothing to update", out.shift
+
+ assert out.empty?, out.inspect
+ end
+
+ def test_execute_up_to_date
+ util_clear_gems
+
+ Gem::Installer.new(@a2_path).install
+
+ @cmd.options[:args] = []
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ out = @ui.output.split "\n"
+ assert_equal "Updating installed gems", out.shift
+ assert_equal "Nothing to update", out.shift
+
+ assert out.empty?, out.inspect
+ end
+
+end
+
diff --git a/trunk/test/rubygems/test_gem_config_file.rb b/trunk/test/rubygems/test_gem_config_file.rb
new file mode 100644
index 0000000000..06321d4e7c
--- /dev/null
+++ b/trunk/test/rubygems/test_gem_config_file.rb
@@ -0,0 +1,276 @@
+#!/usr/bin/env ruby
+#--
+# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
+# All rights reserved.
+# See LICENSE.txt for permissions.
+#++
+
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/config_file'
+
+class TestGemConfigFile < RubyGemTestCase
+
+ def setup
+ super
+
+ @temp_conf = File.join @tempdir, '.gemrc'
+
+ @cfg_args = %W[--config-file #{@temp_conf}]
+
+ @orig_SYSTEM_WIDE_CONFIG_FILE = Gem::ConfigFile::SYSTEM_WIDE_CONFIG_FILE
+ Gem::ConfigFile.send :remove_const, :SYSTEM_WIDE_CONFIG_FILE
+ Gem::ConfigFile.send :const_set, :SYSTEM_WIDE_CONFIG_FILE,
+ File.join(@tempdir, 'system-gemrc')
+ Gem::ConfigFile::OPERATING_SYSTEM_DEFAULTS.clear
+ Gem::ConfigFile::PLATFORM_DEFAULTS.clear
+
+ util_config_file
+ end
+
+ def teardown
+ Gem::ConfigFile::OPERATING_SYSTEM_DEFAULTS.clear
+ Gem::ConfigFile::PLATFORM_DEFAULTS.clear
+ Gem::ConfigFile.send :remove_const, :SYSTEM_WIDE_CONFIG_FILE
+ Gem::ConfigFile.send :const_set, :SYSTEM_WIDE_CONFIG_FILE,
+ @orig_SYSTEM_WIDE_CONFIG_FILE
+
+ super
+ end
+
+ def test_initialize
+ assert_equal @temp_conf, @cfg.config_file_name
+
+ assert_equal false, @cfg.backtrace
+ assert_equal true, @cfg.update_sources
+ assert_equal false, @cfg.benchmark
+ assert_equal Gem::ConfigFile::DEFAULT_BULK_THRESHOLD, @cfg.bulk_threshold
+ assert_equal true, @cfg.verbose
+ assert_equal [@gem_repo], Gem.sources
+
+ File.open @temp_conf, 'w' do |fp|
+ fp.puts ":backtrace: true"
+ fp.puts ":update_sources: false"
+ fp.puts ":benchmark: true"
+ fp.puts ":bulk_threshold: 10"
+ fp.puts ":verbose: false"
+ fp.puts ":sources:"
+ fp.puts " - http://more-gems.example.com"
+ fp.puts "install: --wrappers"
+ end
+
+ util_config_file
+
+ assert_equal true, @cfg.backtrace
+ assert_equal true, @cfg.benchmark
+ assert_equal 10, @cfg.bulk_threshold
+ assert_equal false, @cfg.verbose
+ assert_equal false, @cfg.update_sources
+ assert_equal %w[http://more-gems.example.com], Gem.sources
+ assert_equal '--wrappers', @cfg[:install]
+ end
+
+ def test_initialize_handle_arguments_config_file
+ util_config_file %W[--config-file #{@temp_conf}]
+
+ assert_equal @temp_conf, @cfg.config_file_name
+ end
+
+ def test_initialize_handle_arguments_config_file_with_other_params
+ util_config_file %W[--config-file #{@temp_conf} --backtrace]
+
+ assert_equal @temp_conf, @cfg.config_file_name
+ end
+
+ def test_initialize_handle_arguments_config_file_equals
+ util_config_file %W[--config-file=#{@temp_conf}]
+
+ assert_equal @temp_conf, @cfg.config_file_name
+ end
+
+ def test_initialize_operating_system_override
+ Gem::ConfigFile::OPERATING_SYSTEM_DEFAULTS[:bulk_threshold] = 1
+ Gem::ConfigFile::OPERATING_SYSTEM_DEFAULTS['install'] = '--no-env-shebang'
+
+ Gem::ConfigFile::PLATFORM_DEFAULTS[:bulk_threshold] = 2
+
+ util_config_file
+
+ assert_equal 2, @cfg.bulk_threshold
+ assert_equal '--no-env-shebang', @cfg[:install]
+ end
+
+ def test_initialize_platform_override
+ Gem::ConfigFile::PLATFORM_DEFAULTS[:bulk_threshold] = 2
+ Gem::ConfigFile::PLATFORM_DEFAULTS['install'] = '--no-env-shebang'
+
+ File.open Gem::ConfigFile::SYSTEM_WIDE_CONFIG_FILE, 'w' do |fp|
+ fp.puts ":bulk_threshold: 3"
+ end
+
+ util_config_file
+
+ assert_equal 3, @cfg.bulk_threshold
+ assert_equal '--no-env-shebang', @cfg[:install]
+ end
+
+ def test_initialize_system_wide_override
+ File.open Gem::ConfigFile::SYSTEM_WIDE_CONFIG_FILE, 'w' do |fp|
+ fp.puts ":backtrace: false"
+ fp.puts ":bulk_threshold: 2048"
+ end
+
+ File.open @temp_conf, 'w' do |fp|
+ fp.puts ":backtrace: true"
+ end
+
+ util_config_file
+
+ assert_equal 2048, @cfg.bulk_threshold
+ assert_equal true, @cfg.backtrace
+ end
+
+ def test_handle_arguments
+ args = %w[--backtrace --bunch --of --args here]
+
+ @cfg.handle_arguments args
+
+ assert_equal %w[--bunch --of --args here], @cfg.args
+ end
+
+ def test_handle_arguments_backtrace
+ assert_equal false, @cfg.backtrace
+
+ args = %w[--backtrace]
+
+ @cfg.handle_arguments args
+
+ assert_equal true, @cfg.backtrace
+ end
+
+ def test_handle_arguments_benchmark
+ assert_equal false, @cfg.benchmark
+
+ args = %w[--benchmark]
+
+ @cfg.handle_arguments args
+
+ assert_equal true, @cfg.benchmark
+ end
+
+ def test_handle_arguments_debug
+ old_dollar_DEBUG = $DEBUG
+ assert_equal false, $DEBUG
+
+ args = %w[--debug]
+
+ @cfg.handle_arguments args
+
+ assert_equal true, $DEBUG
+ ensure
+ $DEBUG = old_dollar_DEBUG
+ end
+
+ def test_handle_arguments_override
+ File.open @temp_conf, 'w' do |fp|
+ fp.puts ":benchmark: false"
+ end
+
+ util_config_file %W[--benchmark --config-file=#{@temp_conf}]
+
+ assert_equal true, @cfg.benchmark
+ end
+
+ def test_handle_arguments_traceback
+ assert_equal false, @cfg.backtrace
+
+ args = %w[--traceback]
+
+ @cfg.handle_arguments args
+
+ assert_equal true, @cfg.backtrace
+ end
+
+ def test_really_verbose
+ assert_equal false, @cfg.really_verbose
+
+ @cfg.verbose = true
+
+ assert_equal false, @cfg.really_verbose
+
+ @cfg.verbose = 1
+
+ assert_equal true, @cfg.really_verbose
+ end
+
+ def test_write
+ @cfg.backtrace = true
+ @cfg.benchmark = true
+ @cfg.update_sources = false
+ @cfg.bulk_threshold = 10
+ @cfg.verbose = false
+ Gem.sources.replace %w[http://more-gems.example.com]
+ @cfg[:install] = '--wrappers'
+
+ @cfg.write
+
+ util_config_file
+
+ # These should not be written out to the config file.
+ assert_equal false, @cfg.backtrace, 'backtrace'
+ assert_equal false, @cfg.benchmark, 'benchmark'
+ assert_equal Gem::ConfigFile::DEFAULT_BULK_THRESHOLD, @cfg.bulk_threshold,
+ 'bulk_threshold'
+ assert_equal true, @cfg.update_sources, 'update_sources'
+ assert_equal true, @cfg.verbose, 'verbose'
+
+ assert_equal '--wrappers', @cfg[:install], 'install'
+
+ # this should be written out to the config file.
+ assert_equal %w[http://more-gems.example.com], Gem.sources
+ end
+
+ def test_write_from_hash
+ File.open @temp_conf, 'w' do |fp|
+ fp.puts ":backtrace: true"
+ fp.puts ":benchmark: true"
+ fp.puts ":bulk_threshold: 10"
+ fp.puts ":update_sources: false"
+ fp.puts ":verbose: false"
+ fp.puts ":sources:"
+ fp.puts " - http://more-gems.example.com"
+ fp.puts "install: --wrappers"
+ end
+
+ util_config_file
+
+ @cfg.backtrace = :junk
+ @cfg.benchmark = :junk
+ @cfg.update_sources = :junk
+ @cfg.bulk_threshold = 20
+ @cfg.verbose = :junk
+ Gem.sources.replace %w[http://even-more-gems.example.com]
+ @cfg[:install] = '--wrappers --no-rdoc'
+
+ @cfg.write
+
+ util_config_file
+
+ # These should not be written out to the config file
+ assert_equal true, @cfg.backtrace, 'backtrace'
+ assert_equal true, @cfg.benchmark, 'benchmark'
+ assert_equal 10, @cfg.bulk_threshold, 'bulk_threshold'
+ assert_equal false, @cfg.update_sources, 'update_sources'
+ assert_equal false, @cfg.verbose, 'verbose'
+
+ assert_equal '--wrappers --no-rdoc', @cfg[:install], 'install'
+
+ assert_equal %w[http://even-more-gems.example.com], Gem.sources
+ end
+
+ def util_config_file(args = @cfg_args)
+ @cfg = Gem::ConfigFile.new args
+ end
+
+end
+
diff --git a/trunk/test/rubygems/test_gem_dependency.rb b/trunk/test/rubygems/test_gem_dependency.rb
new file mode 100644
index 0000000000..315c49d6ce
--- /dev/null
+++ b/trunk/test/rubygems/test_gem_dependency.rb
@@ -0,0 +1,140 @@
+#--
+# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
+# All rights reserved.
+# See LICENSE.txt for permissions.
+#++
+
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/version'
+
+class TestGemDependency < RubyGemTestCase
+
+ def setup
+ super
+
+ @pkg1_0 = Gem::Dependency.new 'pkg', ['> 1.0']
+ @pkg1_1 = Gem::Dependency.new 'pkg', ['> 1.1']
+
+ @oth1_0 = Gem::Dependency.new 'other', ['> 1.0']
+
+ @r1_0 = Gem::Requirement.new ['> 1.0']
+ end
+
+ def test_initialize
+ assert_equal "pkg", @pkg1_0.name
+ assert_equal @r1_0, @pkg1_0.version_requirements
+ end
+
+ def test_initialize_double
+ dep = Gem::Dependency.new("pkg", ["> 1.0", "< 2.0"])
+
+ assert_equal Gem::Requirement.new(["> 1.0", "< 2.0"]),
+ dep.version_requirements
+ end
+
+ def test_initialize_empty
+ dep = Gem::Dependency.new("pkg", [])
+ req = @r1_0
+
+ req.instance_eval do
+ @version = ">= 1.0"
+ @op = ">="
+ @nums = [1,0]
+ @requirements = nil
+ end
+
+ dep.instance_eval do
+ @version_requirement = req
+ @version_requirements = nil
+ end
+
+ assert_equal Gem::Requirement.new([">= 1.0"]), dep.version_requirements
+ end
+
+ def test_initialize_version
+ dep = Gem::Dependency.new 'pkg', Gem::Version.new('2')
+
+ assert_equal 'pkg', dep.name
+
+ assert_equal Gem::Requirement.new('= 2'), dep.version_requirements
+ end
+
+ def test_initialize_with_type
+ dep = Gem::Dependency.new("pkg", [], :development)
+ assert_equal(:development, dep.type)
+ end
+
+ def test_type_is_runtime_by_default
+ assert_equal(:runtime, Gem::Dependency.new("pkg", []).type)
+ end
+
+ def test_type_is_restricted
+ assert_raise(ArgumentError) do
+ Gem::Dependency.new("pkg", [:sometimes])
+ end
+ end
+
+ def test_equals2
+ assert_equal @pkg1_0, @pkg1_0.dup
+ assert_equal @pkg1_0.dup, @pkg1_0
+
+ assert_not_equal @pkg1_0, @pkg1_1, "requirements different"
+ assert_not_equal @pkg1_1, @pkg1_0, "requirements different"
+
+ assert_not_equal @pkg1_0, @oth1_0, "names different"
+ assert_not_equal @oth1_0, @pkg1_0, "names different"
+
+ assert_not_equal @pkg1_0, Object.new
+ assert_not_equal Object.new, @pkg1_0
+ end
+
+ def test_equals2_type
+ runtime = Gem::Dependency.new("pkg", [])
+ development = Gem::Dependency.new("pkg", [], :development)
+
+ assert_not_equal(runtime, development)
+ 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'
+
+ pa0 = dep 'a', '>= 0'
+ 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(!(pa0r =~ b0), 'fail match regex')
+ assert(!(pa0r =~ Object.new), 'fail match Object')
+ end
+
+ def test_hash
+ assert_equal @pkg1_0.hash, @pkg1_0.dup.hash
+ assert_equal @pkg1_0.dup.hash, @pkg1_0.hash
+
+ assert_not_equal @pkg1_0.hash, @pkg1_1.hash, "requirements different"
+ assert_not_equal @pkg1_1.hash, @pkg1_0.hash, "requirements different"
+
+ assert_not_equal @pkg1_0.hash, @oth1_0.hash, "names different"
+ assert_not_equal @oth1_0.hash, @pkg1_0.hash, "names different"
+ end
+
+ def test_hash_type
+ runtime = Gem::Dependency.new("pkg", [])
+ development = Gem::Dependency.new("pkg", [], :development)
+
+ assert_not_equal(runtime.hash, development.hash)
+ end
+end
+
diff --git a/trunk/test/rubygems/test_gem_dependency_installer.rb b/trunk/test/rubygems/test_gem_dependency_installer.rb
new file mode 100644
index 0000000000..10e7fdfbda
--- /dev/null
+++ b/trunk/test/rubygems/test_gem_dependency_installer.rb
@@ -0,0 +1,637 @@
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/dependency_installer'
+
+class TestGemDependencyInstaller < RubyGemTestCase
+
+ def setup
+ super
+
+ @gems_dir = File.join @tempdir, 'gems'
+ @cache_dir = File.join @gemhome, 'cache'
+ FileUtils.mkdir @gems_dir
+
+ 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'
+
+ @b1, @b1_gem = util_gem 'b', '1' do |s|
+ s.add_dependency 'a'
+ s.add_development_dependency 'aa'
+ end
+
+ @d1, @d1_gem = util_gem 'd', '1'
+ @d2, @d2_gem = util_gem 'd', '2'
+
+ @x1_m, @x1_m_gem = util_gem 'x', '1' do |s|
+ s.platform = Gem::Platform.new %w[cpu my_platform 1]
+ end
+
+ @x1_o, @x1_o_gem = util_gem 'x', '1' do |s|
+ s.platform = Gem::Platform.new %w[cpu other_platform 1]
+ end
+
+ @w1, @w1_gem = util_gem 'w', '1' do |s| s.add_dependency 'x' end
+
+ @y1, @y1_gem = util_gem 'y', '1'
+ @y1_1_p, @y1_1_p_gem = util_gem 'y', '1.1' do |s|
+ s.platform = Gem::Platform.new %w[cpu my_platform 1]
+ end
+
+ @z1, @z1_gem = util_gem 'z', '1' do |s| s.add_dependency 'y' end
+
+ @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
+
+ util_clear_gems
+ end
+
+ def test_install
+ FileUtils.mv @a1_gem, @tempdir
+ inst = nil
+
+ Dir.chdir @tempdir do
+ inst = Gem::DependencyInstaller.new
+ inst.install 'a'
+ end
+
+ assert_equal Gem::SourceIndex.new(@a1.full_name => @a1),
+ Gem::SourceIndex.from_installed_gems
+
+ assert_equal [@a1], inst.installed_gems
+ end
+
+ def test_install_all_dependencies
+ e1, e1_gem = util_gem 'e', '1' do |s|
+ s.add_dependency 'b'
+ end
+
+ util_clear_gems
+
+ FileUtils.mv @a1_gem, @tempdir
+ FileUtils.mv @b1_gem, @tempdir
+ FileUtils.mv e1_gem, @tempdir
+ inst = nil
+
+ Dir.chdir @tempdir do
+ inst = Gem::DependencyInstaller.new :ignore_dependencies => true
+ inst.install 'b'
+ end
+
+ Dir.chdir @tempdir do
+ inst = Gem::DependencyInstaller.new
+ inst.install 'e'
+ end
+
+ assert_equal %w[e-1 a-1], inst.installed_gems.map { |s| s.full_name }
+ end
+
+ def test_install_cache_dir
+ FileUtils.mv @a1_gem, @tempdir
+ FileUtils.mv @b1_gem, @tempdir
+ inst = nil
+
+ Dir.chdir @tempdir do
+ inst = Gem::DependencyInstaller.new :cache_dir => @tempdir
+ inst.install 'b'
+ end
+
+ assert_equal %w[a-1 b-1], inst.installed_gems.map { |s| s.full_name }
+
+ assert File.exist?(File.join(@tempdir, 'cache', "#{@a1.full_name}.gem"))
+ assert File.exist?(File.join(@tempdir, 'cache', "#{@b1.full_name}.gem"))
+ end
+
+ def test_install_dependencies_satisfied
+ a2, a2_gem = util_gem 'a', '2'
+
+ FileUtils.rm_rf File.join(@gemhome, 'gems')
+ Gem.source_index.refresh!
+
+ FileUtils.mv @a1_gem, @tempdir
+ FileUtils.mv a2_gem, @tempdir # not in index
+ FileUtils.mv @b1_gem, @tempdir
+ inst = nil
+
+ Dir.chdir @tempdir do
+ inst = Gem::DependencyInstaller.new
+ inst.install 'a-2'
+ end
+
+ FileUtils.rm File.join(@tempdir, "#{a2.full_name}.gem")
+
+ Dir.chdir @tempdir do
+ inst = Gem::DependencyInstaller.new
+ inst.install 'b'
+ end
+
+ installed = Gem::SourceIndex.from_installed_gems.map { |n,s| s.full_name }
+
+ assert_equal %w[a-2 b-1], installed.sort
+
+ assert_equal %w[b-1], inst.installed_gems.map { |s| s.full_name }
+ end
+
+ def test_install_dependency
+ FileUtils.mv @a1_gem, @tempdir
+ FileUtils.mv @b1_gem, @tempdir
+ inst = nil
+
+ Dir.chdir @tempdir do
+ inst = Gem::DependencyInstaller.new
+ inst.install 'b'
+ end
+
+ assert_equal %w[a-1 b-1], inst.installed_gems.map { |s| s.full_name }
+ end
+
+ def test_install_dependency_development
+ FileUtils.mv @a1_gem, @tempdir
+ FileUtils.mv @aa1_gem, @tempdir
+ FileUtils.mv @b1_gem, @tempdir
+ inst = nil
+
+ Dir.chdir @tempdir do
+ inst = Gem::DependencyInstaller.new(:development => true)
+ inst.install 'b'
+ end
+
+ assert_equal %w[a-1 aa-1 b-1], inst.installed_gems.map { |s| s.full_name }
+ end
+
+ def test_install_dependency_existing
+ Gem::Installer.new(@a1_gem).install
+ FileUtils.mv @a1_gem, @tempdir
+ FileUtils.mv @b1_gem, @tempdir
+ inst = nil
+
+ Dir.chdir @tempdir do
+ inst = Gem::DependencyInstaller.new
+ inst.install 'b'
+ end
+
+ assert_equal %w[b-1], inst.installed_gems.map { |s| s.full_name }
+ end
+
+ def test_install_dependency_old
+ e1, e1_gem = util_gem 'e', '1'
+ f1, f1_gem = util_gem 'f', '1' do |s| s.add_dependency 'e' end
+ f2, f2_gem = util_gem 'f', '2'
+
+ FileUtils.mv e1_gem, @tempdir
+ FileUtils.mv f1_gem, @tempdir
+ FileUtils.mv f2_gem, @tempdir
+ inst = nil
+
+ Dir.chdir @tempdir do
+ inst = Gem::DependencyInstaller.new
+ inst.install 'f'
+ end
+
+ assert_equal %w[f-2], inst.installed_gems.map { |s| s.full_name }
+ end
+
+ def test_install_local
+ FileUtils.mv @a1_gem, @tempdir
+ inst = nil
+
+ Dir.chdir @tempdir do
+ inst = Gem::DependencyInstaller.new :domain => :local
+ inst.install 'a-1.gem'
+ end
+
+ assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name }
+ end
+
+ def test_install_local_dependency
+ FileUtils.mv @a1_gem, @tempdir
+ FileUtils.mv @b1_gem, @tempdir
+
+ inst = nil
+
+ Dir.chdir @tempdir do
+ inst = Gem::DependencyInstaller.new :domain => :local
+ inst.install 'b-1.gem'
+ end
+
+ assert_equal %w[a-1 b-1], inst.installed_gems.map { |s| s.full_name }
+ end
+
+ def test_install_local_dependency_installed
+ FileUtils.mv @a1_gem, @tempdir
+ FileUtils.mv @b1_gem, @tempdir
+
+ inst = nil
+
+ Dir.chdir @tempdir do
+ Gem::Installer.new('a-1.gem').install
+
+ inst = Gem::DependencyInstaller.new :domain => :local
+ inst.install 'b-1.gem'
+ end
+
+ assert_equal %w[b-1], inst.installed_gems.map { |s| s.full_name }
+ end
+
+ def test_install_local_subdir
+ inst = nil
+
+ Dir.chdir @tempdir do
+ inst = Gem::DependencyInstaller.new :domain => :local
+ inst.install 'gems/a-1.gem'
+ end
+
+ assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name }
+ end
+
+ def test_install_env_shebang
+ FileUtils.mv @a1_gem, @tempdir
+ inst = nil
+
+ Dir.chdir @tempdir do
+ inst = Gem::DependencyInstaller.new :env_shebang => true, :wrappers => true
+ inst.install 'a'
+ end
+
+ assert_match %r|\A#!/usr/bin/env #{Gem::ConfigMap[:RUBY_INSTALL_NAME]}\n|,
+ File.read(File.join(@gemhome, 'bin', 'a_bin'))
+ end
+
+ def test_install_force
+ FileUtils.mv @b1_gem, @tempdir
+ si = util_setup_spec_fetcher @b1
+ @fetcher.data['http://gems.example.com/gems/yaml'] = si.to_yaml
+ inst = nil
+
+ Dir.chdir @tempdir do
+ inst = Gem::DependencyInstaller.new :force => true
+ inst.install 'b'
+ end
+
+ assert_equal %w[b-1], inst.installed_gems.map { |s| s.full_name }
+ end
+
+ def test_install_ignore_dependencies
+ FileUtils.mv @b1_gem, @tempdir
+ inst = nil
+
+ Dir.chdir @tempdir do
+ inst = Gem::DependencyInstaller.new :ignore_dependencies => true
+ inst.install 'b'
+ end
+
+ assert_equal %w[b-1], inst.installed_gems.map { |s| s.full_name }
+ end
+
+ def test_install_install_dir
+ FileUtils.mv @a1_gem, @tempdir
+ gemhome2 = File.join @tempdir, 'gemhome2'
+ Dir.mkdir gemhome2
+ inst = nil
+
+ Dir.chdir @tempdir do
+ inst = Gem::DependencyInstaller.new :install_dir => gemhome2
+ inst.install 'a'
+ end
+
+ assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name }
+
+ assert File.exist?(File.join(gemhome2, 'specifications',
+ "#{@a1.full_name}.gemspec"))
+ assert File.exist?(File.join(gemhome2, 'cache',
+ "#{@a1.full_name}.gem"))
+ end
+
+ def test_install_domain_both
+ a1_data = nil
+ File.open @a1_gem, 'rb' do |fp|
+ a1_data = fp.read
+ end
+
+ @fetcher.data['http://gems.example.com/gems/a-1.gem'] = a1_data
+
+ FileUtils.mv @b1_gem, @tempdir
+ inst = nil
+
+ Dir.chdir @tempdir do
+ inst = Gem::DependencyInstaller.new :domain => :both
+ inst.install 'b'
+ end
+
+ assert_equal %w[a-1 b-1], inst.installed_gems.map { |s| s.full_name }
+ a1, b1 = inst.installed_gems
+
+ a1_expected = File.join(@gemhome, 'specifications',
+ "#{a1.full_name}.gemspec")
+ b1_expected = File.join(@gemhome, 'specifications',
+ "#{b1.full_name}.gemspec")
+
+ assert_equal a1_expected, a1.loaded_from
+ assert_equal b1_expected, b1.loaded_from
+ end
+
+ def test_install_domain_both_no_network
+ @fetcher.data["http://gems.example.com/gems/Marshal.#{@marshal_version}"] =
+ proc do
+ raise Gem::RemoteFetcher::FetchError
+ end
+
+ FileUtils.mv @a1_gem, @tempdir
+ FileUtils.mv @b1_gem, @tempdir
+ inst = nil
+
+ Dir.chdir @tempdir do
+ inst = Gem::DependencyInstaller.new :domain => :both
+ inst.install 'b'
+ end
+
+ assert_equal %w[a-1 b-1], inst.installed_gems.map { |s| s.full_name }
+ end
+
+ def test_install_domain_local
+ FileUtils.mv @b1_gem, @tempdir
+ inst = nil
+
+ Gem.source_index.gems.delete @a1.full_name
+
+ Dir.chdir @tempdir do
+ e = assert_raise Gem::InstallError do
+ inst = Gem::DependencyInstaller.new :domain => :local
+ inst.install 'b'
+ end
+ assert_equal 'b requires a (>= 0, runtime)', e.message
+ end
+
+ assert_equal [], inst.installed_gems.map { |s| s.full_name }
+ end
+
+ def test_install_domain_remote
+ a1_data = nil
+ File.open @a1_gem, 'rb' do |fp|
+ a1_data = fp.read
+ end
+
+ @fetcher.data['http://gems.example.com/gems/a-1.gem'] = a1_data
+
+ inst = Gem::DependencyInstaller.new :domain => :remote
+ inst.install 'a'
+
+ assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name }
+ end
+
+ def test_install_dual_repository
+ FileUtils.mv @a1_gem, @tempdir
+ FileUtils.mv @b1_gem, @tempdir
+ inst = nil
+
+ gemhome2 = "#{@gemhome}2"
+
+ Dir.chdir @tempdir do
+ inst = Gem::DependencyInstaller.new :install_dir => gemhome2
+ inst.install 'a'
+ end
+
+ ENV['GEM_HOME'] = @gemhome
+ ENV['GEM_PATH'] = [@gemhome, gemhome2].join File::PATH_SEPARATOR
+ Gem.clear_paths
+
+ Dir.chdir @tempdir do
+ inst = Gem::DependencyInstaller.new
+ inst.install 'b'
+ end
+
+ assert_equal %w[b-1], inst.installed_gems.map { |s| s.full_name }
+ end
+
+ def test_install_remote
+ a1_data = nil
+ File.open @a1_gem, 'rb' do |fp|
+ a1_data = fp.read
+ end
+
+ @fetcher.data['http://gems.example.com/gems/a-1.gem'] = a1_data
+
+ inst = Gem::DependencyInstaller.new
+
+ Dir.chdir @tempdir do
+ inst.install 'a'
+ end
+
+ assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name }
+ end
+
+ def test_install_remote_dep
+ a1_data = nil
+ File.open @a1_gem, 'rb' do |fp|
+ a1_data = fp.read
+ end
+
+ @fetcher.data['http://gems.example.com/gems/a-1.gem'] = a1_data
+
+ inst = Gem::DependencyInstaller.new
+
+ Dir.chdir @tempdir do
+ dep = Gem::Dependency.new @a1.name, @a1.version
+ inst.install dep
+ end
+
+ assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name }
+ end
+
+ def test_install_domain_remote_platform_newer
+ a2_o, a2_o_gem = util_gem 'a', '2' do |s|
+ s.platform = Gem::Platform.new %w[cpu other_platform 1]
+ end
+
+ util_clear_gems
+
+ si = util_setup_spec_fetcher @a1, a2_o
+
+ @fetcher.data['http://gems.example.com/gems/yaml'] = si.to_yaml
+
+ a1_data = nil
+ a2_o_data = nil
+
+ File.open @a1_gem, 'rb' do |fp| a1_data = fp.read end
+ File.open a2_o_gem, 'rb' do |fp| a2_o_data = fp.read end
+
+ @fetcher.data["http://gems.example.com/gems/#{@a1.full_name}.gem"] =
+ a1_data
+ @fetcher.data["http://gems.example.com/gems/#{a2_o.full_name}.gem"] =
+ a2_o_data
+
+ inst = Gem::DependencyInstaller.new :domain => :remote
+ inst.install 'a'
+
+ assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name }
+ end
+
+ def test_install_reinstall
+ Gem::Installer.new(@a1_gem).install
+ FileUtils.mv @a1_gem, @tempdir
+ inst = nil
+
+ Dir.chdir @tempdir do
+ inst = Gem::DependencyInstaller.new
+ inst.install 'a'
+ end
+
+ assert_equal Gem::SourceIndex.new(@a1.full_name => @a1),
+ Gem::SourceIndex.from_installed_gems
+
+ assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name }
+ end
+
+ if defined? OpenSSL then
+ def test_install_security_policy
+ data = File.open(@a1_gem, 'rb') { |f| f.read }
+ @fetcher.data['http://gems.example.com/gems/a-1.gem'] = data
+
+ data = File.open(@b1_gem, 'rb') { |f| f.read }
+ @fetcher.data['http://gems.example.com/gems/b-1.gem'] = data
+
+ policy = Gem::Security::HighSecurity
+ inst = Gem::DependencyInstaller.new :security_policy => policy
+
+ e = assert_raise Gem::Exception do
+ inst.install 'b'
+ end
+
+ assert_equal 'Unsigned gem', e.message
+
+ assert_equal %w[], inst.installed_gems.map { |s| s.full_name }
+ end
+ end
+
+ # Wrappers don't work on mswin
+ unless win_platform? then
+ def test_install_no_wrappers
+ @fetcher.data['http://gems.example.com/gems/a-1.gem'] = read_binary(@a1_gem)
+
+ inst = Gem::DependencyInstaller.new :wrappers => false
+ inst.install 'a'
+
+ assert_no_match(%r|This file was generated by RubyGems.|,
+ File.read(File.join(@gemhome, 'bin', 'a_bin')))
+ end
+ end
+
+ def test_install_version
+ data = File.open(@d2_gem, 'rb') { |f| f.read }
+ @fetcher.data['http://gems.example.com/gems/d-2.gem'] = data
+
+ data = File.open(@d1_gem, 'rb') { |f| f.read }
+ @fetcher.data['http://gems.example.com/gems/d-1.gem'] = data
+
+ inst = Gem::DependencyInstaller.new
+
+ inst.install 'd', '= 1'
+
+ assert_equal %w[d-1], inst.installed_gems.map { |s| s.full_name }
+ end
+
+ def test_install_version_default
+ data = File.open(@d2_gem, 'rb') { |f| f.read }
+ @fetcher.data['http://gems.example.com/gems/d-2.gem'] = data
+
+ data = File.open(@d1_gem, 'rb') { |f| f.read }
+ @fetcher.data['http://gems.example.com/gems/d-1.gem'] = data
+
+ inst = Gem::DependencyInstaller.new
+ inst.install 'd'
+
+ assert_equal %w[d-2], inst.installed_gems.map { |s| s.full_name }
+ end
+
+ def test_find_gems_gems_with_sources
+ inst = Gem::DependencyInstaller.new
+ dep = Gem::Dependency.new 'b', '>= 0'
+
+ assert_equal [[@b1, @gem_repo]],
+ inst.find_gems_with_sources(dep)
+ end
+
+ def test_find_gems_with_sources_local
+ FileUtils.mv @a1_gem, @tempdir
+ inst = Gem::DependencyInstaller.new
+ dep = Gem::Dependency.new 'a', '>= 0'
+ gems = nil
+
+ Dir.chdir @tempdir do
+ gems = inst.find_gems_with_sources dep
+ end
+
+ assert_equal 2, gems.length
+ remote = gems.first
+ assert_equal 'a-1', remote.first.full_name, 'remote spec'
+ assert_equal @gem_repo, remote.last, 'remote path'
+
+ local = gems.last
+ assert_equal 'a-1', local.first.full_name, 'local spec'
+ assert_equal File.join(@tempdir, "#{@a1.full_name}.gem"),
+ local.last, 'local path'
+ end
+
+ def test_gather_dependencies
+ inst = Gem::DependencyInstaller.new
+ inst.find_spec_by_name_and_version 'b'
+ inst.gather_dependencies
+
+ assert_equal %w[a-1 b-1], inst.gems_to_install.map { |s| s.full_name }
+ end
+
+ def test_gather_dependencies_dropped
+ b2, = util_gem 'b', '2'
+ c1, = util_gem 'c', '1' do |s| s.add_dependency 'b' end
+
+ util_clear_gems
+
+ si = util_setup_spec_fetcher @a1, @b1, b2, c1
+
+ inst = Gem::DependencyInstaller.new
+ inst.find_spec_by_name_and_version 'c'
+ inst.gather_dependencies
+
+ assert_equal %w[b-2 c-1], inst.gems_to_install.map { |s| s.full_name }
+ end
+
+ def test_gather_dependencies_platform_alternate
+ util_set_arch 'cpu-my_platform1'
+
+ inst = Gem::DependencyInstaller.new
+ inst.find_spec_by_name_and_version 'w'
+ inst.gather_dependencies
+
+ assert_equal %w[x-1-cpu-my_platform-1 w-1],
+ inst.gems_to_install.map { |s| s.full_name }
+ end
+
+ def test_gather_dependencies_platform_bump
+ inst = Gem::DependencyInstaller.new
+ inst.find_spec_by_name_and_version 'z'
+ inst.gather_dependencies
+
+ assert_equal %w[y-1 z-1], inst.gems_to_install.map { |s| s.full_name }
+ end
+
+ def test_gather_dependencies_old_required
+ e1, = util_gem 'e', '1' do |s| s.add_dependency 'd', '= 1' end
+
+ util_clear_gems
+
+ si = util_setup_spec_fetcher @d1, @d2, e1
+
+ inst = Gem::DependencyInstaller.new
+ inst.find_spec_by_name_and_version 'e'
+ inst.gather_dependencies
+
+ assert_equal %w[d-1 e-1], inst.gems_to_install.map { |s| s.full_name }
+ end
+
+end
+
diff --git a/trunk/test/rubygems/test_gem_dependency_list.rb b/trunk/test/rubygems/test_gem_dependency_list.rb
new file mode 100644
index 0000000000..5fdc227f05
--- /dev/null
+++ b/trunk/test/rubygems/test_gem_dependency_list.rb
@@ -0,0 +1,212 @@
+#!/usr/bin/env ruby
+#--
+# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
+# All rights reserved.
+# See LICENSE.txt for permissions.
+#++
+
+
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/dependency_list'
+
+class TestGemDependencyList < RubyGemTestCase
+
+ def setup
+ super
+
+ @deplist = Gem::DependencyList.new
+
+ @a1 = quick_gem 'a', '1'
+ @a2 = quick_gem 'a', '2'
+ @a3 = quick_gem 'a', '3'
+
+ @b1 = quick_gem 'b', '1' do |s| s.add_dependency 'a', '>= 1' end
+ @b2 = quick_gem 'b', '2' do |s| s.add_dependency 'a', '>= 1' end
+
+ @c1 = quick_gem 'c', '1' do |s| s.add_dependency 'b', '>= 1' end
+ @c2 = quick_gem 'c', '2'
+
+ @d1 = quick_gem 'd', '1' do |s| s.add_dependency 'c', '>= 1' end
+ end
+
+ def test_self_from_source_index
+ hash = {
+ 'a-1' => @a1,
+ 'b-2' => @b2,
+ }
+
+ si = Gem::SourceIndex.new hash
+ deps = Gem::DependencyList.from_source_index si
+
+ assert_equal %w[b-2 a-1], deps.dependency_order.map { |s| s.full_name }
+ end
+
+ def test_active_count
+ assert_equal 0, @deplist.send(:active_count, [], {})
+ assert_equal 1, @deplist.send(:active_count, [@a1], {})
+ assert_equal 0, @deplist.send(:active_count, [@a1],
+ { @a1.full_name => true })
+ end
+
+ def test_add
+ assert_equal [], @deplist.dependency_order
+
+ @deplist.add @a1, @b2
+
+ assert_equal [@b2, @a1], @deplist.dependency_order
+ end
+
+ def test_dependency_order
+ @deplist.add @a1, @b1, @c1, @d1
+
+ order = @deplist.dependency_order
+
+ assert_equal %w[d-1 c-1 b-1 a-1], order.map { |s| s.full_name }
+ end
+
+ def test_dependency_order_circle
+ @a1.add_dependency 'c', '>= 1'
+ @deplist.add @a1, @b1, @c1
+
+ order = @deplist.dependency_order
+
+ assert_equal %w[b-1 c-1 a-1], order.map { |s| s.full_name }
+ end
+
+ def test_dependency_order_diamond
+ util_diamond
+ e1 = quick_gem 'e', '1'
+ @deplist.add e1
+ @a1.add_dependency 'e', '>= 1'
+
+ order = @deplist.dependency_order
+
+ assert_equal %w[d-1 c-2 b-1 a-2 e-1], order.map { |s| s.full_name },
+ 'deps of trimmed specs not included'
+ end
+
+ def test_dependency_order_no_dependendencies
+ @deplist.add @a1, @c2
+
+ order = @deplist.dependency_order
+
+ assert_equal %w[c-2 a-1], order.map { |s| s.full_name }
+ end
+
+ def test_find_name
+ @deplist.add @a1, @b2
+
+ assert_equal "a-1", @deplist.find_name("a-1").full_name
+ assert_equal "b-2", @deplist.find_name("b-2").full_name
+
+ assert_nil @deplist.find_name("c-2")
+ end
+
+ def test_ok_eh
+ assert @deplist.ok?, 'no dependencies'
+
+ @deplist.add @b2
+
+ assert ! @deplist.ok?, 'unsatisfied dependency'
+
+ @deplist.add @a1
+
+ assert @deplist.ok?, 'satisfied dependency'
+ end
+
+ def test_ok_eh_mismatch
+ a1 = quick_gem 'a', '1'
+ a2 = quick_gem 'a', '2'
+
+ b = quick_gem 'b', '1' do |s| s.add_dependency 'a', '= 1' end
+ c = quick_gem 'c', '1' do |s| s.add_dependency 'a', '= 2' end
+
+ d = quick_gem 'd', '1' do |s|
+ s.add_dependency 'b'
+ s.add_dependency 'c'
+ end
+
+ @deplist.add a1, a2, b, c, d
+
+ assert @deplist.ok?, 'this will break on require'
+ end
+
+ def test_ok_eh_redundant
+ @deplist.add @a1, @a3, @b2
+
+ @deplist.remove_by_name("a-1")
+
+ assert @deplist.ok?
+ end
+
+ def test_ok_to_remove_eh
+ @deplist.add @a1
+
+ assert @deplist.ok_to_remove?("a-1")
+
+ @deplist.add @b2
+
+ assert ! @deplist.ok_to_remove?("a-1")
+
+ @deplist.add @a2
+
+ assert @deplist.ok_to_remove?("a-1")
+ assert @deplist.ok_to_remove?("a-2")
+ assert @deplist.ok_to_remove?("b-2")
+ end
+
+ def test_ok_to_remove_eh_after_sibling_removed
+ @deplist.add @a1, @a2, @b2
+
+ assert @deplist.ok_to_remove?("a-1")
+ assert @deplist.ok_to_remove?("a-2")
+
+ @deplist.remove_by_name("a-1")
+
+ assert ! @deplist.ok_to_remove?("a-2")
+ end
+
+ def test_remove_by_name
+ @deplist.add @a1, @b2
+
+ @deplist.remove_by_name "a-1"
+
+ assert ! @deplist.ok?
+ end
+
+ def test_tsort_each_node
+ util_diamond
+
+ order = %w[a-1 a-2 b-1 c-2 d-1]
+
+ @deplist.tsort_each_node do |node|
+ assert_equal order.shift, node.full_name
+ end
+
+ assert order.empty?
+ end
+
+ def test_tsort_each_child
+ util_diamond
+
+ order = %w[a-2]
+
+ @deplist.tsort_each_child(@b1) do |node|
+ assert_equal order.shift, node.full_name
+ end
+
+ assert order.empty?
+ end
+
+ # d1 -> b1 -> a1
+ # d1 -> c2 -> a2
+ def util_diamond
+ @c2.add_dependency 'a', '>= 2'
+ @d1.add_dependency 'b'
+
+ @deplist.add @a1, @a2, @b1, @c2, @d1
+ end
+
+end
+
diff --git a/trunk/test/rubygems/test_gem_digest.rb b/trunk/test/rubygems/test_gem_digest.rb
new file mode 100755
index 0000000000..9d825b2796
--- /dev/null
+++ b/trunk/test/rubygems/test_gem_digest.rb
@@ -0,0 +1,44 @@
+#!/usr/bin/env ruby
+#--
+# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
+# All rights reserved.
+# See LICENSE.txt for permissions.
+#++
+
+require "test/unit"
+require "rubygems/digest/md5"
+require "rubygems/digest/sha1"
+require "rubygems/digest/sha2"
+
+class TestRubygemsGemDigest < Test::Unit::TestCase
+ def test_sha256_hex_digest_works
+ digester = Gem::SHA256.new
+ assert_equal "b5d4045c3f466fa91fe2cc6abe79232a1a57cdf104f7a26e716e0a1e2789df78", digester.hexdigest("ABC")
+ end
+
+ def test_sha256_digest_works
+ digester = Gem::SHA256.new
+ assert_equal "\265\324\004\\?Fo\251\037\342\314j\276y#*\032W\315\361\004\367\242nqn\n\036'\211\337x",
+ digester.digest("ABC")
+ end
+
+ def test_sha1_hex_digest_works
+ digester = Gem::SHA1.new
+ assert_equal "3c01bdbb26f358bab27f267924aa2c9a03fcfdb8", digester.hexdigest("ABC")
+ end
+
+ def test_sha1_digest_works
+ digester = Gem::SHA1.new
+ assert_equal "<\001\275\273&\363X\272\262\177&y$\252,\232\003\374\375\270", digester.digest("ABC")
+ end
+
+ def test_md5_hex_digest_works
+ digester = Gem::MD5.new
+ assert_equal "902fbdd2b1df0c4f70b4a5d23525e932", digester.hexdigest("ABC")
+ end
+
+ def test_md5_digest_works
+ digester = Gem::MD5.new
+ assert_equal "\220/\275\322\261\337\fOp\264\245\3225%\3512", digester.digest("ABC")
+ end
+end \ No newline at end of file
diff --git a/trunk/test/rubygems/test_gem_doc_manager.rb b/trunk/test/rubygems/test_gem_doc_manager.rb
new file mode 100644
index 0000000000..e52fb9f0cd
--- /dev/null
+++ b/trunk/test/rubygems/test_gem_doc_manager.rb
@@ -0,0 +1,32 @@
+#--
+# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
+# All rights reserved.
+# See LICENSE.txt for permissions.
+#++
+
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/doc_manager'
+
+class TestGemDocManager < RubyGemTestCase
+
+ def setup
+ super
+
+ @spec = quick_gem 'a'
+ @manager = Gem::DocManager.new(@spec)
+ end
+
+ def test_uninstall_doc_unwritable
+ orig_mode = File.stat(@spec.installation_path).mode
+ File.chmod 0, @spec.installation_path
+
+ assert_raise Gem::FilePermissionError do
+ @manager.uninstall_doc
+ end
+ ensure
+ File.chmod orig_mode, @spec.installation_path
+ end
+
+end
+
diff --git a/trunk/test/rubygems/test_gem_ext_configure_builder.rb b/trunk/test/rubygems/test_gem_ext_configure_builder.rb
new file mode 100644
index 0000000000..9ce17075bc
--- /dev/null
+++ b/trunk/test/rubygems/test_gem_ext_configure_builder.rb
@@ -0,0 +1,86 @@
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/ext'
+
+class TestGemExtConfigureBuilder < RubyGemTestCase
+
+ def setup
+ super
+
+ @makefile_body = "all:\n\t@echo ok\ninstall:\n\t@echo ok"
+
+ @ext = File.join @tempdir, 'ext'
+ @dest_path = File.join @tempdir, 'prefix'
+
+ FileUtils.mkdir_p @ext
+ FileUtils.mkdir_p @dest_path
+ end
+
+ def test_self_build
+ return if RUBY_PLATFORM =~ /mswin/ # HACK
+
+ File.open File.join(@ext, './configure'), 'w' do |configure|
+ configure.puts "#!/bin/sh\necho \"#{@makefile_body}\" > Makefile"
+ end
+
+ output = []
+
+ Dir.chdir @ext do
+ Gem::Ext::ConfigureBuilder.build nil, nil, @dest_path, output
+ end
+
+ assert_equal "sh ./configure --prefix=#{@dest_path}", output.shift
+ assert_equal "", output.shift
+ assert_equal "make", output.shift
+ assert_match(/^ok$/m, output.shift)
+ assert_equal "make install", output.shift
+ assert_match(/^ok$/m, output.shift)
+ end
+
+ def test_self_build_fail
+ return if RUBY_PLATFORM =~ /mswin/ # HACK
+ output = []
+
+ error = assert_raise Gem::InstallError do
+ Dir.chdir @ext do
+ Gem::Ext::ConfigureBuilder.build nil, nil, @dest_path, output
+ end
+ end
+
+ shell_error_msg = %r{(\./configure: .*)|(Can't open \./configure)}
+ sh_prefix_configure = "sh ./configure --prefix="
+
+ expected = %r(configure failed:
+
+#{Regexp.escape sh_prefix_configure}#{Regexp.escape @dest_path}
+.*?: #{shell_error_msg})
+
+ assert_match expected, error.message
+
+ assert_equal "#{sh_prefix_configure}#{@dest_path}", output.shift
+ assert_match %r(#{shell_error_msg}\n), output.shift
+ assert_equal true, output.empty?
+ end
+
+ def test_self_build_has_makefile
+ File.open File.join(@ext, 'Makefile'), 'w' do |makefile|
+ makefile.puts @makefile_body
+ end
+
+ output = []
+ Dir.chdir @ext do
+ 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
+ end
+
+end
+
diff --git a/trunk/test/rubygems/test_gem_ext_ext_conf_builder.rb b/trunk/test/rubygems/test_gem_ext_ext_conf_builder.rb
new file mode 100644
index 0000000000..fb21fa0755
--- /dev/null
+++ b/trunk/test/rubygems/test_gem_ext_ext_conf_builder.rb
@@ -0,0 +1,122 @@
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/ext'
+
+class TestGemExtExtConfBuilder < RubyGemTestCase
+
+ def setup
+ super
+
+ @ext = File.join @tempdir, 'ext'
+ @dest_path = File.join @tempdir, 'prefix'
+
+ FileUtils.mkdir_p @ext
+ FileUtils.mkdir_p @dest_path
+ end
+
+ def test_class_build
+ File.open File.join(@ext, 'extconf.rb'), 'w' do |extconf|
+ extconf.puts "require 'mkmf'\ncreate_makefile 'foo'"
+ end
+
+ output = []
+
+ Dir.chdir @ext do
+ Gem::Ext::ExtConfBuilder.build 'extconf.rb', nil, @dest_path, output
+ end
+
+ expected = [
+ "ruby extconf.rb",
+ "creating Makefile\n",
+ "make",
+ "make: Nothing to be done for `all'.\n",
+ "make install",
+ "make: Nothing to be done for `install'.\n"
+ ]
+
+ assert_match(/^#{Gem.ruby} extconf.rb/, output[0])
+ assert_equal "creating Makefile\n", output[1]
+ case RUBY_PLATFORM
+ when /mswin/ then
+ assert_equal "nmake", output[2]
+ assert_equal "nmake install", output[4]
+ else
+ assert_equal "make", output[2]
+ assert_equal "make install", output[4]
+ end
+ end
+
+ def test_class_build_extconf_fail
+ File.open File.join(@ext, 'extconf.rb'), 'w' do |extconf|
+ extconf.puts "require 'mkmf'"
+ extconf.puts "have_library 'nonexistent' or abort 'need libnonexistent'"
+ extconf.puts "create_makefile 'foo'"
+ end
+
+ output = []
+
+ error = assert_raise Gem::InstallError do
+ Dir.chdir @ext do
+ Gem::Ext::ExtConfBuilder.build 'extconf.rb', nil, @dest_path, output
+ end
+ end
+
+ assert_match(/\Aextconf failed:
+
+#{Gem.ruby} extconf.rb.*
+checking for main\(\) in .*?nonexistent/m, error.message)
+
+ assert_match(/^#{Gem.ruby} extconf.rb/, output[0])
+ end
+
+ def test_class_make
+ output = []
+ makefile_path = File.join(@ext, 'Makefile')
+ File.open makefile_path, 'w' do |makefile|
+ makefile.puts "RUBYARCHDIR = $(foo)$(target_prefix)"
+ makefile.puts "RUBYLIBDIR = $(bar)$(target_prefix)"
+ makefile.puts "all:"
+ makefile.puts "install:"
+ end
+
+ Dir.chdir @ext do
+ 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
+
+ edited_makefile = <<-EOF
+RUBYARCHDIR = #{@ext}$(target_prefix)
+RUBYLIBDIR = #{@ext}$(target_prefix)
+all:
+install:
+ EOF
+
+ assert_equal edited_makefile, File.read(makefile_path)
+ end
+
+ def test_class_make_no_Makefile
+ error = assert_raise Gem::InstallError do
+ Dir.chdir @ext do
+ Gem::Ext::ExtConfBuilder.make @ext, ['output']
+ end
+ end
+
+ expected = <<-EOF.strip
+Makefile not found:
+
+output
+ EOF
+
+ assert_equal expected, error.message
+ end
+
+end
+
diff --git a/trunk/test/rubygems/test_gem_ext_rake_builder.rb b/trunk/test/rubygems/test_gem_ext_rake_builder.rb
new file mode 100644
index 0000000000..6d9184e804
--- /dev/null
+++ b/trunk/test/rubygems/test_gem_ext_rake_builder.rb
@@ -0,0 +1,76 @@
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/ext'
+
+class TestGemExtRakeBuilder < RubyGemTestCase
+ def setup
+ super
+
+ @ext = File.join @tempdir, 'ext'
+ @dest_path = File.join @tempdir, 'prefix'
+
+ FileUtils.mkdir_p @ext
+ FileUtils.mkdir_p @dest_path
+ end
+
+ def test_class_build
+ File.open File.join(@ext, 'mkrf_conf.rb'), 'w' do |mkrf_conf|
+ mkrf_conf.puts <<-EO_MKRF
+ File.open("Rakefile","w") do |f|
+ f.puts "task :default"
+ end
+ EO_MKRF
+ end
+
+ output = []
+ realdir = nil # HACK /tmp vs. /private/tmp
+
+ build_rake_in do
+ Dir.chdir @ext do
+ realdir = Dir.pwd
+ Gem::Ext::RakeBuilder.build 'mkrf_conf.rb', nil, @dest_path, output
+ end
+ end
+
+ expected = [
+ "#{@@ruby} mkrf_conf.rb",
+ "",
+ "#{@@rake} RUBYARCHDIR=#{@dest_path} RUBYLIBDIR=#{@dest_path}",
+ "(in #{realdir})\n"
+ ]
+
+ assert_equal expected, output
+ end
+
+ def test_class_build_fail
+ File.open File.join(@ext, 'mkrf_conf.rb'), 'w' do |mkrf_conf|
+ mkrf_conf.puts <<-EO_MKRF
+ File.open("Rakefile","w") do |f|
+ f.puts "task :default do abort 'fail' end"
+ end
+ EO_MKRF
+ end
+
+ output = []
+
+ error = assert_raise Gem::InstallError do
+ build_rake_in do
+ Dir.chdir @ext do
+ Gem::Ext::RakeBuilder.build "mkrf_conf.rb", nil, @dest_path, output
+ end
+ end
+ end
+
+ expected = <<-EOF.strip
+rake failed:
+
+#{@@ruby} mkrf_conf.rb
+
+#{@@rake} RUBYARCHDIR=#{@dest_path} RUBYLIBDIR=#{@dest_path}
+ EOF
+
+ assert_equal expected, error.message.split("\n")[0..4].join("\n")
+ end
+
+end
+
diff --git a/trunk/test/rubygems/test_gem_format.rb b/trunk/test/rubygems/test_gem_format.rb
new file mode 100644
index 0000000000..4014acfed9
--- /dev/null
+++ b/trunk/test/rubygems/test_gem_format.rb
@@ -0,0 +1,69 @@
+#--
+# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
+# All rights reserved.
+# See LICENSE.txt for permissions.
+#++
+
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require File.join(File.expand_path(File.dirname(__FILE__)), 'simple_gem')
+require 'rubygems/format'
+
+class TestGemFormat < RubyGemTestCase
+
+ def setup
+ super
+
+ @simple_gem = SIMPLE_GEM
+ end
+
+ def test_from_file_by_path
+ util_make_gems
+
+ gems = Dir[File.join(@gemhome, 'cache', '*.gem')]
+
+ names = [@a1, @a2, @a_evil9, @b2, @c1_2, @pl1].map do |spec|
+ spec.original_name
+ end
+
+ gems_n_names = gems.sort.zip names
+
+ gems_n_names.each do |gemfile, name|
+ spec = Gem::Format.from_file_by_path(gemfile).spec
+
+ assert_equal name, spec.original_name
+ end
+ end
+
+ def test_from_file_by_path_nonexistent
+ assert_raise Gem::Exception do
+ Gem::Format.from_file_by_path '/nonexistent'
+ end
+ end
+
+ def test_from_io_garbled
+ e = assert_raise Gem::Package::FormatError do
+ # subtly bogus input
+ Gem::Format.from_io(StringIO.new(@simple_gem.upcase))
+ end
+
+ assert_equal 'No metadata found!', e.message
+
+ e = assert_raise Gem::Package::FormatError do
+ # Totally bogus input
+ Gem::Format.from_io(StringIO.new(@simple_gem.reverse))
+ end
+
+ assert_equal 'No metadata found!', e.message
+
+ e = assert_raise Gem::Package::FormatError do
+ # This was intentionally screws up YAML parsing.
+ Gem::Format.from_io(StringIO.new(@simple_gem.gsub(/:/, "boom")))
+ end
+
+ assert_equal 'No metadata found!', e.message
+ end
+
+end
+
+
diff --git a/trunk/test/rubygems/test_gem_gem_path_searcher.rb b/trunk/test/rubygems/test_gem_gem_path_searcher.rb
new file mode 100644
index 0000000000..c9da4d2b05
--- /dev/null
+++ b/trunk/test/rubygems/test_gem_gem_path_searcher.rb
@@ -0,0 +1,60 @@
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/gem_path_searcher'
+
+class Gem::GemPathSearcher
+ attr_accessor :gemspecs
+ attr_accessor :lib_dirs
+
+ public :init_gemspecs
+ public :matching_file
+ public :lib_dirs_for
+end
+
+class TestGemGemPathSearcher < RubyGemTestCase
+
+ def setup
+ super
+
+ @foo1 = quick_gem 'foo', '0.1' do |s|
+ s.require_paths << 'lib2'
+ s.files << 'lib/foo.rb'
+ end
+
+ path = File.join 'gems', @foo1.full_name, 'lib', 'foo.rb'
+ write_file(path) { |fp| fp.puts "# #{path}" }
+
+ @foo2 = quick_gem 'foo', '0.2'
+ @bar1 = quick_gem 'bar', '0.1'
+ @bar2 = quick_gem 'bar', '0.2'
+
+ @fetcher = Gem::FakeFetcher.new
+ Gem::RemoteFetcher.fetcher = @fetcher
+
+ Gem.source_index = util_setup_spec_fetcher @foo1, @foo2, @bar1, @bar2
+
+ @gps = Gem::GemPathSearcher.new
+ end
+
+ def test_find
+ assert_equal @foo1, @gps.find('foo')
+ end
+
+ def test_init_gemspecs
+ assert_equal [@bar2, @bar1, @foo2, @foo1], @gps.init_gemspecs
+ end
+
+ def test_lib_dirs_for
+ lib_dirs = @gps.lib_dirs_for(@foo1)
+ expected = File.join @gemhome, 'gems', @foo1.full_name, '{lib,lib2}'
+
+ assert_equal expected, lib_dirs
+ end
+
+ def test_matching_file
+ assert !@gps.matching_file(@foo1, 'bar')
+ assert @gps.matching_file(@foo1, 'foo')
+ end
+
+end
+
diff --git a/trunk/test/rubygems/test_gem_gem_runner.rb b/trunk/test/rubygems/test_gem_gem_runner.rb
new file mode 100644
index 0000000000..4e3239f015
--- /dev/null
+++ b/trunk/test/rubygems/test_gem_gem_runner.rb
@@ -0,0 +1,35 @@
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/gem_runner'
+
+class TestGemGemRunner < RubyGemTestCase
+
+ def test_do_configuration
+ Gem.clear_paths
+
+ temp_conf = File.join @tempdir, '.gemrc'
+
+ other_gem_path = File.join @tempdir, 'other_gem_path'
+ other_gem_home = File.join @tempdir, 'other_gem_home'
+
+ Gem.ensure_gem_subdirectories other_gem_path
+ Gem.ensure_gem_subdirectories other_gem_home
+
+ File.open temp_conf, 'w' do |fp|
+ fp.puts "gem: --commands"
+ fp.puts "gemhome: #{other_gem_home}"
+ fp.puts "gempath:"
+ fp.puts " - #{other_gem_path}"
+ fp.puts "rdoc: --all"
+ end
+
+ gr = Gem::GemRunner.new
+ gr.send :do_configuration, %W[--config-file #{temp_conf}]
+
+ assert_equal [other_gem_path, other_gem_home], Gem.path
+ assert_equal %w[--commands], Gem::Command.extra_args
+ assert_equal %w[--all], Gem::DocManager.configured_args
+ end
+
+end
+
diff --git a/trunk/test/rubygems/test_gem_indexer.rb b/trunk/test/rubygems/test_gem_indexer.rb
new file mode 100644