rubygems-update 0.9.4 → 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rubygems-update might be problematic. Click here for more details.
- data/ChangeLog +587 -0
- data/README +0 -1
- data/Rakefile +39 -12
- data/TODO +0 -5
- data/bin/gem +7 -7
- data/bin/update_rubygems +1 -1
- data/examples/application/an-app.gemspec +1 -1
- data/gemspecs/cgikit-1.1.0.gemspec +1 -2
- data/gemspecs/jabber4r.gemspec +1 -1
- data/gemspecs/linguistics.gemspec +1 -1
- data/gemspecs/ook.gemspec +1 -1
- data/gemspecs/progressbar.gemspec +1 -1
- data/gemspecs/redcloth.gemspec +1 -1
- data/gemspecs/rublog.gemspec +1 -1
- data/gemspecs/ruby-doom.gemspec +1 -1
- data/gemspecs/rubyjdwp.gemspec +1 -1
- data/gemspecs/statistics.gemspec +1 -1
- data/lib/rubygems.rb +167 -105
- data/lib/rubygems/builder.rb +12 -10
- data/lib/rubygems/command.rb +177 -60
- data/lib/rubygems/command_manager.rb +30 -38
- data/lib/rubygems/commands/build_command.rb +42 -46
- data/lib/rubygems/commands/cert_command.rb +72 -69
- data/lib/rubygems/commands/check_command.rb +63 -63
- data/lib/rubygems/commands/cleanup_command.rb +25 -7
- data/lib/rubygems/commands/contents_command.rb +70 -62
- data/lib/rubygems/commands/dependency_command.rb +131 -86
- data/lib/rubygems/commands/environment_command.rb +67 -46
- data/lib/rubygems/commands/fetch_command.rb +62 -0
- data/lib/rubygems/commands/generate_index_command.rb +57 -0
- data/lib/rubygems/commands/help_command.rb +163 -73
- data/lib/rubygems/commands/install_command.rb +114 -128
- data/lib/rubygems/commands/list_command.rb +10 -8
- data/lib/rubygems/commands/lock_command.rb +101 -0
- data/lib/rubygems/commands/mirror_command.rb +105 -0
- data/lib/rubygems/commands/outdated_command.rb +24 -15
- data/lib/rubygems/commands/pristine_command.rb +118 -88
- data/lib/rubygems/commands/query_command.rb +109 -77
- data/lib/rubygems/commands/rdoc_command.rb +13 -10
- data/lib/rubygems/commands/search_command.rb +10 -8
- data/lib/rubygems/commands/server_command.rb +48 -0
- data/lib/rubygems/commands/sources_command.rb +104 -83
- data/lib/rubygems/commands/specification_command.rb +65 -51
- data/lib/rubygems/commands/uninstall_command.rb +17 -12
- data/lib/rubygems/commands/unpack_command.rb +68 -68
- data/lib/rubygems/commands/update_command.rb +72 -25
- data/lib/rubygems/commands/which_command.rb +86 -0
- data/lib/rubygems/config_file.rb +202 -78
- data/lib/rubygems/custom_require.rb +7 -88
- data/lib/rubygems/dependency.rb +65 -0
- data/lib/rubygems/dependency_installer.rb +232 -0
- data/lib/rubygems/dependency_list.rb +133 -105
- data/lib/rubygems/digest/md5.rb +4 -1
- data/lib/rubygems/digest/sha2.rb +1 -1
- data/lib/rubygems/doc_manager.rb +41 -19
- data/lib/rubygems/exceptions.rb +63 -0
- data/lib/rubygems/ext.rb +18 -0
- data/lib/rubygems/ext/builder.rb +56 -0
- data/lib/rubygems/ext/configure_builder.rb +24 -0
- data/lib/rubygems/ext/ext_conf_builder.rb +23 -0
- data/lib/rubygems/ext/rake_builder.rb +27 -0
- data/lib/rubygems/format.rb +16 -6
- data/lib/rubygems/gem_openssl.rb +43 -6
- data/lib/rubygems/gem_path_searcher.rb +84 -0
- data/lib/rubygems/gem_runner.rb +20 -5
- data/lib/rubygems/indexer.rb +163 -0
- data/lib/rubygems/indexer/abstract_index_builder.rb +80 -0
- data/lib/rubygems/indexer/marshal_index_builder.rb +17 -0
- data/lib/rubygems/indexer/master_index_builder.rb +53 -0
- data/lib/rubygems/indexer/quick_index_builder.rb +48 -0
- data/lib/rubygems/install_update_options.rb +87 -0
- data/lib/rubygems/installer.rb +316 -562
- data/lib/rubygems/local_remote_options.rb +106 -0
- data/lib/rubygems/old_format.rb +5 -13
- data/lib/rubygems/open-uri.rb +2 -0
- data/lib/rubygems/package.rb +28 -32
- data/lib/rubygems/platform.rb +187 -0
- data/lib/rubygems/remote_fetcher.rb +46 -29
- data/lib/rubygems/remote_installer.rb +11 -18
- data/lib/rubygems/requirement.rb +157 -0
- data/lib/rubygems/rubygems_version.rb +1 -1
- data/lib/rubygems/security.rb +715 -457
- data/lib/rubygems/server.rb +77 -59
- data/lib/rubygems/source_index.rb +154 -83
- data/lib/rubygems/source_info_cache.rb +73 -30
- data/lib/rubygems/source_info_cache_entry.rb +12 -3
- data/lib/rubygems/specification.rb +378 -145
- data/lib/rubygems/uninstaller.rb +183 -0
- data/lib/rubygems/user_interaction.rb +38 -9
- data/lib/rubygems/validator.rb +53 -24
- data/lib/rubygems/version.rb +126 -289
- data/lib/rubygems/version_option.rb +49 -0
- data/pkgs/sources/lib/sources.rb +1 -4
- data/pkgs/sources/sources.gemspec +3 -3
- data/scripts/gemdoc.rb +0 -1
- data/setup.rb +166 -1505
- data/test/bogussources.rb +0 -1
- data/test/data/gem-private_key.pem +27 -0
- data/test/data/gem-public_cert.pem +20 -0
- data/test/functional.rb +3 -105
- data/test/gemutilities.rb +145 -24
- data/test/insure_session.rb +0 -1
- data/test/{test_datadir.rb → test_config.rb} +7 -13
- data/test/test_gem.rb +360 -9
- data/test/test_gem_builder.rb +34 -0
- data/test/{test_command.rb → test_gem_command.rb} +119 -62
- data/test/{test_parse_commands.rb → test_gem_command_manager.rb} +64 -40
- data/test/test_gem_commands_build_command.rb +75 -0
- data/test/test_gem_commands_cert_command.rb +122 -0
- data/test/test_gem_commands_check_command.rb +25 -0
- data/test/test_gem_commands_contents_command.rb +92 -0
- data/test/test_gem_commands_dependency_command.rb +108 -0
- data/test/test_gem_commands_environment_command.rb +117 -0
- data/test/test_gem_commands_fetch_command.rb +34 -0
- data/test/test_gem_commands_generate_index_command.rb +32 -0
- data/test/test_gem_commands_install_command.rb +160 -0
- data/test/test_gem_commands_mirror_command.rb +56 -0
- data/test/test_gem_commands_pristine_command.rb +100 -0
- data/test/test_gem_commands_query_command.rb +82 -0
- data/test/test_gem_commands_sources_command.rb +147 -0
- data/test/test_gem_commands_specification_command.rb +93 -0
- data/test/test_gem_commands_unpack_command.rb +55 -0
- data/test/test_gem_config_file.rb +210 -0
- data/test/test_gem_dependency.rb +89 -0
- data/test/test_gem_dependency_installer.rb +542 -0
- data/test/test_gem_dependency_list.rb +212 -0
- data/test/test_gem_doc_manager.rb +32 -0
- data/test/test_gem_ext_configure_builder.rb +13 -17
- data/test/test_gem_ext_ext_conf_builder.rb +9 -9
- data/test/test_gem_ext_rake_builder.rb +23 -11
- data/test/test_gem_format.rb +69 -0
- data/test/test_gem_gem_path_searcher.rb +57 -0
- data/test/test_gem_gem_runner.rb +35 -0
- data/test/test_gem_indexer.rb +119 -0
- data/test/test_gem_install_update_options.rb +40 -0
- data/test/test_gem_installer.rb +796 -0
- data/test/test_gem_local_remote_options.rb +84 -0
- data/test/test_gem_outdated_command.rb +11 -9
- data/test/test_gem_platform.rb +240 -0
- data/test/{test_remote_fetcher.rb → test_gem_remote_fetcher.rb} +124 -55
- data/test/{test_remote_installer.rb → test_gem_remote_installer.rb} +3 -4
- data/test/test_gem_requirement.rb +223 -0
- data/test/test_gem_server.rb +71 -0
- data/test/test_gem_source_index.rb +429 -0
- data/test/test_gem_source_info_cache.rb +79 -17
- data/test/test_gem_source_info_cache_entry.rb +11 -9
- data/test/test_gem_specification.rb +738 -0
- data/test/test_gem_stream_ui.rb +117 -0
- data/test/test_gem_validator.rb +70 -0
- data/test/test_gem_version.rb +191 -0
- data/test/test_gem_version_option.rb +77 -0
- data/test/{test_require_gem.rb → test_kernel.rb} +19 -12
- data/test/test_open_uri.rb +1 -2
- data/test/test_package.rb +45 -34
- metadata +116 -141
- data/Releases +0 -127
- data/bin/gem_mirror +0 -73
- data/bin/gem_server +0 -6
- data/bin/gemlock +0 -127
- data/bin/gemri +0 -24
- data/bin/gemwhich +0 -89
- data/bin/index_gem_repository.rb +0 -302
- data/lib/gemconfigure.rb +0 -24
- data/lib/rubygems/gem_commands.rb +0 -273
- data/pkgs/sources/sources-0.0.1.gem +0 -0
- data/post-install.rb +0 -121
- data/test/brokenbuildgem.rb +0 -35
- data/test/data/PostMessage-0.0.1.gem +0 -0
- data/test/data/a-0.0.1.gem +0 -0
- data/test/data/a-0.0.2.gem +0 -0
- data/test/data/b-0.0.2.gem +0 -0
- data/test/data/broken-1.0.0.gem +0 -0
- data/test/data/broken_build/broken-build.gemspec +0 -20
- data/test/data/broken_build/ext/extconf.rb +0 -3
- data/test/data/broken_build/ext/foo.c +0 -1
- data/test/data/c-1.2.gem +0 -0
- data/test/data/gemhome/cache/a-0.0.1.gem +0 -0
- data/test/data/gemhome/cache/a-0.0.2.gem +0 -0
- data/test/data/gemhome/cache/b-0.0.2.gem +0 -0
- data/test/data/gemhome/cache/c-1.2.gem +0 -0
- data/test/data/gemhome/gems/a-0.0.1/lib/code.rb +0 -1
- data/test/data/gemhome/gems/a-0.0.2/lib/code.rb +0 -1
- data/test/data/gemhome/gems/b-0.0.2/lib/code.rb +0 -1
- data/test/data/gemhome/gems/c-1.2/lib/code.rb +0 -1
- data/test/data/gemhome/specifications/a-0.0.1.gemspec +0 -8
- data/test/data/gemhome/specifications/a-0.0.2.gemspec +0 -8
- data/test/data/gemhome/specifications/b-0.0.2.gemspec +0 -8
- data/test/data/gemhome/specifications/c-1.2.gemspec +0 -8
- data/test/data/legacy/keyedlist-0.4.0.ruby +0 -11
- data/test/data/legacy/keyedlist-0.4.0.yaml +0 -16
- data/test/data/lib/code.rb +0 -1
- data/test/data/one/README.one +0 -1
- data/test/data/one/lib/one.rb +0 -9
- data/test/data/one/one-0.0.1.gem +0 -0
- data/test/data/one/one.gemspec +0 -17
- data/test/data/one/one.yaml +0 -40
- data/test/data/post_install.gemspec +0 -19
- data/test/functional_extension_gems.rb +0 -48
- data/test/functional_generate_yaml_index.rb +0 -104
- data/test/gemenvironment.rb +0 -59
- data/test/io_capture.rb +0 -33
- data/test/mock/gems/gems/sources-0.0.1/lib/sources.rb +0 -11
- data/test/mock/gems/specifications/sources-0.0.1.gemspec +0 -8
- data/test/onegem.rb +0 -35
- data/test/test_builder.rb +0 -34
- data/test/test_check_command.rb +0 -34
- data/test/test_configfile.rb +0 -42
- data/test/test_dependency_list.rb +0 -169
- data/test/test_file_list.rb +0 -101
- data/test/test_format.rb +0 -49
- data/test/test_gem_sources_command.rb +0 -135
- data/test/test_gemloadpaths.rb +0 -51
- data/test/test_gempaths.rb +0 -170
- data/test/test_installer.rb +0 -369
- data/test/test_loadmanager.rb +0 -48
- data/test/test_process_commands.rb +0 -52
- data/test/test_source_index.rb +0 -231
- data/test/test_specific_extras.rb +0 -46
- data/test/test_specification.rb +0 -565
- data/test/test_user_interaction.rb +0 -48
- data/test/test_validator.rb +0 -59
- data/test/test_version_comparison.rb +0 -321
- data/test/testgem.rc +0 -7
- data/test/user_capture.rb +0 -7
- data/test/yaml_data.rb +0 -63
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
|
3
|
+
require 'rubygems/gem_path_searcher'
|
4
|
+
|
5
|
+
class Gem::GemPathSearcher
|
6
|
+
attr_accessor :gemspecs
|
7
|
+
attr_accessor :lib_dirs
|
8
|
+
|
9
|
+
public :init_gemspecs
|
10
|
+
public :matching_file
|
11
|
+
public :lib_dirs_for
|
12
|
+
end
|
13
|
+
|
14
|
+
class TestGemGemPathSearcher < RubyGemTestCase
|
15
|
+
|
16
|
+
def setup
|
17
|
+
super
|
18
|
+
|
19
|
+
@foo1 = quick_gem 'foo', '0.1' do |s|
|
20
|
+
s.require_paths << 'lib2'
|
21
|
+
s.files << 'lib/foo.rb'
|
22
|
+
end
|
23
|
+
|
24
|
+
path = File.join 'gems', @foo1.full_name, 'lib', 'foo.rb'
|
25
|
+
write_file(path) { |fp| fp.puts "# #{path}" }
|
26
|
+
|
27
|
+
@foo2 = quick_gem 'foo', '0.2'
|
28
|
+
@bar1 = quick_gem 'bar', '0.1'
|
29
|
+
@bar2 = quick_gem 'bar', '0.2'
|
30
|
+
|
31
|
+
Gem.source_index = util_setup_source_info_cache @foo1, @foo2, @bar1, @bar2
|
32
|
+
|
33
|
+
@gps = Gem::GemPathSearcher.new
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_find
|
37
|
+
assert_equal @foo1, @gps.find('foo')
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_init_gemspecs
|
41
|
+
assert_equal [@bar2, @bar1, @foo2, @foo1], @gps.init_gemspecs
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_lib_dirs_for
|
45
|
+
lib_dirs = @gps.lib_dirs_for(@foo1)
|
46
|
+
expected = File.join @gemhome, 'gems', @foo1.full_name, '{lib,lib2}'
|
47
|
+
|
48
|
+
assert_equal expected, lib_dirs
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_matching_file
|
52
|
+
assert !@gps.matching_file(@foo1, 'bar')
|
53
|
+
assert @gps.matching_file(@foo1, 'foo')
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
|
3
|
+
require 'rubygems/gem_runner'
|
4
|
+
|
5
|
+
class TestGemGemRunner < RubyGemTestCase
|
6
|
+
|
7
|
+
def test_do_configuration
|
8
|
+
Gem.clear_paths
|
9
|
+
|
10
|
+
temp_conf = File.join @tempdir, '.gemrc'
|
11
|
+
|
12
|
+
other_gem_path = File.join @tempdir, 'other_gem_path'
|
13
|
+
other_gem_home = File.join @tempdir, 'other_gem_home'
|
14
|
+
|
15
|
+
Gem.ensure_gem_subdirectories other_gem_path
|
16
|
+
Gem.ensure_gem_subdirectories other_gem_home
|
17
|
+
|
18
|
+
File.open temp_conf, 'w' do |fp|
|
19
|
+
fp.puts "gem: --commands"
|
20
|
+
fp.puts "gemhome: #{other_gem_home}"
|
21
|
+
fp.puts "gempath:"
|
22
|
+
fp.puts " - #{other_gem_path}"
|
23
|
+
fp.puts "rdoc: --all"
|
24
|
+
end
|
25
|
+
|
26
|
+
gr = Gem::GemRunner.new
|
27
|
+
gr.send :do_configuration, %W[--config-file #{temp_conf}]
|
28
|
+
|
29
|
+
assert_equal [other_gem_path, other_gem_home], Gem.path
|
30
|
+
assert_equal %w[--commands], Gem::Command.extra_args
|
31
|
+
assert_equal %w[--all], Gem::DocManager.configured_args
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
@@ -0,0 +1,119 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
|
3
|
+
# All rights reserved.
|
4
|
+
# See LICENSE.txt for permissions.
|
5
|
+
#++
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
|
9
|
+
|
10
|
+
require 'rubygems/indexer'
|
11
|
+
|
12
|
+
unless ''.respond_to? :to_xs then
|
13
|
+
warn "Gem::Indexer tests are being skipped. Install builder gem."
|
14
|
+
end
|
15
|
+
|
16
|
+
class TestGemIndexer < RubyGemTestCase
|
17
|
+
|
18
|
+
def setup
|
19
|
+
super
|
20
|
+
|
21
|
+
util_make_gems
|
22
|
+
|
23
|
+
gems = File.join(@tempdir, 'gems')
|
24
|
+
FileUtils.mkdir_p gems
|
25
|
+
cache_gems = File.join @gemhome, 'cache', '*.gem'
|
26
|
+
FileUtils.mv Dir[cache_gems], gems
|
27
|
+
|
28
|
+
@indexer = Gem::Indexer.new @tempdir
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_initialize
|
32
|
+
assert_equal @tempdir, @indexer.dest_directory
|
33
|
+
assert_equal File.join(Dir.tmpdir, "gem_generate_index_#{$$}"),
|
34
|
+
@indexer.directory
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_generate_index
|
38
|
+
use_ui @ui do
|
39
|
+
@indexer.generate_index
|
40
|
+
end
|
41
|
+
|
42
|
+
assert File.exist?(File.join(@tempdir, 'yaml'))
|
43
|
+
assert File.exist?(File.join(@tempdir, 'yaml.Z'))
|
44
|
+
assert File.exist?(File.join(@tempdir, "Marshal.#{@marshal_version}"))
|
45
|
+
assert File.exist?(File.join(@tempdir, "Marshal.#{@marshal_version}.Z"))
|
46
|
+
|
47
|
+
quickdir = File.join @tempdir, 'quick'
|
48
|
+
marshal_quickdir = File.join quickdir, "Marshal.#{@marshal_version}"
|
49
|
+
|
50
|
+
assert File.directory?(quickdir)
|
51
|
+
assert File.directory?(marshal_quickdir)
|
52
|
+
|
53
|
+
assert_indexed quickdir, "index"
|
54
|
+
assert_indexed quickdir, "index.rz"
|
55
|
+
|
56
|
+
assert_indexed quickdir, "#{@a0_0_1.full_name}.gemspec.rz"
|
57
|
+
assert_indexed quickdir, "#{@a0_0_2.full_name}.gemspec.rz"
|
58
|
+
assert_indexed quickdir, "#{@b0_0_2.full_name}.gemspec.rz"
|
59
|
+
assert_indexed quickdir, "#{@c1_2.full_name}.gemspec.rz"
|
60
|
+
|
61
|
+
assert_indexed quickdir, "#{@pl1.original_name}.gemspec.rz"
|
62
|
+
deny_indexed quickdir, "#{@pl1.full_name}.gemspec.rz"
|
63
|
+
|
64
|
+
assert_indexed marshal_quickdir, "#{@a0_0_1.full_name}.gemspec.rz"
|
65
|
+
assert_indexed marshal_quickdir, "#{@a0_0_2.full_name}.gemspec.rz"
|
66
|
+
|
67
|
+
deny_indexed quickdir, "#{@c1_2.full_name}.gemspec"
|
68
|
+
deny_indexed marshal_quickdir, "#{@c1_2.full_name}.gemspec"
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_generate_index_ui
|
72
|
+
use_ui @ui do
|
73
|
+
@indexer.generate_index
|
74
|
+
end
|
75
|
+
|
76
|
+
expected = <<-EOF
|
77
|
+
Generating index for 5 gems in #{@tempdir}
|
78
|
+
.....
|
79
|
+
Loaded all gems
|
80
|
+
Generating master indexes (this may take a while)
|
81
|
+
EOF
|
82
|
+
|
83
|
+
assert_equal expected, @ui.output
|
84
|
+
assert_equal '', @ui.error
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_generate_index_contents
|
88
|
+
use_ui @ui do
|
89
|
+
@indexer.generate_index
|
90
|
+
end
|
91
|
+
|
92
|
+
yaml_path = File.join(@tempdir, 'yaml')
|
93
|
+
dump_path = File.join(@tempdir, "Marshal.#{@marshal_version}")
|
94
|
+
|
95
|
+
yaml_index = YAML.load_file(yaml_path)
|
96
|
+
dump_str = nil
|
97
|
+
File.open dump_path, 'rb' do |fp| dump_str = fp.read end
|
98
|
+
dump_index = Marshal.load dump_str
|
99
|
+
|
100
|
+
dump_index.each do |_,gem|
|
101
|
+
gem.send :remove_instance_variable, :@loaded
|
102
|
+
end
|
103
|
+
|
104
|
+
assert_equal yaml_index, dump_index,
|
105
|
+
"expected YAML and Marshal to produce identical results"
|
106
|
+
end
|
107
|
+
|
108
|
+
def assert_indexed(dir, name)
|
109
|
+
file = File.join dir, name
|
110
|
+
assert File.exist?(file), "#{file} does not exist"
|
111
|
+
end
|
112
|
+
|
113
|
+
def deny_indexed(dir, name)
|
114
|
+
file = File.join dir, name
|
115
|
+
assert !File.exist?(file), "#{file} exists"
|
116
|
+
end
|
117
|
+
|
118
|
+
end if ''.respond_to? :to_xs
|
119
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
|
3
|
+
require 'rubygems/install_update_options'
|
4
|
+
require 'rubygems/command'
|
5
|
+
|
6
|
+
class TestGemInstallUpdateOptions < RubyGemTestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
|
11
|
+
@cmd = Gem::Command.new 'dummy', 'dummy'
|
12
|
+
@cmd.extend Gem::InstallUpdateOptions
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_add_install_update_options
|
16
|
+
@cmd.add_install_update_options
|
17
|
+
|
18
|
+
args = %w[-i /install_to --rdoc --ri -E -f -t -w -P HighSecurity
|
19
|
+
--ignore-dependencies --include-dependencies]
|
20
|
+
|
21
|
+
assert @cmd.handles?(args)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_security_policy
|
25
|
+
@cmd.add_install_update_options
|
26
|
+
|
27
|
+
@cmd.handle_options %w[-P HighSecurity]
|
28
|
+
|
29
|
+
assert_equal Gem::Security::HighSecurity, @cmd.options[:security_policy]
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_security_policy_unknown
|
33
|
+
@cmd.add_install_update_options
|
34
|
+
|
35
|
+
assert_raise OptionParser::InvalidArgument do
|
36
|
+
@cmd.handle_options %w[-P UnknownSecurity]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,796 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
|
3
|
+
# All rights reserved.
|
4
|
+
# See LICENSE.txt for permissions.
|
5
|
+
#++
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
|
9
|
+
require 'rubygems/installer'
|
10
|
+
|
11
|
+
class Gem::Installer
|
12
|
+
attr_writer :format
|
13
|
+
attr_writer :gem_dir
|
14
|
+
attr_writer :gem_home
|
15
|
+
attr_writer :env_shebang
|
16
|
+
attr_writer :ignore_dependencies
|
17
|
+
attr_writer :security_policy
|
18
|
+
attr_writer :spec
|
19
|
+
attr_writer :wrappers
|
20
|
+
end
|
21
|
+
|
22
|
+
class TestGemInstaller < RubyGemTestCase
|
23
|
+
|
24
|
+
def setup
|
25
|
+
super
|
26
|
+
|
27
|
+
@spec = quick_gem "a"
|
28
|
+
@gem = File.join @tempdir, "#{@spec.full_name}.gem"
|
29
|
+
|
30
|
+
util_build_gem @spec
|
31
|
+
FileUtils.mv File.join(@gemhome, 'cache', "#{@spec.full_name}.gem"),
|
32
|
+
@tempdir
|
33
|
+
|
34
|
+
@installer = Gem::Installer.new @gem
|
35
|
+
@installer.gem_dir = util_gem_dir
|
36
|
+
@installer.gem_home = @gemhome
|
37
|
+
@installer.spec = @spec
|
38
|
+
end
|
39
|
+
|
40
|
+
def util_gem_dir(version = '0.0.2')
|
41
|
+
File.join @gemhome, "gems", "a-#{version}" # HACK
|
42
|
+
end
|
43
|
+
|
44
|
+
def util_gem_bindir(version = '0.0.2')
|
45
|
+
File.join util_gem_dir(version), "bin"
|
46
|
+
end
|
47
|
+
|
48
|
+
def util_inst_bindir
|
49
|
+
File.join @gemhome, "bin"
|
50
|
+
end
|
51
|
+
|
52
|
+
def util_make_exec(version = '0.0.2', shebang = "#!/usr/bin/ruby")
|
53
|
+
@spec.executables = ["my_exec"]
|
54
|
+
|
55
|
+
FileUtils.mkdir_p util_gem_bindir(version)
|
56
|
+
exec_file = File.join(util_gem_bindir(version), "my_exec")
|
57
|
+
File.open exec_file, 'w' do |f|
|
58
|
+
f.puts shebang
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_app_script_text
|
63
|
+
util_make_exec '0.0.2', ''
|
64
|
+
|
65
|
+
expected = <<-EOF
|
66
|
+
#!#{Gem.ruby}
|
67
|
+
#
|
68
|
+
# This file was generated by RubyGems.
|
69
|
+
#
|
70
|
+
# The application 'a' is installed as part of a gem, and
|
71
|
+
# this file is here to facilitate running it.
|
72
|
+
#
|
73
|
+
|
74
|
+
require 'rubygems'
|
75
|
+
|
76
|
+
version = \">= 0\"
|
77
|
+
|
78
|
+
if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
|
79
|
+
version = $1
|
80
|
+
ARGV.shift
|
81
|
+
end
|
82
|
+
|
83
|
+
gem 'a', version
|
84
|
+
load 'my_exec'
|
85
|
+
EOF
|
86
|
+
|
87
|
+
wrapper = @installer.app_script_text 'my_exec'
|
88
|
+
assert_equal expected, wrapper
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_build_extensions_none
|
92
|
+
use_ui @ui do
|
93
|
+
@installer.build_extensions
|
94
|
+
end
|
95
|
+
|
96
|
+
assert_equal '', @ui.output
|
97
|
+
assert_equal '', @ui.error
|
98
|
+
|
99
|
+
assert !File.exist?('gem_make.out')
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_build_extensions_extconf_bad
|
103
|
+
@spec.extensions << 'extconf.rb'
|
104
|
+
|
105
|
+
e = assert_raise Gem::Installer::ExtensionBuildError do
|
106
|
+
use_ui @ui do
|
107
|
+
@installer.build_extensions
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
assert_match(/\AERROR: Failed to build gem native extension.$/, e.message)
|
112
|
+
|
113
|
+
assert_equal "Building native extensions. This could take a while...\n",
|
114
|
+
@ui.output
|
115
|
+
assert_equal '', @ui.error
|
116
|
+
|
117
|
+
gem_make_out = File.join @gemhome, 'gems', @spec.full_name, 'gem_make.out'
|
118
|
+
expected = <<-EOF
|
119
|
+
#{Gem.ruby} extconf.rb
|
120
|
+
#{Gem.ruby}: No such file or directory -- extconf.rb (LoadError)
|
121
|
+
EOF
|
122
|
+
|
123
|
+
assert_equal expected, File.read(gem_make_out)
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_build_extensions_unsupported
|
127
|
+
@spec.extensions << nil
|
128
|
+
|
129
|
+
e = assert_raise Gem::Installer::ExtensionBuildError do
|
130
|
+
use_ui @ui do
|
131
|
+
@installer.build_extensions
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
assert_match(/^No builder for extension ''$/, e.message)
|
136
|
+
|
137
|
+
assert_equal "Building native extensions. This could take a while...\n",
|
138
|
+
@ui.output
|
139
|
+
assert_equal '', @ui.error
|
140
|
+
|
141
|
+
assert_equal "No builder for extension ''\n", File.read('gem_make.out')
|
142
|
+
ensure
|
143
|
+
FileUtils.rm_f 'gem_make.out'
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_ensure_dependency
|
147
|
+
dep = Gem::Dependency.new 'a', '>= 0.0.2'
|
148
|
+
assert @installer.ensure_dependency(@spec, dep)
|
149
|
+
|
150
|
+
dep = Gem::Dependency.new 'b', '> 0.0.2'
|
151
|
+
e = assert_raise Gem::InstallError do
|
152
|
+
@installer.ensure_dependency @spec, dep
|
153
|
+
end
|
154
|
+
|
155
|
+
assert_equal 'a requires b (> 0.0.2)', e.message
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_expand_and_validate_gem_dir
|
159
|
+
@installer.gem_dir = '/nonexistent'
|
160
|
+
expanded_gem_dir = @installer.send(:expand_and_validate_gem_dir)
|
161
|
+
if win_platform?
|
162
|
+
expected = File.join(Config::CONFIG['bindir'][0..2], 'nonexistent').downcase
|
163
|
+
expanded_gem_dir = expanded_gem_dir.downcase
|
164
|
+
else
|
165
|
+
expected = '/nonexistent'
|
166
|
+
end
|
167
|
+
|
168
|
+
assert_equal expected, expanded_gem_dir
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_extract_files
|
172
|
+
format = Object.new
|
173
|
+
def format.file_entries
|
174
|
+
[[{'size' => 7, 'mode' => 0400, 'path' => 'thefile'}, 'thefile']]
|
175
|
+
end
|
176
|
+
|
177
|
+
@installer.format = format
|
178
|
+
|
179
|
+
@installer.extract_files
|
180
|
+
|
181
|
+
assert_equal 'thefile', File.read(File.join(util_gem_dir, 'thefile'))
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_extract_files_bad_dest
|
185
|
+
@installer.gem_dir = 'somedir'
|
186
|
+
@installer.format = nil
|
187
|
+
e = assert_raise ArgumentError do
|
188
|
+
@installer.extract_files
|
189
|
+
end
|
190
|
+
|
191
|
+
assert_equal 'format required to extract from', e.message
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_extract_files_relative
|
195
|
+
format = Object.new
|
196
|
+
def format.file_entries
|
197
|
+
[[{'size' => 10, 'mode' => 0644, 'path' => '../thefile'}, '../thefile']]
|
198
|
+
end
|
199
|
+
|
200
|
+
@installer.format = format
|
201
|
+
|
202
|
+
e = assert_raise Gem::InstallError do
|
203
|
+
@installer.extract_files
|
204
|
+
end
|
205
|
+
|
206
|
+
assert_equal "attempt to install file into \"../thefile\" under #{util_gem_dir.inspect}",
|
207
|
+
e.message
|
208
|
+
assert_equal false, File.file?(File.join(@tempdir, '../thefile')),
|
209
|
+
"You may need to remove this file if you broke the test once"
|
210
|
+
end
|
211
|
+
|
212
|
+
def test_extract_files_absolute
|
213
|
+
format = Object.new
|
214
|
+
def format.file_entries
|
215
|
+
[[{'size' => 8, 'mode' => 0644, 'path' => '/thefile'}, '/thefile']]
|
216
|
+
end
|
217
|
+
|
218
|
+
@installer.format = format
|
219
|
+
|
220
|
+
e = assert_raise Gem::InstallError do
|
221
|
+
@installer.extract_files
|
222
|
+
end
|
223
|
+
|
224
|
+
assert_equal 'attempt to install file into "/thefile"', e.message
|
225
|
+
assert_equal false, File.file?(File.join('/thefile')),
|
226
|
+
"You may need to remove this file if you broke the test once"
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_generate_bin_scripts
|
230
|
+
@installer.wrappers = true
|
231
|
+
util_make_exec
|
232
|
+
@installer.gem_dir = util_gem_dir
|
233
|
+
|
234
|
+
@installer.generate_bin
|
235
|
+
assert_equal true, File.directory?(util_inst_bindir)
|
236
|
+
installed_exec = File.join(util_inst_bindir, "my_exec")
|
237
|
+
assert_equal true, File.exist?(installed_exec)
|
238
|
+
assert_equal(0100755, File.stat(installed_exec).mode) unless win_platform?
|
239
|
+
|
240
|
+
wrapper = File.read installed_exec
|
241
|
+
assert_match %r|generated by RubyGems|, wrapper
|
242
|
+
end
|
243
|
+
|
244
|
+
def test_generate_bin_scripts_install_dir
|
245
|
+
@installer.wrappers = true
|
246
|
+
@spec.executables = ["my_exec"]
|
247
|
+
|
248
|
+
gem_dir = File.join "#{@gemhome}2", 'gems', @spec.full_name
|
249
|
+
gem_bindir = File.join gem_dir, 'bin'
|
250
|
+
FileUtils.mkdir_p gem_bindir
|
251
|
+
File.open File.join(gem_bindir, "my_exec"), 'w' do |f|
|
252
|
+
f.puts "#!/bin/ruby"
|
253
|
+
end
|
254
|
+
|
255
|
+
@installer.gem_home = "#{@gemhome}2"
|
256
|
+
@installer.gem_dir = gem_dir
|
257
|
+
|
258
|
+
@installer.generate_bin
|
259
|
+
|
260
|
+
installed_exec = File.join("#{@gemhome}2", 'bin', 'my_exec')
|
261
|
+
assert_equal true, File.exist?(installed_exec)
|
262
|
+
assert_equal(0100755, File.stat(installed_exec).mode) unless win_platform?
|
263
|
+
|
264
|
+
wrapper = File.read installed_exec
|
265
|
+
assert_match %r|generated by RubyGems|, wrapper
|
266
|
+
end
|
267
|
+
|
268
|
+
def test_generate_bin_scripts_no_execs
|
269
|
+
@installer.wrappers = true
|
270
|
+
@installer.generate_bin
|
271
|
+
assert_equal false, File.exist?(util_inst_bindir)
|
272
|
+
end
|
273
|
+
|
274
|
+
def test_generate_bin_scripts_no_perms
|
275
|
+
@installer.wrappers = true
|
276
|
+
util_make_exec
|
277
|
+
|
278
|
+
Dir.mkdir util_inst_bindir
|
279
|
+
File.chmod 0000, util_inst_bindir
|
280
|
+
|
281
|
+
assert_raises Gem::FilePermissionError do
|
282
|
+
@installer.generate_bin
|
283
|
+
end
|
284
|
+
|
285
|
+
ensure
|
286
|
+
File.chmod 0700, util_inst_bindir unless $DEBUG
|
287
|
+
end
|
288
|
+
|
289
|
+
def test_generate_bin_symlinks
|
290
|
+
return if win_platform? #Windows FS do not support symlinks
|
291
|
+
|
292
|
+
@installer.wrappers = false
|
293
|
+
util_make_exec
|
294
|
+
@installer.gem_dir = util_gem_dir
|
295
|
+
|
296
|
+
@installer.generate_bin
|
297
|
+
assert_equal true, File.directory?(util_inst_bindir)
|
298
|
+
installed_exec = File.join(util_inst_bindir, "my_exec")
|
299
|
+
assert_equal true, File.symlink?(installed_exec)
|
300
|
+
assert_equal(File.join(util_gem_dir, "bin", "my_exec"),
|
301
|
+
File.readlink(installed_exec))
|
302
|
+
end
|
303
|
+
|
304
|
+
def test_generate_bin_symlinks_no_execs
|
305
|
+
@installer.wrappers = false
|
306
|
+
@installer.generate_bin
|
307
|
+
assert_equal false, File.exist?(util_inst_bindir)
|
308
|
+
end
|
309
|
+
|
310
|
+
def test_generate_bin_symlinks_no_perms
|
311
|
+
@installer.wrappers = false
|
312
|
+
util_make_exec
|
313
|
+
@installer.gem_dir = util_gem_dir
|
314
|
+
|
315
|
+
Dir.mkdir util_inst_bindir
|
316
|
+
File.chmod 0000, util_inst_bindir
|
317
|
+
|
318
|
+
assert_raises Gem::FilePermissionError do
|
319
|
+
@installer.generate_bin
|
320
|
+
end
|
321
|
+
|
322
|
+
ensure
|
323
|
+
File.chmod 0700, util_inst_bindir unless $DEBUG
|
324
|
+
end
|
325
|
+
|
326
|
+
def test_generate_bin_symlinks_update_newer
|
327
|
+
return if win_platform? #Windows FS do not support symlinks
|
328
|
+
|
329
|
+
@installer.wrappers = false
|
330
|
+
util_make_exec
|
331
|
+
@installer.gem_dir = util_gem_dir
|
332
|
+
|
333
|
+
@installer.generate_bin
|
334
|
+
installed_exec = File.join(util_inst_bindir, "my_exec")
|
335
|
+
assert_equal(File.join(util_gem_dir, "bin", "my_exec"),
|
336
|
+
File.readlink(installed_exec))
|
337
|
+
|
338
|
+
@spec = Gem::Specification.new do |s|
|
339
|
+
s.files = ['lib/code.rb']
|
340
|
+
s.name = "a"
|
341
|
+
s.version = "0.0.3"
|
342
|
+
s.summary = "summary"
|
343
|
+
s.description = "desc"
|
344
|
+
s.require_path = 'lib'
|
345
|
+
end
|
346
|
+
|
347
|
+
util_make_exec '0.0.3'
|
348
|
+
@installer.gem_dir = File.join util_gem_dir('0.0.3')
|
349
|
+
@installer.generate_bin
|
350
|
+
installed_exec = File.join(util_inst_bindir, "my_exec")
|
351
|
+
assert_equal(File.join(util_gem_bindir('0.0.3'), "my_exec"),
|
352
|
+
File.readlink(installed_exec),
|
353
|
+
"Ensure symlink moved to latest version")
|
354
|
+
end
|
355
|
+
|
356
|
+
def test_generate_bin_symlinks_update_older
|
357
|
+
return if win_platform? #Windows FS do not support symlinks
|
358
|
+
|
359
|
+
@installer.wrappers = false
|
360
|
+
util_make_exec
|
361
|
+
@installer.gem_dir = util_gem_dir
|
362
|
+
|
363
|
+
@installer.generate_bin
|
364
|
+
installed_exec = File.join(util_inst_bindir, "my_exec")
|
365
|
+
assert_equal(File.join(util_gem_dir, "bin", "my_exec"),
|
366
|
+
File.readlink(installed_exec))
|
367
|
+
|
368
|
+
spec = Gem::Specification.new do |s|
|
369
|
+
s.files = ['lib/code.rb']
|
370
|
+
s.name = "a"
|
371
|
+
s.version = "0.0.1"
|
372
|
+
s.summary = "summary"
|
373
|
+
s.description = "desc"
|
374
|
+
s.require_path = 'lib'
|
375
|
+
end
|
376
|
+
|
377
|
+
util_make_exec '0.0.1'
|
378
|
+
@installer.gem_dir = util_gem_dir('0.0.1')
|
379
|
+
@installer.spec = spec
|
380
|
+
|
381
|
+
@installer.generate_bin
|
382
|
+
|
383
|
+
installed_exec = File.join(util_inst_bindir, "my_exec")
|
384
|
+
assert_equal(File.join(util_gem_dir('0.0.2'), "bin", "my_exec"),
|
385
|
+
File.readlink(installed_exec),
|
386
|
+
"Ensure symlink not moved")
|
387
|
+
end
|
388
|
+
|
389
|
+
def test_generate_bin_symlinks_update_remove_wrapper
|
390
|
+
return if win_platform? #Windows FS do not support symlinks
|
391
|
+
|
392
|
+
@installer.wrappers = true
|
393
|
+
util_make_exec
|
394
|
+
@installer.gem_dir = util_gem_dir
|
395
|
+
|
396
|
+
@installer.generate_bin
|
397
|
+
installed_exec = File.join(util_inst_bindir, "my_exec")
|
398
|
+
assert_equal true, File.exist?(installed_exec)
|
399
|
+
|
400
|
+
@spec = Gem::Specification.new do |s|
|
401
|
+
s.files = ['lib/code.rb']
|
402
|
+
s.name = "a"
|
403
|
+
s.version = "0.0.3"
|
404
|
+
s.summary = "summary"
|
405
|
+
s.description = "desc"
|
406
|
+
s.require_path = 'lib'
|
407
|
+
end
|
408
|
+
|
409
|
+
@installer.wrappers = false
|
410
|
+
util_make_exec '0.0.3'
|
411
|
+
@installer.gem_dir = util_gem_dir '0.0.3'
|
412
|
+
@installer.generate_bin
|
413
|
+
installed_exec = File.join(util_inst_bindir, "my_exec")
|
414
|
+
assert_equal(File.join(util_gem_dir('0.0.3'), "bin", "my_exec"),
|
415
|
+
File.readlink(installed_exec),
|
416
|
+
"Ensure symlink moved to latest version")
|
417
|
+
end
|
418
|
+
|
419
|
+
def test_generate_bin_symlinks_win32
|
420
|
+
old_arch = Config::CONFIG["arch"]
|
421
|
+
Config::CONFIG["arch"] = "win32"
|
422
|
+
@installer.wrappers = false
|
423
|
+
util_make_exec
|
424
|
+
@installer.gem_dir = util_gem_dir
|
425
|
+
|
426
|
+
use_ui @ui do
|
427
|
+
@installer.generate_bin
|
428
|
+
end
|
429
|
+
|
430
|
+
assert_equal true, File.directory?(util_inst_bindir)
|
431
|
+
installed_exec = File.join(util_inst_bindir, "my_exec")
|
432
|
+
assert_equal true, File.exist?(installed_exec)
|
433
|
+
|
434
|
+
assert_match(/Unable to use symlinks on win32, installing wrapper/i,
|
435
|
+
@ui.error)
|
436
|
+
|
437
|
+
expected_mode = win_platform? ? 0100644 : 0100755
|
438
|
+
assert_equal expected_mode, File.stat(installed_exec).mode
|
439
|
+
|
440
|
+
wrapper = File.read installed_exec
|
441
|
+
assert_match(/generated by RubyGems/, wrapper)
|
442
|
+
ensure
|
443
|
+
Config::CONFIG["arch"] = old_arch
|
444
|
+
end
|
445
|
+
|
446
|
+
def test_generate_bin_uses_default_shebang
|
447
|
+
return if win_platform? #Windows FS do not support symlinks
|
448
|
+
|
449
|
+
@installer.wrappers = true
|
450
|
+
util_make_exec
|
451
|
+
|
452
|
+
@installer.generate_bin
|
453
|
+
|
454
|
+
default_shebang = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
|
455
|
+
shebang_line = open("#{@gemhome}/bin/my_exec") { |f| f.readlines.first }
|
456
|
+
assert_match(/\A#!/, shebang_line)
|
457
|
+
assert_match(/#{default_shebang}/, shebang_line)
|
458
|
+
end
|
459
|
+
|
460
|
+
def test_install
|
461
|
+
util_setup_gem
|
462
|
+
|
463
|
+
use_ui @ui do
|
464
|
+
assert_equal @spec, @installer.install
|
465
|
+
end
|
466
|
+
|
467
|
+
gemdir = File.join @gemhome, 'gems', @spec.full_name
|
468
|
+
assert File.exist?(gemdir)
|
469
|
+
|
470
|
+
exe = File.join(gemdir, 'bin', 'executable')
|
471
|
+
assert File.exist?(exe)
|
472
|
+
exe_mode = File.stat(exe).mode & 0111
|
473
|
+
assert_equal 0111, exe_mode, "0%o" % exe_mode unless win_platform?
|
474
|
+
|
475
|
+
assert File.exist?(File.join(gemdir, 'lib', 'code.rb'))
|
476
|
+
|
477
|
+
assert File.exist?(File.join(gemdir, 'ext', 'a', 'Rakefile'))
|
478
|
+
|
479
|
+
spec_file = File.join(@gemhome, 'specifications',
|
480
|
+
"#{@spec.full_name}.gemspec")
|
481
|
+
|
482
|
+
assert_equal spec_file, @spec.loaded_from
|
483
|
+
assert File.exist?(spec_file)
|
484
|
+
end
|
485
|
+
|
486
|
+
def test_install_bad_gem
|
487
|
+
gem = nil
|
488
|
+
|
489
|
+
use_ui @ui do
|
490
|
+
Dir.chdir @tempdir do Gem::Builder.new(@spec).build end
|
491
|
+
gem = File.join @tempdir, "#{@spec.full_name}.gem"
|
492
|
+
end
|
493
|
+
|
494
|
+
gem_data = File.open gem, 'rb' do |fp| fp.read 1024 end
|
495
|
+
File.open gem, 'wb' do |fp| fp.write gem_data end
|
496
|
+
|
497
|
+
e = assert_raise Gem::InstallError do
|
498
|
+
use_ui @ui do
|
499
|
+
@installer = Gem::Installer.new gem
|
500
|
+
@installer.install
|
501
|
+
end
|
502
|
+
end
|
503
|
+
|
504
|
+
assert_equal "invalid gem format for #{gem}", e.message
|
505
|
+
end
|
506
|
+
|
507
|
+
def test_install_check_dependencies
|
508
|
+
@spec.add_dependency 'b', '> 5'
|
509
|
+
util_setup_gem
|
510
|
+
|
511
|
+
use_ui @ui do
|
512
|
+
assert_raise Gem::InstallError do
|
513
|
+
@installer.install
|
514
|
+
end
|
515
|
+
end
|
516
|
+
end
|
517
|
+
|
518
|
+
def test_install_force
|
519
|
+
use_ui @ui do
|
520
|
+
installer = Gem::Installer.new old_ruby_required, :force => true
|
521
|
+
installer.install
|
522
|
+
end
|
523
|
+
|
524
|
+
gem_dir = File.join(@gemhome, 'gems', 'old_ruby_required-0.0.1')
|
525
|
+
assert File.exist?(gem_dir)
|
526
|
+
end
|
527
|
+
|
528
|
+
def test_install_ignore_dependencies
|
529
|
+
@spec.add_dependency 'b', '> 5'
|
530
|
+
util_setup_gem
|
531
|
+
@installer.ignore_dependencies = true
|
532
|
+
|
533
|
+
use_ui @ui do
|
534
|
+
assert_equal @spec, @installer.install
|
535
|
+
end
|
536
|
+
|
537
|
+
gemdir = File.join @gemhome, 'gems', @spec.full_name
|
538
|
+
assert File.exist?(gemdir)
|
539
|
+
|
540
|
+
exe = File.join(gemdir, 'bin', 'executable')
|
541
|
+
assert File.exist?(exe)
|
542
|
+
exe_mode = File.stat(exe).mode & 0111
|
543
|
+
assert_equal 0111, exe_mode, "0%o" % exe_mode unless win_platform?
|
544
|
+
assert File.exist?(File.join(gemdir, 'lib', 'code.rb'))
|
545
|
+
|
546
|
+
assert File.exist?(File.join(@gemhome, 'specifications',
|
547
|
+
"#{@spec.full_name}.gemspec"))
|
548
|
+
end
|
549
|
+
|
550
|
+
def test_install_missing_dirs
|
551
|
+
FileUtils.rm_f File.join(Gem.dir, 'cache')
|
552
|
+
FileUtils.rm_f File.join(Gem.dir, 'docs')
|
553
|
+
FileUtils.rm_f File.join(Gem.dir, 'specifications')
|
554
|
+
|
555
|
+
use_ui @ui do
|
556
|
+
Dir.chdir @tempdir do Gem::Builder.new(@spec).build end
|
557
|
+
gem = File.join @tempdir, "#{@spec.full_name}.gem"
|
558
|
+
|
559
|
+
@installer.install
|
560
|
+
end
|
561
|
+
|
562
|
+
File.directory? File.join(Gem.dir, 'cache')
|
563
|
+
File.directory? File.join(Gem.dir, 'docs')
|
564
|
+
File.directory? File.join(Gem.dir, 'specifications')
|
565
|
+
|
566
|
+
assert File.exist?(File.join(@gemhome, 'cache', "#{@spec.full_name}.gem"))
|
567
|
+
assert File.exist?(File.join(@gemhome, 'specifications',
|
568
|
+
"#{@spec.full_name}.gemspec"))
|
569
|
+
end
|
570
|
+
|
571
|
+
def test_install_with_message
|
572
|
+
@spec.post_install_message = 'I am a shiny gem!'
|
573
|
+
|
574
|
+
use_ui @ui do
|
575
|
+
Dir.chdir @tempdir do Gem::Builder.new(@spec).build end
|
576
|
+
|
577
|
+
@installer.install
|
578
|
+
end
|
579
|
+
|
580
|
+
assert_match %r|I am a shiny gem!|, @ui.output
|
581
|
+
end
|
582
|
+
|
583
|
+
def test_install_writable
|
584
|
+
util_setup_gem
|
585
|
+
|
586
|
+
orig_mode = File.stat(Gem.dir).mode
|
587
|
+
File.chmod 0000, Gem.dir
|
588
|
+
|
589
|
+
e = assert_raise Gem::FilePermissionError do
|
590
|
+
@installer.install
|
591
|
+
end
|
592
|
+
|
593
|
+
assert_equal "You don't have write permissions into the #{@gemhome} directory.",
|
594
|
+
e.message
|
595
|
+
ensure
|
596
|
+
File.chmod orig_mode, Gem.dir
|
597
|
+
end
|
598
|
+
|
599
|
+
def test_install_wrong_ruby_version
|
600
|
+
use_ui @ui do
|
601
|
+
installer = Gem::Installer.new old_ruby_required
|
602
|
+
e = assert_raise Gem::InstallError do
|
603
|
+
installer.install
|
604
|
+
end
|
605
|
+
assert_equal 'old_ruby_required requires Ruby version = 1.4.6',
|
606
|
+
e.message
|
607
|
+
end
|
608
|
+
end
|
609
|
+
|
610
|
+
def test_install_wrong_rubygems_version
|
611
|
+
spec = quick_gem 'old_rubygems_required', '0.0.1' do |s|
|
612
|
+
s.required_rubygems_version = '< 0.0.0'
|
613
|
+
end
|
614
|
+
|
615
|
+
util_build_gem spec
|
616
|
+
|
617
|
+
gem = File.join @gemhome, 'cache', "#{spec.full_name}.gem"
|
618
|
+
|
619
|
+
use_ui @ui do
|
620
|
+
@installer = Gem::Installer.new gem
|
621
|
+
e = assert_raise Gem::InstallError do
|
622
|
+
@installer.install
|
623
|
+
end
|
624
|
+
assert_equal 'old_rubygems_required requires RubyGems version < 0.0.0',
|
625
|
+
e.message
|
626
|
+
end
|
627
|
+
end
|
628
|
+
|
629
|
+
def test_installation_satisfies_dependency_eh
|
630
|
+
dep = Gem::Dependency.new 'a', '>= 0.0.2'
|
631
|
+
assert @installer.installation_satisfies_dependency?(dep)
|
632
|
+
|
633
|
+
dep = Gem::Dependency.new 'a', '> 0.0.2'
|
634
|
+
assert ! @installer.installation_satisfies_dependency?(dep)
|
635
|
+
end
|
636
|
+
|
637
|
+
def test_shebang
|
638
|
+
util_make_exec '0.0.2', "#!/usr/bin/ruby"
|
639
|
+
|
640
|
+
shebang = @installer.shebang 'my_exec'
|
641
|
+
|
642
|
+
assert_equal "#!#{Gem.ruby}", shebang
|
643
|
+
end
|
644
|
+
|
645
|
+
def test_shebang_arguments
|
646
|
+
util_make_exec '0.0.2', "#!/usr/bin/ruby -ws"
|
647
|
+
|
648
|
+
shebang = @installer.shebang 'my_exec'
|
649
|
+
|
650
|
+
assert_equal "#!#{Gem.ruby} -ws", shebang
|
651
|
+
end
|
652
|
+
|
653
|
+
def test_shebang_empty
|
654
|
+
util_make_exec '0.0.2', ''
|
655
|
+
|
656
|
+
shebang = @installer.shebang 'my_exec'
|
657
|
+
assert_equal "#!#{Gem.ruby}", shebang
|
658
|
+
end
|
659
|
+
|
660
|
+
def test_shebang_env
|
661
|
+
util_make_exec '0.0.2', "#!/usr/bin/env ruby"
|
662
|
+
|
663
|
+
shebang = @installer.shebang 'my_exec'
|
664
|
+
|
665
|
+
assert_equal "#!#{Gem.ruby}", shebang
|
666
|
+
end
|
667
|
+
|
668
|
+
def test_shebang_env_arguments
|
669
|
+
util_make_exec '0.0.2', "#!/usr/bin/env ruby -ws"
|
670
|
+
|
671
|
+
shebang = @installer.shebang 'my_exec'
|
672
|
+
|
673
|
+
assert_equal "#!#{Gem.ruby} -ws", shebang
|
674
|
+
end
|
675
|
+
|
676
|
+
def test_shebang_env_shebang
|
677
|
+
util_make_exec '0.0.2', ''
|
678
|
+
@installer.env_shebang = true
|
679
|
+
|
680
|
+
shebang = @installer.shebang 'my_exec'
|
681
|
+
assert_equal "#!/usr/bin/env ruby", shebang
|
682
|
+
end
|
683
|
+
|
684
|
+
def test_shebang_nested
|
685
|
+
util_make_exec '0.0.2', "#!/opt/local/ruby/bin/ruby"
|
686
|
+
|
687
|
+
shebang = @installer.shebang 'my_exec'
|
688
|
+
|
689
|
+
assert_equal "#!#{Gem.ruby}", shebang
|
690
|
+
end
|
691
|
+
|
692
|
+
def test_shebang_nested_arguments
|
693
|
+
util_make_exec '0.0.2', "#!/opt/local/ruby/bin/ruby -ws"
|
694
|
+
|
695
|
+
shebang = @installer.shebang 'my_exec'
|
696
|
+
|
697
|
+
assert_equal "#!#{Gem.ruby} -ws", shebang
|
698
|
+
end
|
699
|
+
|
700
|
+
def test_shebang_version
|
701
|
+
util_make_exec '0.0.2', "#!/usr/bin/ruby18"
|
702
|
+
|
703
|
+
shebang = @installer.shebang 'my_exec'
|
704
|
+
|
705
|
+
assert_equal "#!#{Gem.ruby}", shebang
|
706
|
+
end
|
707
|
+
|
708
|
+
def test_shebang_version_arguments
|
709
|
+
util_make_exec '0.0.2', "#!/usr/bin/ruby18 -ws"
|
710
|
+
|
711
|
+
shebang = @installer.shebang 'my_exec'
|
712
|
+
|
713
|
+
assert_equal "#!#{Gem.ruby} -ws", shebang
|
714
|
+
end
|
715
|
+
|
716
|
+
def test_shebang_version_env
|
717
|
+
util_make_exec '0.0.2', "#!/usr/bin/env ruby18"
|
718
|
+
|
719
|
+
shebang = @installer.shebang 'my_exec'
|
720
|
+
|
721
|
+
assert_equal "#!#{Gem.ruby}", shebang
|
722
|
+
end
|
723
|
+
|
724
|
+
def test_shebang_version_env_arguments
|
725
|
+
util_make_exec '0.0.2', "#!/usr/bin/env ruby18 -ws"
|
726
|
+
|
727
|
+
shebang = @installer.shebang 'my_exec'
|
728
|
+
|
729
|
+
assert_equal "#!#{Gem.ruby} -ws", shebang
|
730
|
+
end
|
731
|
+
|
732
|
+
def test_unpack
|
733
|
+
util_setup_gem
|
734
|
+
|
735
|
+
dest = File.join @gemhome, 'gems', @spec.full_name
|
736
|
+
|
737
|
+
@installer.unpack dest
|
738
|
+
|
739
|
+
assert File.exist?(File.join(dest, 'lib', 'code.rb'))
|
740
|
+
assert File.exist?(File.join(dest, 'bin', 'executable'))
|
741
|
+
end
|
742
|
+
|
743
|
+
def test_write_spec
|
744
|
+
spec_dir = File.join @gemhome, 'specifications'
|
745
|
+
spec_file = File.join spec_dir, "#{@spec.full_name}.gemspec"
|
746
|
+
FileUtils.rm spec_file
|
747
|
+
assert !File.exist?(spec_file)
|
748
|
+
|
749
|
+
@installer.spec = @spec
|
750
|
+
@installer.gem_home = @gemhome
|
751
|
+
|
752
|
+
@installer.write_spec
|
753
|
+
|
754
|
+
assert File.exist?(spec_file)
|
755
|
+
assert_equal @spec, eval(File.read(spec_file))
|
756
|
+
end
|
757
|
+
|
758
|
+
def old_ruby_required
|
759
|
+
spec = quick_gem 'old_ruby_required', '0.0.1' do |s|
|
760
|
+
s.required_ruby_version = '= 1.4.6'
|
761
|
+
end
|
762
|
+
|
763
|
+
util_build_gem spec
|
764
|
+
|
765
|
+
File.join @gemhome, 'cache', "#{spec.full_name}.gem"
|
766
|
+
end
|
767
|
+
|
768
|
+
def util_setup_gem
|
769
|
+
@spec.files = File.join('lib', 'code.rb')
|
770
|
+
@spec.executables << 'executable'
|
771
|
+
@spec.extensions << File.join('ext', 'a', 'mkrf_conf.rb')
|
772
|
+
|
773
|
+
Dir.chdir @tempdir do
|
774
|
+
FileUtils.mkdir_p 'bin'
|
775
|
+
FileUtils.mkdir_p 'lib'
|
776
|
+
FileUtils.mkdir_p File.join('ext', 'a')
|
777
|
+
File.open File.join('bin', 'executable'), 'w' do |f| f.puts '1' end
|
778
|
+
File.open File.join('lib', 'code.rb'), 'w' do |f| f.puts '1' end
|
779
|
+
File.open File.join('ext', 'a', 'mkrf_conf.rb'), 'w' do |f|
|
780
|
+
f << <<-EOF
|
781
|
+
File.open 'Rakefile', 'w' do |rf| rf.puts "task :default" end
|
782
|
+
EOF
|
783
|
+
end
|
784
|
+
|
785
|
+
use_ui @ui do
|
786
|
+
FileUtils.rm @gem
|
787
|
+
Gem::Builder.new(@spec).build
|
788
|
+
end
|
789
|
+
end
|
790
|
+
|
791
|
+
@installer = Gem::Installer.new @gem
|
792
|
+
end
|
793
|
+
|
794
|
+
end
|
795
|
+
|
796
|
+
|