libgems 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) 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 +113 -0
  6. data/lib/gauntlet_libgems.rb +50 -0
  7. data/lib/libgems.rb +1246 -0
  8. data/lib/libgems/builder.rb +102 -0
  9. data/lib/libgems/command.rb +534 -0
  10. data/lib/libgems/command_manager.rb +182 -0
  11. data/lib/libgems/commands/build_command.rb +53 -0
  12. data/lib/libgems/commands/cert_command.rb +86 -0
  13. data/lib/libgems/commands/check_command.rb +80 -0
  14. data/lib/libgems/commands/cleanup_command.rb +106 -0
  15. data/lib/libgems/commands/contents_command.rb +98 -0
  16. data/lib/libgems/commands/dependency_command.rb +195 -0
  17. data/lib/libgems/commands/environment_command.rb +133 -0
  18. data/lib/libgems/commands/fetch_command.rb +67 -0
  19. data/lib/libgems/commands/generate_index_command.rb +133 -0
  20. data/lib/libgems/commands/help_command.rb +172 -0
  21. data/lib/libgems/commands/install_command.rb +178 -0
  22. data/lib/libgems/commands/list_command.rb +35 -0
  23. data/lib/libgems/commands/lock_command.rb +110 -0
  24. data/lib/libgems/commands/mirror_command.rb +111 -0
  25. data/lib/libgems/commands/outdated_command.rb +33 -0
  26. data/lib/libgems/commands/owner_command.rb +75 -0
  27. data/lib/libgems/commands/pristine_command.rb +93 -0
  28. data/lib/libgems/commands/push_command.rb +56 -0
  29. data/lib/libgems/commands/query_command.rb +280 -0
  30. data/lib/libgems/commands/rdoc_command.rb +91 -0
  31. data/lib/libgems/commands/search_command.rb +31 -0
  32. data/lib/libgems/commands/server_command.rb +86 -0
  33. data/lib/libgems/commands/sources_command.rb +157 -0
  34. data/lib/libgems/commands/specification_command.rb +125 -0
  35. data/lib/libgems/commands/stale_command.rb +27 -0
  36. data/lib/libgems/commands/uninstall_command.rb +83 -0
  37. data/lib/libgems/commands/unpack_command.rb +121 -0
  38. data/lib/libgems/commands/update_command.rb +160 -0
  39. data/lib/libgems/commands/which_command.rb +86 -0
  40. data/lib/libgems/config_file.rb +345 -0
  41. data/lib/libgems/custom_require.rb +44 -0
  42. data/lib/libgems/defaults.rb +101 -0
  43. data/lib/libgems/dependency.rb +227 -0
  44. data/lib/libgems/dependency_installer.rb +286 -0
  45. data/lib/libgems/dependency_list.rb +208 -0
  46. data/lib/libgems/doc_manager.rb +242 -0
  47. data/lib/libgems/errors.rb +35 -0
  48. data/lib/libgems/exceptions.rb +91 -0
  49. data/lib/libgems/ext.rb +18 -0
  50. data/lib/libgems/ext/builder.rb +56 -0
  51. data/lib/libgems/ext/configure_builder.rb +25 -0
  52. data/lib/libgems/ext/ext_conf_builder.rb +24 -0
  53. data/lib/libgems/ext/rake_builder.rb +39 -0
  54. data/lib/libgems/format.rb +81 -0
  55. data/lib/libgems/gem_openssl.rb +92 -0
  56. data/lib/libgems/gem_path_searcher.rb +100 -0
  57. data/lib/libgems/gem_runner.rb +79 -0
  58. data/lib/libgems/gemcutter_utilities.rb +49 -0
  59. data/lib/libgems/indexer.rb +720 -0
  60. data/lib/libgems/install_update_options.rb +125 -0
  61. data/lib/libgems/installer.rb +604 -0
  62. data/lib/libgems/local_remote_options.rb +135 -0
  63. data/lib/libgems/old_format.rb +153 -0
  64. data/lib/libgems/package.rb +97 -0
  65. data/lib/libgems/package/f_sync_dir.rb +23 -0
  66. data/lib/libgems/package/tar_header.rb +266 -0
  67. data/lib/libgems/package/tar_input.rb +222 -0
  68. data/lib/libgems/package/tar_output.rb +144 -0
  69. data/lib/libgems/package/tar_reader.rb +106 -0
  70. data/lib/libgems/package/tar_reader/entry.rb +141 -0
  71. data/lib/libgems/package/tar_writer.rb +241 -0
  72. data/lib/libgems/package_task.rb +126 -0
  73. data/lib/libgems/platform.rb +183 -0
  74. data/lib/libgems/remote_fetcher.rb +414 -0
  75. data/lib/libgems/require_paths_builder.rb +18 -0
  76. data/lib/libgems/requirement.rb +153 -0
  77. data/lib/libgems/security.rb +814 -0
  78. data/lib/libgems/server.rb +872 -0
  79. data/lib/libgems/source_index.rb +597 -0
  80. data/lib/libgems/source_info_cache.rb +395 -0
  81. data/lib/libgems/source_info_cache_entry.rb +56 -0
  82. data/lib/libgems/spec_fetcher.rb +337 -0
  83. data/lib/libgems/specification.rb +1487 -0
  84. data/lib/libgems/test_utilities.rb +147 -0
  85. data/lib/libgems/text.rb +65 -0
  86. data/lib/libgems/uninstaller.rb +278 -0
  87. data/lib/libgems/user_interaction.rb +527 -0
  88. data/lib/libgems/validator.rb +240 -0
  89. data/lib/libgems/version.rb +316 -0
  90. data/lib/libgems/version_option.rb +65 -0
  91. data/lib/rbconfig/datadir.rb +20 -0
  92. data/test/bogussources.rb +8 -0
  93. data/test/data/gem-private_key.pem +27 -0
  94. data/test/data/gem-public_cert.pem +20 -0
  95. data/test/fake_certlib/openssl.rb +7 -0
  96. data/test/foo/discover.rb +0 -0
  97. data/test/gem_installer_test_case.rb +97 -0
  98. data/test/gem_package_tar_test_case.rb +132 -0
  99. data/test/gemutilities.rb +605 -0
  100. data/test/insure_session.rb +43 -0
  101. data/test/mockgemui.rb +56 -0
  102. data/test/plugin/exception/libgems_plugin.rb +2 -0
  103. data/test/plugin/load/libgems_plugin.rb +1 -0
  104. data/test/plugin/standarderror/libgems_plugin.rb +2 -0
  105. data/test/private_key.pem +27 -0
  106. data/test/public_cert.pem +20 -0
  107. data/test/rubygems_plugin.rb +21 -0
  108. data/test/simple_gem.rb +66 -0
  109. data/test/test_config.rb +12 -0
  110. data/test/test_gem.rb +780 -0
  111. data/test/test_gem_builder.rb +27 -0
  112. data/test/test_gem_command.rb +178 -0
  113. data/test/test_gem_command_manager.rb +207 -0
  114. data/test/test_gem_commands_build_command.rb +74 -0
  115. data/test/test_gem_commands_cert_command.rb +124 -0
  116. data/test/test_gem_commands_check_command.rb +18 -0
  117. data/test/test_gem_commands_contents_command.rb +156 -0
  118. data/test/test_gem_commands_dependency_command.rb +216 -0
  119. data/test/test_gem_commands_environment_command.rb +144 -0
  120. data/test/test_gem_commands_fetch_command.rb +76 -0
  121. data/test/test_gem_commands_generate_index_command.rb +135 -0
  122. data/test/test_gem_commands_install_command.rb +315 -0
  123. data/test/test_gem_commands_list_command.rb +36 -0
  124. data/test/test_gem_commands_lock_command.rb +68 -0
  125. data/test/test_gem_commands_mirror_command.rb +60 -0
  126. data/test/test_gem_commands_outdated_command.rb +40 -0
  127. data/test/test_gem_commands_owner_command.rb +105 -0
  128. data/test/test_gem_commands_pristine_command.rb +108 -0
  129. data/test/test_gem_commands_push_command.rb +81 -0
  130. data/test/test_gem_commands_query_command.rb +426 -0
  131. data/test/test_gem_commands_server_command.rb +59 -0
  132. data/test/test_gem_commands_sources_command.rb +209 -0
  133. data/test/test_gem_commands_specification_command.rb +139 -0
  134. data/test/test_gem_commands_stale_command.rb +38 -0
  135. data/test/test_gem_commands_uninstall_command.rb +83 -0
  136. data/test/test_gem_commands_unpack_command.rb +199 -0
  137. data/test/test_gem_commands_update_command.rb +207 -0
  138. data/test/test_gem_commands_which_command.rb +66 -0
  139. data/test/test_gem_config_file.rb +287 -0
  140. data/test/test_gem_dependency.rb +149 -0
  141. data/test/test_gem_dependency_installer.rb +661 -0
  142. data/test/test_gem_dependency_list.rb +230 -0
  143. data/test/test_gem_doc_manager.rb +31 -0
  144. data/test/test_gem_ext_configure_builder.rb +84 -0
  145. data/test/test_gem_ext_ext_conf_builder.rb +173 -0
  146. data/test/test_gem_ext_rake_builder.rb +81 -0
  147. data/test/test_gem_format.rb +70 -0
  148. data/test/test_gem_gem_path_searcher.rb +78 -0
  149. data/test/test_gem_gem_runner.rb +45 -0
  150. data/test/test_gem_gemcutter_utilities.rb +103 -0
  151. data/test/test_gem_indexer.rb +673 -0
  152. data/test/test_gem_install_update_options.rb +68 -0
  153. data/test/test_gem_installer.rb +857 -0
  154. data/test/test_gem_local_remote_options.rb +97 -0
  155. data/test/test_gem_package_tar_header.rb +130 -0
  156. data/test/test_gem_package_tar_input.rb +112 -0
  157. data/test/test_gem_package_tar_output.rb +97 -0
  158. data/test/test_gem_package_tar_reader.rb +46 -0
  159. data/test/test_gem_package_tar_reader_entry.rb +109 -0
  160. data/test/test_gem_package_tar_writer.rb +144 -0
  161. data/test/test_gem_package_task.rb +59 -0
  162. data/test/test_gem_platform.rb +264 -0
  163. data/test/test_gem_remote_fetcher.rb +740 -0
  164. data/test/test_gem_requirement.rb +292 -0
  165. data/test/test_gem_server.rb +356 -0
  166. data/test/test_gem_silent_ui.rb +113 -0
  167. data/test/test_gem_source_index.rb +461 -0
  168. data/test/test_gem_spec_fetcher.rb +410 -0
  169. data/test/test_gem_specification.rb +1334 -0
  170. data/test/test_gem_stream_ui.rb +218 -0
  171. data/test/test_gem_text.rb +43 -0
  172. data/test/test_gem_uninstaller.rb +146 -0
  173. data/test/test_gem_validator.rb +63 -0
  174. data/test/test_gem_version.rb +181 -0
  175. data/test/test_gem_version_option.rb +89 -0
  176. data/test/test_kernel.rb +59 -0
  177. metadata +402 -0
@@ -0,0 +1,109 @@
1
+ require File.expand_path('../gem_package_tar_test_case', __FILE__)
2
+ require 'libgems/package'
3
+
4
+ class TestGemPackageTarReaderEntry < TarTestCase
5
+
6
+ def setup
7
+ super
8
+
9
+ @contents = ('a'..'z').to_a.join * 100
10
+
11
+ @tar = ''
12
+ @tar << tar_file_header("lib/foo", "", 0, @contents.size)
13
+ @tar << @contents
14
+ @tar << "\0" * (512 - (@tar.size % 512))
15
+
16
+ @entry = util_entry @tar
17
+ end
18
+
19
+ def test_bytes_read
20
+ assert_equal 0, @entry.bytes_read
21
+
22
+ @entry.getc
23
+
24
+ assert_equal 1, @entry.bytes_read
25
+ end
26
+
27
+ def test_close
28
+ @entry.close
29
+
30
+ assert @entry.bytes_read
31
+
32
+ e = assert_raises IOError do @entry.eof? end
33
+ assert_equal 'closed LibGems::Package::TarReader::Entry', e.message
34
+
35
+ e = assert_raises IOError do @entry.getc end
36
+ assert_equal 'closed LibGems::Package::TarReader::Entry', e.message
37
+
38
+ e = assert_raises IOError do @entry.pos end
39
+ assert_equal 'closed LibGems::Package::TarReader::Entry', e.message
40
+
41
+ e = assert_raises IOError do @entry.read end
42
+ assert_equal 'closed LibGems::Package::TarReader::Entry', e.message
43
+
44
+ e = assert_raises IOError do @entry.rewind end
45
+ assert_equal 'closed LibGems::Package::TarReader::Entry', e.message
46
+ end
47
+
48
+ def test_closed_eh
49
+ @entry.close
50
+
51
+ assert @entry.closed?
52
+ end
53
+
54
+ def test_eof_eh
55
+ @entry.read
56
+
57
+ assert @entry.eof?
58
+ end
59
+
60
+ def test_full_name
61
+ assert_equal 'lib/foo', @entry.full_name
62
+ end
63
+
64
+ def test_getc
65
+ assert_equal ?a, @entry.getc
66
+ end
67
+
68
+ def test_directory_eh
69
+ assert_equal false, @entry.directory?
70
+ assert_equal true, util_dir_entry.directory?
71
+ end
72
+
73
+ def test_file_eh
74
+ assert_equal true, @entry.file?
75
+ assert_equal false, util_dir_entry.file?
76
+ end
77
+
78
+ def test_pos
79
+ assert_equal 0, @entry.pos
80
+
81
+ @entry.getc
82
+
83
+ assert_equal 1, @entry.pos
84
+ end
85
+
86
+ def test_read
87
+ assert_equal @contents, @entry.read
88
+ end
89
+
90
+ def test_read_big
91
+ assert_equal @contents, @entry.read(@contents.size * 2)
92
+ end
93
+
94
+ def test_read_small
95
+ assert_equal @contents[0...100], @entry.read(100)
96
+ end
97
+
98
+ def test_rewind
99
+ char = @entry.getc
100
+
101
+ @entry.rewind
102
+
103
+ assert_equal 0, @entry.pos
104
+
105
+ assert_equal char, @entry.getc
106
+ end
107
+
108
+ end
109
+
@@ -0,0 +1,144 @@
1
+ require File.expand_path('../gem_package_tar_test_case', __FILE__)
2
+ require 'libgems/package/tar_writer'
3
+
4
+ class TestTarWriter < TarTestCase
5
+
6
+ def setup
7
+ super
8
+
9
+ @data = 'abcde12345'
10
+ @io = TempIO.new
11
+ @tar_writer = LibGems::Package::TarWriter.new @io
12
+ end
13
+
14
+ def teardown
15
+ @tar_writer.close unless @tar_writer.closed?
16
+
17
+ super
18
+ end
19
+
20
+ def test_add_file
21
+ @tar_writer.add_file 'x', 0644 do |f| f.write 'a' * 10 end
22
+
23
+ assert_headers_equal(tar_file_header('x', '', 0644, 10),
24
+ @io.string[0, 512])
25
+ assert_equal "aaaaaaaaaa#{"\0" * 502}", @io.string[512, 512]
26
+ assert_equal 1024, @io.pos
27
+ end
28
+
29
+ def test_add_file_simple
30
+ @tar_writer.add_file_simple 'x', 0644, 10 do |io| io.write "a" * 10 end
31
+
32
+ assert_headers_equal(tar_file_header('x', '', 0644, 10),
33
+ @io.string[0, 512])
34
+
35
+ assert_equal "aaaaaaaaaa#{"\0" * 502}", @io.string[512, 512]
36
+ assert_equal 1024, @io.pos
37
+ end
38
+
39
+ def test_add_file_simple_padding
40
+ @tar_writer.add_file_simple 'x', 0, 100
41
+
42
+ assert_headers_equal tar_file_header('x', '', 0, 100),
43
+ @io.string[0, 512]
44
+
45
+ assert_equal "\0" * 512, @io.string[512, 512]
46
+ end
47
+
48
+ def test_add_file_simple_data
49
+ @tar_writer.add_file_simple("lib/foo/bar", 0, 10) { |f| f.write @data }
50
+ @tar_writer.flush
51
+
52
+ assert_equal @data + ("\0" * (512-@data.size)),
53
+ @io.string[512, 512]
54
+ end
55
+
56
+ def test_add_file_simple_size
57
+ assert_raises LibGems::Package::TarWriter::FileOverflow do
58
+ @tar_writer.add_file_simple("lib/foo/bar", 0, 10) do |io|
59
+ io.write "1" * 11
60
+ end
61
+ end
62
+ end
63
+
64
+ def test_add_file_unseekable
65
+ assert_raises LibGems::Package::NonSeekableIO do
66
+ LibGems::Package::TarWriter.new(Object.new).add_file 'x', 0
67
+ end
68
+ end
69
+
70
+ def test_close
71
+ @tar_writer.close
72
+
73
+ assert_equal "\0" * 1024, @io.string
74
+
75
+ e = assert_raises IOError do
76
+ @tar_writer.close
77
+ end
78
+ assert_equal 'closed LibGems::Package::TarWriter', e.message
79
+
80
+ e = assert_raises IOError do
81
+ @tar_writer.flush
82
+ end
83
+ assert_equal 'closed LibGems::Package::TarWriter', e.message
84
+
85
+ e = assert_raises IOError do
86
+ @tar_writer.add_file 'x', 0
87
+ end
88
+ assert_equal 'closed LibGems::Package::TarWriter', e.message
89
+
90
+ e = assert_raises IOError do
91
+ @tar_writer.add_file_simple 'x', 0, 0
92
+ end
93
+ assert_equal 'closed LibGems::Package::TarWriter', e.message
94
+
95
+ e = assert_raises IOError do
96
+ @tar_writer.mkdir 'x', 0
97
+ end
98
+ assert_equal 'closed LibGems::Package::TarWriter', e.message
99
+ end
100
+
101
+ def test_mkdir
102
+ @tar_writer.mkdir 'foo', 0644
103
+
104
+ assert_headers_equal tar_dir_header('foo', '', 0644),
105
+ @io.string[0, 512]
106
+ assert_equal 512, @io.pos
107
+ end
108
+
109
+ def test_split_name
110
+ assert_equal ['b' * 100, 'a' * 155],
111
+ @tar_writer.split_name("#{'a' * 155}/#{'b' * 100}")
112
+
113
+ assert_equal ["#{'qwer/' * 19}bla", 'a' * 151],
114
+ @tar_writer.split_name("#{'a' * 151}/#{'qwer/' * 19}bla")
115
+ end
116
+
117
+ def test_split_name_too_long_name
118
+ name = File.join 'a', 'b' * 100
119
+ assert_equal ['b' * 100, 'a'], @tar_writer.split_name(name)
120
+
121
+ assert_raises LibGems::Package::TooLongFileName do
122
+ name = File.join 'a', 'b' * 101
123
+ @tar_writer.split_name name
124
+ end
125
+ end
126
+
127
+ def test_split_name_too_long_prefix
128
+ name = File.join 'a' * 155, 'b'
129
+ assert_equal ['b', 'a' * 155], @tar_writer.split_name(name)
130
+
131
+ assert_raises LibGems::Package::TooLongFileName do
132
+ name = File.join 'a' * 156, 'b'
133
+ @tar_writer.split_name name
134
+ end
135
+ end
136
+
137
+ def test_split_name_too_long_total
138
+ assert_raises LibGems::Package::TooLongFileName do
139
+ @tar_writer.split_name 'a' * 257
140
+ end
141
+ end
142
+
143
+ end
144
+
@@ -0,0 +1,59 @@
1
+ require File.expand_path('../gemutilities', __FILE__)
2
+ require 'libgems'
3
+ require 'libgems/package_task'
4
+
5
+ class TestGemPackageTask < RubyGemTestCase
6
+
7
+ def test_gem_package
8
+ gem = LibGems::Specification.new do |g|
9
+ g.name = "pkgr"
10
+ g.version = "1.2.3"
11
+ g.files = Rake::FileList["x"].resolve
12
+ end
13
+ pkg = LibGems::PackageTask.new(gem) do |p|
14
+ p.package_files << "y"
15
+ end
16
+ assert_equal ["x", "y"], pkg.package_files
17
+ end
18
+
19
+ def test_gem_package_with_current_platform
20
+ gem = LibGems::Specification.new do |g|
21
+ g.name = "pkgr"
22
+ g.version = "1.2.3"
23
+ g.files = Rake::FileList["x"].resolve
24
+ g.platform = LibGems::Platform::CURRENT
25
+ end
26
+ pkg = LibGems::PackageTask.new(gem) do |p|
27
+ p.package_files << "y"
28
+ end
29
+ assert_equal ["x", "y"], pkg.package_files
30
+ end
31
+
32
+ def test_gem_package_with_ruby_platform
33
+ gem = LibGems::Specification.new do |g|
34
+ g.name = "pkgr"
35
+ g.version = "1.2.3"
36
+ g.files = Rake::FileList["x"].resolve
37
+ g.platform = LibGems::Platform::RUBY
38
+ end
39
+ pkg = LibGems::PackageTask.new(gem) do |p|
40
+ p.package_files << "y"
41
+ end
42
+ assert_equal ["x", "y"], pkg.package_files
43
+ end
44
+
45
+ def test_package_dir_path
46
+ gem = LibGems::Specification.new do |g|
47
+ g.name = 'nokogiri'
48
+ g.version = '1.5.0'
49
+ g.platform = 'java'
50
+ end
51
+
52
+ pkg = LibGems::PackageTask.new gem
53
+ pkg.define
54
+
55
+ assert_equal 'pkg/nokogiri-1.5.0-java', pkg.package_dir_path
56
+ end
57
+
58
+ end
59
+
@@ -0,0 +1,264 @@
1
+ require File.expand_path('../gemutilities', __FILE__)
2
+ require 'libgems/platform'
3
+ require 'rbconfig'
4
+
5
+ class TestGemPlatform < RubyGemTestCase
6
+
7
+ def test_self_local
8
+ util_set_arch 'i686-darwin8.10.1'
9
+
10
+ assert_equal LibGems::Platform.new(%w[x86 darwin 8]), LibGems::Platform.local
11
+ end
12
+
13
+ def test_self_match
14
+ assert LibGems::Platform.match(nil), 'nil == ruby'
15
+ assert LibGems::Platform.match(LibGems::Platform.local), 'exact match'
16
+ assert LibGems::Platform.match(LibGems::Platform.local.to_s), '=~ match'
17
+ assert LibGems::Platform.match(LibGems::Platform::RUBY), 'ruby'
18
+ end
19
+
20
+ def test_self_new
21
+ assert_equal LibGems::Platform.local, LibGems::Platform.new(LibGems::Platform::CURRENT)
22
+ assert_equal LibGems::Platform::RUBY, LibGems::Platform.new(LibGems::Platform::RUBY)
23
+ assert_equal LibGems::Platform::RUBY, LibGems::Platform.new(nil)
24
+ assert_equal LibGems::Platform::RUBY, LibGems::Platform.new('')
25
+ end
26
+
27
+ def test_initialize
28
+ test_cases = {
29
+ 'amd64-freebsd6' => ['amd64', 'freebsd', '6'],
30
+ 'hppa2.0w-hpux11.31' => ['hppa2.0w', 'hpux', '11'],
31
+ 'java' => [nil, 'java', nil],
32
+ 'jruby' => [nil, 'java', nil],
33
+ 'universal-dotnet' => ['universal', 'dotnet', nil],
34
+ 'universal-dotnet2.0' => ['universal', 'dotnet', '2.0'],
35
+ 'universal-dotnet4.0' => ['universal', 'dotnet', '4.0'],
36
+ 'powerpc-aix5.3.0.0' => ['powerpc', 'aix', '5'],
37
+ 'powerpc-darwin7' => ['powerpc', 'darwin', '7'],
38
+ 'powerpc-darwin8' => ['powerpc', 'darwin', '8'],
39
+ 'powerpc-linux' => ['powerpc', 'linux', nil],
40
+ 'powerpc64-linux' => ['powerpc64', 'linux', nil],
41
+ 'sparc-solaris2.10' => ['sparc', 'solaris', '2.10'],
42
+ 'sparc-solaris2.8' => ['sparc', 'solaris', '2.8'],
43
+ 'sparc-solaris2.9' => ['sparc', 'solaris', '2.9'],
44
+ 'universal-darwin8' => ['universal', 'darwin', '8'],
45
+ 'universal-darwin9' => ['universal', 'darwin', '9'],
46
+ 'i386-cygwin' => ['x86', 'cygwin', nil],
47
+ 'i686-darwin' => ['x86', 'darwin', nil],
48
+ 'i686-darwin8.4.1' => ['x86', 'darwin', '8'],
49
+ 'i386-freebsd4.11' => ['x86', 'freebsd', '4'],
50
+ 'i386-freebsd5' => ['x86', 'freebsd', '5'],
51
+ 'i386-freebsd6' => ['x86', 'freebsd', '6'],
52
+ 'i386-freebsd7' => ['x86', 'freebsd', '7'],
53
+ 'i386-java1.5' => ['x86', 'java', '1.5'],
54
+ 'x86-java1.6' => ['x86', 'java', '1.6'],
55
+ 'i386-java1.6' => ['x86', 'java', '1.6'],
56
+ 'i686-linux' => ['x86', 'linux', nil],
57
+ 'i586-linux' => ['x86', 'linux', nil],
58
+ 'i486-linux' => ['x86', 'linux', nil],
59
+ 'i386-linux' => ['x86', 'linux', nil],
60
+ 'i586-linux-gnu' => ['x86', 'linux', nil],
61
+ 'i386-linux-gnu' => ['x86', 'linux', nil],
62
+ 'i386-mingw32' => ['x86', 'mingw32', nil],
63
+ 'i386-mswin32' => ['x86', 'mswin32', nil],
64
+ 'i386-mswin32_80' => ['x86', 'mswin32', '80'],
65
+ 'i386-mswin32-80' => ['x86', 'mswin32', '80'],
66
+ 'x86-mswin32' => ['x86', 'mswin32', nil],
67
+ 'x86-mswin32_60' => ['x86', 'mswin32', '60'],
68
+ 'x86-mswin32-60' => ['x86', 'mswin32', '60'],
69
+ 'i386-netbsdelf' => ['x86', 'netbsdelf', nil],
70
+ 'i386-openbsd4.0' => ['x86', 'openbsd', '4.0'],
71
+ 'i386-solaris2.10' => ['x86', 'solaris', '2.10'],
72
+ 'i386-solaris2.8' => ['x86', 'solaris', '2.8'],
73
+ 'mswin32' => ['x86', 'mswin32', nil],
74
+ 'x86_64-linux' => ['x86_64', 'linux', nil],
75
+ 'x86_64-openbsd3.9' => ['x86_64', 'openbsd', '3.9'],
76
+ 'x86_64-openbsd4.0' => ['x86_64', 'openbsd', '4.0'],
77
+ }
78
+
79
+ test_cases.each do |arch, expected|
80
+ platform = LibGems::Platform.new arch
81
+ assert_equal expected, platform.to_a, arch.inspect
82
+ end
83
+ end
84
+
85
+ def test_initialize_command_line
86
+ expected = ['x86', 'mswin32', nil]
87
+
88
+ platform = LibGems::Platform.new 'i386-mswin32'
89
+
90
+ assert_equal expected, platform.to_a, 'i386-mswin32'
91
+
92
+ expected = ['x86', 'mswin32', '80']
93
+
94
+ platform = LibGems::Platform.new 'i386-mswin32-80'
95
+
96
+ assert_equal expected, platform.to_a, 'i386-mswin32-80'
97
+
98
+ expected = ['x86', 'solaris', '2.10']
99
+
100
+ platform = LibGems::Platform.new 'i386-solaris-2.10'
101
+
102
+ assert_equal expected, platform.to_a, 'i386-solaris-2.10'
103
+ end
104
+
105
+ def test_initialize_mswin32_vc6
106
+ orig_RUBY_SO_NAME = RbConfig::CONFIG['RUBY_SO_NAME']
107
+ RbConfig::CONFIG['RUBY_SO_NAME'] = 'msvcrt-ruby18'
108
+
109
+ expected = ['x86', 'mswin32', nil]
110
+
111
+ platform = LibGems::Platform.new 'i386-mswin32'
112
+
113
+ assert_equal expected, platform.to_a, 'i386-mswin32 VC6'
114
+ ensure
115
+ RbConfig::CONFIG['RUBY_SO_NAME'] = orig_RUBY_SO_NAME
116
+ end
117
+
118
+ def test_initialize_platform
119
+ platform = LibGems::Platform.new 'cpu-my_platform1'
120
+ expected = LibGems::Platform.new platform
121
+
122
+ assert_equal 'cpu', platform.cpu
123
+ assert_equal 'my_platform', platform.os
124
+ assert_equal '1', platform.version
125
+ end
126
+
127
+ def test_initialize_test
128
+ platform = LibGems::Platform.new 'cpu-my_platform1'
129
+ assert_equal 'cpu', platform.cpu
130
+ assert_equal 'my_platform', platform.os
131
+ assert_equal '1', platform.version
132
+
133
+ platform = LibGems::Platform.new 'cpu-other_platform1'
134
+ assert_equal 'cpu', platform.cpu
135
+ assert_equal 'other_platform', platform.os
136
+ assert_equal '1', platform.version
137
+ end
138
+
139
+ def test_empty
140
+ platform = LibGems::Platform.new 'cpu-other_platform1'
141
+ assert_respond_to platform, :empty?
142
+ assert_equal false, platform.empty?
143
+ end
144
+
145
+ def test_to_s
146
+ if win_platform? then
147
+ assert_equal 'x86-mswin32-60', LibGems::Platform.local.to_s
148
+ else
149
+ assert_equal 'x86-darwin-8', LibGems::Platform.local.to_s
150
+ end
151
+ end
152
+
153
+ def test_equals2
154
+ my = LibGems::Platform.new %w[cpu my_platform 1]
155
+ other = LibGems::Platform.new %w[cpu other_platform 1]
156
+
157
+ assert_equal my, my
158
+ refute_equal my, other
159
+ refute_equal other, my
160
+ end
161
+
162
+ def test_equals3
163
+ my = LibGems::Platform.new %w[cpu my_platform 1]
164
+ other = LibGems::Platform.new %w[cpu other_platform 1]
165
+
166
+ assert(my === my)
167
+ refute(other === my)
168
+ refute(my === other)
169
+ end
170
+
171
+ def test_equals3_cpu
172
+ ppc_darwin8 = LibGems::Platform.new 'powerpc-darwin8.0'
173
+ uni_darwin8 = LibGems::Platform.new 'universal-darwin8.0'
174
+ x86_darwin8 = LibGems::Platform.new 'i686-darwin8.0'
175
+
176
+ util_set_arch 'powerpc-darwin8'
177
+ assert((ppc_darwin8 === LibGems::Platform.local), 'powerpc =~ universal')
178
+ assert((uni_darwin8 === LibGems::Platform.local), 'powerpc =~ universal')
179
+ refute((x86_darwin8 === LibGems::Platform.local), 'powerpc =~ universal')
180
+
181
+ util_set_arch 'i686-darwin8'
182
+ refute((ppc_darwin8 === LibGems::Platform.local), 'powerpc =~ universal')
183
+ assert((uni_darwin8 === LibGems::Platform.local), 'x86 =~ universal')
184
+ assert((x86_darwin8 === LibGems::Platform.local), 'powerpc =~ universal')
185
+
186
+ util_set_arch 'universal-darwin8'
187
+ assert((ppc_darwin8 === LibGems::Platform.local), 'universal =~ ppc')
188
+ assert((uni_darwin8 === LibGems::Platform.local), 'universal =~ universal')
189
+ assert((x86_darwin8 === LibGems::Platform.local), 'universal =~ x86')
190
+ end
191
+
192
+ def test_equals3_version
193
+ util_set_arch 'i686-darwin8'
194
+
195
+ x86_darwin = LibGems::Platform.new ['x86', 'darwin', nil]
196
+ x86_darwin7 = LibGems::Platform.new ['x86', 'darwin', '7']
197
+ x86_darwin8 = LibGems::Platform.new ['x86', 'darwin', '8']
198
+ x86_darwin9 = LibGems::Platform.new ['x86', 'darwin', '9']
199
+
200
+ assert((x86_darwin === LibGems::Platform.local), 'x86_darwin === x86_darwin8')
201
+ assert((x86_darwin8 === LibGems::Platform.local), 'x86_darwin8 === x86_darwin8')
202
+
203
+ refute((x86_darwin7 === LibGems::Platform.local), 'x86_darwin7 === x86_darwin8')
204
+ refute((x86_darwin9 === LibGems::Platform.local), 'x86_darwin9 === x86_darwin8')
205
+ end
206
+
207
+ def test_equals_tilde
208
+ util_set_arch 'i386-mswin32'
209
+
210
+ assert_match 'mswin32', LibGems::Platform.local
211
+ assert_match 'i386-mswin32', LibGems::Platform.local
212
+
213
+ # oddballs
214
+ assert_match 'i386-mswin32-mq5.3', LibGems::Platform.local
215
+ assert_match 'i386-mswin32-mq6', LibGems::Platform.local
216
+ refute_match 'win32-1.8.2-VC7', LibGems::Platform.local
217
+ refute_match 'win32-1.8.4-VC6', LibGems::Platform.local
218
+ refute_match 'win32-source', LibGems::Platform.local
219
+ refute_match 'windows', LibGems::Platform.local
220
+
221
+ util_set_arch 'i686-linux'
222
+ assert_match 'i486-linux', LibGems::Platform.local
223
+ assert_match 'i586-linux', LibGems::Platform.local
224
+ assert_match 'i686-linux', LibGems::Platform.local
225
+
226
+ util_set_arch 'i686-darwin8'
227
+ assert_match 'i686-darwin8.4.1', LibGems::Platform.local
228
+ assert_match 'i686-darwin8.8.2', LibGems::Platform.local
229
+
230
+ util_set_arch 'java'
231
+ assert_match 'java', LibGems::Platform.local
232
+ assert_match 'jruby', LibGems::Platform.local
233
+
234
+ util_set_arch 'universal-dotnet2.0'
235
+ assert_match 'universal-dotnet', LibGems::Platform.local
236
+ assert_match 'universal-dotnet-2.0', LibGems::Platform.local
237
+ refute_match 'universal-dotnet-4.0', LibGems::Platform.local
238
+ assert_match 'dotnet', LibGems::Platform.local
239
+ assert_match 'dotnet-2.0', LibGems::Platform.local
240
+ refute_match 'dotnet-4.0', LibGems::Platform.local
241
+
242
+ util_set_arch 'universal-dotnet4.0'
243
+ assert_match 'universal-dotnet', LibGems::Platform.local
244
+ refute_match 'universal-dotnet-2.0', LibGems::Platform.local
245
+ assert_match 'universal-dotnet-4.0', LibGems::Platform.local
246
+ assert_match 'dotnet', LibGems::Platform.local
247
+ refute_match 'dotnet-2.0', LibGems::Platform.local
248
+ assert_match 'dotnet-4.0', LibGems::Platform.local
249
+
250
+ util_set_arch 'powerpc-darwin'
251
+ assert_match 'powerpc-darwin', LibGems::Platform.local
252
+
253
+ util_set_arch 'powerpc-darwin7'
254
+ assert_match 'powerpc-darwin7.9.0', LibGems::Platform.local
255
+
256
+ util_set_arch 'powerpc-darwin8'
257
+ assert_match 'powerpc-darwin8.10.0', LibGems::Platform.local
258
+
259
+ util_set_arch 'sparc-solaris2.8'
260
+ assert_match 'sparc-solaris2.8-mq5.3', LibGems::Platform.local
261
+ end
262
+
263
+ end
264
+