2012-11-29 01:52:18 -05:00
|
|
|
require 'rubygems'
|
2012-12-14 00:09:37 -05:00
|
|
|
require 'rubygems/test_case'
|
2012-11-29 01:52:18 -05:00
|
|
|
require 'rubygems/rdoc'
|
|
|
|
|
|
|
|
class TestGemRDoc < Gem::TestCase
|
2012-12-09 21:50:12 -05:00
|
|
|
Gem::RDoc.load_rdoc
|
|
|
|
rdoc_4 = Gem::Requirement.new('> 3').satisfied_by?(Gem::RDoc.rdoc_version)
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
2013-11-11 19:16:41 -05:00
|
|
|
@a = util_spec 'a' do |s|
|
2012-12-14 00:09:37 -05:00
|
|
|
s.rdoc_options = %w[--main MyTitle]
|
|
|
|
s.extra_rdoc_files = %w[README]
|
|
|
|
end
|
|
|
|
|
|
|
|
write_file File.join(@tempdir, 'lib', 'a.rb')
|
|
|
|
write_file File.join(@tempdir, 'README')
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2012-12-14 00:09:37 -05:00
|
|
|
install_gem @a
|
|
|
|
|
|
|
|
@hook = Gem::RDoc.new @a
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
begin
|
|
|
|
Gem::RDoc.load_rdoc
|
|
|
|
rescue Gem::DocumentError => e
|
|
|
|
skip e.message
|
|
|
|
end
|
|
|
|
|
|
|
|
Gem.configuration[:rdoc] = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# RDoc 4 ships with its own Gem::RDoc which overrides this one which is
|
|
|
|
# shipped for backwards compatibility.
|
|
|
|
|
2012-12-16 18:00:04 -05:00
|
|
|
def rdoc_4?
|
|
|
|
Gem::Requirement.new('>= 4.0.0.preview2').satisfied_by? \
|
|
|
|
@hook.class.rdoc_version
|
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def rdoc_3?
|
2012-12-14 00:09:37 -05:00
|
|
|
Gem::Requirement.new('~> 3.0').satisfied_by? @hook.class.rdoc_version
|
2012-11-29 01:52:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def rdoc_3_8_or_better?
|
2012-12-14 00:09:37 -05:00
|
|
|
Gem::Requirement.new('>= 3.8').satisfied_by? @hook.class.rdoc_version
|
2012-11-29 01:52:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_initialize
|
2012-12-16 18:00:04 -05:00
|
|
|
if rdoc_4? then
|
|
|
|
refute @hook.generate_rdoc
|
|
|
|
else
|
|
|
|
assert @hook.generate_rdoc
|
|
|
|
end
|
2012-12-14 00:09:37 -05:00
|
|
|
assert @hook.generate_ri
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
rdoc = Gem::RDoc.new @a, false, false
|
|
|
|
|
|
|
|
refute rdoc.generate_rdoc
|
|
|
|
refute rdoc.generate_ri
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_delete_legacy_args
|
|
|
|
args = %w[
|
|
|
|
--inline-source
|
|
|
|
--one-file
|
|
|
|
--promiscuous
|
|
|
|
-p
|
|
|
|
]
|
|
|
|
|
2012-12-14 00:09:37 -05:00
|
|
|
@hook.delete_legacy_args args
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
assert_empty args
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_document
|
|
|
|
skip 'RDoc 3 required' unless rdoc_3?
|
|
|
|
|
|
|
|
options = RDoc::Options.new
|
|
|
|
options.files = []
|
|
|
|
|
2012-12-14 00:09:37 -05:00
|
|
|
rdoc = @hook.new_rdoc
|
|
|
|
@hook.instance_variable_set :@rdoc, rdoc
|
|
|
|
@hook.instance_variable_set :@file_info, []
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2012-12-14 00:09:37 -05:00
|
|
|
@hook.document 'darkfish', options, @a.doc_dir('rdoc')
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2012-12-14 00:09:37 -05:00
|
|
|
assert @hook.rdoc_installed?
|
2012-12-09 21:50:12 -05:00
|
|
|
end unless rdoc_4
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
def test_generate
|
|
|
|
skip 'RDoc 3 required' unless rdoc_3?
|
|
|
|
|
|
|
|
FileUtils.mkdir_p @a.doc_dir
|
|
|
|
FileUtils.mkdir_p File.join(@a.gem_dir, 'lib')
|
|
|
|
|
2012-12-14 00:09:37 -05:00
|
|
|
@hook.generate
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2012-12-14 00:09:37 -05:00
|
|
|
assert @hook.rdoc_installed?
|
|
|
|
assert @hook.ri_installed?
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2012-12-14 00:09:37 -05:00
|
|
|
rdoc = @hook.instance_variable_get :@rdoc
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
refute rdoc.options.hyperlink_all
|
2012-12-09 21:50:12 -05:00
|
|
|
end unless rdoc_4
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
def test_generate_configuration_rdoc_array
|
|
|
|
skip 'RDoc 3 required' unless rdoc_3?
|
|
|
|
|
|
|
|
Gem.configuration[:rdoc] = %w[-A]
|
|
|
|
|
|
|
|
FileUtils.mkdir_p @a.doc_dir
|
|
|
|
FileUtils.mkdir_p File.join(@a.gem_dir, 'lib')
|
|
|
|
|
2012-12-14 00:09:37 -05:00
|
|
|
@hook.generate
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2012-12-14 00:09:37 -05:00
|
|
|
rdoc = @hook.instance_variable_get :@rdoc
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
assert rdoc.options.hyperlink_all
|
2012-12-09 21:50:12 -05:00
|
|
|
end unless rdoc_4
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
def test_generate_configuration_rdoc_string
|
|
|
|
skip 'RDoc 3 required' unless rdoc_3?
|
|
|
|
|
|
|
|
Gem.configuration[:rdoc] = '-A'
|
|
|
|
|
|
|
|
FileUtils.mkdir_p @a.doc_dir
|
|
|
|
FileUtils.mkdir_p File.join(@a.gem_dir, 'lib')
|
|
|
|
|
2012-12-14 00:09:37 -05:00
|
|
|
@hook.generate
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2012-12-14 00:09:37 -05:00
|
|
|
rdoc = @hook.instance_variable_get :@rdoc
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
assert rdoc.options.hyperlink_all
|
2012-12-09 21:50:12 -05:00
|
|
|
end unless rdoc_4
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
def test_generate_disabled
|
2012-12-14 00:09:37 -05:00
|
|
|
@hook.generate_rdoc = false
|
|
|
|
@hook.generate_ri = false
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2012-12-14 00:09:37 -05:00
|
|
|
@hook.generate
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2012-12-14 00:09:37 -05:00
|
|
|
refute @hook.rdoc_installed?
|
|
|
|
refute @hook.ri_installed?
|
2012-11-29 01:52:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_generate_force
|
|
|
|
skip 'RDoc 3 required' unless rdoc_3?
|
|
|
|
|
|
|
|
FileUtils.mkdir_p @a.doc_dir 'ri'
|
|
|
|
FileUtils.mkdir_p @a.doc_dir 'rdoc'
|
|
|
|
FileUtils.mkdir_p File.join(@a.gem_dir, 'lib')
|
|
|
|
|
2012-12-14 00:09:37 -05:00
|
|
|
@hook.force = true
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2012-12-14 00:09:37 -05:00
|
|
|
@hook.generate
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
assert_path_exists File.join(@a.doc_dir('rdoc'), 'index.html')
|
|
|
|
assert_path_exists File.join(@a.doc_dir('ri'), 'cache.ri')
|
2012-12-09 21:50:12 -05:00
|
|
|
end unless rdoc_4
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
def test_generate_no_overwrite
|
|
|
|
skip 'RDoc 3 required' unless rdoc_3?
|
|
|
|
|
|
|
|
FileUtils.mkdir_p @a.doc_dir 'ri'
|
|
|
|
FileUtils.mkdir_p @a.doc_dir 'rdoc'
|
|
|
|
FileUtils.mkdir_p File.join(@a.gem_dir, 'lib')
|
|
|
|
|
2012-12-14 00:09:37 -05:00
|
|
|
@hook.generate
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
refute_path_exists File.join(@a.doc_dir('rdoc'), 'index.html')
|
|
|
|
refute_path_exists File.join(@a.doc_dir('ri'), 'cache.ri')
|
2012-12-09 21:50:12 -05:00
|
|
|
end unless rdoc_4
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
def test_generate_legacy
|
|
|
|
skip 'RDoc < 3.8 required' if rdoc_3_8_or_better?
|
|
|
|
|
|
|
|
FileUtils.mkdir_p @a.doc_dir
|
|
|
|
FileUtils.mkdir_p File.join(@a.gem_dir, 'lib')
|
|
|
|
|
2012-12-14 00:09:37 -05:00
|
|
|
@hook.generate_legacy
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2012-12-14 00:09:37 -05:00
|
|
|
assert @hook.rdoc_installed?
|
|
|
|
assert @hook.ri_installed?
|
2012-12-09 21:50:12 -05:00
|
|
|
end unless rdoc_4
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
def test_legacy_rdoc
|
|
|
|
skip 'RDoc < 3.8 required' if rdoc_3_8_or_better?
|
|
|
|
|
|
|
|
FileUtils.mkdir_p @a.doc_dir
|
|
|
|
FileUtils.mkdir_p File.join(@a.gem_dir, 'lib')
|
|
|
|
|
2012-12-14 00:09:37 -05:00
|
|
|
@hook.legacy_rdoc '--op', @a.doc_dir('rdoc')
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2012-12-14 00:09:37 -05:00
|
|
|
assert @hook.rdoc_installed?
|
2012-12-09 21:50:12 -05:00
|
|
|
end unless rdoc_4
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
def test_new_rdoc
|
2012-12-14 00:09:37 -05:00
|
|
|
assert_kind_of RDoc::RDoc, @hook.new_rdoc
|
2012-11-29 01:52:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_rdoc_installed?
|
2012-12-14 00:09:37 -05:00
|
|
|
refute @hook.rdoc_installed?
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
FileUtils.mkdir_p @a.doc_dir 'rdoc'
|
|
|
|
|
2012-12-14 00:09:37 -05:00
|
|
|
assert @hook.rdoc_installed?
|
2012-11-29 01:52:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_remove
|
|
|
|
FileUtils.mkdir_p @a.doc_dir 'rdoc'
|
|
|
|
FileUtils.mkdir_p @a.doc_dir 'ri'
|
|
|
|
|
2012-12-14 00:09:37 -05:00
|
|
|
@hook.remove
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2012-12-14 00:09:37 -05:00
|
|
|
refute @hook.rdoc_installed?
|
|
|
|
refute @hook.ri_installed?
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
assert_path_exists @a.doc_dir
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_remove_unwritable
|
|
|
|
skip 'chmod not supported' if Gem.win_platform?
|
|
|
|
FileUtils.mkdir_p @a.base_dir
|
|
|
|
FileUtils.chmod 0, @a.base_dir
|
|
|
|
|
|
|
|
e = assert_raises Gem::FilePermissionError do
|
2012-12-14 00:09:37 -05:00
|
|
|
@hook.remove
|
2012-11-29 01:52:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal @a.base_dir, e.directory
|
|
|
|
ensure
|
|
|
|
FileUtils.chmod(0755, @a.base_dir) if File.directory?(@a.base_dir)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_ri_installed?
|
2012-12-14 00:09:37 -05:00
|
|
|
refute @hook.ri_installed?
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
FileUtils.mkdir_p @a.doc_dir 'ri'
|
|
|
|
|
2012-12-14 00:09:37 -05:00
|
|
|
assert @hook.ri_installed?
|
2012-11-29 01:52:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_setup
|
2012-12-14 00:09:37 -05:00
|
|
|
@hook.setup
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
assert_path_exists @a.doc_dir
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_setup_unwritable
|
|
|
|
skip 'chmod not supported' if Gem.win_platform?
|
|
|
|
FileUtils.mkdir_p @a.doc_dir
|
|
|
|
FileUtils.chmod 0, @a.doc_dir
|
|
|
|
|
|
|
|
e = assert_raises Gem::FilePermissionError do
|
2012-12-14 00:09:37 -05:00
|
|
|
@hook.setup
|
2012-11-29 01:52:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal @a.doc_dir, e.directory
|
|
|
|
ensure
|
2012-12-14 00:09:37 -05:00
|
|
|
if File.exist? @a.doc_dir
|
|
|
|
FileUtils.chmod 0755, @a.doc_dir
|
|
|
|
FileUtils.rm_r @a.doc_dir
|
|
|
|
end
|
2012-11-29 01:52:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2012-12-14 00:09:37 -05:00
|
|
|
|