summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-29 06:52:18 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-29 06:52:18 +0000
commit9694bb8cac12969300692dac5a1cf7aa4e3a46cd ()
treec3cb423d701f7049ba9382de052e2a937cd1302d /test
parent3f606b7063fc7a8b191556365ad343a314719a8d (diff)
* lib/rubygems*: Updated to RubyGems 2.0
* test/rubygems*: ditto. * common.mk (prelude): Updated for RubyGems 2.0 source rearrangement. * tool/change_maker.rb: Allow invalid UTF-8 characters in source files. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37976 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--test/rubygems/alternate_cert.pem9
-rw-r--r--test/rubygems/alternate_cert_32.pem9
-rw-r--r--test/rubygems/alternate_key.pem9
-rw-r--r--test/rubygems/bad_rake.rb1
-rw-r--r--test/rubygems/child_cert.pem9
-rw-r--r--test/rubygems/child_cert_32.pem9
-rw-r--r--test/rubygems/child_key.pem9
-rw-r--r--test/rubygems/data/null-type.gemspec.rzbin553 -> 554 bytes
-rw-r--r--test/rubygems/expired_cert.pem9
-rw-r--r--test/rubygems/future_cert.pem9
-rw-r--r--test/rubygems/future_cert_32.pem9
-rw-r--r--test/rubygems/good_rake.rb1
-rw-r--r--test/rubygems/grandchild_cert.pem9
-rw-r--r--test/rubygems/grandchild_cert_32.pem9
-rw-r--r--test/rubygems/grandchild_key.pem9
-rw-r--r--test/rubygems/invalid_issuer_cert.pem9
-rw-r--r--test/rubygems/invalid_issuer_cert_32.pem9
-rw-r--r--test/rubygems/invalid_key.pem9
-rw-r--r--test/rubygems/invalid_signer_cert.pem9
-rw-r--r--test/rubygems/invalid_signer_cert_32.pem9
-rw-r--r--test/rubygems/invalidchild_cert.pem9
-rw-r--r--test/rubygems/invalidchild_cert_32.pem9
-rw-r--r--test/rubygems/invalidchild_key.pem9
-rw-r--r--test/rubygems/plugin/exception/rubygems_plugin.rb2
-rw-r--r--test/rubygems/plugin/standarderror/rubygems_plugin.rb2
-rw-r--r--test/rubygems/private_key.pem32
-rw-r--r--test/rubygems/public_cert.pem26
-rw-r--r--test/rubygems/public_cert_32.pem10
-rw-r--r--test/rubygems/public_key.pem4
-rw-r--r--test/rubygems/rubygems/commands/crash_command.rb2
-rw-r--r--test/rubygems/test_config.rb10
-rw-r--r--test/rubygems/test_deprecate.rb76
-rw-r--r--test/rubygems/test_gem.rb366
-rw-r--r--test/rubygems/test_gem_available_set.rb106
-rw-r--r--test/rubygems/test_gem_builder.rb44
-rw-r--r--test/rubygems/test_gem_command.rb10
-rw-r--r--test/rubygems/test_gem_command_manager.rb64
-rw-r--r--test/rubygems/test_gem_commands_build_command.rb30
-rw-r--r--test/rubygems/test_gem_commands_cert_command.rb483
-rw-r--r--test/rubygems/test_gem_commands_cleanup_command.rb19
-rw-r--r--test/rubygems/test_gem_commands_contents_command.rb23
-rw-r--r--test/rubygems/test_gem_commands_dependency_command.rb5
-rw-r--r--test/rubygems/test_gem_commands_fetch_command.rb39
-rw-r--r--test/rubygems/test_gem_commands_generate_index_command.rb85
-rw-r--r--test/rubygems/test_gem_commands_help_command.rb3
-rw-r--r--test/rubygems/test_gem_commands_install_command.rb695
-rw-r--r--test/rubygems/test_gem_commands_mirror.rb32
-rw-r--r--test/rubygems/test_gem_commands_owner_command.rb12
-rw-r--r--test/rubygems/test_gem_commands_pristine_command.rb103
-rw-r--r--test/rubygems/test_gem_commands_push_command.rb70
-rw-r--r--test/rubygems/test_gem_commands_query_command.rb51
-rw-r--r--test/rubygems/test_gem_commands_search_command.rb25
-rw-r--r--test/rubygems/test_gem_commands_sources_command.rb27
-rw-r--r--test/rubygems/test_gem_commands_specification_command.rb34
-rw-r--r--test/rubygems/test_gem_commands_uninstall_command.rb122
-rw-r--r--test/rubygems/test_gem_commands_unpack_command.rb6
-rw-r--r--test/rubygems/test_gem_commands_update_command.rb94
-rw-r--r--test/rubygems/test_gem_commands_which_command.rb8
-rw-r--r--test/rubygems/test_gem_commands_yank_command.rb97
-rw-r--r--test/rubygems/test_gem_config_file.rb87
-rw-r--r--test/rubygems/test_gem_dependency.rb46
-rw-r--r--test/rubygems/test_gem_dependency_installer.rb246
-rw-r--r--test/rubygems/test_gem_dependency_list.rb9
-rw-r--r--test/rubygems/test_gem_dependency_resolver.rb327
-rw-r--r--test/rubygems/test_gem_doc_manager.rb32
-rw-r--r--test/rubygems/test_gem_ext_ext_conf_builder.rb13
-rw-r--r--test/rubygems/test_gem_ext_rake_builder.rb26
-rw-r--r--test/rubygems/test_gem_format.rb88
-rw-r--r--test/rubygems/test_gem_gem_path_searcher.rb94
-rw-r--r--test/rubygems/test_gem_gem_runner.rb32
-rw-r--r--test/rubygems/test_gem_gemcutter_utilities.rb19
-rw-r--r--test/rubygems/test_gem_indexer.rb295
-rw-r--r--test/rubygems/test_gem_install_update_options.rb86
-rw-r--r--test/rubygems/test_gem_installer.rb405
-rw-r--r--test/rubygems/test_gem_local_remote_options.rb10
-rw-r--r--test/rubygems/test_gem_name_tuple.rb15
-rw-r--r--test/rubygems/test_gem_package.rb547
-rw-r--r--test/rubygems/test_gem_package_old.rb37
-rw-r--r--test/rubygems/test_gem_package_tar_input.rb129
-rw-r--r--test/rubygems/test_gem_package_tar_output.rb101
-rw-r--r--test/rubygems/test_gem_package_tar_reader.rb32
-rw-r--r--test/rubygems/test_gem_package_tar_writer.rb85
-rw-r--r--test/rubygems/test_gem_path_support.rb34
-rw-r--r--test/rubygems/test_gem_platform.rb12
-rw-r--r--test/rubygems/test_gem_rdoc.rb245
-rw-r--r--test/rubygems/test_gem_remote_fetcher.rb73
-rw-r--r--test/rubygems/test_gem_request_set.rb70
-rw-r--r--test/rubygems/test_gem_requirement.rb61
-rw-r--r--test/rubygems/test_gem_security.rb232
-rw-r--r--test/rubygems/test_gem_security_policy.rb376
-rw-r--r--test/rubygems/test_gem_security_signer.rb189
-rw-r--r--test/rubygems/test_gem_security_trust_dir.rb94
-rw-r--r--test/rubygems/test_gem_server.rb67
-rw-r--r--test/rubygems/test_gem_source.rb188
-rw-r--r--test/rubygems/test_gem_source_index.rb250
-rw-r--r--test/rubygems/test_gem_source_list.rb87
-rw-r--r--test/rubygems/test_gem_source_local.rb83
-rw-r--r--test/rubygems/test_gem_source_specific_file.rb33
-rw-r--r--test/rubygems/test_gem_spec_fetcher.rb346
-rw-r--r--test/rubygems/test_gem_specification.rb338
-rw-r--r--test/rubygems/test_gem_uninstaller.rb147
-rw-r--r--test/rubygems/test_gem_validator.rb55
-rw-r--r--test/rubygems/test_gem_version.rb25
-rw-r--r--test/rubygems/test_require.rb193
-rw-r--r--test/rubygems/wrong_key_cert.pem9
-rw-r--r--test/rubygems/wrong_key_cert_32.pem9
106 files changed, 6736 insertions, 2240 deletions
@@ -0,0 +1,9 @@
@@ -0,0 +1,9 @@
@@ -0,0 +1,9 @@
@@ -0,0 +1 @@
@@ -0,0 +1,9 @@
@@ -0,0 +1,9 @@
@@ -0,0 +1,9 @@
Binary files differ
@@ -0,0 +1,9 @@
@@ -0,0 +1,9 @@
@@ -0,0 +1,9 @@
@@ -0,0 +1 @@
@@ -0,0 +1,9 @@
@@ -0,0 +1,9 @@
@@ -0,0 +1,9 @@
@@ -0,0 +1,9 @@
@@ -0,0 +1,9 @@
@@ -0,0 +1,9 @@
@@ -0,0 +1,9 @@
@@ -0,0 +1,9 @@
@@ -0,0 +1,9 @@
@@ -0,0 +1,9 @@
@@ -0,0 +1,9 @@
@@ -1,2 +1,2 @@
TestGem::TEST_PLUGIN_EXCEPTION = :loaded
-raise Exception.new('boom') \ No newline at end of file
@@ -1,2 +1,2 @@
TestGem::TEST_PLUGIN_STANDARDERROR = :loaded
-raise StandardError.new('boom') \ No newline at end of file
@@ -1,27 +1,9 @@
-----BEGIN RSA PRIVATE KEY-----
-MIIEpAIBAAKCAQEAm24C6xixiAxO+i1f3L8XRMwrmLkt6BvT60mZ7g8HsklH3af7
-KNHA6vo/G6sujs2UsNO4HY8BTEneiVOXXWQlcsJ+Z5wEPlIu4zFueAmLefx+n9lE
-ulNIUDoyUenKX4spoMRnX8k4lXL05ho/6JFq0JdDY2DmAaQ4vvTz5mh9kZiybtHQ
-fzcpbA51uY+sjdQRCPDHyUUfh0SmWJlLYMwcBdVeCiGUPBLi+iP5x1btO4uiJK6Q
-IMaV1H3SUCYtKGQKl7qwFd8k8ZBcHYOtmK61tupg3vqWQc0em6SxPj5lws8+1MVK
-twBNIDx24jF4ntxBRNKMZ7FN5SbAgDYkPAQIDAQABAoIBAGQilgK8X/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-----
@@ -1,20 +1,10 @@
-----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-----
@@ -0,0 +1,10 @@
@@ -0,0 +1,4 @@
@@ -2,4 +2,4 @@ class Gem::Commands::CrashCommand < Gem::Command
raise "crash"
-end \ No newline at end of file
@@ -4,12 +4,10 @@ require 'rubygems'
class TestConfig < Gem::TestCase
def test_datadir
- _, err = capture_io do
- datadir = RbConfig::CONFIG['datadir']
- assert_equal "#{datadir}/xyz", RbConfig.datadir('xyz')
- end
-
- assert_match(/deprecate/, err)
end
end
@@ -0,0 +1,76 @@
@@ -1,21 +1,22 @@
require 'rubygems/test_case'
require 'rubygems'
-require 'rubygems/gem_openssl'
require 'rubygems/installer'
require 'pathname'
require 'tmpdir'
class TestGem < Gem::TestCase
def setup
super
@additional = %w[a b].map { |d| File.join @tempdir, d }
- @default_dir_re = if RUBY_VERSION > '1.9' then
- %r|/.*?[Rr]uby.*?/[Gg]ems/[0-9.]+|
- else
- %r|/[Rr]uby/[Gg]ems/[0-9.]+|
- end
util_remove_interrupt_command
end
@@ -48,7 +49,7 @@ class TestGem < Gem::TestCase
end
def unresolved_names
- Gem.unresolved_deps.values.map(&:to_s).sort
end
# TODO: move these to specification
@@ -60,7 +61,9 @@ class TestGem < Gem::TestCase
install_specs a1, b1, b2
a1.activate
- require "b/c"
assert_equal %w(a-1 b-1), loaded_spec_names
end
@@ -131,6 +134,82 @@ class TestGem < Gem::TestCase
end
end
# TODO: move these to specification
def test_self_activate_ambiguous_unrelated
save_loaded_features do
@@ -456,16 +535,6 @@ class TestGem < Gem::TestCase
assert_activate %w[d-1 e-1], e1, "d"
end
- def test_self_available?
- util_make_gems
- Gem::Deprecate.skip_during do
- assert(Gem.available?("a"))
- assert(Gem.available?("a", "1"))
- assert(Gem.available?("a", ">1"))
- assert(!Gem.available?("monkeys"))
- end
- end
-
def test_self_bin_path_no_exec_name
e = assert_raises ArgumentError do
Gem.bin_path 'a'
@@ -523,14 +592,8 @@ class TestGem < Gem::TestCase
def test_self_bindir_default_dir
default = Gem.default_dir
- bindir = if defined?(RUBY_FRAMEWORK_VERSION) then
- '/usr/bin'
- else
- RbConfig::CONFIG['bindir']
- end
- assert_equal bindir, Gem.bindir(default)
- assert_equal bindir, Gem.bindir(Pathname.new(default))
end
def test_self_clear_paths
@@ -573,10 +636,6 @@ class TestGem < Gem::TestCase
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_RUBY_INSTALL_NAME = Gem::ConfigMap[:ruby_install_name]
Gem::ConfigMap[:ruby_install_name] = 'ruby'
@@ -681,19 +740,6 @@ class TestGem < Gem::TestCase
end
end
- def test_ensure_ssl_available
- orig_Gem_ssl_available = Gem.ssl_available?
-
- Gem.ssl_available = true
- Gem.ensure_ssl_available
-
- Gem.ssl_available = false
- e = assert_raises 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_find_files
cwd = File.expand_path("test/rubygems", @@project_dir)
$LOAD_PATH.unshift cwd
@@ -756,7 +802,7 @@ class TestGem < Gem::TestCase
Gem.instance_variable_set :@paths, nil
- assert_equal [Gem.dir, *Gem.default_path].uniq, Gem.path
ensure
Object.const_set :APPLE_GEM_HOME, orig_APPLE_GEM_HOME if orig_APPLE_GEM_HOME
end
@@ -795,10 +841,11 @@ class TestGem < Gem::TestCase
ENV['GEM_PATH'] = @additional.join(File::PATH_SEPARATOR)
- assert_equal [Gem.dir, *@additional], Gem.path
assert_equal path_count + @additional.size, Gem.path.size,
"extra path components: #{Gem.path[2..-1].inspect}"
end
def test_self_path_duplicate
@@ -811,7 +858,8 @@ class TestGem < Gem::TestCase
assert_equal @gemhome, Gem.dir
- assert_equal [Gem.dir, *@additional], Gem.path
end
def test_self_path_overlap
@@ -823,7 +871,8 @@ class TestGem < Gem::TestCase
assert_equal @gemhome, Gem.dir
- assert_equal [Gem.dir, *@additional], Gem.path
end
def test_self_platforms
@@ -933,6 +982,10 @@ class TestGem < Gem::TestCase
util_restore_RUBY_VERSION
end
def test_self_paths_eq
other = File.join @tempdir, 'other'
path = [@userhome, other].join File::PATH_SEPARATOR
@@ -943,7 +996,7 @@ class TestGem < Gem::TestCase
ENV["GEM_HOME"] = @gemhome
Gem.paths = { "GEM_PATH" => path }
- assert_equal [@gemhome, @userhome, other], Gem.path
end
def test_self_paths_eq_nonexistent_home
@@ -956,13 +1009,71 @@ class TestGem < Gem::TestCase
Gem.paths = { "GEM_PATH" => other }
- assert_equal [@gemhome, other], Gem.path
end
- def test_self_source_index
- Gem::Deprecate.skip_during do
- assert_kind_of Gem::SourceIndex, Gem.source_index
- end
end
def test_self_sources
@@ -982,19 +1093,7 @@ class TestGem < Gem::TestCase
Gem.try_activate 'a_file'
end
- assert_match %r%Could not find b %, e.message
- 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
@@ -1003,7 +1102,7 @@ class TestGem < Gem::TestCase
Gem.use_paths @gemhome, @additional
assert_equal @gemhome, Gem.dir
- assert_equal [Gem.dir, *@additional], Gem.path
end
def test_self_user_dir
@@ -1019,6 +1118,46 @@ class TestGem < Gem::TestCase
end
end
if Gem.win_platform? && '1.9' > RUBY_VERSION
# Ruby 1.9 properly handles ~ path expansion, so no need to run such tests.
def test_self_user_home_userprofile
@@ -1105,23 +1244,6 @@ class TestGem < Gem::TestCase
assert_equal :loaded, TEST_PLUGIN_EXCEPTION rescue nil
end
- def test_latest_load_paths
- spec = quick_spec 'a', '4' do |s|
- s.require_paths = ["lib"]
- end
-
- install_gem spec
-
- # @exec_path = File.join spec.full_gem_path, spec.bindir, 'exec'
- # @abin_path = File.join spec.full_gem_path, spec.bindir, 'abin'
- # FileUtils.mkdir_p File.join(stem, "gems", "test-3")
-
- Gem::Deprecate.skip_during do
- expected = [File.join(@gemhome, "gems", "a-4", "lib")]
- assert_equal expected, Gem.latest_load_paths
- end
- end
-
def test_gem_path_ordering
refute_equal Gem.dir, Gem.user_dir
@@ -1202,6 +1324,84 @@ class TestGem < Gem::TestCase
"Wrong spec selected"
end
def with_plugin(path)
test_plugin_path = File.expand_path("test/rubygems/plugin/#{path}",
@@project_dir)
@@ -0,0 +1,106 @@
@@ -1,44 +0,0 @@
-require 'rubygems/test_case'
-require 'rubygems/builder'
-require 'rubygems/package'
-
-class TestGemBuilder < Gem::TestCase
-
- def test_build
- builder = Gem::Builder.new quick_spec('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
-
- def test_build_specification_result
- util_make_gems
-
- spec = build_gem_and_yield_spec @a1
-
- assert_operator @a1, :eql?, spec
- end
-
- def build_gem_and_yield_spec(spec)
- builder = Gem::Builder.new spec
-
- spec = Dir.chdir @tempdir do
- FileUtils.mkdir 'lib'
- File.open('lib/code.rb', 'w') { |f| f << "something" }
- Gem::Package.open(File.open(builder.build, 'rb')) { |x| x.metadata }
- end
- end
-end
@@ -109,6 +109,16 @@ class TestGemCommand < Gem::TestCase
assert @xopt, "Should have done xopt"
end
# Returning false from the command handler invokes the usage output.
def test_invoke_with_help
done = false
@@ -6,7 +6,47 @@ class TestGemCommandManager < Gem::TestCase
def setup
super
- @command_manager = Gem::CommandManager.instance
end
def test_run_interrupt
@@ -14,6 +54,8 @@ class TestGemCommandManager < Gem::TestCase
$: << File.expand_path("test/rubygems", @@project_dir)
Gem.load_env_plugins
use_ui @ui do
assert_raises Gem::MockGemUi::TermError do
@command_manager.run 'interrupt'
@@ -54,6 +96,7 @@ class TestGemCommandManager < Gem::TestCase
assert_match(/invalid option: --bad-arg/i, @ui.error)
end
def test_process_args_install
#capture all install options
use_ui @ui do
@@ -65,7 +108,7 @@ class TestGemCommandManager < Gem::TestCase
#check defaults
@command_manager.process_args("install")
- 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]
@@ -77,7 +120,7 @@ class TestGemCommandManager < Gem::TestCase
check_options = nil
@command_manager.process_args(
"install --force --local --rdoc --install-dir . --version 3.0 --no-wrapper --bindir . ")
- 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]
@@ -102,6 +145,7 @@ class TestGemCommandManager < Gem::TestCase
end
end
def test_process_args_uninstall
#capture all uninstall options
check_options = nil
@@ -121,6 +165,7 @@ class TestGemCommandManager < Gem::TestCase
assert_equal Gem::Requirement.new('3.0'), check_options[:version]
end
def test_process_args_check
#capture all check options
check_options = nil
@@ -131,16 +176,15 @@ class TestGemCommandManager < Gem::TestCase
#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
@@ -159,6 +203,7 @@ class TestGemCommandManager < Gem::TestCase
assert_equal 'foobar.rb', check_options[:args].first
end
def test_process_args_query
#capture all query options
check_options = nil
@@ -191,6 +236,7 @@ class TestGemCommandManager < Gem::TestCase
assert_equal :both, check_options[:domain]
end
def test_process_args_update
#capture all update options
check_options = nil
@@ -201,12 +247,12 @@ class TestGemCommandManager < Gem::TestCase
#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 --rdoc --install-dir .")
- assert_equal true, check_options[:generate_rdoc]
assert_equal true, check_options[:force]
assert_equal Dir.pwd, check_options[:install_dir]
end
@@ -1,6 +1,6 @@
require 'rubygems/test_case'
require 'rubygems/commands/build_command'
-require 'rubygems/format'
class TestGemCommandsBuildCommand < Gem::TestCase
@@ -24,16 +24,6 @@ class TestGemCommandsBuildCommand < Gem::TestCase
util_test_build_gem @gem, gemspec_file
end
- def test_execute_yaml
- gemspec_file = File.join(@tempdir, @gem.spec_name)
-
- 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_spec
@gem.date = "2010-11-08"
@@ -72,7 +62,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase
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
@@ -87,32 +77,34 @@ class TestGemCommandsBuildCommand < Gem::TestCase
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, File.basename(gem.cache_file)
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
def test_execute_force
- @gem.instance_variable_set :@required_rubygems_version, nil
-
gemspec_file = File.join(@tempdir, @gem.spec_name)
File.open gemspec_file, 'w' do |gs|
- gs.write @gem.to_yaml
end
@cmd.options[:args] = [gemspec_file]
@cmd.options[:force] = true
- util_test_build_gem @gem, gemspec_file
end
-
end
@@ -8,117 +8,516 @@ end
class TestGemCommandsCertCommand < Gem::TestCase
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__), @@project_dir)
- 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 [email protected]]
- 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),
- @cmd.options[: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),
- @cmd.options[: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
- refute 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
@@ -85,5 +85,24 @@ class TestGemCommandsCleanupCommand < Gem::TestCase
assert_path_exists @a_1.gem_dir
end
end
@@ -127,6 +127,29 @@ lib/foo.rb
assert_equal "", @ui.error
end
def test_handle_options
refute @cmd.options[:lib_only]
assert @cmd.options[:prefix]
@@ -51,8 +51,13 @@ Gem b-2
Gem c-1.2
Gem pl-1-x86-linux
EOF
assert_equal expected, @ui.output
@@ -26,8 +26,8 @@ class TestGemCommandsFetchCommand < Gem::TestCase
end
end
- assert File.exist?(File.join(@tempdir, @a2.file_name)),
- "#{@a2.full_name} not fetched"
end
def test_execute_prerelease
@@ -49,19 +49,23 @@ class TestGemCommandsFetchCommand < Gem::TestCase
end
end
- assert File.exist?(File.join(@tempdir, @a2_pre.file_name)),
- "#{@a2_pre.full_name} not fetched"
end
- def test_execute_version
- util_setup_fake_fetcher
- util_setup_spec_fetcher @a1, @a2
- @fetcher.data["#{@gem_repo}gems/#{@a1.file_name}"] =
- File.read(@a1.cache_file)
@cmd.options[:args] = [@a2.name]
- @cmd.options[:version] = Gem::Requirement.new '1'
use_ui @ui do
Dir.chdir @tempdir do
@@ -69,16 +73,11 @@ class TestGemCommandsFetchCommand < Gem::TestCase
end
end
- assert File.exist?(File.join(@tempdir, @a1.file_name)),
- "#{@a1.full_name} not fetched"
end
- def test_execute_handles_sources_properly
- repo = "http://gems.example.com"
- @uri = URI.parse repo
-
- Gem.sources.replace [repo]
-
util_setup_fake_fetcher
util_setup_spec_fetcher @a1, @a2
@@ -94,8 +93,8 @@ class TestGemCommandsFetchCommand < Gem::TestCase
end
end
- assert File.exist?(File.join(@tempdir, @a1.file_name)),
- "#{@a1.full_name} not fetched"
end
end
@@ -16,27 +16,9 @@ class TestGemCommandsGenerateIndexCommand < Gem::TestCase
@cmd.execute
end
- marshal = File.join @gemhome, 'Marshal.4.8'
- marshal_z = File.join @gemhome, 'Marshal.4.8.Z'
- assert File.exist?(marshal), marshal
- assert File.exist?(marshal_z), marshal_z
- end
-
- def test_execute_rss_update
- @cmd.options[:update] = true
- @cmd.options[:rss_host] = 'example.com'
- @cmd.options[:rss_gems_host] = 'gems.example.com'
-
- use_ui @ui do
- assert_raises Gem::MockGemUi::TermError do
- @cmd.execute
- end
- end
-
- assert_equal "ERROR: --update not compatible with RSS generation\n",
- @ui.error
- assert_empty @ui.output
end
def test_handle_options_directory
@@ -58,69 +40,6 @@ class TestGemCommandsGenerateIndexCommand < Gem::TestCase
assert_equal 'C:/nonexistent', @cmd.options[:directory]
end
- def test_handle_options_invalid
- e = assert_raises OptionParser::InvalidOption do
- @cmd.handle_options %w[--no-modern --no-legacy]
- end
-
- assert_equal 'invalid option: --no-legacy no indicies will be built',
- e.message
-
- @cmd = Gem::Commands::GenerateIndexCommand.new
- e = assert_raises OptionParser::InvalidOption do
- @cmd.handle_options %w[--no-legacy --no-modern]
- end
-
- assert_equal 'invalid option: --no-modern no indicies will be built',
- e.message
- end
-
- def test_handle_options_legacy
- @cmd.handle_options %w[--legacy]
-
- assert @cmd.options[:build_legacy]
- assert @cmd.options[:build_modern], ':build_modern not set'
- end
-
- def test_handle_options_modern
- @cmd.handle_options %w[--modern]
-
- assert @cmd.options[:build_legacy]
- assert @cmd.options[:build_modern], ':build_modern not set'
- end
-
- def test_handle_options_no_legacy
- @cmd.handle_options %w[--no-legacy]
-
- refute @cmd.options[:build_legacy]
- assert @cmd.options[:build_modern]
- end
-
- def test_handle_options_no_modern
- @cmd.handle_options %w[--no-modern]
-
- assert @cmd.options[:build_legacy]
- refute @cmd.options[:build_modern]
- end
-
- def test_handle_options_rss_gems_host
- @cmd.handle_options %w[--rss-gems-host gems.example.com]
-
- assert_equal 'gems.example.com', @cmd.options[:rss_gems_host]
- end
-
- def test_handle_options_rss_host
- @cmd.handle_options %w[--rss-host example.com]
-
- assert_equal 'example.com', @cmd.options[:rss_host]
- end
-
- def test_handle_options_rss_title
- @cmd.handle_options %w[--rss-title Example\ Gems]
-
- assert_equal 'Example Gems', @cmd.options[:rss_title]
- end
-
def test_handle_options_update
@cmd.handle_options %w[--update]
@@ -1,8 +1,9 @@
require "rubygems"
require "rubygems/test_case"
require "rubygems/commands/help_command"
-require "rubygems/format"
require "rubygems/command_manager"
class TestGemCommandsHelpCommand < Gem::TestCase
def setup
@@ -1,21 +1,23 @@
require 'rubygems/test_case'
require 'rubygems/commands/install_command'
-begin
- gem "rdoc"
- gem "json"
-rescue Gem::LoadError
- # ignore
-end
-
class TestGemCommandsInstallCommand < Gem::TestCase
def setup
super
@cmd = Gem::Commands::InstallCommand.new
- @cmd.options[:generate_rdoc] = false
- @cmd.options[:generate_ri] = false
end
def test_execute_exclude_prerelease
@@ -36,8 +38,7 @@ class TestGemCommandsInstallCommand < Gem::TestCase
assert_equal 0, e.exit_code, @ui.error
end
- assert_match(/Successfully installed #{@a2.full_name}$/, @ui.output)
- refute_match(/Successfully installed #{@a2_pre.full_name}$/, @ui.output)
end
def test_execute_explicit_version_includes_prerelease
@@ -61,26 +62,7 @@ class TestGemCommandsInstallCommand < Gem::TestCase
assert_equal 0, e.exit_code, @ui.error
end
- refute_match(/Successfully installed #{@a2.full_name}$/, @ui.output)
- assert_match(/Successfully installed #{@a2_pre.full_name}$/, @ui.output)
- end
-
- def test_execute_include_dependencies
- @cmd.options[:include_dependencies] = true
- @cmd.options[:args] = []
-
- assert_raises 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
@@ -104,13 +86,14 @@ class TestGemCommandsInstallCommand < Gem::TestCase
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_no_user_install
skip 'skipped on MS Windows (chmod has no effect)' if win_platform?
util_setup_fake_fetcher
@@ -206,8 +189,8 @@ class TestGemCommandsInstallCommand < Gem::TestCase
errs = @ui.error.split("\n")
- assert_match(/WARNING: Error fetching data/, errs.shift)
assert_match(/ould not find a valid gem 'nonexistent'/, errs.shift)
end
def test_execute_nonexistent_with_hint
@@ -234,7 +217,92 @@ ERROR: Possible alternatives: non_existent_with_hint
assert_equal expected, @ui.error
end
- def test_execute_prerelease
util_setup_fake_fetcher :prerelease
util_clear_gems
util_setup_spec_fetcher @a2, @a2_pre
@@ -254,14 +322,82 @@ ERROR: Possible alternatives: non_existent_with_hint
assert_equal 0, e.exit_code, @ui.error
end
- refute_match(/Successfully installed #{@a2.full_name}$/, @ui.output)
- assert_match(/Successfully installed #{@a2_pre.full_name}$/, @ui.output)
end
- def test_execute_remote
- @cmd.options[:generate_rdoc] = true
- @cmd.options[:generate_ri] = true
util_setup_fake_fetcher
util_setup_spec_fetcher
@@ -279,16 +415,56 @@ ERROR: Possible alternatives: non_existent_with_hint
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
@@ -312,13 +488,33 @@ ERROR: Possible alternatives: non_existent_with_hint
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
def test_execute_conservative
util_setup_fake_fetcher
util_setup_spec_fetcher
@@ -344,11 +540,414 @@ ERROR: Possible alternatives: non_existent_with_hint
end
end
out = @ui.output.split "\n"
assert_equal "", @ui.error
- assert_equal "Successfully installed #{@b2.full_name}", out.shift
assert_equal "1 gem installed", out.shift
assert out.empty?, out.inspect
end
end
@@ -0,0 +1,32 @@
@@ -80,10 +80,8 @@ EOF
response = "You don't have permission to push to this gem"
@fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 403, 'Forbidden']
- assert_raises Gem::MockGemUi::TermError do
- use_ui @ui do
- @cmd.add_owners("freewill", ["[email protected]"])
- end
end
assert_match response, @ui.output
@@ -122,10 +120,8 @@ EOF
response = "You don't have permission to push to this gem"
@fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 403, 'Forbidden']
- assert_raises Gem::MockGemUi::TermError do
- use_ui @ui do
- @cmd.remove_owners("freewill", ["[email protected]"])
- end
end
assert_match response, @ui.output
@@ -9,20 +9,31 @@ class TestGemCommandsPristineCommand < Gem::TestCase
end
def test_execute
- a = quick_spec 'a' do |s| s.executables = %w[foo] end
write_file File.join(@tempdir, 'bin', 'foo') do |fp|
fp.puts "#!/usr/bin/ruby"
end
install_gem a
- foo_path = File.join @gemhome, 'gems', a.full_name, 'bin', 'foo'
write_file foo_path do |io|
io.puts 'I changed it!'
end
@cmd.options[:args] = %w[a]
use_ui @ui do
@@ -30,6 +41,7 @@ class TestGemCommandsPristineCommand < Gem::TestCase
end
assert_equal "#!/usr/bin/ruby\n", File.read(foo_path), foo_path
out = @ui.output.split "\n"
@@ -46,9 +58,11 @@ class TestGemCommandsPristineCommand < Gem::TestCase
install_gem a
- gem_bin = File.join @gemhome, 'gems', a.full_name, 'bin', 'foo'
FileUtils.rm gem_bin
@cmd.handle_options %w[--all]
@@ -57,6 +71,7 @@ class TestGemCommandsPristineCommand < Gem::TestCase
end
assert File.exist?(gem_bin)
out = @ui.output.split "\n"
@@ -65,7 +80,7 @@ class TestGemCommandsPristineCommand < Gem::TestCase
assert_empty out, out.inspect
end
- def test_execute_no_exetension
a = quick_spec 'a' do |s| s.extensions << 'ext/a/extconf.rb' end
ext_path = File.join @tempdir, 'ext', 'a', 'extconf.rb'
@@ -90,6 +105,38 @@ class TestGemCommandsPristineCommand < Gem::TestCase
assert_empty out, out.inspect
end
def test_execute_many
a = quick_spec 'a'
b = quick_spec 'b'
@@ -195,5 +242,53 @@ class TestGemCommandsPristineCommand < Gem::TestCase
assert_match %r|at least one gem name|, e.message
end
end
@@ -13,6 +13,9 @@ class TestGemCommandsPushCommand < Gem::TestCase
def setup
super
@gems_dir = File.join @tempdir, 'gems'
@cache_dir = File.join @gemhome, "cache"
@@ -23,6 +26,8 @@ class TestGemCommandsPushCommand < Gem::TestCase
"ed244fbf2b1a52e012da8616c512fa47f9aa5250"
@spec, @path = util_gem "freewill", "1.0.0"
@fetcher = Gem::FakeFetcher.new
Gem::RemoteFetcher.fetcher = @fetcher
@@ -35,35 +40,84 @@ class TestGemCommandsPushCommand < Gem::TestCase
@cmd.send_gem(@path)
end
- assert_match %r{Pushing gem to #{Gem.host}...}, @ui.output
assert_equal Net::HTTP::Post, @fetcher.last_request.class
assert_equal Gem.read_binary(@path), @fetcher.last_request.body
assert_equal File.size(@path), @fetcher.last_request["Content-Length"].to_i
assert_equal "application/octet-stream", @fetcher.last_request["Content-Type"]
- assert_equal Gem.configuration.rubygems_api_key, @fetcher.last_request["Authorization"]
assert_match @response, @ui.output
end
def test_sending_gem_default
@response = "Successfully registered gem: freewill (1.0.0)"
- @fetcher.data["#{Gem.host}/api/v1/gems"] = [@response, 200, 'OK']
send_battery
end
def test_sending_gem_host
@response = "Successfully registered gem: freewill (1.0.0)"
- @fetcher.data["#{Gem.host}/api/v1/gems"] = [@response, 200, 'OK']
- @cmd.options[:host] = "#{Gem.host}"
send_battery
end
def test_sending_gem_ENV
@response = "Successfully registered gem: freewill (1.0.0)"
- @fetcher.data["#{Gem.host}/api/v1/gems"] = [@response, 200, 'OK']
ENV["RUBYGEMS_HOST"] = "#{Gem.host}"
send_battery
@@ -78,7 +132,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
def test_sending_gem_denied
response = "You don't have permission to push to this gem"
- @fetcher.data["#{Gem.host}/api/v1/gems"] = [response, 403, 'Forbidden']
assert_raises Gem::MockGemUi::TermError do
use_ui @ui do
@@ -91,7 +145,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
def test_sending_gem_key
@response = "Successfully registered gem: freewill (1.0.0)"
- @fetcher.data["#{Gem.host}/api/v1/gems"] = [@response, 200, "OK"]
File.open Gem.configuration.credentials_path, 'a' do |f|
f.write ':other: 701229f217cdf23b1344c7b4b54ca97'
end
@@ -349,5 +349,56 @@ pl (1 i386-linux)
assert_equal "WARNING: prereleases are always shown locally\n", @ui.error
end
end
@@ -0,0 +1,25 @@
@@ -99,6 +99,25 @@ Error fetching http://beta-gems.example.com:
assert_equal '', @ui.error
end
def test_execute_add_bad_uri
@cmd.handle_options %w[--add beta-gems.example.com]
@@ -125,11 +144,6 @@ beta-gems.example.com is not a URI
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
@@ -141,7 +155,8 @@ beta-gems.example.com is not a URI
assert_equal expected, @ui.output
assert_equal '', @ui.error
- refute File.exist?(fetcher.dir), 'cache dir removed'
end
def test_execute_remove
@@ -71,7 +71,21 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase
end
assert_equal '', @ui.output
- assert_equal "ERROR: Unknown gem 'foo'\n", @ui.error
end
def test_execute_exact_match
@@ -103,6 +117,24 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase
assert_equal "foo", YAML.load(@ui.output)
end
def test_execute_marshal
foo = new_spec 'foo', '2'
@@ -13,49 +13,32 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
end
@cmd = Gem::Commands::UninstallCommand.new
- @cmd.options[:executables] = true
@executable = File.join(@gemhome, 'bin', 'executable')
end
- def test_execute_mulitple
- @other = quick_gem 'c'
- util_make_exec @other
- util_build_gem @other
-
- @other_installer = util_installer @other, @gemhome
-
- ui = Gem::MockGemUi.new
- util_setup_gem ui
-
- build_rake_in do
- use_ui ui do
- @other_installer.install
- end
- end
-
- @cmd.options[:args] = [@spec.name, @other.name]
-
- use_ui @ui do
- @cmd.execute
end
- output = @ui.output.split "\n"
- assert_includes output, "Successfully uninstalled #{@spec.full_name}"
- assert_includes output, "Successfully uninstalled #{@other.full_name}"
- end
- def test_execute_mulitple_nonexistent
- @cmd.options[:args] = %w[x y]
- use_ui @ui do
@cmd.execute
end
- output = @ui.output.split "\n"
- assert_includes output, 'INFO: gem "x" is not installed'
- assert_includes output, 'INFO: gem "y" is not installed'
end
def test_execute_removes_executable
@@ -79,6 +62,7 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
open @executable, "wb+" do |f| f.puts "binary" end
@cmd.options[:args] = [@spec.name]
use_ui @ui do
@cmd.execute
@@ -102,6 +86,7 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
formatted_executable = File.join @gemhome, 'bin', 'foo-executable-bar'
assert_equal true, File.exist?(formatted_executable)
@cmd.options[:format_executable] = true
@cmd.execute
@@ -123,6 +108,7 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
end
end
@cmd.options[:args] = ["pre"]
use_ui @ui do
@@ -133,5 +119,79 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
assert_match(/Successfully uninstalled/, output)
end
end
@@ -191,8 +191,8 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
use_ui @ui do
Dir.chdir @tempdir do
- Gem::Builder.new(foo_spec).build
- Gem::Builder.new(foo_bar_spec).build
end
end
@@ -209,7 +209,7 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
end
end
- assert File.exist?(File.join(@tempdir, foo_spec.full_name))
end
def test_handle_options_metadata
@@ -14,20 +14,22 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
@cmd = Gem::Commands::UpdateCommand.new
- @cmd.options[:generate_rdoc] = false
- @cmd.options[:generate_ri] = false
- util_setup_fake_fetcher
util_clear_gems
- util_setup_spec_fetcher @a1, @a2
@a1_path = @a1.cache_file
@a2_path = @a2.cache_file
@fetcher.data["#{@gem_repo}gems/#{File.basename @a1_path}"] =
read_binary @a1_path
@fetcher.data["#{@gem_repo}gems/#{File.basename @a2_path}"] =
read_binary @a2_path
end
def test_execute
@@ -36,8 +38,6 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
Gem::Installer.new(@a1_path).install
@cmd.options[:args] = []
- @cmd.options[:generate_rdoc] = false
- @cmd.options[:generate_ri] = false
use_ui @ui do
@cmd.execute
@@ -46,7 +46,6 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
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_empty out
end
@@ -91,8 +90,6 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
@cmd.options[:args] = []
@cmd.options[:system] = true
- @cmd.options[:generate_rdoc] = false
- @cmd.options[:generate_ri] = false
use_ui @ui do
@cmd.execute
@@ -100,7 +97,6 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
out = @ui.output.split "\n"
assert_equal "Updating rubygems-update", out.shift
- assert_equal "Successfully installed rubygems-update-9", out.shift
assert_equal "Installing RubyGems 9", out.shift
assert_equal "RubyGems system software updated", out.shift
@@ -115,8 +111,6 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
@cmd.options[:args] = []
@cmd.options[:system] = true
- @cmd.options[:generate_rdoc] = false
- @cmd.options[:generate_ri] = false
assert_raises Gem::MockGemUi::SystemExitException do
use_ui @ui do
@@ -138,8 +132,6 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
@cmd.options[:args] = []
@cmd.options[:system] = true
- @cmd.options[:generate_rdoc] = false
- @cmd.options[:generate_ri] = false
use_ui @ui do
@cmd.execute
@@ -147,7 +139,6 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
out = @ui.output.split "\n"
assert_equal "Updating rubygems-update", out.shift
- assert_equal "Successfully installed rubygems-update-9", out.shift
assert_equal "Installing RubyGems 9", out.shift
assert_equal "RubyGems system software updated", out.shift
@@ -163,8 +154,6 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
@cmd.options[:args] = []
@cmd.options[:system] = "8"
- @cmd.options[:generate_rdoc] = false
- @cmd.options[:generate_ri] = false
use_ui @ui do
@cmd.execute
@@ -172,7 +161,6 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
out = @ui.output.split "\n"
assert_equal "Updating rubygems-update", out.shift
- assert_equal "Successfully installed rubygems-update-8", out.shift
assert_equal "Installing RubyGems 8", out.shift
assert_equal "RubyGems system software updated", out.shift
@@ -188,8 +176,6 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
@cmd.options[:args] = []
@cmd.options[:system] = "9"
- @cmd.options[:generate_rdoc] = false
- @cmd.options[:generate_ri] = false
use_ui @ui do
@cmd.execute
@@ -197,7 +183,6 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
out = @ui.output.split "\n"
assert_equal "Updating rubygems-update", out.shift
- assert_equal "Successfully installed rubygems-update-9", out.shift
assert_equal "Installing RubyGems 9", out.shift
assert_equal "RubyGems system software updated", out.shift
@@ -207,8 +192,6 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def test_execute_system_with_gems
@cmd.options[:args] = %w[gem]
@cmd.options[:system] = true
- @cmd.options[:generate_rdoc] = false
- @cmd.options[:generate_ri] = false
assert_raises Gem::MockGemUi::TermError do
use_ui @ui do
@@ -270,15 +253,33 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
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_empty out
end
def test_execute_named
util_clear_gems
@@ -293,7 +294,6 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
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_empty out
@@ -317,6 +317,26 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
assert_empty out
end
def test_execute_up_to_date
util_clear_gems
@@ -339,11 +359,10 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
@cmd.handle_options %w[--system]
expected = {
- :generate_ri => true,
- :system => true,
- :force => false,
- :args => [],
- :generate_rdoc => true,
}
assert_equal expected, @cmd.options
@@ -359,11 +378,10 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
@cmd.handle_options %w[--system 1.3.7]
expected = {
- :generate_ri => true,
- :system => "1.3.7",
- :force => false,
- :args => [],
- :generate_rdoc => true,
}
assert_equal expected, @cmd.options
@@ -41,19 +41,19 @@ class TestGemCommandsWhichCommand < Gem::TestCase
util_foo_bar
- @cmd.handle_options %w[foo_bar missing]
use_ui @ui do
@cmd.execute
end
assert_equal "#{@foo_bar.full_gem_path}/lib/foo_bar.rb\n", @ui.output
- assert_match %r%Can.t find ruby library file or shared library missing\n%,
@ui.error
end
def test_execute_missing
- @cmd.handle_options %w[missing]
use_ui @ui do
assert_raises Gem::MockGemUi::TermError do
@@ -62,7 +62,7 @@ class TestGemCommandsWhichCommand < Gem::TestCase
end
assert_equal '', @ui.output
- assert_match %r%Can.t find ruby library file or shared library missing\n%,
@ui.error
end
@@ -0,0 +1,97 @@
@@ -17,6 +17,9 @@ class TestGemConfigFile < Gem::TestCase
Gem::ConfigFile::OPERATING_SYSTEM_DEFAULTS.clear
Gem::ConfigFile::PLATFORM_DEFAULTS.clear
util_config_file
end
@@ -27,6 +30,8 @@ class TestGemConfigFile < Gem::TestCase
Gem::ConfigFile.send :const_set, :SYSTEM_WIDE_CONFIG_FILE,
@orig_SYSTEM_WIDE_CONFIG_FILE
super
end
@@ -35,7 +40,6 @@ class TestGemConfigFile < Gem::TestCase
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
@@ -43,7 +47,6 @@ class TestGemConfigFile < Gem::TestCase
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:"
@@ -59,7 +62,6 @@ class TestGemConfigFile < Gem::TestCase
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
@@ -131,6 +133,37 @@ class TestGemConfigFile < Gem::TestCase
assert_equal true, @cfg.backtrace
end
def test_handle_arguments
args = %w[--backtrace --bunch --of --args here]
@@ -149,16 +182,6 @@ class TestGemConfigFile < Gem::TestCase
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
@@ -174,12 +197,12 @@ class TestGemConfigFile < Gem::TestCase
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
@@ -206,7 +229,6 @@ class TestGemConfigFile < Gem::TestCase
def test_write
@cfg.backtrace = true
- @cfg.benchmark = true
@cfg.update_sources = false
@cfg.bulk_threshold = 10
@cfg.verbose = false
@@ -219,7 +241,6 @@ class TestGemConfigFile < Gem::TestCase
# 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'
@@ -234,7 +255,6 @@ class TestGemConfigFile < Gem::TestCase
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"
@@ -246,7 +266,6 @@ class TestGemConfigFile < Gem::TestCase
util_config_file
@cfg.backtrace = :junk
- @cfg.benchmark = :junk
@cfg.update_sources = :junk
@cfg.bulk_threshold = 20
@cfg.verbose = :junk
@@ -259,7 +278,6 @@ class TestGemConfigFile < Gem::TestCase
# 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'
@@ -295,6 +313,26 @@ class TestGemConfigFile < Gem::TestCase
:other => 'a5fdbb6ba150cbb83aad2bb2fede64c'}, @cfg.api_keys)
end
def test_load_ssl_verify_mode_from_config
File.open @temp_conf, 'w' do |fp|
fp.puts ":ssl_verify_mode: 1"
@@ -315,5 +353,12 @@ class TestGemConfigFile < Gem::TestCase
@cfg = Gem::ConfigFile.new args
end
end
@@ -9,6 +9,15 @@ class TestGemDependency < Gem::TestCase
assert_equal req("> 1.0"), d.requirement
end
def test_initialize_double
d = dep "pkg", "> 1.0", "< 2.0"
assert_equal req("> 1.0", "< 2.0"), d.requirement
@@ -173,5 +182,42 @@ class TestGemDependency < Gem::TestCase
assert dep('a', '= 1').specific?
end
end
@@ -23,6 +23,14 @@ class TestGemDependencyInstaller < Gem::TestCase
s.add_development_dependency 'aa'
end
util_clear_gems
util_reset_gems
end
@@ -42,6 +50,62 @@ class TestGemDependencyInstaller < Gem::TestCase
assert_equal [@a1], inst.installed_gems
end
def test_install_all_dependencies
util_setup_gems
@@ -69,14 +133,44 @@ class TestGemDependencyInstaller < Gem::TestCase
assert_equal %w[e-1 a-1], inst.installed_gems.map { |s| s.full_name }
end
- def test_install_cache_dir
util_setup_gems
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
@@ -103,7 +197,7 @@ class TestGemDependencyInstaller < Gem::TestCase
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new
- inst.install 'a-2'
end
FileUtils.rm File.join(@tempdir, a2.file_name)
@@ -117,19 +211,67 @@ class TestGemDependencyInstaller < Gem::TestCase
assert_equal %w[b-1], inst.installed_gems.map { |s| s.full_name }
end
- def test_install_dependency
util_setup_gems
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
@@ -152,6 +294,50 @@ class TestGemDependencyInstaller < Gem::TestCase
assert_equal %w[a-1 aa-1 b-1], inst.installed_gems.map { |s| s.full_name }
end
def test_install_dependency_existing
util_setup_gems
@@ -517,11 +703,12 @@ class TestGemDependencyInstaller < Gem::TestCase
policy = Gem::Security::HighSecurity
inst = Gem::DependencyInstaller.new :security_policy => policy
- e = assert_raises 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
@@ -581,7 +768,14 @@ class TestGemDependencyInstaller < Gem::TestCase
Gem::Specification.reset
- assert_equal [[@b1, @gem_repo]], inst.find_gems_with_sources(dep)
end
def test_find_gems_with_sources_local
@@ -590,21 +784,24 @@ class TestGemDependencyInstaller < Gem::TestCase
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.file_name),
- local.last, 'local path'
end
def test_find_gems_with_sources_prerelease
@@ -615,7 +812,7 @@ class TestGemDependencyInstaller < Gem::TestCase
dependency = Gem::Dependency.new('a', Gem::Requirement.default)
releases =
- installer.find_gems_with_sources(dependency).map { |gems, *| gems }
assert releases.any? { |s| s.name == 'a' and s.version.to_s == '1' }
refute releases.any? { |s| s.name == 'a' and s.version.to_s == '1.a' }
@@ -623,9 +820,22 @@ class TestGemDependencyInstaller < Gem::TestCase
dependency.prerelease = true
prereleases =
- installer.find_gems_with_sources(dependency).map { |gems, *| gems }
- assert_equal [@a1_pre], prereleases
end
def assert_resolve expected, *specs
@@ -24,15 +24,6 @@ class TestGemDependencyList < Gem::TestCase
@d1 = quick_spec 'd', '1' do |s| s.add_dependency 'c', '>= 1' end
end
- def test_self_from_source_index
- util_clear_gems
- install_specs @a1, @b2
-
- deps = Gem::Deprecate.skip_during { Gem::DependencyList.from_source_index }
-
- 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], {})
@@ -0,0 +1,327 @@
@@ -1,32 +0,0 @@
-require 'rubygems/test_case'
-require 'rubygems/doc_manager'
-
-class TestGemDocManager < Gem::TestCase
-
- def setup
- super
-
- @spec = quick_gem 'a', 2
- @manager = Gem::DocManager.new(@spec)
- end
-
- def test_uninstall_doc_unwritable
- path = @spec.base_dir
- orig_mode = File.stat(path).mode
-
- # File.chmod has no effect on MS Windows directories (it needs ACL).
- if win_platform?
- skip("test_uninstall_doc_unwritable skipped on MS Windows")
- else
- FileUtils.chmod 0000, path
- end
-
- assert_raises Gem::FilePermissionError do
- @manager.uninstall_doc
- end
- ensure
- FileUtils.chmod orig_mode, path
- end
-
-end
-
@@ -1,3 +1,5 @@
require 'rubygems/test_case'
require 'rubygems/ext'
@@ -119,6 +121,7 @@ checking for main\(\) in .*?nonexistent/m, error.message)
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:"
@@ -132,14 +135,10 @@ checking for main\(\) in .*?nonexistent/m, error.message)
assert_equal make_command, output[0]
assert_equal "#{make_command} install", output[2]
- 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
@@ -24,18 +24,18 @@ class TestGemExtRakeBuilder < Gem::TestCase
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
- output = output.join "\n"
- refute_match %r%^rake failed:%, output
- assert_match %r%^#{Regexp.escape @@ruby} mkrf_conf\.rb%, output
- assert_match %r%^#{Regexp.escape @@rake} RUBYARCHDIR=#{Regexp.escape @dest_path} RUBYLIBDIR=#{Regexp.escape @dest_path}%, output
end
def test_class_build_fail
@@ -44,22 +44,22 @@ class TestGemExtRakeBuilder < Gem::TestCase
File.open("Rakefile","w") do |f|
f.puts "task :default do abort 'fail' end"
end
- EO_MKRF
end
output = []
- error = assert_raises 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
- assert_match %r%^rake failed:%, error.message
- assert_match %r%^#{Regexp.escape @@ruby} mkrf_conf\.rb%, error.message
- assert_match %r%^#{Regexp.escape @@rake} RUBYARCHDIR=#{Regexp.escape @dest_path} RUBYLIBDIR=#{Regexp.escape @dest_path}%, error.message
end
end
@@ -1,88 +0,0 @@
-require 'rubygems/package/tar_test_case'
-require 'rubygems/simple_gem'
-require 'rubygems/format'
-
-class TestGemFormat < Gem::Package::TarTestCase
-
- def setup
- super
-
- @simple_gem = SIMPLE_GEM
- end
-
- # HACK this test should do less
- def test_class_from_file_by_path
- util_make_gems
-
- gems = Dir[File.join(@gemhome, "cache", "*.gem")]
-
- names = [@a1, @a2, @a3a, @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_class_from_file_by_path_corrupt
- Tempfile.open 'corrupt' do |io|
- data = Gem.gzip 'a' * 10
- io.write tar_file_header('metadata.gz', "\000x", 0644, data.length)
- io.write data
- io.rewind
-
- e = assert_raises Gem::Package::FormatError do
- Gem::Format.from_file_by_path io.path
- end
-
- sub_message = 'Gem::Package::TarInvalidError: tar is corrupt, name contains null byte'
- assert_equal "corrupt gem (#{sub_message}) in #{io.path}", e.message
- assert_equal io.path, e.path
- end
- end
-
- def test_class_from_file_by_path_empty
- util_make_gems
-
- empty_gem = File.join @tempdir, 'empty.gem'
- FileUtils.touch empty_gem
-
- assert_nil Gem::Format.from_file_by_path(empty_gem)
- end
-
- def test_class_from_file_by_path_nonexistent
- assert_raises Gem::Exception do
- Gem::Format.from_file_by_path '/a/path/that/is/nonexistent'
- end
- end
-
- def test_class_from_io_garbled
- e = assert_raises 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_raises 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_raises 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
-
@@ -1,94 +0,0 @@
-require 'rubygems/test_case'
-require 'rubygems/gem_path_searcher'
-
-class Gem::GemPathSearcher
- attr_accessor :gemspecs
- attr_accessor :lib_dirs
-end
-
-class TestGemGemPathSearcher < Gem::TestCase
- def setup
- super
-
- @foo1 = new_spec 'foo', '0.1', nil, "lib/foo.rb"
- @foo1.require_paths << 'lib2'
- path = File.join 'gems', @foo1.full_name, 'lib', 'foo.rb'
- write_file(path) { |fp| fp.puts "# #{path}" }
-
- @foo2 = new_spec 'foo', '0.2'
- @bar1 = new_spec 'bar', '0.1'
- @bar2 = new_spec 'bar', '0.2'
- @nrp = new_spec 'nil_require_paths', '0.1' do |s|
- s.require_paths = nil
- end
-
- util_setup_fake_fetcher
- Gem::Specification.reset
- util_setup_spec_fetcher @foo1, @foo2, @bar1, @bar2
-
- @fetcher = Gem::FakeFetcher.new
- Gem::RemoteFetcher.fetcher = @fetcher
-
- @gps = Gem::Deprecate.skip_during { Gem::GemPathSearcher.new }
- end
-
- def test_find
- Gem::Deprecate.skip_during do
- assert_equal @foo1, @gps.find('foo')
- end
- end
-
- def test_find_all
- Gem::Deprecate.skip_during do
- assert_equal [@foo1], @gps.find_all('foo')
- end
- end
-
- def test_init_gemspecs
- Gem::Deprecate.skip_during do
- util_clear_gems
- util_setup_spec_fetcher @foo1, @foo2, @bar1, @bar2
- expected = [@bar2, @bar1, @foo2, @foo1].map(&:full_name)
- actual = @gps.init_gemspecs.map(&:full_name)
- assert_equal expected, actual
- end
- end
-
- def test_lib_dirs_for
- Gem::Deprecate.skip_during do
- lib_dirs = @gps.lib_dirs_for(@foo1)
- expected = File.join @gemhome, 'gems', @foo1.full_name, '{lib,lib2}'
-
- assert_equal expected, lib_dirs
- end
- end
-
- def test_lib_dirs_for_nil_require_paths
- Gem::Deprecate.skip_during do
- assert_nil @gps.lib_dirs_for(@nrp)
- end
- end
-
- def test_matching_file_eh
- Gem::Deprecate.skip_during do
- refute @gps.matching_file?(@foo1, 'bar')
- assert @gps.matching_file?(@foo1, 'foo')
- end
- end
-
- def test_matching_files
- Gem::Deprecate.skip_during do
- assert_equal [], @gps.matching_files(@foo1, 'bar')
-
- expected = File.join @foo1.full_gem_path, 'lib', 'foo.rb'
-
- assert_equal [expected], @gps.matching_files(@foo1, 'foo')
- end
- end
-
- def test_matching_files_nil_require_paths
- Gem::Deprecate.skip_during do
- assert_empty @gps.matching_files(@nrp, 'foo')
- end
- end
-end
@@ -3,6 +3,18 @@ require 'rubygems/gem_runner'
class TestGemGemRunner < Gem::TestCase
def test_do_configuration
Gem.clear_paths
@@ -25,17 +37,27 @@ class TestGemGemRunner < Gem::TestCase
gr = Gem::GemRunner.new
gr.send :do_configuration, %W[--config-file #{temp_conf}]
- assert_equal [other_gem_home, other_gem_path], Gem.path
assert_equal %w[--commands], Gem::Command.extra_args
- assert_equal %w[--all], Gem::DocManager.configured_args
end
- def test_build_args__are_handled
Gem.clear_paths
- Gem::GemRunner.new.run(%W[help -- --build_arg1 --build_arg2])
- assert_equal %w[--build_arg1 --build_arg2], Gem::Command.build_args
end
end
@@ -15,6 +15,25 @@ class TestGemGemcutterUtilities < Gem::TestCase
@cmd.extend Gem::GemcutterUtilities
end
def test_api_key
keys = { :rubygems_api_key => 'KEY' }
FileUtils.mkdir_p File.dirname Gem.configuration.credentials_path
@@ -24,22 +24,13 @@ class TestGemIndexer < Gem::TestCase
@d2_0_b = quick_spec 'd', '2.0.b'
util_build_gem @d2_0_b
- @_tempdir = @tempdir
@tempdir = File.join(@tempdir, 'indexer')
gems = File.join(@tempdir, 'gems')
FileUtils.mkdir_p gems
FileUtils.mv Dir[File.join(@gemhome, "cache", '*.gem')], gems
- @indexer = Gem::Indexer.new(@tempdir,
- :rss_title => 'ExampleForge gems',
- :rss_host => 'example.com',
- :rss_gems_host => 'gems.example.com')
- end
-
- def teardown
- @tempdir = @_tempdir
- super
end
def test_initialize
@@ -48,18 +39,10 @@ class TestGemIndexer < Gem::TestCase
@indexer.directory
indexer = Gem::Indexer.new @tempdir
- assert indexer.build_legacy
assert indexer.build_modern
- indexer = Gem::Indexer.new @tempdir, :build_legacy => false,
- :build_modern => true
- refute indexer.build_legacy
assert indexer.build_modern
-
- indexer = Gem::Indexer.new @tempdir, :build_legacy => true,
- :build_modern => false
- assert indexer.build_legacy
- refute indexer.build_modern
end
def test_build_indicies
@@ -79,7 +62,9 @@ class TestGemIndexer < Gem::TestCase
["b", Gem::Version.new("2"), "ruby"],
["c", Gem::Version.new("1.2"), "ruby"],
["d", Gem::Version.new("2.0"), "ruby"],
- ["pl", Gem::Version.new("1"), "i386-linux"]]
assert_equal expected, specs
@@ -93,7 +78,9 @@ class TestGemIndexer < Gem::TestCase
["b", Gem::Version.new("2"), "ruby"],
["c", Gem::Version.new("1.2"), "ruby"],
["d", Gem::Version.new("2.0"), "ruby"],
- ["pl", Gem::Version.new("1"), "i386-linux"]]
assert_equal expected, latest_specs, 'latest_specs'
end
@@ -103,9 +90,6 @@ class TestGemIndexer < Gem::TestCase
@indexer.generate_index
end
- assert_indexed @tempdir, "Marshal.#{@marshal_version}"
- assert_indexed @tempdir, "Marshal.#{@marshal_version}.Z"
-
quickdir = File.join @tempdir, 'quick'
marshal_quickdir = File.join quickdir, "Marshal.#{@marshal_version}"
@@ -122,208 +106,10 @@ class TestGemIndexer < Gem::TestCase
assert_indexed @tempdir, "latest_specs.#{@marshal_version}"
assert_indexed @tempdir, "latest_specs.#{@marshal_version}.gz"
-
- expected = <<-EOF
-<?xml version=\"1.0\"?>
-<rss version=\"2.0\">
- <channel>
- <title>ExampleForge gems</title>
- <link>http://example.com</link>
- <description>Recently released gems from http://example.com</description>
- <generator>RubyGems v#{Gem::VERSION}</generator>
- <docs>http://cyber.law.harvard.edu/rss/rss.html</docs>
- <item>
- <title>a-2</title>
- <description>
-&lt;pre&gt;This is a test description&lt;/pre&gt;
- </description>
- <author>[email protected] (A User)</author>
- <guid>a-2</guid>
- <enclosure url=\"http://gems.example.com/gems/a-2.gem\"
- length=\"3072\" type=\"application/octet-stream\" />
- <pubDate>#{@a2.date.rfc2822}</pubDate>
- <link>http://example.com</link>
- </item>
- <item>
- <title>a-3.a</title>
- <description>
-&lt;pre&gt;This is a test description&lt;/pre&gt;
- </description>
- <author>[email protected] (A User)</author>
- <guid>a-3.a</guid>
- <enclosure url=\"http://gems.example.com/gems/a-3.a.gem\"
- length=\"3072\" type=\"application/octet-stream\" />
- <pubDate>#{@a3a.date.rfc2822}</pubDate>
- <link>http://example.com</link>
- </item>
- <item>
- <title>a_evil-9</title>
- <description>
-&lt;pre&gt;This is a test description&lt;/pre&gt;
- </description>
- <author>[email protected] (A User)</author>
- <guid>a_evil-9</guid>
- <enclosure url=\"http://gems.example.com/gems/a_evil-9.gem\"
- length=\"3072\" type=\"application/octet-stream\" />
- <pubDate>#{@a_evil9.date.rfc2822}</pubDate>
- <link>http://example.com</link>
- </item>
- <item>
- <title>b-2</title>
- <description>
-&lt;pre&gt;This is a test description&lt;/pre&gt;
- </description>
- <author>[email protected] (A User)</author>
- <guid>b-2</guid>
- <enclosure url=\"http://gems.example.com/gems/b-2.gem\"
- length=\"3072\" type=\"application/octet-stream\" />
- <pubDate>#{@b2.date.rfc2822}</pubDate>
- <link>http://example.com</link>
- </item>
- <item>
- <title>c-1.2</title>
- <description>
-&lt;pre&gt;This is a test description&lt;/pre&gt;
- </description>
- <author>[email protected] (A User)</author>
- <guid>c-1.2</guid>
- <enclosure url=\"http://gems.example.com/gems/c-1.2.gem\"
- length=\"3072\" type=\"application/octet-stream\" />
- <pubDate>#{@c1_2.date.rfc2822}</pubDate>
- <link>http://example.com</link>
- </item>
- <item>
- <title>d-2.0.a</title>
- <description>
-&lt;pre&gt;This is a test description&lt;/pre&gt;
- </description>
- <author>[email protected] (A User)</author>
- <guid>d-2.0.a</guid>
- <enclosure url=\"http://gems.example.com/gems/d-2.0.a.gem\"
- length=\"3072\" type=\"application/octet-stream\" />
- <pubDate>#{@d2_0_a.date.rfc2822}</pubDate>
- <link>http://example.com</link>
- </item>
- <item>
- <title>d-2.0.b</title>
- <description>
-&lt;pre&gt;This is a test description&lt;/pre&gt;
- </description>
- <author>[email protected] (A User)</author>
- <guid>d-2.0.b</guid>
- <enclosure url=\"http://gems.example.com/gems/d-2.0.b.gem\"
- length=\"3072\" type=\"application/octet-stream\" />
- <pubDate>#{@d2_0_b.date.rfc2822}</pubDate>
- <link>http://example.com</link>
- </item>
- <item>
- <title>pl-1-x86-linux</title>
- <description>
-&lt;pre&gt;This is a test description&lt;/pre&gt;
- </description>
- <author>[email protected] (A User)</author>
- <guid>pl-1-x86-linux</guid>
- <enclosure url=\"http://gems.example.com/gems/pl-1-x86-linux.gem\"
- length=\"3072\" type=\"application/octet-stream\" />
- <pubDate>#{@pl1.date.rfc2822}</pubDate>
- <link>http://example.com</link>
- </item>
- <item>
- <title>a-1</title>
- <description>
-&lt;pre&gt;This line is really, really long. So long, in fact, that it is more than
-eighty characters long! The purpose of this line is for testing wrapping
-behavior because sometimes people don't wrap their text to eighty characters.
-Without the wrapping, the text might not look good in the RSS feed.
-
-Also, a list:
- * An entry that's actually kind of sort
- * an entry that's really long, which will probably get wrapped funny.
-That's ok, somebody wasn't thinking straight when they made it more than
-eighty characters.&lt;/pre&gt;
- </description>
- <author>[email protected] (Example), [email protected] (Example2)</author>
- <guid>a-1</guid>
- <enclosure url=\"http://gems.example.com/gems/a-1.gem\"
- length=\"3584\" type=\"application/octet-stream\" />
- <pubDate>#{@a1.date.rfc2822}</pubDate>
- <link>http://a.example.com</link>
- </item>
- </channel>
-</rss>
- EOF
-
- gems_rss = File.read File.join(@tempdir, 'index.rss')
-
- assert_equal expected, gems_rss
- end
-
- def test_generate_index_legacy
- @indexer.build_modern = false
- @indexer.build_legacy = true
-
- use_ui @ui do
- @indexer.generate_index
- end
-
- assert_indexed @tempdir, "Marshal.#{@marshal_version}"
- assert_indexed @tempdir, "Marshal.#{@marshal_version}.Z"
-
- quickdir = File.join @tempdir, 'quick'
- marshal_quickdir = File.join quickdir, "Marshal.#{@marshal_version}"
-
- assert File.directory?(quickdir)
- assert File.directory?(marshal_quickdir)
-
- assert_indexed marshal_quickdir, "#{File.basename(@a1.spec_file)}.rz"
- assert_indexed marshal_quickdir, "#{File.basename(@a2.spec_file)}.rz"
-
- refute_indexed marshal_quickdir, "#{File.basename(@c1_2.spec_file)}"
-
- refute_indexed @tempdir, "specs.#{@marshal_version}"
- refute_indexed @tempdir, "specs.#{@marshal_version}.gz"
-
- refute_indexed @tempdir, "latest_specs.#{@marshal_version}"
- refute_indexed @tempdir, "latest_specs.#{@marshal_version}.gz"
- end
-
- def test_generate_index_legacy_back_to_back
- @indexer.build_modern = true
- @indexer.build_legacy = true
-
- use_ui @ui do
- @indexer.generate_index
- end
-
- @indexer = Gem::Indexer.new @tempdir
- @indexer.build_modern = false
- @indexer.build_legacy = true
-
- use_ui @ui do
- @indexer.generate_index
- end
-
- assert_indexed @tempdir, "Marshal.#{@marshal_version}"
- assert_indexed @tempdir, "Marshal.#{@marshal_version}.Z"
-
- quickdir = File.join @tempdir, 'quick'
- marshal_quickdir = File.join quickdir, "Marshal.#{@marshal_version}"
-
- assert File.directory?(marshal_quickdir)
-
- assert_indexed marshal_quickdir, "#{File.basename(@a1.spec_file)}.rz"
- assert_indexed marshal_quickdir, "#{File.basename(@a2.spec_file)}.rz"
-
- assert_indexed @tempdir, "specs.#{@marshal_version}"
- assert_indexed @tempdir, "specs.#{@marshal_version}.gz"
-
- assert_indexed @tempdir, "latest_specs.#{@marshal_version}"
- assert_indexed @tempdir, "latest_specs.#{@marshal_version}.gz"
end
def test_generate_index_modern
@indexer.build_modern = true
- @indexer.build_legacy = false
use_ui @ui do
@indexer.generate_index
@@ -369,7 +155,6 @@ eighty characters.&lt;/pre&gt;
def test_generate_index_modern_back_to_back
@indexer.build_modern = true
- @indexer.build_legacy = true
use_ui @ui do
@indexer.generate_index
@@ -377,15 +162,10 @@ eighty characters.&lt;/pre&gt;
@indexer = Gem::Indexer.new @tempdir
@indexer.build_modern = true
- @indexer.build_legacy = false
use_ui @ui do
@indexer.generate_index
end
-
- assert_indexed @tempdir, "Marshal.#{@marshal_version}"
- assert_indexed @tempdir, "Marshal.#{@marshal_version}.Z"
-
quickdir = File.join @tempdir, 'quick'
marshal_quickdir = File.join quickdir, "Marshal.#{@marshal_version}"
@@ -407,14 +187,13 @@ eighty characters.&lt;/pre&gt;
@indexer.generate_index
end
- assert_match %r%^\.\.\.\.\.\.\.\.\.\.$%, @ui.output
- assert_match %r%^Generating Marshal quick index gemspecs for 10 gems$%,
@ui.output
assert_match %r%^Complete$%, @ui.output
assert_match %r%^Generating specs index$%, @ui.output
assert_match %r%^Generating latest specs index$%, @ui.output
assert_match %r%^Generating prerelease specs index$%, @ui.output
- assert_match %r%^Generating Marshal master index$%, @ui.output
assert_match %r%^Complete$%, @ui.output
assert_match %r%^Compressing indicies$%, @ui.output
@@ -438,7 +217,9 @@ eighty characters.&lt;/pre&gt;
['b', Gem::Version.new(2), 'ruby'],
['c', Gem::Version.new('1.2'), 'ruby'],
['d', Gem::Version.new('2.0'), 'ruby'],
['pl', Gem::Version.new(1), 'i386-linux'],
]
assert_equal expected, specs
@@ -472,7 +253,9 @@ eighty characters.&lt;/pre&gt;
['b', Gem::Version.new(2), 'ruby'],
['c', Gem::Version.new('1.2'), 'ruby'],
['d', Gem::Version.new('2.0'), 'ruby'],
['pl', Gem::Version.new(1), 'i386-linux'],
]
assert_equal expected, latest_specs
@@ -500,6 +283,20 @@ eighty characters.&lt;/pre&gt;
prerelease_specs
end
def test_update_index
use_ui @ui do
@indexer.generate_index
@@ -524,30 +321,32 @@ eighty characters.&lt;/pre&gt;
FileUtils.mv @d2_1.cache_file, gems
FileUtils.mv @d2_1_a.cache_file, gems
- use_ui @ui do
- @indexer.update_index
- end
- assert_indexed marshal_quickdir, "#{File.basename(@d2_1.spec_file)}.rz"
- specs_index = Marshal.load Gem.read_binary(@indexer.dest_specs_index)
- assert_includes specs_index, @d2_1_tuple
- refute_includes specs_index, @d2_1_a_tuple
- latest_specs_index = Marshal.load \
- Gem.read_binary(@indexer.dest_latest_specs_index)
- assert_includes latest_specs_index, @d2_1_tuple
- assert_includes latest_specs_index,
- [@d2_0.name, @d2_0.version, @d2_0.original_platform]
- refute_includes latest_specs_index, @d2_1_a_tuple
- pre_specs_index = Marshal.load \
- Gem.read_binary(@indexer.dest_prerelease_specs_index)
- assert_includes pre_specs_index, @d2_1_a_tuple
- refute_includes pre_specs_index, @d2_1_tuple
end
def assert_indexed(dir, name)
@@ -1,24 +1,104 @@
require 'rubygems/installer_test_case'
require 'rubygems/install_update_options'
require 'rubygems/command'
class TestGemInstallUpdateOptions < Gem::InstallerTestCase
def setup
super
- @cmd = Gem::Command.new 'dummy', 'dummy'
@cmd.extend Gem::InstallUpdateOptions
@cmd.add_install_update_options
end
def test_add_install_update_options
- args = %w[-i /install_to --rdoc --ri -E -f -w -P HighSecurity
- --ignore-dependencies --format-exec --include-dependencies]
assert @cmd.handles?(args)
end
def test_security_policy
@cmd.handle_options %w[-P HighSecurity]
@@ -2,24 +2,24 @@ require 'rubygems/installer_test_case'
class TestGemInstaller < Gem::InstallerTestCase
- def util_setup_install
- @gemhome = @installer_tmp
- Gem.use_paths @installer_tmp
- @spec = Gem::Specification.find_by_name 'a'
- @user_spec = Gem::Specification.find_by_name 'b'
- @installer.spec = @spec
- @installer.gem_home = @installer_tmp
- @installer.gem_dir = @spec.gem_dir
- @user_installer.spec = @user_spec
- @user_installer.gem_home = @installer_tmp
end
- def test_app_script_text
- util_setup_install
- @spec.version = 2
util_make_exec @spec, ''
expected = <<-EOF
@@ -53,8 +53,6 @@ load Gem.bin_path('a', 'executable', version)
end
def test_build_extensions_none
- util_setup_install
-
use_ui @ui do
@installer.build_extensions
end
@@ -66,8 +64,7 @@ load Gem.bin_path('a', 'executable', version)
end
def test_build_extensions_extconf_bad
- util_setup_install
-
@spec.extensions << 'extconf.rb'
e = assert_raises Gem::Installer::ExtensionBuildError do
@@ -91,9 +88,9 @@ load Gem.bin_path('a', 'executable', version)
end
def test_build_extensions_unsupported
- util_setup_install
-
- gem_make_out = File.join @gemhome, 'gems', @spec.full_name, 'gem_make.out'
@spec.extensions << nil
e = assert_raises Gem::Installer::ExtensionBuildError do
@@ -113,95 +110,148 @@ load Gem.bin_path('a', 'executable', version)
FileUtils.rm_f gem_make_out
end
- def test_ensure_dependency
- util_setup_install
- dep = Gem::Dependency.new 'a', '>= 2'
- assert @installer.ensure_dependency(@spec, dep)
- dep = Gem::Dependency.new 'b', '> 2'
- e = assert_raises Gem::InstallError do
- @installer.ensure_dependency @spec, dep
end
- assert_equal 'a requires b (> 2)', e.message
end
- def test_extract_files
- util_setup_install
- format = Object.new
- def format.file_entries
- [[{'size' => 7, 'mode' => 0400, 'path' => 'thefile'}, 'content']]
end
- @installer.format = format
- @installer.extract_files
- thefile_path = File.join(util_gem_dir, 'thefile')
- assert_equal 'content', File.read(thefile_path)
- unless Gem.win_platform? then
- assert_equal 0400, File.stat(thefile_path).mode & 0777
end
- end
- def test_extract_files_bad_dest
- util_setup_install
- @installer.gem_dir = 'somedir'
- @installer.format = nil
- e = assert_raises ArgumentError do
- @installer.extract_files
- end
- assert_equal 'format required to extract from', e.message
end
- def test_extract_files_relative
- util_setup_install
- format = Object.new
- def format.file_entries
- [[{'size' => 10, 'mode' => 0644, 'path' => '../thefile'}, '../thefile']]
- end
- @installer.format = format
- e = assert_raises Gem::InstallError do
- @installer.extract_files
end
- dir = util_gem_dir
- expected = "attempt to install file into \"../thefile\" under #{dir}"
- assert_equal expected, e.message
- assert_equal false, File.file?(File.join(@tempdir, '../thefile')),
- "You may need to remove this file if you broke the test once"
end
- def test_extract_files_absolute
- util_setup_install
- format = Object.new
- def format.file_entries
- [[{'size' => 8, 'mode' => 0644, 'path' => '/thefile'}, '/thefile']]
- end
- @installer.format = format
e = assert_raises Gem::InstallError do
- @installer.extract_files
end
- assert_equal 'attempt to install file into /thefile', e.message
- assert_equal false, File.file?(File.join('/thefile')),
- "You may need to remove this file if you broke the test once"
end
- def test_generate_bin_bindir
- util_setup_install
@installer.wrappers = true
@spec.executables = %w[executable]
@@ -227,16 +277,15 @@ load Gem.bin_path('a', 'executable', version)
end
def test_generate_bin_bindir_with_user_install_warning
- util_setup_install
-
- bin_dir = Gem.win_platform? ? File.expand_path(ENV["WINDIR"]) : "/usr/bin"
options = {
:bin_dir => bin_dir,
:install_dir => "/non/existant"
}
- inst = Gem::Installer.new nil, options
Gem::Installer.path_warning = false
@@ -248,16 +297,14 @@ load Gem.bin_path('a', 'executable', version)
end
def test_generate_bin_script
- util_setup_install
-
@installer.wrappers = true
util_make_exec
@installer.gem_dir = util_gem_dir
@installer.generate_bin
- assert_equal true, File.directory?(util_inst_bindir)
- installed_exec = File.join(util_inst_bindir, 'executable')
- assert_equal true, File.exist?(installed_exec)
assert_equal mask, File.stat(installed_exec).mode unless win_platform?
wrapper = File.read installed_exec
@@ -265,8 +312,6 @@ load Gem.bin_path('a', 'executable', version)
end
def test_generate_bin_script_format
- util_setup_install
-
@installer.format_executable = true
@installer.wrappers = true
util_make_exec
@@ -282,8 +327,6 @@ load Gem.bin_path('a', 'executable', version)
end
def test_generate_bin_script_format_disabled
- util_setup_install
-
@installer.wrappers = true
util_make_exec
@installer.gem_dir = util_gem_dir
@@ -298,10 +341,7 @@ load Gem.bin_path('a', 'executable', version)
end
def test_generate_bin_script_install_dir
- util_setup_install
-
@installer.wrappers = true
- @spec.executables = %w[executable]
gem_dir = File.join("#{@gemhome}2", "gems", @spec.full_name)
gem_bindir = File.join gem_dir, 'bin'
@@ -312,11 +352,12 @@ load Gem.bin_path('a', 'executable', version)
@installer.gem_home = "#{@gemhome}2"
@installer.gem_dir = gem_dir
@installer.generate_bin
installed_exec = File.join("#{@gemhome}2", "bin", 'executable')
- assert_equal true, File.exist?(installed_exec)
assert_equal mask, File.stat(installed_exec).mode unless win_platform?
wrapper = File.read installed_exec
@@ -324,8 +365,6 @@ load Gem.bin_path('a', 'executable', version)
end
def test_generate_bin_script_no_execs
- util_setup_install
-
util_execless
@installer.wrappers = true
@@ -335,8 +374,6 @@ load Gem.bin_path('a', 'executable', version)
end
def test_generate_bin_script_no_perms
- util_setup_install
-
@installer.wrappers = true
util_make_exec
@@ -356,8 +393,6 @@ load Gem.bin_path('a', 'executable', version)
end
def test_generate_bin_script_no_shebang
- util_setup_install
-
@installer.wrappers = true
@spec.executables = %w[executable]
@@ -381,8 +416,6 @@ load Gem.bin_path('a', 'executable', version)
end
def test_generate_bin_script_wrappers
- util_setup_install
-
@installer.wrappers = true
util_make_exec
@installer.gem_dir = util_gem_dir
@@ -408,8 +441,6 @@ load Gem.bin_path('a', 'executable', version)
end
def test_generate_bin_symlink
- util_setup_install
-
return if win_platform? #Windows FS do not support symlinks
@installer.wrappers = false
@@ -425,8 +456,6 @@ load Gem.bin_path('a', 'executable', version)
end
def test_generate_bin_symlink_no_execs
- util_setup_install
-
util_execless
@installer.wrappers = false
@@ -436,8 +465,6 @@ load Gem.bin_path('a', 'executable', version)
end
def test_generate_bin_symlink_no_perms
- util_setup_install
-
@installer.wrappers = false
util_make_exec
@installer.gem_dir = util_gem_dir
@@ -458,8 +485,6 @@ load Gem.bin_path('a', 'executable', version)
end
def test_generate_bin_symlink_update_newer
- util_setup_install
-
return if win_platform? #Windows FS do not support symlinks
@installer.wrappers = false
@@ -480,7 +505,6 @@ load Gem.bin_path('a', 'executable', version)
s.require_path = 'lib'
end
- @spec.version = 3
util_make_exec
@installer.gem_dir = util_gem_dir @spec
@installer.generate_bin
@@ -491,8 +515,6 @@ load Gem.bin_path('a', 'executable', version)
end
def test_generate_bin_symlink_update_older
- util_setup_install
-
return if win_platform? #Windows FS do not support symlinks
@installer.wrappers = false
@@ -529,8 +551,6 @@ load Gem.bin_path('a', 'executable', version)
end
def test_generate_bin_symlink_update_remove_wrapper
- util_setup_install
-
return if win_platform? #Windows FS do not support symlinks
@installer.wrappers = true
@@ -538,8 +558,9 @@ load Gem.bin_path('a', 'executable', version)
@installer.gem_dir = util_gem_dir
@installer.generate_bin
installed_exec = File.join util_inst_bindir, 'executable'
- assert_equal true, File.exist?(installed_exec)
@spec = Gem::Specification.new do |s|
s.files = ['lib/code.rb']
@@ -549,21 +570,21 @@ load Gem.bin_path('a', 'executable', version)
s.description = "desc"
s.require_path = 'lib'
end
@installer.wrappers = false
- @spec.version = 3
- util_make_exec
@installer.gem_dir = util_gem_dir
@installer.generate_bin
- installed_exec = File.join(util_inst_bindir, 'executable')
- assert_equal(File.join(util_gem_dir, 'bin', 'executable'),
File.readlink(installed_exec),
"Ensure symlink moved to latest version")
end
def test_generate_bin_symlink_win32
- util_setup_install
-
old_win_platform = Gem.win_platform?
Gem.win_platform = true
@installer.wrappers = false
@@ -588,8 +609,6 @@ load Gem.bin_path('a', 'executable', version)
end
def test_generate_bin_uses_default_shebang
- util_setup_install
-
return if win_platform? #Windows FS do not support symlinks
@installer.wrappers = true
@@ -784,7 +803,7 @@ load Gem.bin_path('a', 'executable', version)
File.open File.join('lib', 'other.rb'), 'w' do |f| f.puts '1' end
use_ui ui do
FileUtils.rm @gem
- Gem::Builder.new(@spec).build
end
end
@installer = Gem::Installer.new @gem
@@ -799,27 +818,6 @@ load Gem.bin_path('a', 'executable', version)
"code.rb from prior install of same gem shouldn't remain here")
end
- def test_install_bad_gem
- gem = nil
-
- use_ui @ui do
- Dir.chdir @tempdir do Gem::Builder.new(@spec).build end
- gem = File.join @tempdir, @spec.file_name
- end
-
- gem_data = File.open gem, 'rb' do |fp| fp.read 1024 end
- File.open gem, 'wb' do |fp| fp.write gem_data end
-
- e = assert_raises Gem::InstallError do
- use_ui @ui do
- @installer = Gem::Installer.new gem
- @installer.install
- end
- end
-
- assert_equal "invalid gem format for #{gem}", e.message
- end
-
def test_install_check_dependencies
@spec.add_dependency 'b', '> 5'
util_setup_gem
@@ -833,13 +831,15 @@ load Gem.bin_path('a', 'executable', version)
def test_install_check_dependencies_install_dir
gemhome2 = "#{@gemhome}2"
- @spec.add_dependency 'b'
- quick_gem 'b', 2
FileUtils.mv @gemhome, gemhome2
- Gem::Specification.dirs = [gemhome2] # TODO: switch all dirs= to use_paths
util_setup_gem
@@ -897,8 +897,6 @@ load Gem.bin_path('a', 'executable', version)
FileUtils.rm_f File.join(Gem.dir, 'specifications')
use_ui @ui do
- Dir.chdir @tempdir do Gem::Builder.new(@spec).build end
-
@installer.install
end
@@ -992,7 +990,7 @@ load Gem.bin_path('a', 'executable', version)
@spec.post_install_message = 'I am a shiny gem!'
use_ui @ui do
- path = Gem::Builder.new(@spec).build
@installer = Gem::Installer.new path
@installer.install
@@ -1032,7 +1030,7 @@ load Gem.bin_path('a', 'executable', version)
end
def test_installation_satisfies_dependency_eh
- util_setup_install
dep = Gem::Dependency.new 'a', '>= 2'
assert @installer.installation_satisfies_dependency?(dep)
@@ -1042,8 +1040,6 @@ load Gem.bin_path('a', 'executable', version)
end
def test_shebang
- util_setup_install
-
util_make_exec @spec, "#!/usr/bin/ruby"
shebang = @installer.shebang 'executable'
@@ -1052,8 +1048,6 @@ load Gem.bin_path('a', 'executable', version)
end
def test_shebang_arguments
- util_setup_install
-
util_make_exec @spec, "#!/usr/bin/ruby -ws"
shebang = @installer.shebang 'executable'
@@ -1062,8 +1056,6 @@ load Gem.bin_path('a', 'executable', version)
end
def test_shebang_empty
- util_setup_install
-
util_make_exec @spec, ''
shebang = @installer.shebang 'executable'
@@ -1071,8 +1063,6 @@ load Gem.bin_path('a', 'executable', version)
end
def test_shebang_env
- util_setup_install
-
util_make_exec @spec, "#!/usr/bin/env ruby"
shebang = @installer.shebang 'executable'
@@ -1081,8 +1071,6 @@ load Gem.bin_path('a', 'executable', version)
end
def test_shebang_env_arguments
- util_setup_install
-
util_make_exec @spec, "#!/usr/bin/env ruby -ws"
shebang = @installer.shebang 'executable'
@@ -1091,8 +1079,6 @@ load Gem.bin_path('a', 'executable', version)
end
def test_shebang_env_shebang
- util_setup_install
-
util_make_exec @spec, ''
@installer.env_shebang = true
@@ -1105,8 +1091,6 @@ load Gem.bin_path('a', 'executable', version)
end
def test_shebang_nested
- util_setup_install
-
util_make_exec @spec, "#!/opt/local/ruby/bin/ruby"
shebang = @installer.shebang 'executable'
@@ -1115,8 +1099,6 @@ load Gem.bin_path('a', 'executable', version)
end
def test_shebang_nested_arguments
- util_setup_install
-
util_make_exec @spec, "#!/opt/local/ruby/bin/ruby -ws"
shebang = @installer.shebang 'executable'
@@ -1125,8 +1107,6 @@ load Gem.bin_path('a', 'executable', version)
end
def test_shebang_version
- util_setup_install
-
util_make_exec @spec, "#!/usr/bin/ruby18"
shebang = @installer.shebang 'executable'
@@ -1135,8 +1115,6 @@ load Gem.bin_path('a', 'executable', version)
end
def test_shebang_version_arguments
- util_setup_install
-
util_make_exec @spec, "#!/usr/bin/ruby18 -ws"
shebang = @installer.shebang 'executable'
@@ -1145,8 +1123,6 @@ load Gem.bin_path('a', 'executable', version)
end
def test_shebang_version_env
- util_setup_install
-
util_make_exec @spec, "#!/usr/bin/env ruby18"
shebang = @installer.shebang 'executable'
@@ -1155,8 +1131,6 @@ load Gem.bin_path('a', 'executable', version)
end
def test_shebang_version_env_arguments
- util_setup_install
-
util_make_exec @spec, "#!/usr/bin/env ruby18 -ws"
shebang = @installer.shebang 'executable'
@@ -1164,9 +1138,48 @@ load Gem.bin_path('a', 'executable', version)
assert_equal "#!#{Gem.ruby} -ws", shebang
end
- def test_unpack
- util_setup_install
util_setup_gem
dest = File.join @gemhome, 'gems', @spec.full_name
@@ -1178,29 +1191,21 @@ load Gem.bin_path('a', 'executable', version)
end
def test_write_spec
- util_setup_install
-
- spec_dir = File.join @gemhome, 'specifications'
- spec_file = File.join spec_dir, @spec.spec_name
- FileUtils.rm spec_file
- refute File.exist?(spec_file)
@installer.spec = @spec
@installer.gem_home = @gemhome
@installer.write_spec
- assert File.exist?(spec_file)
- assert_equal @spec, eval(File.read(spec_file))
end
def test_write_spec_writes_cached_spec
- util_setup_install
-
- spec_dir = File.join @gemhome, 'specifications'
- spec_file = File.join spec_dir, @spec.spec_name
- FileUtils.rm spec_file
- refute File.exist?(spec_file)
@spec.files = %w[a.rb b.rb c.rb]
@@ -1212,13 +1217,11 @@ load Gem.bin_path('a', 'executable', version)
# cached specs have no file manifest:
@spec.files = []
- assert_equal @spec, eval(File.read(spec_file))
end
def test_dir
- util_setup_install
-
- assert_match %r!/installer/gems/a-2\z!, @installer.dir
end
def old_ruby_required
@@ -1238,6 +1241,18 @@ load Gem.bin_path('a', 'executable', version)
@installer = util_installer @spec, @gemhome
end
def mask
0100755 & (~File.umask)
end
@@ -40,6 +40,8 @@ class TestGemLocalRemoteOptions < Gem::TestCase
end
def test_clear_sources_option_idiot_proof
@cmd.add_local_remote_options
@cmd.handle_options %W[--clear-sources]
assert_equal Gem.default_sources, Gem.sources
@@ -78,10 +80,14 @@ class TestGemLocalRemoteOptions < Gem::TestCase
s4 = URI.parse 'http://more-gems.example.com/' # Intentional duplicate
original_sources = Gem.sources.dup
@cmd.handle_options %W[--source #{s1} --source #{s2} --source #{s3} --source #{s4}]
- assert_equal [original_sources, s1.to_s, s2.to_s, "#{s3}/"].flatten,
- Gem.sources
end
def test_update_sources_option
@@ -0,0 +1,15 @@
@@ -0,0 +1,547 @@
@@ -0,0 +1,37 @@
@@ -1,129 +0,0 @@
-require 'rubygems/package/tar_test_case'
-require 'rubygems/package/tar_input'
-
-class TestGemPackageTarInput < Gem::Package::TarTestCase
-
- # Sometimes the setgid bit doesn't take. Don't know if this is a problem on
- # all systems, or just some. But for now, we will ignore it in the tests.
- SETGID_BIT = 02000
-
- def setup
- super
-
- inner_tar = tar_file_header("bla", "", 0612, 10)
- inner_tar += "0123456789" + "\0" * 502
- inner_tar += tar_file_header("foo", "", 0636, 5)
- inner_tar += "01234" + "\0" * 507
- inner_tar += tar_dir_header("__dir__", "", 0600)
- inner_tar += "\0" * 1024
- str = TempIO.new
-
- begin
- os = Zlib::GzipWriter.new str
- os.write inner_tar
- ensure
- os.finish
- end
-
- str.rewind
-
- @file = File.join @tempdir, 'bla.tar'
-
- File.open @file, 'wb' do |f|
- f.write tar_file_header("data.tar.gz", "", 0644, str.string.size)
- f.write str.string
- f.write "\0" * ((512 - (str.string.size % 512)) % 512 )
-
- @spec = Gem::Specification.new do |spec|
- spec.author = "Mauricio :)"
- end
-
- meta = @spec.to_yaml
-
- f.write tar_file_header("metadata", "", 0644, meta.size)
- f.write meta + "\0" * (1024 - meta.size)
- f.write "\0" * 1024
- end
-
- @entry_names = %w{bla foo __dir__}
- @entry_sizes = [10, 5, 0]
- #FIXME: are these modes system dependent?
- @entry_modes = [0100612, 0100636, 040600]
- @entry_files = %W[#{@tempdir}/bla #{@tempdir}/foo]
- @entry_contents = %w[0123456789 01234]
- end
-
- def test_initialize_no_metadata_file
- Tempfile.open 'no_meta' do |io|
- io.write tar_file_header('a', '', 0644, 1)
- io.write 'a'
- io.rewind
-
- e = assert_raises Gem::Package::FormatError do
- open io.path, Gem.binary_mode do |file|
- Gem::Package::TarInput.open file do end
- end
- end
-
- assert_equal "no metadata found in #{io.path}", e.message
- assert_equal io.path, e.path
- end
- end
-
- def test_each
- open @file, 'rb' do |io|
- Gem::Package::TarInput.open io do |tar_input|
- count = 0
-
- tar_input.each_with_index do |entry, i|
- count = i
-
- assert_kind_of Gem::Package::TarReader::Entry, entry
- assert_equal @entry_names[i], entry.header.name
- assert_equal @entry_sizes[i], entry.header.size
- end
-
- assert_equal 2, count
-
- assert_equal @spec, tar_input.metadata
- end
- end
- end
-
- def test_extract_entry
- open @file, 'rb' do |io|
- Gem::Package::TarInput.open io do |tar_input|
- assert_equal @spec, tar_input.metadata
-
- count = 0
-
- tar_input.each_with_index do |entry, i|
- count = i
- tar_input.extract_entry @tempdir, entry
- name = File.join @tempdir, entry.header.name
-
- if entry.directory? then
- assert File.directory?(name)
- else
- assert File.file?(name)
- assert_equal @entry_sizes[i], File.stat(name).size
- #FIXME: win32? !!
- end
-
- unless Gem.win_platform? then
- assert_equal @entry_modes[i], File.stat(name).mode & (~SETGID_BIT)
- end
- end
-
- assert_equal 2, count
- end
- end
-
- @entry_files.each_with_index do |x, i|
- assert File.file?(x)
- assert_equal @entry_contents[i], Gem.read_binary(x)
- end
- end
-
-end
-
@@ -1,101 +0,0 @@
-require 'rubygems/package/tar_test_case'
-require 'rubygems/package/tar_output'
-require 'rubygems/security'
-
-class TestGemPackageTarOutput < Gem::Package::TarTestCase
-
- def setup
- super
-
- @file = File.join @tempdir, 'bla2.tar'
- end
-
- def test_self_open
- open @file, 'wb' do |tar_io|
- Gem::Package::TarOutput.open tar_io do |tar_writer|
- tar_writer.add_file_simple 'README', 0, 17 do |io|
- io.write "This is a README\n"
- end
-
- tar_writer.metadata = "This is some metadata\n"
- end
- end
-
- files = util_extract
-
- name, data = files.shift
- assert_equal 'data.tar.gz', name
-
- gz = Zlib::GzipReader.new StringIO.new(data)
-
- Gem::Package::TarReader.new gz do |tar_reader|
- tar_reader.each do |entry|
- assert_equal 'README', entry.full_name
- assert_equal "This is a README\n", entry.read
- end
- end
-
- gz.close
-
- name, data = files.shift
- assert_equal 'metadata.gz', name
-
- gz = Zlib::GzipReader.new StringIO.new(data)
- assert_equal "This is some metadata\n", gz.read
-
- assert_empty files
- ensure
- gz.close if gz
- end
-
- if defined? OpenSSL then
- def test_self_open_signed
- @private_key = File.expand_path('test/rubygems/private_key.pem', @@project_dir)
- @public_cert = File.expand_path('test/rubygems/public_cert.pem', @@project_dir)
-
- signer = Gem::Security::Signer.new @private_key, [@public_cert]
-
- open @file, 'wb' do |tar_io|
- Gem::Package::TarOutput.open tar_io, signer do |tar_writer|
- tar_writer.add_file_simple 'README', 0, 17 do |io|
- io.write "This is a README\n"
- end
-
- tar_writer.metadata = "This is some metadata\n"
- end
- end
-
- files = util_extract
-
- name, data = files.shift
- assert_equal 'data.tar.gz', name
-
- name, data = files.shift
- assert_equal 'metadata.gz', name
-
- name, data = files.shift
- assert_equal 'data.tar.gz.sig', name
-
- name, data = files.shift
- assert_equal 'metadata.gz.sig', name
-
- assert_empty files
- end
- end
-
- def util_extract
- files = []
-
- open @file, 'rb' do |io|
- Gem::Package::TarReader.new io do |tar_reader|
- tar_reader.each do |entry|
- files << [entry.full_name, entry.read]
- end
- end
- end
-
- files
- end
-
-end
-
@@ -42,5 +42,37 @@ class TestGemPackageTarReader < Gem::Package::TarTestCase
end
end
end
@@ -1,7 +1,7 @@
require 'rubygems/package/tar_test_case'
require 'rubygems/package/tar_writer'
-class TestTarWriter < Gem::Package::TarTestCase
def setup
super
@@ -26,6 +26,89 @@ class TestTarWriter < Gem::Package::TarTestCase
assert_equal 1024, @io.pos
end
def test_add_file_simple
@tar_writer.add_file_simple 'x', 0644, 10 do |io| io.write "a" * 10 end
@@ -22,10 +22,10 @@ class TestGemPathSupport < Gem::TestCase
def test_initialize_home
ps = Gem::PathSupport.new "GEM_HOME" => "#{@tempdir}/foo"
- expected = File.join(@tempdir, "foo")
- assert_equal expected, ps.home
- assert_equal [expected, *util_path], ps.path
end
if defined?(File::ALT_SEPARATOR) and File::ALT_SEPARATOR
@@ -43,9 +43,9 @@ class TestGemPathSupport < Gem::TestCase
assert_equal ENV["GEM_HOME"], ps.home
expected = [
- ENV["GEM_HOME"],
File.join(@tempdir, 'foo'),
File.join(@tempdir, 'bar'),
]
assert_equal expected, ps.path
@@ -61,32 +61,6 @@ class TestGemPathSupport < Gem::TestCase
assert_equal expected, ps.path
end
- def test_path_equals
- ps = Gem::PathSupport.new
-
- ps.send :path=, ['a', 'b']
-
- assert_equal [@tempdir, 'a', 'b'], ps.path
- end
-
- def test_path_equals_empty
- ps = Gem::PathSupport.new
-
- ps.send :path=, nil
-
- assert_equal [@tempdir, 'something'], ps.path
- end
-
- def test_path_equals_empty_no_GEM_PATH
- ENV.delete 'GEM_PATH'
-
- ps = Gem::PathSupport.new
-
- ps.send :path=, nil
-
- assert_equal [@tempdir, *Gem.default_path], ps.path
- end
-
def util_path
ENV["GEM_PATH"].split(File::PATH_SEPARATOR)
end
@@ -51,6 +51,8 @@ class TestGemPlatform < Gem::TestCase
'i386-freebsd5' => ['x86', 'freebsd', '5'],
'i386-freebsd6' => ['x86', 'freebsd', '6'],
'i386-freebsd7' => ['x86', 'freebsd', '7'],
'i386-java1.5' => ['x86', 'java', '1.5'],
'x86-java1.6' => ['x86', 'java', '1.6'],
'i386-java1.6' => ['x86', 'java', '1.6'],
@@ -67,8 +69,7 @@ class TestGemPlatform < Gem::TestCase
'x86-mswin32' => ['x86', 'mswin32', nil],
'x86-mswin32_60' => ['x86', 'mswin32', '60'],
'x86-mswin32-60' => ['x86', 'mswin32', '60'],
- 'i386-netbsdelf5.1.' => ['x86', 'netbsdelf', '5'],
- 'x86_64-netbsd6.99.7' => ['x86_64', 'netbsd', '6'],
'i386-openbsd4.0' => ['x86', 'openbsd', '4.0'],
'i386-solaris2.10' => ['x86', 'solaris', '2.10'],
'i386-solaris2.8' => ['x86', 'solaris', '2.8'],
@@ -76,6 +77,7 @@ class TestGemPlatform < Gem::TestCase
'x86_64-linux' => ['x86_64', 'linux', nil],
'x86_64-openbsd3.9' => ['x86_64', 'openbsd', '3.9'],
'x86_64-openbsd4.0' => ['x86_64', 'openbsd', '4.0'],
}
test_cases.each do |arch, expected|
@@ -137,12 +139,6 @@ class TestGemPlatform < Gem::TestCase
assert_equal '1', platform.version
end
- def test_empty
- platform = Gem::Platform.new 'cpu-other_platform1'
- assert_respond_to platform, :empty?
- assert_equal false, Gem::Deprecate.skip_during { platform.empty? }
- end
-
def test_to_s
if win_platform? then
assert_equal 'x86-mswin32-60', Gem::Platform.local.to_s
@@ -0,0 +1,245 @@
@@ -1,12 +1,10 @@
require 'rubygems/test_case'
require 'ostruct'
require 'webrick'
-begin
- require 'webrick/https'
-rescue LoadError
-end
require 'rubygems/remote_fetcher'
-require 'rubygems/format'
# = Testing Proxy Settings
#
@@ -90,6 +88,8 @@ gems:
ENV.delete 'HTTP_PROXY_USER'
ENV.delete 'http_proxy_pass'
ENV.delete 'HTTP_PROXY_PASS'
base_server_uri = "http://localhost:#{SERVER_PORT}"
@proxy_uri = "http://localhost:#{PROXY_PORT}"
@@ -104,6 +104,7 @@ gems:
# TODO: why does the remote fetcher need it written to disk?
@a1, @a1_gem = util_gem 'a', '1' do |s| s.executables << 'a_bin' end
Gem::RemoteFetcher.fetcher = nil
@@ -176,6 +177,21 @@ gems:
end
end
def util_fuck_with_fetcher data, blow = false
fetcher = Gem::RemoteFetcher.fetcher
fetcher.instance_variable_set :@test_data, data
@@ -281,8 +297,8 @@ gems:
inst = Gem::RemoteFetcher.fetcher
end
- assert_equal File.join(@tempdir, @a1.file_name),
- inst.download(@a1, local_path)
ensure
FileUtils.chmod 0755, @a1.cache_dir
end
@@ -308,6 +324,7 @@ gems:
s.platform = Gem::Platform::CURRENT
s.instance_variable_set :@original_platform, original_platform
end
e1_data = nil
File.open e1_gem, 'rb' do |fp|
@@ -337,7 +354,7 @@ gems:
cache_path = @a1.cache_file
FileUtils.mv local_path, cache_path
- gem = Gem::Format.from_file_by_path cache_path
assert_equal cache_path, inst.download(gem.spec, cache_path)
end
@@ -345,7 +362,7 @@ gems:
def test_download_unsupported
inst = Gem::RemoteFetcher.fetcher
- e = assert_raises Gem::InstallError do
inst.download @a1, 'ftp://gems.rubyforge.org'
end
@@ -627,6 +644,32 @@ gems:
assert_equal "too many redirects (#{url})", e.message
end
def test_request
uri = URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}"
util_stub_connection_for :body => :junk, :code => 200
@@ -752,7 +795,7 @@ gems:
with_configured_fetcher(":ssl_ca_cert: #{temp_ca_cert}") do |fetcher|
fetcher.fetch_path("https://localhost:#{ssl_server.config[:Port]}/yaml")
end
- end if defined?(OpenSSL::PKey)
def test_do_not_allow_insecure_ssl_connection_by_default
ssl_server = self.class.start_ssl_server
@@ -761,14 +804,14 @@ gems:
fetcher.fetch_path("https://localhost:#{ssl_server.config[:Port]}/yaml")
end
end
- end if defined?(OpenSSL::PKey)
def test_ssl_connection_allow_verify_none
ssl_server = self.class.start_ssl_server
with_configured_fetcher(":ssl_verify_mode: 0") do |fetcher|
fetcher.fetch_path("https://localhost:#{ssl_server.config[:Port]}/yaml")
end
- end if defined?(OpenSSL::PKey)
def test_do_not_follow_insecure_redirect
ssl_server = self.class.start_ssl_server
@@ -778,7 +821,7 @@ gems:
fetcher.fetch_path("https://localhost:#{ssl_server.config[:Port]}/insecure_redirect?to=#{@server_uri}")
end
end
- end if defined?(OpenSSL::PKey)
def with_configured_fetcher(config_str = nil, &block)
if config_str
@@ -856,7 +899,7 @@ gems:
end
DIR = File.expand_path(File.dirname(__FILE__))
- DH_PARAM = defined?(OpenSSL::PKey) ? OpenSSL::PKey::DH.new(128) : nil
def start_ssl_server(config = {})
null_logger = NilLog.new
@@ -894,7 +937,7 @@ gems:
end
end
server
- end if DH_PARAM
@@ -0,0 +1,70 @@
@@ -21,9 +21,19 @@ class TestGemRequirement < Gem::TestCase
assert_requirement_equal "= 2", v(2)
end
- def test_class_available_as_gem_version_requirement
- assert_same Gem::Requirement, Gem::Version::Requirement,
- "Gem::Version::Requirement is aliased for old YAML compatibility."
end
def test_parse
@@ -37,17 +47,19 @@ class TestGemRequirement < Gem::TestCase
end
def test_parse_bad
- e = assert_raises ArgumentError do
Gem::Requirement.parse nil
end
assert_equal 'Illformed requirement [nil]', e.message
- e = assert_raises ArgumentError do
Gem::Requirement.parse ""
end
assert_equal 'Illformed requirement [""]', e.message
end
def test_prerelease_eh
@@ -67,28 +79,37 @@ class TestGemRequirement < Gem::TestCase
def test_satisfied_by_eh_bang_equal
r = req '!= 1.2'
- assert_satisfied_by nil, r
assert_satisfied_by "1.1", r
refute_satisfied_by "1.2", r
assert_satisfied_by "1.3", r
end
def test_satisfied_by_eh_blank
r = req "1.2"
- refute_satisfied_by nil, r
refute_satisfied_by "1.1", r
assert_satisfied_by "1.2", r
refute_satisfied_by "1.3", r
end
def test_satisfied_by_eh_equal
r = req "= 1.2"
- refute_satisfied_by nil, r
refute_satisfied_by "1.1", r
assert_satisfied_by "1.2", r
refute_satisfied_by "1.3", r
end
def test_satisfied_by_eh_gt
@@ -98,7 +119,7 @@ class TestGemRequirement < Gem::TestCase
refute_satisfied_by "1.2", r
assert_satisfied_by "1.3", r
- assert_raises NoMethodError do
r.satisfied_by? nil
end
end
@@ -110,7 +131,7 @@ class TestGemRequirement < Gem::TestCase
assert_satisfied_by "1.2", r
assert_satisfied_by "1.3", r
- assert_raises NoMethodError do
r.satisfied_by? nil
end
end
@@ -122,7 +143,7 @@ class TestGemRequirement < Gem::TestCase
assert_satisfied_by "1.2", r
refute_satisfied_by "1.3", r
- assert_raises NoMethodError do
r.satisfied_by? nil
end
end
@@ -134,7 +155,7 @@ class TestGemRequirement < Gem::TestCase
refute_satisfied_by "1.2", r
refute_satisfied_by "1.3", r
- assert_raises NoMethodError do
r.satisfied_by? nil
end
end
@@ -146,7 +167,7 @@ class TestGemRequirement < Gem::TestCase
assert_satisfied_by "1.2", r
refute_satisfied_by "1.3", r
- assert_raises NoMethodError do
r.satisfied_by? nil
end
end
@@ -158,7 +179,7 @@ class TestGemRequirement < Gem::TestCase
assert_satisfied_by "1.2", r
assert_satisfied_by "1.3", r
- assert_raises NoMethodError do
r.satisfied_by? nil
end
end
@@ -200,12 +221,22 @@ class TestGemRequirement < Gem::TestCase
def test_illformed_requirements
[ ">>> 1.3.5", "> blah" ].each do |rq|
- assert_raises ArgumentError, "req [#{rq}] should fail" do
Gem::Requirement.new rq
end
end
end
def test_satisfied_by_eh_boxed
refute_satisfied_by "1.3", "~> 1.4"
assert_satisfied_by "1.4", "~> 1.4"
@@ -4,33 +4,35 @@ require 'rubygems/fix_openssl_warnings' if RUBY_VERSION < "1.9"
class TestGemSecurity < Gem::TestCase
def setup
super
- Gem::Security::OPT[:trust_dir] = File.join(Gem.user_home, '.gem', 'trust')
- end
- def teardown
- super
- Gem::Security::OPT[:trust_dir] = File.join(Gem.user_home, '.gem', 'trust')
end
- def test_class_build_cert
- name = OpenSSL::X509::Name.parse "CN=nobody/DC=example"
- key = OpenSSL::PKey::RSA.new 512
- opt = { :cert_age => 60 }
- cert = Gem::Security.build_cert name, key, opt
assert_kind_of OpenSSL::X509::Certificate, cert
assert_equal 2, cert.version
- assert_equal 0, cert.serial
assert_equal key.public_key.to_pem, cert.public_key.to_pem
assert_in_delta Time.now, cert.not_before, 10
assert_in_delta Time.now + 60, cert.not_after, 10
assert_equal name.to_s, cert.subject.to_s
- assert_equal 3, cert.extensions.length
constraints = cert.extensions.find { |ext| ext.oid == 'basicConstraints' }
assert_equal 'CA:FALSE', constraints.value
@@ -41,60 +43,204 @@ class TestGemSecurity < Gem::TestCase
key_ident = cert.extensions.find { |ext| ext.oid == 'subjectKeyIdentifier' }
assert_equal 59, key_ident.value.length
- assert_equal name.to_s, cert.issuer.to_s
assert_equal name.to_s, cert.subject.to_s
end
- def test_class_build_self_signed_cert
email = 'nobody@example'
- opt = {
- :cert_age => 60,
- :key_size => 512,
- :save_cert => false,
- :save_key => false,
- }
- result = Gem::Security.build_self_signed_cert email, opt
- key = result[:key]
- assert_kind_of OpenSSL::PKey::RSA, key
- # assert_equal 512, key.something_here
- cert = result[:cert]
- assert_equal '/CN=nobody/DC=example', cert.issuer.to_s
- end
- def test_class_sign_cert
- name = OpenSSL::X509::Name.parse "CN=nobody/DC=example"
- key = OpenSSL::PKey::RSA.new 512
- cert = OpenSSL::X509::Certificate.new
- cert.subject = name
- cert.public_key = key.public_key
- signed = Gem::Security.sign_cert cert, key, cert
- assert cert.verify key
- assert_equal name.to_s, signed.subject.to_s
end
def test_class_email_to_name
- munger = Gem::Security::OPT[:munge_re]
-
assert_equal '/CN=nobody/DC=example',
- Gem::Security.email_to_name('nobody@example', munger).to_s
assert_equal '/CN=nobody/DC=example/DC=com',
- Gem::Security.email_to_name('[email protected]', munger).to_s
assert_equal '/CN=no.body/DC=example',
- Gem::Security.email_to_name('no.body@example', munger).to_s
assert_equal '/CN=no_body/DC=example',
- Gem::Security.email_to_name('no+body@example', munger).to_s
end
-end if defined?(OpenSSL)
@@ -0,0 +1,376 @@
@@ -0,0 +1,189 @@
@@ -0,0 +1,94 @@
@@ -18,55 +18,50 @@ class TestGemServer < Gem::TestCase
@res = WEBrick::HTTPResponse.new :HTTPVersion => '1.0'
end
- def test_spec_dirs
- s = Gem::Server.new Gem.dir, process_based_port, false
- assert_equal [File.join(Gem.dir, 'specifications')], s.spec_dirs
-
- s = Gem::Server.new [Gem.dir, Gem.dir], process_based_port, false
- assert_equal [File.join(Gem.dir, 'specifications'),
- File.join(Gem.dir, 'specifications')], s.spec_dirs
end
- def test_Marshal
- data = StringIO.new "GET /Marshal.#{Gem.marshal_version} HTTP/1.0\r\n\r\n"
- @req.parse data
- Gem::Deprecate.skip_during do
- @server.Marshal @req, @res
- end
- assert_equal 200, @res.status, @res.body
- assert_match %r| \d\d:\d\d:\d\d |, @res['date']
- assert_equal 'application/octet-stream', @res['content-type']
- Gem::Deprecate.skip_during do
- si = Gem::SourceIndex.new
- si.add_specs @a1, @a2
- assert_equal si, Marshal.load(@res.body)
- end
- end
- def test_Marshal_Z
- data = StringIO.new "GET /Marshal.#{Gem.marshal_version}.Z HTTP/1.0\r\n\r\n"
- @req.parse data
- Gem::Deprecate.skip_during do
- @server.Marshal @req, @res
- end
- assert_equal 200, @res.status, @res.body
- assert_match %r| \d\d:\d\d:\d\d |, @res['date']
- assert_equal 'application/x-deflate', @res['content-type']
- Gem::Deprecate.skip_during do
- si = Gem::SourceIndex.new
- si.add_specs @a1, @a2
- assert_equal si, Marshal.load(Gem.inflate(@res.body))
- end
end
def test_latest_specs
@@ -0,0 +1,188 @@
@@ -1,250 +0,0 @@
-require 'rubygems/test_case'
-require 'rubygems/source_index'
-require 'rubygems/config_file'
-require 'rubygems/deprecate'
-
-class TestGemSourceIndex < Gem::TestCase
- def setup
- super
-
- util_setup_fake_fetcher
-
- @source_index = Gem::Deprecate.skip_during { Gem.source_index }
- end
-
- def test_find_name
- Gem::Deprecate.skip_during do
- assert_equal [@a1, @a2, @a3a], @source_index.find_name('a')
- assert_equal [@a2], @source_index.find_name('a', '= 2')
- assert_equal [], @source_index.find_name('bogusstring')
- assert_equal [], @source_index.find_name('a', '= 3')
-
- source_index = Gem::SourceIndex.new
- source_index.add_spec @a1
- source_index.add_spec @a2
-
- assert_equal [@a1], source_index.find_name(@a1.name, '= 1')
-
- r1 = Gem::Requirement.create '= 1'
- assert_equal [@a1], source_index.find_name(@a1.name, r1)
- end
- end
-
- def test_find_name_empty_cache
- Gem::Deprecate.skip_during do
- empty_source_index = Gem::SourceIndex.new
- assert_equal [], empty_source_index.find_name("foo")
- end
- end
-
- # HACK: deprecated impl is failing tests, but I may want to port it over
- def test_latest_specs
- Gem::Deprecate.skip_during do
- p1_ruby = quick_spec 'p', '1'
- p1_platform = quick_spec 'p', '1' do |spec|
- spec.platform = Gem::Platform::CURRENT
- end
-
- a1_platform = quick_spec @a1.name, (@a1.version) do |s|
- s.platform = Gem::Platform.new 'x86-my_platform1'
- end
-
- a2_platform = quick_spec @a2.name, (@a2.version) do |s|
- s.platform = Gem::Platform.new 'x86-my_platform1'
- end
-
- a2_platform_other = quick_spec @a2.name, (@a2.version) do |s|
- s.platform = Gem::Platform.new 'x86-other_platform1'
- end
-
- a3_platform_other = quick_spec @a2.name, (@a2.version.bump) do |s|
- s.platform = Gem::Platform.new 'x86-other_platform1'
- end
-
- @source_index.add_spec p1_ruby
- @source_index.add_spec p1_platform
- @source_index.add_spec a1_platform
- @source_index.add_spec a2_platform
- @source_index.add_spec a2_platform_other
- @source_index.add_spec a3_platform_other
-
- expected = [
- @a2.full_name,
- a2_platform.full_name,
- a3_platform_other.full_name,
- @b2.full_name,
- @c1_2.full_name,
- @a_evil9.full_name,
- p1_ruby.full_name,
- p1_platform.full_name,
- @pl1.full_name
- ].sort
-
- latest_specs = @source_index.latest_specs.map { |s| s.full_name }.sort
-
- assert_equal expected, latest_specs
- end
- end
-
- def test_load_gems_in
- Gem::Deprecate.skip_during do
- spec_dir1 = File.join @gemhome, 'specifications'
- spec_dir2 = File.join @tempdir, 'gemhome2', 'specifications'
-
- FileUtils.rm_r spec_dir1
-
- FileUtils.mkdir_p spec_dir1
- FileUtils.mkdir_p spec_dir2
-
- a1 = quick_spec 'a', '1' do |spec| spec.author = 'author 1' end
- a2 = quick_spec 'a', '1' do |spec| spec.author = 'author 2' end
-
- path1 = File.join(spec_dir1, a1.spec_name)
- path2 = File.join(spec_dir2, a2.spec_name)
-
- File.open path1, 'w' do |fp|
- fp.write a1.to_ruby
- end
-
- File.open path2, 'w' do |fp|
- fp.write a2.to_ruby
- end
-
- @source_index.load_gems_in File.dirname(path1), File.dirname(path2)
-
- assert_equal a1.author, @source_index.specification(a1.full_name).author
- end
- end
-
- # REFACTOR: move to test_gem_commands_outdated_command.rb
- def test_outdated
- Gem::Deprecate.skip_during do
- util_setup_spec_fetcher
-
- assert_equal [], @source_index.outdated
-
- updated = quick_spec @a2.name, (@a2.version.bump)
- util_setup_spec_fetcher updated
-
- assert_equal [updated.name], @source_index.outdated
-
- updated_platform = quick_spec @a2.name, (updated.version.bump) do |s|
- s.platform = Gem::Platform.new 'x86-other_platform1'
- end
-
- util_setup_spec_fetcher updated, updated_platform
-
- assert_equal [updated_platform.name], @source_index.outdated
- end
- end
-
- def test_prerelease_specs_kept_in_right_place
- Gem::Deprecate.skip_during do
- gem_a1_alpha = quick_spec 'abba', '1.a'
- @source_index.add_spec gem_a1_alpha
-
- refute_includes @source_index.latest_specs, gem_a1_alpha
- assert_includes @source_index.latest_specs(true), gem_a1_alpha
- assert_empty @source_index.find_name gem_a1_alpha.full_name
- assert_includes @source_index.prerelease_specs, gem_a1_alpha
- end
- end
-
- def test_refresh_bang
- Gem::Deprecate.skip_during do
- a1_spec = File.join @gemhome, "specifications", @a1.spec_name
-
- FileUtils.mv a1_spec, @tempdir
-
- Gem::Specification.reset
- Gem.send :class_variable_set, :@@source_index, nil
- source_index = Gem.source_index
-
- refute_includes source_index.gems.keys.sort, @a1.full_name
-
- FileUtils.mv File.join(@tempdir, @a1.spec_name), a1_spec
-
- source_index.refresh!
-
- assert source_index.gems.include?(@a1.full_name)
- end
- end
-
- def test_remove_spec
- Gem::Deprecate.skip_during do
- si = Gem.source_index
-
- expected = si.gems.keys.sort
-
- expected.delete "a-1"
- @source_index.remove_spec 'a-1'
-
- assert_equal expected, si.gems.keys.sort
-
- expected.delete "a-3.a"
- @source_index.remove_spec 'a-3.a'
-
- assert_equal expected, si.gems.keys.sort
- end
- end
-
- def test_search
- Gem::Deprecate.skip_during do
- requirement = Gem::Requirement.create '= 9'
- with_version = Gem::Dependency.new(/^a/, requirement)
- assert_equal [@a_evil9], @source_index.search(with_version)
-
- with_default = Gem::Dependency.new(/^a/, Gem::Requirement.default)
- assert_equal [@a1, @a2, @a3a, @a_evil9], @source_index.search(with_default)
-
- c1_1_dep = Gem::Dependency.new 'c', '~> 1.1'
- assert_equal [@c1_2], @source_index.search(c1_1_dep)
- end
- end
-
- def test_search_platform
- Gem::Deprecate.skip_during do
- util_set_arch 'x86-my_platform1'
-
- a1 = quick_spec 'a', '1'
- a1_mine = quick_spec 'a', '1' do |s|
- s.platform = Gem::Platform.new 'x86-my_platform1'
- end
- a1_other = quick_spec 'a', '1' do |s|
- s.platform = Gem::Platform.new 'x86-other_platform1'
- end
-
- si = Gem::SourceIndex.new
- si.add_specs a1, a1_mine, a1_other
-
- dep = Gem::Dependency.new 'a', Gem::Requirement.new('1')
-
- gems = si.search dep, true
-
- assert_equal [a1, a1_mine], gems.sort
- end
- end
-
- def test_signature
- Gem::Deprecate.skip_during do
- sig = @source_index.gem_signature('foo-1.2.3')
- assert_equal 64, sig.length
- assert_match(/^[a-f0-9]{64}$/, sig)
- end
- end
-
- def test_specification
- Gem::Deprecate.skip_during do
- assert_equal @a1, @source_index.specification(@a1.full_name)
-
- assert_nil @source_index.specification("foo-1.2.4")
- end
- end
-
- def test_index_signature
- Gem::Deprecate.skip_during do
- sig = @source_index.index_signature
- assert_match(/^[a-f0-9]{64}$/, sig)
- end
- end
-end
@@ -0,0 +1,87 @@
@@ -0,0 +1,83 @@
@@ -0,0 +1,33 @@
@@ -3,10 +3,15 @@ require 'rubygems/spec_fetcher'
class TestGemSpecFetcher < Gem::TestCase
def setup
super
@uri = URI.parse @gem_repo
util_setup_fake_fetcher
@@ -16,108 +21,114 @@ class TestGemSpecFetcher < Gem::TestCase
Gem::Specification.remove_spec @b2
- @specs = Gem::Specification.map { |spec|
- [spec.name, spec.version, spec.original_platform]
}.sort
# TODO: couldn't all of this come from the fake spec fetcher?
@latest_specs = Gem::Specification.latest_specs.sort.map { |spec|
- [spec.name, spec.version, spec.original_platform]
}
- prerelease = Gem::Specification.find_all { |s| s.version.prerelease? }
- @prerelease_specs = prerelease.map { |spec|
- [spec.name, spec.version, spec.original_platform]
- }.sort
-
v = Gem.marshal_version
- s_zip = util_gzip(Marshal.dump(@specs))
- l_zip = util_gzip(Marshal.dump(@latest_specs))
- p_zip = util_gzip(Marshal.dump(@prerelease_specs))
@fetcher.data["#{@gem_repo}specs.#{v}.gz"] = s_zip
@fetcher.data["#{@gem_repo}latest_specs.#{v}.gz"] = l_zip
@fetcher.data["#{@gem_repo}prerelease_specs.#{v}.gz"] = p_zip
@sf = Gem::SpecFetcher.new
end
- def test_fetch_all
d = "#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}"
@fetcher.data["#{d}#{@a1.spec_name}.rz"] = util_zip(Marshal.dump(@a1))
@fetcher.data["#{d}#{@a2.spec_name}.rz"] = util_zip(Marshal.dump(@a2))
@fetcher.data["#{d}#{@a_pre.spec_name}.rz"] = util_zip(Marshal.dump(@a_pre))
@fetcher.data["#{d}#{@a3a.spec_name}.rz"] = util_zip(Marshal.dump(@a3a))
- dep = Gem::Dependency.new 'a', 1
- specs_and_sources = @sf.fetch dep, true
spec_names = specs_and_sources.map do |spec, source_uri|
[spec.full_name, source_uri]
end
- expected = [[@a1.full_name, @gem_repo], [@a2.full_name, @gem_repo]]
assert_equal expected, spec_names
assert_same specs_and_sources.first.last, specs_and_sources.last.last
end
- def test_fetch_latest
d = "#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}"
@fetcher.data["#{d}#{@a1.spec_name}.rz"] = util_zip(Marshal.dump(@a1))
@fetcher.data["#{d}#{@a2.spec_name}.rz"] = util_zip(Marshal.dump(@a2))
@fetcher.data["#{d}#{@a_pre.spec_name}.rz"] = util_zip(Marshal.dump(@a_pre))
- dep = Gem::Dependency.new 'a', 1
- specs_and_sources = @sf.fetch dep
spec_names = specs_and_sources.map do |spec, source_uri|
[spec.full_name, source_uri]
end
- assert_equal [[@a2.full_name, @gem_repo]], spec_names
end
- def test_fetch_prerelease
d = "#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}"
@fetcher.data["#{d}#{@a1.spec_name}.rz"] = util_zip(Marshal.dump(@a1))
@fetcher.data["#{d}#{@a2.spec_name}.rz"] = util_zip(Marshal.dump(@a2))
@fetcher.data["#{d}#{@a_pre.spec_name}.rz"] = util_zip(Marshal.dump(@a_pre))
- specs_and_sources = @sf.fetch dep('a', '1.a'), false, true, true
spec_names = specs_and_sources.map do |spec, source_uri|
[spec.full_name, source_uri]
end
- assert_equal [[@a_pre.full_name, @gem_repo]], spec_names
end
- def test_fetch_platform
util_set_arch 'i386-linux'
@fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@pl1.original_name}.gemspec.rz"] =
util_zip(Marshal.dump(@pl1))
dep = Gem::Dependency.new 'pl', 1
- specs_and_sources = @sf.fetch dep
spec_names = specs_and_sources.map do |spec, source_uri|
[spec.full_name, source_uri]
end
- assert_equal [[@pl1.full_name, @gem_repo]], spec_names
end
- def test_fetch_with_errors_mismatched_platform
util_set_arch 'hrpa-989'
@fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@pl1.original_name}.gemspec.rz"] =
util_zip(Marshal.dump(@pl1))
dep = Gem::Dependency.new 'pl', 1
- specs_and_sources, errors = @sf.fetch_with_errors dep
assert_equal 0, specs_and_sources.size
assert_equal 1, errors.size
@@ -125,284 +136,95 @@ class TestGemSpecFetcher < Gem::TestCase
assert_equal "i386-linux", errors[0].platforms.first
end
- def test_fetch_spec
- spec_uri = "#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a1.spec_name}"
- @fetcher.data["#{spec_uri}.rz"] = util_zip(Marshal.dump(@a1))
-
- spec = @sf.fetch_spec ['a', Gem::Version.new(1), 'ruby'], @uri
- assert_equal @a1.full_name, spec.full_name
-
- cache_dir = @sf.cache_dir URI.parse(spec_uri)
-
- cache_file = File.join cache_dir, @a1.spec_name
-
- assert File.exist?(cache_file)
- end
-
- def test_fetch_spec_cached
- spec_uri = "#{@gem_repo}/#{Gem::MARSHAL_SPEC_DIR}#{@a1.spec_name}"
- @fetcher.data["#{spec_uri}.rz"] = nil
-
- cache_dir = @sf.cache_dir URI.parse(spec_uri)
- FileUtils.mkdir_p cache_dir
-
- cache_file = File.join cache_dir, @a1.spec_name
-
- open cache_file, 'wb' do |io|
- Marshal.dump @a1, io
end
- spec = @sf.fetch_spec ['a', Gem::Version.new(1), 'ruby'], @uri
- assert_equal @a1.full_name, spec.full_name
- end
-
- def test_fetch_spec_platform
- @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@pl1.original_name}.gemspec.rz"] =
- util_zip(Marshal.dump(@pl1))
-
- spec = @sf.fetch_spec ['pl', Gem::Version.new(1), 'i386-linux'], @uri
-
- assert_equal @pl1.full_name, spec.full_name
- end
- def test_fetch_spec_platform_ruby
- @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a1.spec_name}.rz"] =
- util_zip(Marshal.dump(@a1))
-
- spec = @sf.fetch_spec ['a', Gem::Version.new(1), nil], @uri
- assert_equal @a1.full_name, spec.full_name
-
- spec = @sf.fetch_spec ['a', Gem::Version.new(1), ''], @uri
- assert_equal @a1.full_name, spec.full_name
- end
-
- def test_find_matching_all
- dep = Gem::Dependency.new 'a', 1
- specs = @sf.find_matching dep, true
-
- expected = [
- [['a', Gem::Version.new(1), Gem::Platform::RUBY], @gem_repo],
- [['a', Gem::Version.new(2), Gem::Platform::RUBY], @gem_repo],
- ]
-
- assert_equal expected, specs
- end
-
- def test_find_matching_latest
- dep = Gem::Dependency.new 'a', 1
- specs = @sf.find_matching dep
-
- expected = [
- [['a', Gem::Version.new(2), Gem::Platform::RUBY], @gem_repo],
- ]
-
- assert_equal expected, specs
- end
-
- def test_find_matching_prerelease
- dep = Gem::Dependency.new 'a', '1.a'
- specs = @sf.find_matching dep, false, true, true
-
- expected = [
- [['a', Gem::Version.new('1.a'), Gem::Platform::RUBY], @gem_repo],
- ]
-
- assert_equal expected, specs
- end
-
- def test_find_matching_platform
- util_set_arch 'i386-linux'
-
- dep = Gem::Dependency.new 'pl', 1
- specs = @sf.find_matching dep
-
- expected = [
- [['pl', Gem::Version.new(1), 'i386-linux'], @gem_repo],
- ]
-
- assert_equal expected, specs
-
- util_set_arch 'i386-freebsd6'
-
- dep = Gem::Dependency.new 'pl', 1
- specs = @sf.find_matching dep
-
- assert_equal [], specs
- end
- def test_find_matching_with_errors_matched_platform
- util_set_arch 'i386-linux'
- dep = Gem::Dependency.new 'pl', 1
- specs, errors = @sf.find_matching_with_errors dep
- expected = [
- [['pl', Gem::Version.new(1), 'i386-linux'], @gem_repo],
- ]
- assert_equal expected, specs
- assert_equal 0, errors.size
end
- def test_find_matching_with_errors_invalid_platform
- util_set_arch 'hrpa-899'
-
- dep = Gem::Dependency.new 'pl', 1
- specs, errors = @sf.find_matching_with_errors dep
-
- assert_equal 0, specs.size
- assert_equal 1, errors.size
-
- assert_equal "i386-linux", errors[0].platforms.first
end
- def test_find_all_platforms
- util_set_arch 'i386-freebsd6'
- dep = Gem::Dependency.new 'pl', 1
- specs = @sf.find_matching dep, false, false
-
- expected = [
- [['pl', Gem::Version.new(1), 'i386-linux'], @gem_repo],
- ]
- assert_equal expected, specs
end
- def test_list
- specs = @sf.list
-
- assert_equal [@uri], specs.keys
- assert_equal @latest_specs, specs[@uri].sort
- end
- def test_list_all
- specs = @sf.list true
- assert_equal [@uri], specs.keys
- assert_equal([["a", Gem::Version.new("1"), "ruby"],
- ["a", Gem::Version.new("2"), "ruby"],
- ["a_evil", Gem::Version.new("9"), "ruby"],
- ["c", Gem::Version.new("1.2"), "ruby"],
- ["pl", Gem::Version.new("1"), "i386-linux"]],
- specs[@uri].sort)
end
- def test_list_cache
- specs = @sf.list
- refute specs[@uri].empty?
@fetcher.data["#{@gem_repo}/latest_specs.#{Gem.marshal_version}.gz"] = nil
- cached_specs = @sf.list
assert_equal specs, cached_specs
end
- def test_list_cache_all
- specs = @sf.list true
- refute specs[@uri].empty?
@fetcher.data["#{@gem_repo}/specs.#{Gem.marshal_version}.gz"] = nil
- cached_specs = @sf.list true
assert_equal specs, cached_specs
end
- def test_list_latest_all
- specs = @sf.list false
-
- assert_equal [@latest_specs], specs.values
-
- specs = @sf.list true
-
- assert_equal([[["a", Gem::Version.new("1"), "ruby"],
- ["a", Gem::Version.new("2"), "ruby"],
- ["a_evil", Gem::Version.new("9"), "ruby"],
- ["c", Gem::Version.new("1.2"), "ruby"],
- ["pl", Gem::Version.new("1"), "i386-linux"]]],
- specs.values, 'specs file not loaded')
- end
-
- def test_list_prerelease
- specs = @sf.list false, true
-
- assert_equal @prerelease_specs, specs[@uri].sort
- end
-
- def test_load_specs
- expected = [
- ['a', Gem::Version.new('1.a'), Gem::Platform::RUBY],
- ['a', Gem::Version.new(1), Gem::Platform::RUBY],
- ['a', Gem::Version.new(2), Gem::Platform::RUBY],
- ['a', Gem::Version.new('3.a'), Gem::Platform::RUBY],
- ['a_evil', Gem::Version.new(9), Gem::Platform::RUBY],
- ['c', Gem::Version.new('1.2'), Gem::Platform::RUBY],
- ['pl', Gem::Version.new(1), 'i386-linux'],
- ]
-
- assert_equal expected, @sf.load_specs(@uri, 'specs')
-
- cache_dir = File.join Gem.user_home, '.gem', 'specs', 'gems.example.com%80'
- assert File.exist?(cache_dir), "#{cache_dir} does not exist"
-
- cache_file = File.join cache_dir, "specs.#{Gem.marshal_version}"
- assert File.exist?(cache_file)
- end
-
- def test_load_specs_cached
- @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] = nil
- @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}"] =
- ' ' * Marshal.dump(@latest_specs).length
-
- cache_dir = File.join Gem.user_home, '.gem', 'specs', 'gems.example.com%80'
- FileUtils.mkdir_p cache_dir
-
- cache_file = File.join cache_dir, "latest_specs.#{Gem.marshal_version}"
-
- open cache_file, 'wb' do |io|
- Marshal.dump @latest_specs, io
- end
-
- latest_specs = @sf.load_specs @uri, 'latest_specs'
-
- assert_equal @latest_specs, latest_specs
end
- def test_load_specs_cached_empty
- @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] =
- proc do
- @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] =
- util_gzip(Marshal.dump(@latest_specs))
-
- nil
- end
- cache_dir = File.join Gem.user_home, '.gem', 'specs', 'gems.example.com%80'
- FileUtils.mkdir_p cache_dir
-
- cache_file = File.join cache_dir, "latest_specs.#{Gem.marshal_version}"
-
- open cache_file, 'wb' do |io|
- io.write Marshal.dump(@latest_specs)[0, 10]
- end
-
- latest_specs = @sf.load_specs @uri, 'latest_specs'
-
- assert_equal @latest_specs, latest_specs
end
- def test_cache_dir_escapes_windows_paths
- uri = URI.parse("file:///C:/WINDOWS/Temp/gem_repo")
- cache_dir = @sf.cache_dir(uri).gsub(@sf.dir, '')
- assert cache_dir !~ /:/, "#{cache_dir} should not contain a :"
- end
end
@@ -81,6 +81,7 @@ end
files
homepage
licenses
name
platform
post_install_message
@@ -117,7 +118,6 @@ end
end
def test_self_from_yaml_syck_date_bug
- return unless have_syck # No meanings if no syck
# This is equivalent to (and totally valid) psych 1.0 output and
# causes parse errors on syck.
yaml = @a1.to_yaml
@@ -132,7 +132,6 @@ end
end
def test_self_from_yaml_syck_default_key_bug
- return unless have_syck # No meanings if no syck
# This is equivalent to (and totally valid) psych 1.0 output and
# causes parse errors on syck.
yaml = <<-YAML
@@ -302,6 +301,21 @@ dependencies: []
assert_equal @a2, spec
end
def test_self_load_escape_curly
@a2.name = 'a};raise "improper escaping";%q{'
@@ -421,13 +435,15 @@ dependencies: []
end
def test_emits_zulu_timestamps_properly
t = Time.utc(2012, 3, 12)
@a2.date = t
yaml = with_psych { @a2.to_yaml }
assert_match %r!date: 2012-03-12 00:00:00\.000000000 Z!, yaml
- end if RUBY_VERSION =~ /1\.9\.2/
def test_initialize
spec = Gem::Specification.new do |s|
@@ -571,10 +587,6 @@ dependencies: []
@a2.activate
assert @a2.activated?
-
- Gem::Deprecate.skip_during do
- assert @a2.loaded?
- end
end
def test_add_dependency_with_explicit_type
@@ -643,11 +655,29 @@ dependencies: []
assert_equal Time.utc(2003, 9, 17, 0,0,0), @a1.date
end
def test_dependencies
util_setup_deps
assert_equal [@bonobo, @monkey], @gem.dependencies
end
def test_runtime_dependencies
util_setup_deps
assert_equal [@bonobo], @gem.runtime_dependencies
@@ -812,14 +842,17 @@ dependencies: []
def test_full_name
assert_equal 'a-1', @a1.full_name
@a1.platform = Gem::Platform.new ['universal', 'darwin', nil]
assert_equal 'a-1-universal-darwin', @a1.full_name
@a1.instance_variable_set :@new_platform, 'mswin32'
assert_equal 'a-1-mswin32', @a1.full_name, 'legacy'
return if win_platform?
@a1.platform = 'current'
assert_equal 'a-1-x86-darwin-8', @a1.full_name
end
@@ -832,6 +865,7 @@ dependencies: []
}
test_cases.each do |arch, expected|
util_set_arch arch
@a1.platform = 'current'
assert_equal expected, @a1.full_name
@@ -844,15 +878,12 @@ dependencies: []
refute_equal @a1.hash, @a2.hash
end
- def test_installation_path
- Gem::Deprecate.skip_during do
- assert_equal @gemhome, @a1.installation_path
- @a1.instance_variable_set :@loaded_from, nil
- @a1.instance_variable_set :@loaded, false
- assert_nil @a1.installation_path
- end
end
def test_lib_files
@@ -885,6 +916,20 @@ dependencies: []
assert_equal Gem::Platform::RUBY, @a1.platform
end
def test_platform_equals
@a1.platform = nil
assert_equal Gem::Platform::RUBY, @a1.platform
@@ -978,6 +1023,11 @@ dependencies: []
assert_equal( 1, (s2 <=> s1))
end
def test_spec_name
assert_equal 'a-1.gemspec', @a1.spec_name
end
@@ -1118,7 +1168,7 @@ Gem::Specification.new do |s|
s.test_files = ["test/suite.rb"]
if s.respond_to? :specification_version then
- s.specification_version = 3
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<rake>, [\"> 0.4\"])
@@ -1154,6 +1204,17 @@ end
assert_equal gemspec1, gemspec2
end
def test_to_ruby_platform
@a2.platform = Gem::Platform.local
@a2.instance_variable_set :@original_platform, 'old_platform'
@@ -1210,25 +1271,6 @@ end
assert_match %r|^platform: ruby$|, @a1.to_yaml
end
- def test_to_yaml_emits_syck_compat_yaml
- if YAML.const_defined?(:ENGINE) && YAML::ENGINE.syck?
- begin
- yamler, YAML::ENGINE.yamler = YAML::ENGINE.yamler, 'psych'
- rescue LoadError
- skip 'cannot load psych'
- end
- end
- begin
- @a1.add_dependency "gx", "1.0.0"
-
- y = @a1.to_yaml
-
- refute_match %r!^\s*- - =!, y
- ensure
- YAML::ENGINE.yamler = yamler if yamler
- end
- end
-
def test_validate
util_setup_validate
@@ -1297,6 +1339,26 @@ end
end
end
def test_validate_description
util_setup_validate
@@ -1494,6 +1556,25 @@ end
end
end
def test_validate_platform_legacy
util_setup_validate
@@ -1572,6 +1653,22 @@ end
assert_equal Gem::Version.new('1'), @a1.version
end
def test__load_fixes_Date_objects
spec = new_spec "a", 1
spec.instance_variable_set :@date, Date.today
@@ -1649,8 +1746,10 @@ end
a-3-x86-other_platform-1
a_evil-9
c-1.2
p-1
#{p1_curr.full_name}
]
latest_specs = Gem::Specification.latest_specs.map(&:full_name).sort
@@ -1658,6 +1757,163 @@ end
assert_equal expected, latest_specs
end
def util_setup_deps
@gem = quick_spec "awesome", "1.0" do |awesome|
awesome.add_runtime_dependency "bonobo", []
@@ -1679,7 +1935,7 @@ end
FileUtils.touch File.join("lib", "code.rb")
FileUtils.touch File.join("test", "suite.rb")
- File.open "bin/exec", "w" do |fp|
fp.puts "#!#{Gem.ruby}"
end
end
@@ -1731,16 +1987,4 @@ end
ensure
$VERBOSE = old_verbose
end
-
- def have_syck
- unless defined?(@@have_syck)
- begin
- old_verbose, $VERBOSE = $VERBOSE, nil
- @@have_syck = with_syck {YAML::ENGINE.syck?}
- ensure
- $VERBOSE = old_verbose
- end
- end
- @@have_syck
- end
end
@@ -6,19 +6,17 @@ class TestGemUninstaller < Gem::InstallerTestCase
def setup
super
- @user_spec.executables = ["executable"]
-
build_rake_in do
use_ui ui do
@installer.install
- @user_installer.install
- Gem.use_paths @gemhome, Gem.user_dir
-
- @spec = Gem::Specification.find_by_name 'a'
- @user_spec = Gem::Specification.find_by_name 'b'
end
end
end
def test_initialize_expand_path
@@ -42,7 +40,7 @@ class TestGemUninstaller < Gem::InstallerTestCase
def test_remove_executables_force_keep
uninstaller = Gem::Uninstaller.new nil, :executables => false
- executable = File.join Gem.user_dir, 'bin', 'executable'
assert File.exist?(executable), 'executable not written'
use_ui @ui do
@@ -57,7 +55,7 @@ class TestGemUninstaller < Gem::InstallerTestCase
def test_remove_executables_force_remove
uninstaller = Gem::Uninstaller.new nil, :executables => true
- executable = File.join Gem.user_dir, 'bin', 'executable'
assert File.exist?(executable), 'executable not written'
use_ui @ui do
@@ -77,7 +75,7 @@ class TestGemUninstaller < Gem::InstallerTestCase
end
exec_path = File.join Gem.user_dir, 'bin', 'executable'
- assert_equal false, File.exist?(exec_path), 'removed exec from bin dir'
assert_equal "Removing executable\n", @ui.output
end
@@ -200,7 +198,7 @@ class TestGemUninstaller < Gem::InstallerTestCase
:executables => true,
:user_install => true)
- gem_dir = File.join Gem.user_dir, 'gems', @user_spec.full_name
Gem.pre_uninstall do
assert_path_exists gem_dir
@@ -218,6 +216,23 @@ class TestGemUninstaller < Gem::InstallerTestCase
assert_same uninstaller, @post_uninstall_hook_arg
end
def test_uninstall_selection_greater_than_one
util_make_gems
@@ -225,11 +240,119 @@ class TestGemUninstaller < Gem::InstallerTestCase
uninstaller = Gem::Uninstaller.new('a')
- use_ui Gem::MockGemUi.new("2\n") do
uninstaller.uninstall
end
updated_list = Gem::Specification.find_all_by_name('a')
assert_equal list.length - 1, updated_list.length
end
end
@@ -11,53 +11,26 @@ class TestGemValidator < Gem::TestCase
@validator = Gem::Validator.new
end
- def test_verify_gem_file
- gem_file = File.join @tempdir, 'simple_gem.gem'
- File.open gem_file, 'wb' do |fp| fp.write @simple_gem end
-
- assert_equal nil, @validator.verify_gem_file(gem_file)
- end
-
- def test_verify_gem_file_empty
- e = assert_raises Gem::VerificationError do
- @validator.verify_gem_file ''
- end
-
- assert_equal 'missing gem file ', e.message
- end
-
- def test_verify_gem_file_nonexistent
- file = '/nonexistent/nonexistent.gem'
- e = assert_raises Gem::VerificationError do
- @validator.verify_gem_file file
end
- assert_equal "missing gem file #{file}", e.message
- end
-
- def test_verify_gem
- assert_equal nil, @validator.verify_gem(@simple_gem)
- end
-
- def test_verify_gem_empty
- e = assert_raises Gem::VerificationError do
- @validator.verify_gem ''
- end
- assert_equal 'empty gem file', e.message
- end
- def test_verify_gem_invalid_checksum
- e = assert_raises Gem::VerificationError do
- @validator.verify_gem @simple_gem.upcase
- end
- assert_equal 'invalid checksum for gem file', e.message
- end
- def test_verify_gem_no_sum
- assert_equal nil, @validator.verify_gem('words')
end
-
end
@@ -33,6 +33,9 @@ class TestGemVersion < Gem::TestCase
assert_same fake, Gem::Version.create(fake)
assert_nil Gem::Version.create(nil)
assert_equal v("5.1"), Gem::Version.create("5.1")
end
def test_eql_eh
@@ -56,7 +59,7 @@ class TestGemVersion < Gem::TestCase
end
def test_initialize
- ["1.0", "1.0 ", " 1.0 ", "1.0\n", "\n1.0\n"].each do |good|
assert_version_equal "1.0", good
end
@@ -106,13 +109,13 @@ class TestGemVersion < Gem::TestCase
assert_nil v("1.0") <=> "whatever"
end
- def test_spermy_recommendation
- assert_spermy_equal "~> 1.0", "1"
- assert_spermy_equal "~> 1.0", "1.0"
- assert_spermy_equal "~> 1.2", "1.2"
- assert_spermy_equal "~> 1.2", "1.2.0"
- assert_spermy_equal "~> 1.2", "1.2.3"
- assert_spermy_equal "~> 1.2", "1.2.3.a.4"
end
def test_to_s
@@ -125,10 +128,10 @@ class TestGemVersion < Gem::TestCase
assert v(version).prerelease?, "#{version} is a prerelease"
end
- # Assert that +expected+ is the "spermy" recommendation for +version".
- def assert_spermy_equal expected, version
- assert_equal expected, v(version).spermy_recommendation
end
# Assert that bumping the +unbumped+ version yields the +expected+.
@@ -0,0 +1,193 @@
@@ -0,0 +1,9 @@
@@ -0,0 +1,9 @@