slimgems 1.3.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (185) hide show
  1. data/ChangeLog +5811 -0
  2. data/History.txt +887 -0
  3. data/LICENSE.txt +51 -0
  4. data/README.md +87 -0
  5. data/Rakefile +120 -0
  6. data/bin/gem +25 -0
  7. data/bin/update_slimgems +35 -0
  8. data/bootstrap/Rakefile +4 -0
  9. data/hide_lib_for_update/note.txt +5 -0
  10. data/lib/gauntlet_rubygems.rb +50 -0
  11. data/lib/rbconfig/datadir.rb +20 -0
  12. data/lib/rubygems.rb +1220 -0
  13. data/lib/rubygems/builder.rb +102 -0
  14. data/lib/rubygems/command.rb +534 -0
  15. data/lib/rubygems/command_manager.rb +182 -0
  16. data/lib/rubygems/commands/build_command.rb +53 -0
  17. data/lib/rubygems/commands/cert_command.rb +86 -0
  18. data/lib/rubygems/commands/check_command.rb +80 -0
  19. data/lib/rubygems/commands/cleanup_command.rb +106 -0
  20. data/lib/rubygems/commands/contents_command.rb +98 -0
  21. data/lib/rubygems/commands/dependency_command.rb +195 -0
  22. data/lib/rubygems/commands/environment_command.rb +132 -0
  23. data/lib/rubygems/commands/fetch_command.rb +67 -0
  24. data/lib/rubygems/commands/generate_index_command.rb +133 -0
  25. data/lib/rubygems/commands/help_command.rb +172 -0
  26. data/lib/rubygems/commands/install_command.rb +178 -0
  27. data/lib/rubygems/commands/list_command.rb +35 -0
  28. data/lib/rubygems/commands/lock_command.rb +110 -0
  29. data/lib/rubygems/commands/mirror_command.rb +111 -0
  30. data/lib/rubygems/commands/outdated_command.rb +33 -0
  31. data/lib/rubygems/commands/owner_command.rb +75 -0
  32. data/lib/rubygems/commands/pristine_command.rb +93 -0
  33. data/lib/rubygems/commands/push_command.rb +56 -0
  34. data/lib/rubygems/commands/query_command.rb +280 -0
  35. data/lib/rubygems/commands/rdoc_command.rb +91 -0
  36. data/lib/rubygems/commands/search_command.rb +31 -0
  37. data/lib/rubygems/commands/server_command.rb +86 -0
  38. data/lib/rubygems/commands/setup_command.rb +387 -0
  39. data/lib/rubygems/commands/sources_command.rb +157 -0
  40. data/lib/rubygems/commands/specification_command.rb +125 -0
  41. data/lib/rubygems/commands/stale_command.rb +27 -0
  42. data/lib/rubygems/commands/uninstall_command.rb +83 -0
  43. data/lib/rubygems/commands/unpack_command.rb +121 -0
  44. data/lib/rubygems/commands/update_command.rb +212 -0
  45. data/lib/rubygems/commands/which_command.rb +86 -0
  46. data/lib/rubygems/config_file.rb +345 -0
  47. data/lib/rubygems/custom_require.rb +44 -0
  48. data/lib/rubygems/defaults.rb +101 -0
  49. data/lib/rubygems/dependency.rb +227 -0
  50. data/lib/rubygems/dependency_installer.rb +286 -0
  51. data/lib/rubygems/dependency_list.rb +208 -0
  52. data/lib/rubygems/doc_manager.rb +242 -0
  53. data/lib/rubygems/errors.rb +35 -0
  54. data/lib/rubygems/exceptions.rb +91 -0
  55. data/lib/rubygems/ext.rb +18 -0
  56. data/lib/rubygems/ext/builder.rb +56 -0
  57. data/lib/rubygems/ext/configure_builder.rb +25 -0
  58. data/lib/rubygems/ext/ext_conf_builder.rb +24 -0
  59. data/lib/rubygems/ext/rake_builder.rb +39 -0
  60. data/lib/rubygems/format.rb +81 -0
  61. data/lib/rubygems/gem_openssl.rb +92 -0
  62. data/lib/rubygems/gem_path_searcher.rb +100 -0
  63. data/lib/rubygems/gem_runner.rb +79 -0
  64. data/lib/rubygems/gemcutter_utilities.rb +49 -0
  65. data/lib/rubygems/indexer.rb +720 -0
  66. data/lib/rubygems/install_update_options.rb +125 -0
  67. data/lib/rubygems/installer.rb +604 -0
  68. data/lib/rubygems/local_remote_options.rb +135 -0
  69. data/lib/rubygems/old_format.rb +153 -0
  70. data/lib/rubygems/package.rb +97 -0
  71. data/lib/rubygems/package/f_sync_dir.rb +23 -0
  72. data/lib/rubygems/package/tar_header.rb +266 -0
  73. data/lib/rubygems/package/tar_input.rb +222 -0
  74. data/lib/rubygems/package/tar_output.rb +144 -0
  75. data/lib/rubygems/package/tar_reader.rb +106 -0
  76. data/lib/rubygems/package/tar_reader/entry.rb +141 -0
  77. data/lib/rubygems/package/tar_writer.rb +241 -0
  78. data/lib/rubygems/package_task.rb +126 -0
  79. data/lib/rubygems/platform.rb +183 -0
  80. data/lib/rubygems/remote_fetcher.rb +414 -0
  81. data/lib/rubygems/require_paths_builder.rb +18 -0
  82. data/lib/rubygems/requirement.rb +153 -0
  83. data/lib/rubygems/security.rb +814 -0
  84. data/lib/rubygems/server.rb +872 -0
  85. data/lib/rubygems/source_index.rb +597 -0
  86. data/lib/rubygems/source_info_cache.rb +395 -0
  87. data/lib/rubygems/source_info_cache_entry.rb +56 -0
  88. data/lib/rubygems/spec_fetcher.rb +337 -0
  89. data/lib/rubygems/specification.rb +1486 -0
  90. data/lib/rubygems/test_utilities.rb +147 -0
  91. data/lib/rubygems/text.rb +65 -0
  92. data/lib/rubygems/uninstaller.rb +278 -0
  93. data/lib/rubygems/user_interaction.rb +527 -0
  94. data/lib/rubygems/validator.rb +240 -0
  95. data/lib/rubygems/version.rb +316 -0
  96. data/lib/rubygems/version_option.rb +65 -0
  97. data/lib/ubygems.rb +10 -0
  98. data/setup.rb +42 -0
  99. data/test/bogussources.rb +8 -0
  100. data/test/data/gem-private_key.pem +27 -0
  101. data/test/data/gem-public_cert.pem +20 -0
  102. data/test/fake_certlib/openssl.rb +7 -0
  103. data/test/foo/discover.rb +0 -0
  104. data/test/functional.rb +92 -0
  105. data/test/gem_installer_test_case.rb +97 -0
  106. data/test/gem_package_tar_test_case.rb +132 -0
  107. data/test/gemutilities.rb +605 -0
  108. data/test/insure_session.rb +43 -0
  109. data/test/mockgemui.rb +56 -0
  110. data/test/plugin/exception/rubygems_plugin.rb +2 -0
  111. data/test/plugin/load/rubygems_plugin.rb +1 -0
  112. data/test/plugin/standarderror/rubygems_plugin.rb +2 -0
  113. data/test/private_key.pem +27 -0
  114. data/test/public_cert.pem +20 -0
  115. data/test/rubygems_plugin.rb +21 -0
  116. data/test/simple_gem.rb +66 -0
  117. data/test/test_config.rb +12 -0
  118. data/test/test_gem.rb +766 -0
  119. data/test/test_gem_builder.rb +27 -0
  120. data/test/test_gem_command.rb +178 -0
  121. data/test/test_gem_command_manager.rb +207 -0
  122. data/test/test_gem_commands_build_command.rb +74 -0
  123. data/test/test_gem_commands_cert_command.rb +124 -0
  124. data/test/test_gem_commands_check_command.rb +18 -0
  125. data/test/test_gem_commands_contents_command.rb +156 -0
  126. data/test/test_gem_commands_dependency_command.rb +216 -0
  127. data/test/test_gem_commands_environment_command.rb +144 -0
  128. data/test/test_gem_commands_fetch_command.rb +76 -0
  129. data/test/test_gem_commands_generate_index_command.rb +135 -0
  130. data/test/test_gem_commands_install_command.rb +315 -0
  131. data/test/test_gem_commands_list_command.rb +36 -0
  132. data/test/test_gem_commands_lock_command.rb +68 -0
  133. data/test/test_gem_commands_mirror_command.rb +60 -0
  134. data/test/test_gem_commands_outdated_command.rb +40 -0
  135. data/test/test_gem_commands_owner_command.rb +105 -0
  136. data/test/test_gem_commands_pristine_command.rb +108 -0
  137. data/test/test_gem_commands_push_command.rb +81 -0
  138. data/test/test_gem_commands_query_command.rb +426 -0
  139. data/test/test_gem_commands_server_command.rb +59 -0
  140. data/test/test_gem_commands_sources_command.rb +209 -0
  141. data/test/test_gem_commands_specification_command.rb +139 -0
  142. data/test/test_gem_commands_stale_command.rb +38 -0
  143. data/test/test_gem_commands_uninstall_command.rb +83 -0
  144. data/test/test_gem_commands_unpack_command.rb +199 -0
  145. data/test/test_gem_commands_update_command.rb +353 -0
  146. data/test/test_gem_commands_which_command.rb +66 -0
  147. data/test/test_gem_config_file.rb +287 -0
  148. data/test/test_gem_dependency.rb +149 -0
  149. data/test/test_gem_dependency_installer.rb +661 -0
  150. data/test/test_gem_dependency_list.rb +230 -0
  151. data/test/test_gem_doc_manager.rb +31 -0
  152. data/test/test_gem_ext_configure_builder.rb +84 -0
  153. data/test/test_gem_ext_ext_conf_builder.rb +173 -0
  154. data/test/test_gem_ext_rake_builder.rb +81 -0
  155. data/test/test_gem_format.rb +70 -0
  156. data/test/test_gem_gem_path_searcher.rb +78 -0
  157. data/test/test_gem_gem_runner.rb +45 -0
  158. data/test/test_gem_gemcutter_utilities.rb +103 -0
  159. data/test/test_gem_indexer.rb +673 -0
  160. data/test/test_gem_install_update_options.rb +68 -0
  161. data/test/test_gem_installer.rb +857 -0
  162. data/test/test_gem_local_remote_options.rb +97 -0
  163. data/test/test_gem_package_tar_header.rb +130 -0
  164. data/test/test_gem_package_tar_input.rb +112 -0
  165. data/test/test_gem_package_tar_output.rb +97 -0
  166. data/test/test_gem_package_tar_reader.rb +46 -0
  167. data/test/test_gem_package_tar_reader_entry.rb +109 -0
  168. data/test/test_gem_package_tar_writer.rb +144 -0
  169. data/test/test_gem_package_task.rb +59 -0
  170. data/test/test_gem_platform.rb +264 -0
  171. data/test/test_gem_remote_fetcher.rb +740 -0
  172. data/test/test_gem_requirement.rb +292 -0
  173. data/test/test_gem_server.rb +356 -0
  174. data/test/test_gem_silent_ui.rb +113 -0
  175. data/test/test_gem_source_index.rb +461 -0
  176. data/test/test_gem_spec_fetcher.rb +410 -0
  177. data/test/test_gem_specification.rb +1291 -0
  178. data/test/test_gem_stream_ui.rb +218 -0
  179. data/test/test_gem_text.rb +43 -0
  180. data/test/test_gem_uninstaller.rb +146 -0
  181. data/test/test_gem_validator.rb +63 -0
  182. data/test/test_gem_version.rb +181 -0
  183. data/test/test_gem_version_option.rb +89 -0
  184. data/test/test_kernel.rb +59 -0
  185. metadata +413 -0
@@ -0,0 +1,97 @@
1
+ require File.expand_path('../gemutilities', __FILE__)
2
+ require 'rubygems/local_remote_options'
3
+ require 'rubygems/command'
4
+
5
+ class TestGemLocalRemoteOptions < RubyGemTestCase
6
+
7
+ def setup
8
+ super
9
+
10
+ @cmd = Gem::Command.new 'dummy', 'dummy'
11
+ @cmd.extend Gem::LocalRemoteOptions
12
+ end
13
+
14
+ def test_add_local_remote_options
15
+ @cmd.add_local_remote_options
16
+
17
+ args = %w[-l -r -b -B 10 --source http://gems.example.com -p --update-sources]
18
+ assert @cmd.handles?(args)
19
+ end
20
+
21
+ def test_both_eh
22
+ assert_equal false, @cmd.both?
23
+
24
+ @cmd.options[:domain] = :local
25
+
26
+ assert_equal false, @cmd.both?
27
+
28
+ @cmd.options[:domain] = :both
29
+
30
+ assert_equal true, @cmd.both?
31
+ end
32
+
33
+ def test_local_eh
34
+ assert_equal false, @cmd.local?
35
+
36
+ @cmd.options[:domain] = :local
37
+
38
+ assert_equal true, @cmd.local?
39
+
40
+ @cmd.options[:domain] = :both
41
+
42
+ assert_equal true, @cmd.local?
43
+ end
44
+
45
+ def test_remote_eh
46
+ assert_equal false, @cmd.remote?
47
+
48
+ @cmd.options[:domain] = :remote
49
+
50
+ assert_equal true, @cmd.remote?
51
+
52
+ @cmd.options[:domain] = :both
53
+
54
+ assert_equal true, @cmd.remote?
55
+ end
56
+
57
+ def test_source_option
58
+ @cmd.add_source_option
59
+
60
+ s1 = URI.parse 'http://more-gems.example.com/'
61
+ s2 = URI.parse 'http://even-more-gems.example.com/'
62
+ s3 = URI.parse 'http://other-gems.example.com/some_subdir'
63
+ s4 = URI.parse 'http://more-gems.example.com/' # Intentional duplicate
64
+
65
+ @cmd.handle_options %W[--source #{s1} --source #{s2} --source #{s3} --source #{s4}]
66
+
67
+ assert_equal [s1.to_s, s2.to_s, "#{s3}/"], Gem.sources
68
+ end
69
+
70
+ def test_update_sources_option
71
+ @cmd.add_update_sources_option
72
+
73
+ Gem.configuration.update_sources = false
74
+
75
+ @cmd.handle_options %W[--update-sources]
76
+
77
+ assert_equal true, Gem.configuration.update_sources
78
+
79
+ @cmd.handle_options %W[--no-update-sources]
80
+
81
+ assert_equal false, Gem.configuration.update_sources
82
+ end
83
+
84
+ def test_source_option_bad
85
+ @cmd.add_source_option
86
+
87
+ s1 = 'htp://more-gems.example.com'
88
+
89
+ assert_raises OptionParser::InvalidArgument do
90
+ @cmd.handle_options %W[--source #{s1}]
91
+ end
92
+
93
+ assert_equal [@gem_repo], Gem.sources
94
+ end
95
+
96
+ end
97
+
@@ -0,0 +1,130 @@
1
+ require File.expand_path('../gem_package_tar_test_case', __FILE__)
2
+ require 'rubygems/package'
3
+
4
+ class TestGemPackageTarHeader < TarTestCase
5
+
6
+ def setup
7
+ super
8
+
9
+ header = {
10
+ :name => 'x',
11
+ :mode => 0644,
12
+ :uid => 1000,
13
+ :gid => 10000,
14
+ :size => 100,
15
+ :mtime => 12345,
16
+ :typeflag => '0',
17
+ :linkname => 'link',
18
+ :uname => 'user',
19
+ :gname => 'group',
20
+ :devmajor => 1,
21
+ :devminor => 2,
22
+ :prefix => 'y',
23
+ }
24
+
25
+ @tar_header = Gem::Package::TarHeader.new header
26
+ end
27
+
28
+ def test_self_from
29
+ io = TempIO.new @tar_header.to_s
30
+
31
+ new_header = Gem::Package::TarHeader.from io
32
+
33
+ assert_headers_equal @tar_header, new_header
34
+ end
35
+
36
+ def test_initialize
37
+ assert_equal '', @tar_header.checksum, 'checksum'
38
+ assert_equal 1, @tar_header.devmajor, 'devmajor'
39
+ assert_equal 2, @tar_header.devminor, 'devminor'
40
+ assert_equal 10000, @tar_header.gid, 'gid'
41
+ assert_equal 'group', @tar_header.gname, 'gname'
42
+ assert_equal 'link', @tar_header.linkname, 'linkname'
43
+ assert_equal 'ustar', @tar_header.magic, 'magic'
44
+ assert_equal 0644, @tar_header.mode, 'mode'
45
+ assert_equal 12345, @tar_header.mtime, 'mtime'
46
+ assert_equal 'x', @tar_header.name, 'name'
47
+ assert_equal 'y', @tar_header.prefix, 'prefix'
48
+ assert_equal 100, @tar_header.size, 'size'
49
+ assert_equal '0', @tar_header.typeflag, 'typeflag'
50
+ assert_equal 1000, @tar_header.uid, 'uid'
51
+ assert_equal 'user', @tar_header.uname, 'uname'
52
+ assert_equal '00', @tar_header.version, 'version'
53
+
54
+ refute_empty @tar_header, 'empty'
55
+ end
56
+
57
+ def test_initialize_bad
58
+ assert_raises ArgumentError do
59
+ Gem::Package::TarHeader.new :name => '', :size => '', :mode => ''
60
+ end
61
+
62
+ assert_raises ArgumentError do
63
+ Gem::Package::TarHeader.new :name => '', :size => '', :prefix => ''
64
+ end
65
+
66
+ assert_raises ArgumentError do
67
+ Gem::Package::TarHeader.new :name => '', :prefix => '', :mode => ''
68
+ end
69
+
70
+ assert_raises ArgumentError do
71
+ Gem::Package::TarHeader.new :prefix => '', :size => '', :mode => ''
72
+ end
73
+ end
74
+
75
+ def test_empty_eh
76
+ refute_empty @tar_header
77
+
78
+ @tar_header = Gem::Package::TarHeader.new :name => 'x', :prefix => '',
79
+ :mode => 0, :size => 0,
80
+ :empty => true
81
+
82
+ assert_empty @tar_header
83
+ end
84
+
85
+ def test_equals2
86
+ assert_equal @tar_header, @tar_header
87
+ assert_equal @tar_header, @tar_header.dup
88
+ end
89
+
90
+ def test_to_s
91
+ expected = <<-EOF.split("\n").join
92
+ x\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
93
+ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
94
+ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
95
+ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
96
+ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
97
+ \000\000\000\0000000644\0000001750\0000023420\00000000000144\00000000030071
98
+ \000012467\000 0link\000\000\000\000\000\000\000\000\000\000\000\000\000\000
99
+ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
100
+ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
101
+ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
102
+ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
103
+ \000\000\000\000\000\000ustar\00000user\000\000\000\000\000\000\000\000\000
104
+ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
105
+ group\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
106
+ \000\000\000\000\000\000\000\000\0000000001\0000000002\000y\000\000\000\000
107
+ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
108
+ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
109
+ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
110
+ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
111
+ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
112
+ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
113
+ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
114
+ \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
115
+ \000\000\000\000\000\000\000\000\000\000
116
+ EOF
117
+
118
+ assert_headers_equal expected, @tar_header
119
+ end
120
+
121
+ def test_update_checksum
122
+ assert_equal '', @tar_header.checksum
123
+
124
+ @tar_header.update_checksum
125
+
126
+ assert_equal '012467', @tar_header.checksum
127
+ end
128
+
129
+ end
130
+
@@ -0,0 +1,112 @@
1
+ require File.expand_path('../gem_package_tar_test_case', __FILE__)
2
+ require 'rubygems/package/tar_input'
3
+
4
+ class TestGemPackageTarInput < TarTestCase
5
+
6
+ # Sometimes the setgid bit doesn't take. Don't know if this is a problem on
7
+ # all systems, or just some. But for now, we will ignore it in the tests.
8
+ SETGID_BIT = 02000
9
+
10
+ def setup
11
+ super
12
+
13
+ inner_tar = tar_file_header("bla", "", 0612, 10)
14
+ inner_tar += "0123456789" + "\0" * 502
15
+ inner_tar += tar_file_header("foo", "", 0636, 5)
16
+ inner_tar += "01234" + "\0" * 507
17
+ inner_tar += tar_dir_header("__dir__", "", 0600)
18
+ inner_tar += "\0" * 1024
19
+ str = TempIO.new
20
+
21
+ begin
22
+ os = Zlib::GzipWriter.new str
23
+ os.write inner_tar
24
+ ensure
25
+ os.finish
26
+ end
27
+
28
+ str.rewind
29
+
30
+ @file = File.join @tempdir, 'bla.tar'
31
+
32
+ File.open @file, 'wb' do |f|
33
+ f.write tar_file_header("data.tar.gz", "", 0644, str.string.size)
34
+ f.write str.string
35
+ f.write "\0" * ((512 - (str.string.size % 512)) % 512 )
36
+
37
+ @spec = Gem::Specification.new do |spec|
38
+ spec.author = "Mauricio :)"
39
+ end
40
+
41
+ meta = @spec.to_yaml
42
+
43
+ f.write tar_file_header("metadata", "", 0644, meta.size)
44
+ f.write meta + "\0" * (1024 - meta.size)
45
+ f.write "\0" * 1024
46
+ end
47
+
48
+ @entry_names = %w{bla foo __dir__}
49
+ @entry_sizes = [10, 5, 0]
50
+ #FIXME: are these modes system dependent?
51
+ @entry_modes = [0100612, 0100636, 040600]
52
+ @entry_files = %W[#{@tempdir}/bla #{@tempdir}/foo]
53
+ @entry_contents = %w[0123456789 01234]
54
+ end
55
+
56
+ def test_each_works
57
+ open @file, 'rb' do |io|
58
+ Gem::Package::TarInput.open io do |tar_input|
59
+ count = 0
60
+
61
+ tar_input.each_with_index do |entry, i|
62
+ count = i
63
+
64
+ assert_kind_of Gem::Package::TarReader::Entry, entry
65
+ assert_equal @entry_names[i], entry.header.name
66
+ assert_equal @entry_sizes[i], entry.header.size
67
+ end
68
+
69
+ assert_equal 2, count
70
+
71
+ assert_equal @spec, tar_input.metadata
72
+ end
73
+ end
74
+ end
75
+
76
+ def test_extract_entry_works
77
+ open @file, 'rb' do |io|
78
+ Gem::Package::TarInput.open io do |tar_input|
79
+ assert_equal @spec, tar_input.metadata
80
+
81
+ count = 0
82
+
83
+ tar_input.each_with_index do |entry, i|
84
+ count = i
85
+ tar_input.extract_entry @tempdir, entry
86
+ name = File.join @tempdir, entry.header.name
87
+
88
+ if entry.directory? then
89
+ assert File.directory?(name)
90
+ else
91
+ assert File.file?(name)
92
+ assert_equal @entry_sizes[i], File.stat(name).size
93
+ #FIXME: win32? !!
94
+ end
95
+
96
+ unless Gem.win_platform? then
97
+ assert_equal @entry_modes[i], File.stat(name).mode & (~SETGID_BIT)
98
+ end
99
+ end
100
+
101
+ assert_equal 2, count
102
+ end
103
+ end
104
+
105
+ @entry_files.each_with_index do |x, i|
106
+ assert File.file?(x)
107
+ assert_equal @entry_contents[i], Gem.read_binary(x)
108
+ end
109
+ end
110
+
111
+ end
112
+
@@ -0,0 +1,97 @@
1
+ require File.expand_path('../gem_package_tar_test_case', __FILE__)
2
+ require 'rubygems/package/tar_output'
3
+
4
+ class TestGemPackageTarOutput < TarTestCase
5
+
6
+ def setup
7
+ super
8
+
9
+ @file = File.join @tempdir, 'bla2.tar'
10
+ end
11
+
12
+ def test_self_open
13
+ open @file, 'wb' do |tar_io|
14
+ Gem::Package::TarOutput.open tar_io do |tar_writer|
15
+ tar_writer.add_file_simple 'README', 0, 17 do |io|
16
+ io.write "This is a README\n"
17
+ end
18
+
19
+ tar_writer.metadata = "This is some metadata\n"
20
+ end
21
+ end
22
+
23
+ files = util_extract
24
+
25
+ name, data = files.shift
26
+ assert_equal 'data.tar.gz', name
27
+
28
+ gz = Zlib::GzipReader.new StringIO.new(data)
29
+
30
+ Gem::Package::TarReader.new gz do |tar_reader|
31
+ tar_reader.each do |entry|
32
+ assert_equal 'README', entry.full_name
33
+ assert_equal "This is a README\n", entry.read
34
+ end
35
+ end
36
+
37
+ gz.close
38
+
39
+ name, data = files.shift
40
+ assert_equal 'metadata.gz', name
41
+
42
+ gz = Zlib::GzipReader.new StringIO.new(data)
43
+ assert_equal "This is some metadata\n", gz.read
44
+
45
+ assert_empty files
46
+ ensure
47
+ gz.close if gz
48
+ end
49
+
50
+ if defined? OpenSSL then
51
+ def test_self_open_signed
52
+ signer = Gem::Security::Signer.new @private_key, [@public_cert]
53
+
54
+ open @file, 'wb' do |tar_io|
55
+ Gem::Package::TarOutput.open tar_io, signer do |tar_writer|
56
+ tar_writer.add_file_simple 'README', 0, 17 do |io|
57
+ io.write "This is a README\n"
58
+ end
59
+
60
+ tar_writer.metadata = "This is some metadata\n"
61
+ end
62
+ end
63
+
64
+ files = util_extract
65
+
66
+ name, data = files.shift
67
+ assert_equal 'data.tar.gz', name
68
+
69
+ name, data = files.shift
70
+ assert_equal 'metadata.gz', name
71
+
72
+ name, data = files.shift
73
+ assert_equal 'data.tar.gz.sig', name
74
+
75
+ name, data = files.shift
76
+ assert_equal 'metadata.gz.sig', name
77
+
78
+ assert_empty files
79
+ end
80
+ end
81
+
82
+ def util_extract
83
+ files = []
84
+
85
+ open @file, 'rb' do |io|
86
+ Gem::Package::TarReader.new io do |tar_reader|
87
+ tar_reader.each do |entry|
88
+ files << [entry.full_name, entry.read]
89
+ end
90
+ end
91
+ end
92
+
93
+ files
94
+ end
95
+
96
+ end
97
+
@@ -0,0 +1,46 @@
1
+ require File.expand_path('../gem_package_tar_test_case', __FILE__)
2
+ require 'rubygems/package'
3
+
4
+ class TestGemPackageTarReader < TarTestCase
5
+
6
+ def test_each_entry
7
+ tar = tar_dir_header "foo", "bar", 0
8
+ tar << tar_file_header("bar", "baz", 0, 0)
9
+
10
+ io = TempIO.new tar
11
+
12
+ entries = 0
13
+
14
+ Gem::Package::TarReader.new io do |tar_reader|
15
+ tar_reader.each_entry do |entry|
16
+ assert_kind_of Gem::Package::TarReader::Entry, entry
17
+
18
+ entries += 1
19
+ end
20
+ end
21
+
22
+ assert_equal 2, entries
23
+ end
24
+
25
+ def test_rewind
26
+ content = ('a'..'z').to_a.join(" ")
27
+
28
+ str = tar_file_header("lib/foo", "", 010644, content.size) + content +
29
+ "\0" * (512 - content.size)
30
+ str << "\0" * 1024
31
+
32
+ Gem::Package::TarReader.new(TempIO.new(str)) do |tar_reader|
33
+ 3.times do
34
+ tar_reader.rewind
35
+ i = 0
36
+ tar_reader.each_entry do |entry|
37
+ assert_equal(content, entry.read)
38
+ i += 1
39
+ end
40
+ assert_equal(1, i)
41
+ end
42
+ end
43
+ end
44
+
45
+ end
46
+