diff options
author | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-06-09 21:38:59 +0000 |
---|---|---|
committer | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-06-09 21:38:59 +0000 |
commit | 31c94ffeb5f09d09ac2c86fc9e6614e38251a43d (patch) | |
tree | 10e44506238c7af3d7c9d822111996731726e38d /test/rubygems/test_gem_indexer.rb | |
parent | a6afbaeb3be396c0fdea3b9077d9256c59edcfca (diff) | |
download | ruby-31c94ffeb5f09d09ac2c86fc9e6614e38251a43d.tar.gz |
Update to RubyGems 1.3.4 r2223
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rubygems/test_gem_indexer.rb')
-rw-r--r-- | test/rubygems/test_gem_indexer.rb | 421 |
1 files changed, 400 insertions, 21 deletions
diff --git a/test/rubygems/test_gem_indexer.rb b/test/rubygems/test_gem_indexer.rb index b1932c7335..a48acbbfe6 100644 --- a/test/rubygems/test_gem_indexer.rb +++ b/test/rubygems/test_gem_indexer.rb @@ -19,21 +19,45 @@ class TestGemIndexer < RubyGemTestCase util_make_gems - @d2_0 = quick_gem 'd', '2.0' + @d2_0 = quick_gem 'd', '2.0' do |s| + s.date = Gem::Specification::TODAY - 86400 * 3 + end util_build_gem @d2_0 + @d2_0_a = quick_gem 'd', '2.0.a' + util_build_gem @d2_0_a + + @d2_0_b = quick_gem 'd', '2.0.b' + util_build_gem @d2_0_b + gems = File.join(@tempdir, 'gems') FileUtils.mkdir_p gems cache_gems = File.join @gemhome, 'cache', '*.gem' FileUtils.mv Dir[cache_gems], gems - @indexer = Gem::Indexer.new @tempdir + @indexer = Gem::Indexer.new @tempdir, :rss_title => 'ExampleForge gems', + :rss_host => 'example.com', + :rss_gems_host => 'gems.example.com' end def test_initialize assert_equal @tempdir, @indexer.dest_directory assert_equal File.join(Dir.tmpdir, "gem_generate_index_#{$$}"), @indexer.directory + + indexer = Gem::Indexer.new @tempdir + assert indexer.build_legacy + assert indexer.build_modern + + indexer = Gem::Indexer.new @tempdir, :build_legacy => false, + :build_modern => true + refute indexer.build_legacy + assert indexer.build_modern + + indexer = Gem::Indexer.new @tempdir, :build_legacy => true, + :build_modern => false + assert indexer.build_legacy + refute indexer.build_modern end def test_build_indicies @@ -137,6 +161,296 @@ pl-1-i386-linux assert_indexed @tempdir, "latest_specs.#{@marshal_version}" assert_indexed @tempdir, "latest_specs.#{@marshal_version}.gz" + + expected = <<-EOF +<?xml version="1.0"?> +<rss version="2.0"> + <channel> + <title>ExampleForge gems</title> + <link>http://example.com</link> + <description>Recently released gems from http://example.com</description> + <generator>RubyGems v#{Gem::RubyGemsVersion}</generator> + <docs>http://cyber.law.harvard.edu/rss/rss.html</docs> + <item> + <title>a-2</title> + <description> +<pre>This is a test description</pre> + </description> + <author>example@example.com (A User)</author> + <guid>a-2</guid> + <enclosure url="http://gems.example.com/gems/a-2.gem" + length="3072" type="application/octet-stream" /> + <pubDate>#{Gem::Specification::TODAY.rfc2822}</pubDate> + <link>http://example.com</link> + </item> + <item> + <title>a_evil-9</title> + <description> +<pre>This is a test description</pre> + </description> + <author>example@example.com (A User)</author> + <guid>a_evil-9</guid> + <enclosure url="http://gems.example.com/gems/a_evil-9.gem" + length="3072" type="application/octet-stream" /> + <pubDate>#{Gem::Specification::TODAY.rfc2822}</pubDate> + <link>http://example.com</link> + </item> + <item> + <title>b-2</title> + <description> +<pre>This is a test description</pre> + </description> + <author>example@example.com (A User)</author> + <guid>b-2</guid> + <enclosure url="http://gems.example.com/gems/b-2.gem" + length="3072" type="application/octet-stream" /> + <pubDate>#{Gem::Specification::TODAY.rfc2822}</pubDate> + <link>http://example.com</link> + </item> + <item> + <title>c-1.2</title> + <description> +<pre>This is a test description</pre> + </description> + <author>example@example.com (A User)</author> + <guid>c-1.2</guid> + <enclosure url="http://gems.example.com/gems/c-1.2.gem" + length="3072" type="application/octet-stream" /> + <pubDate>#{Gem::Specification::TODAY.rfc2822}</pubDate> + <link>http://example.com</link> + </item> + <item> + <title>pl-1-x86-linux</title> + <description> +<pre>This is a test description</pre> + </description> + <author>example@example.com (A User)</author> + <guid>pl-1-x86-linux</guid> + <enclosure url="http://gems.example.com/gems/pl-1-x86-linux.gem" + length="3072" type="application/octet-stream" /> + <pubDate>#{Gem::Specification::TODAY.rfc2822}</pubDate> + <link>http://example.com</link> + </item> + <item> + <title>a-1</title> + <description> +<pre>This line is really, really long. So long, in fact, that it is more than +eighty characters long! The purpose of this line is for testing wrapping +behavior because sometimes people don't wrap their text to eighty characters. +Without the wrapping, the text might not look good in the RSS feed. + +Also, a list: + * An entry that's actually kind of sort + * an entry that's really long, which will probably get wrapped funny. +That's ok, somebody wasn't thinking straight when they made it more than +eighty characters.</pre> + </description> + <author>example@example.com (Example), example2@example.com (Example2)</author> + <guid>a-1</guid> + <enclosure url="http://gems.example.com/gems/a-1.gem" + length="3584" type="application/octet-stream" /> + <pubDate>#{(Gem::Specification::TODAY - 86400).rfc2822}</pubDate> + <link>http://a.example.com</link> + </item> + </channel> +</rss> + EOF + + gems_rss = File.read File.join(@tempdir, 'index.rss') + + assert_equal expected, gems_rss + end + + def test_generate_index_legacy + @indexer.build_modern = false + @indexer.build_legacy = true + + use_ui @ui do + @indexer.generate_index + end + + assert_indexed @tempdir, 'yaml' + assert_indexed @tempdir, 'yaml.Z' + assert_indexed @tempdir, "Marshal.#{@marshal_version}" + assert_indexed @tempdir, "Marshal.#{@marshal_version}.Z" + + quickdir = File.join @tempdir, 'quick' + marshal_quickdir = File.join quickdir, "Marshal.#{@marshal_version}" + + assert File.directory?(quickdir) + assert File.directory?(marshal_quickdir) + + assert_indexed quickdir, "index" + assert_indexed quickdir, "index.rz" + + assert_indexed quickdir, "latest_index" + assert_indexed quickdir, "latest_index.rz" + + assert_indexed quickdir, "#{@a1.full_name}.gemspec.rz" + assert_indexed quickdir, "#{@a2.full_name}.gemspec.rz" + assert_indexed quickdir, "#{@b2.full_name}.gemspec.rz" + assert_indexed quickdir, "#{@c1_2.full_name}.gemspec.rz" + + assert_indexed quickdir, "#{@pl1.original_name}.gemspec.rz" + refute_indexed quickdir, "#{@pl1.full_name}.gemspec.rz" + + assert_indexed marshal_quickdir, "#{@a1.full_name}.gemspec.rz" + assert_indexed marshal_quickdir, "#{@a2.full_name}.gemspec.rz" + + refute_indexed quickdir, "#{@c1_2.full_name}.gemspec" + refute_indexed marshal_quickdir, "#{@c1_2.full_name}.gemspec" + + refute_indexed @tempdir, "specs.#{@marshal_version}" + refute_indexed @tempdir, "specs.#{@marshal_version}.gz" + + refute_indexed @tempdir, "latest_specs.#{@marshal_version}" + refute_indexed @tempdir, "latest_specs.#{@marshal_version}.gz" + end + + def test_generate_index_legacy_back_to_back + @indexer.build_modern = true + @indexer.build_legacy = true + + use_ui @ui do + @indexer.generate_index + end + + @indexer = Gem::Indexer.new @tempdir + @indexer.build_modern = false + @indexer.build_legacy = true + + use_ui @ui do + @indexer.generate_index + end + + assert_indexed @tempdir, 'yaml' + assert_indexed @tempdir, 'yaml.Z' + assert_indexed @tempdir, "Marshal.#{@marshal_version}" + assert_indexed @tempdir, "Marshal.#{@marshal_version}.Z" + + quickdir = File.join @tempdir, 'quick' + marshal_quickdir = File.join quickdir, "Marshal.#{@marshal_version}" + + assert File.directory?(quickdir) + assert File.directory?(marshal_quickdir) + + assert_indexed quickdir, "index" + assert_indexed quickdir, "index.rz" + + assert_indexed quickdir, "latest_index" + assert_indexed quickdir, "latest_index.rz" + + assert_indexed quickdir, "#{@a1.full_name}.gemspec.rz" + assert_indexed quickdir, "#{@a2.full_name}.gemspec.rz" + assert_indexed quickdir, "#{@b2.full_name}.gemspec.rz" + assert_indexed quickdir, "#{@c1_2.full_name}.gemspec.rz" + + assert_indexed quickdir, "#{@pl1.original_name}.gemspec.rz" + + assert_indexed marshal_quickdir, "#{@a1.full_name}.gemspec.rz" + assert_indexed marshal_quickdir, "#{@a2.full_name}.gemspec.rz" + + assert_indexed @tempdir, "specs.#{@marshal_version}" + assert_indexed @tempdir, "specs.#{@marshal_version}.gz" + + assert_indexed @tempdir, "latest_specs.#{@marshal_version}" + assert_indexed @tempdir, "latest_specs.#{@marshal_version}.gz" + end + + def test_generate_index_modern + @indexer.build_modern = true + @indexer.build_legacy = false + + use_ui @ui do + @indexer.generate_index + end + + refute_indexed @tempdir, 'yaml' + refute_indexed @tempdir, 'yaml.Z' + refute_indexed @tempdir, "Marshal.#{@marshal_version}" + refute_indexed @tempdir, "Marshal.#{@marshal_version}.Z" + + quickdir = File.join @tempdir, 'quick' + marshal_quickdir = File.join quickdir, "Marshal.#{@marshal_version}" + + assert File.directory?(quickdir), 'quickdir should be directory' + assert File.directory?(marshal_quickdir) + + refute_indexed quickdir, "index" + refute_indexed quickdir, "index.rz" + + refute_indexed quickdir, "latest_index" + refute_indexed quickdir, "latest_index.rz" + + refute_indexed quickdir, "#{@a1.full_name}.gemspec.rz" + refute_indexed quickdir, "#{@a2.full_name}.gemspec.rz" + refute_indexed quickdir, "#{@b2.full_name}.gemspec.rz" + refute_indexed quickdir, "#{@c1_2.full_name}.gemspec.rz" + + refute_indexed quickdir, "#{@pl1.original_name}.gemspec.rz" + refute_indexed quickdir, "#{@pl1.full_name}.gemspec.rz" + + assert_indexed marshal_quickdir, "#{@a1.full_name}.gemspec.rz" + assert_indexed marshal_quickdir, "#{@a2.full_name}.gemspec.rz" + + refute_indexed quickdir, "#{@c1_2.full_name}.gemspec" + refute_indexed marshal_quickdir, "#{@c1_2.full_name}.gemspec" + + assert_indexed @tempdir, "specs.#{@marshal_version}" + assert_indexed @tempdir, "specs.#{@marshal_version}.gz" + + assert_indexed @tempdir, "latest_specs.#{@marshal_version}" + assert_indexed @tempdir, "latest_specs.#{@marshal_version}.gz" + end + + def test_generate_index_modern_back_to_back + @indexer.build_modern = true + @indexer.build_legacy = true + + use_ui @ui do + @indexer.generate_index + end + + @indexer = Gem::Indexer.new @tempdir + @indexer.build_modern = true + @indexer.build_legacy = false + + use_ui @ui do + @indexer.generate_index + end + + assert_indexed @tempdir, 'yaml' + assert_indexed @tempdir, 'yaml.Z' + assert_indexed @tempdir, "Marshal.#{@marshal_version}" + assert_indexed @tempdir, "Marshal.#{@marshal_version}.Z" + + quickdir = File.join @tempdir, 'quick' + marshal_quickdir = File.join quickdir, "Marshal.#{@marshal_version}" + + assert File.directory?(quickdir) + assert File.directory?(marshal_quickdir) + + assert_indexed quickdir, "index" + assert_indexed quickdir, "index.rz" + + assert_indexed quickdir, "latest_index" + assert_indexed quickdir, "latest_index.rz" + + assert_indexed quickdir, "#{@a1.full_name}.gemspec.rz" + assert_indexed quickdir, "#{@a2.full_name}.gemspec.rz" + assert_indexed quickdir, "#{@b2.full_name}.gemspec.rz" + assert_indexed quickdir, "#{@c1_2.full_name}.gemspec.rz" + + assert_indexed quickdir, "#{@pl1.original_name}.gemspec.rz" + + assert_indexed marshal_quickdir, "#{@a1.full_name}.gemspec.rz" + assert_indexed marshal_quickdir, "#{@a2.full_name}.gemspec.rz" + + assert_indexed @tempdir, "specs.#{@marshal_version}" + assert_indexed @tempdir, "specs.#{@marshal_version}.gz" + + assert_indexed @tempdir, "latest_specs.#{@marshal_version}" + assert_indexed @tempdir, "latest_specs.#{@marshal_version}.gz" end def test_generate_index_ui @@ -144,25 +458,25 @@ pl-1-i386-linux @indexer.generate_index end - expected = <<-EOF -Loading 7 gems from #{@tempdir} -....... -Loaded all gems -Generating quick index gemspecs for 7 gems -....... -Complete -Generating specs index -Generating latest specs index -Generating quick index -Generating latest index -Generating Marshal master index -Generating YAML master index for 7 gems (this may take a while) -....... -Complete -Compressing indicies - EOF + assert_match %r%^Loading 10 gems from #{Regexp.escape @tempdir}$%, + @ui.output + assert_match %r%^\.\.\.\.\.\.\.\.\.\.$%, @ui.output + assert_match %r%^Loaded all gems$%, @ui.output + assert_match %r%^Generating Marshal quick index gemspecs for 7 gems$%, + @ui.output + assert_match %r%^Generating YAML quick index gemspecs for 7 gems$%, + @ui.output + assert_match %r%^Complete$%, @ui.output + assert_match %r%^Generating specs index$%, @ui.output + assert_match %r%^Generating latest specs index$%, @ui.output + assert_match %r%^Generating quick index$%, @ui.output + assert_match %r%^Generating latest index$%, @ui.output + assert_match %r%^Generating prerelease specs index$%, @ui.output + assert_match %r%^Generating Marshal master index$%, @ui.output + assert_match %r%^Generating YAML master index for 7 gems \(this may take a while\)$%, @ui.output + assert_match %r%^Complete$%, @ui.output + assert_match %r%^Compressing indicies$%, @ui.output - assert_equal expected, @ui.output assert_equal '', @ui.error end @@ -248,6 +562,71 @@ Compressing indicies 'identical platforms not identical' end + def test_generate_index_prerelease_specs + use_ui @ui do + @indexer.generate_index + end + + prerelease_specs_path = File.join @tempdir, "prerelease_specs.#{@marshal_version}" + + prerelease_specs_dump = Gem.read_binary prerelease_specs_path + prerelease_specs = Marshal.load prerelease_specs_dump + + assert_equal [['a', Gem::Version.new('3.a'), 'ruby'], + ['d', Gem::Version.new('2.0.a'), 'ruby'], + ['d', Gem::Version.new('2.0.b'), 'ruby']], + prerelease_specs + end + + def test_update_index + use_ui @ui do + @indexer.generate_index + end + + quickdir = File.join @tempdir, 'quick' + marshal_quickdir = File.join quickdir, "Marshal.#{@marshal_version}" + + assert File.directory?(quickdir) + assert File.directory?(marshal_quickdir) + + @d2_1 = quick_gem 'd', '2.1' + util_build_gem @d2_1 + @d2_1_tuple = [@d2_1.name, @d2_1.version, @d2_1.original_platform] + + @d2_1_a = quick_gem 'd', '2.2.a' + util_build_gem @d2_1_a + @d2_1_a_tuple = [@d2_1_a.name, @d2_1_a.version, @d2_1_a.original_platform] + + gems = File.join @tempdir, 'gems' + FileUtils.mv File.join(@gemhome, 'cache', "#{@d2_1.full_name}.gem"), gems + FileUtils.mv File.join(@gemhome, 'cache', "#{@d2_1_a.full_name}.gem"), gems + + use_ui @ui do + @indexer.update_index + end + + assert_indexed marshal_quickdir, "#{@d2_1.full_name}.gemspec.rz" + + specs_index = Marshal.load Gem.read_binary(@indexer.dest_specs_index) + + assert_includes specs_index, @d2_1_tuple + refute_includes specs_index, @d2_1_a_tuple + + latest_specs_index = Marshal.load \ + Gem.read_binary(@indexer.dest_latest_specs_index) + + assert_includes latest_specs_index, @d2_1_tuple + assert_includes latest_specs_index, + [@d2_0.name, @d2_0.version, @d2_0.original_platform] + refute_includes latest_specs_index, @d2_1_a_tuple + + pre_specs_index = Marshal.load \ + Gem.read_binary(@indexer.dest_prerelease_specs_index) + + assert_includes pre_specs_index, @d2_1_a_tuple + refute_includes pre_specs_index, @d2_1_tuple + end + def assert_indexed(dir, name) file = File.join dir, name assert File.exist?(file), "#{file} does not exist" @@ -255,7 +634,7 @@ Compressing indicies def refute_indexed(dir, name) file = File.join dir, name - assert !File.exist?(file), "#{file} exists" + refute File.exist?(file), "#{file} exists" end end if ''.respond_to? :to_xs |