2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2012-11-29 01:52:18 -05:00
|
|
|
require 'rubygems'
|
2021-05-12 05:41:32 -04:00
|
|
|
require_relative '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
|
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
|
2021-05-10 23:27:07 -04:00
|
|
|
pend e.message
|
2012-11-29 01:52:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
Gem.configuration[:rdoc] = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_initialize
|
2019-02-14 07:59:03 -05:00
|
|
|
refute @hook.generate_rdoc
|
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_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_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
|
|
|
|
2020-05-25 08:05:45 -04:00
|
|
|
assert_path_exist @a.doc_dir
|
2012-11-29 01:52:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_remove_unwritable
|
2021-05-10 23:27:07 -04:00
|
|
|
pend 'chmod not supported' if Gem.win_platform?
|
|
|
|
pend 'skipped in root privilege' if Process.uid.zero?
|
2012-11-29 01:52:18 -05:00
|
|
|
FileUtils.mkdir_p @a.base_dir
|
|
|
|
FileUtils.chmod 0, @a.base_dir
|
|
|
|
|
2021-05-10 23:25:46 -04:00
|
|
|
e = assert_raise 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
|
|
|
|
2020-05-25 08:05:45 -04:00
|
|
|
assert_path_exist @a.doc_dir
|
2012-11-29 01:52:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_setup_unwritable
|
2021-05-10 23:27:07 -04:00
|
|
|
pend 'chmod not supported' if Gem.win_platform?
|
|
|
|
pend 'skipped in root privilege' if Process.uid.zero?
|
2012-11-29 01:52:18 -05:00
|
|
|
FileUtils.mkdir_p @a.doc_dir
|
|
|
|
FileUtils.chmod 0, @a.doc_dir
|
|
|
|
|
2021-05-10 23:25:46 -04:00
|
|
|
e = assert_raise 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
|