2017-11-27 05:45:24 -05:00
|
|
|
# frozen_string_literal: true
|
2022-02-09 21:31:06 -05:00
|
|
|
require 'rubygems'
|
|
|
|
require 'fileutils'
|
|
|
|
require 'tmpdir'
|
|
|
|
require_relative '../../lib/rdoc/rubygems_hook'
|
|
|
|
require 'test/unit'
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2021-06-17 20:51:23 -04:00
|
|
|
class TestRDocRubygemsHook < Test::Unit::TestCase
|
2011-06-16 00:59:24 -04:00
|
|
|
def setup
|
2021-06-17 20:51:23 -04:00
|
|
|
@a = Gem::Specification.new do |s|
|
|
|
|
s.platform = Gem::Platform::RUBY
|
|
|
|
s.name = "a"
|
|
|
|
s.version = 2
|
2012-12-14 00:16:56 -05:00
|
|
|
s.rdoc_options = %w[--main MyTitle]
|
|
|
|
s.extra_rdoc_files = %w[README]
|
|
|
|
end
|
2021-06-23 01:15:54 -04:00
|
|
|
@tempdir = File.realpath(Dir.mktmpdir("test_rubygems_hook_"))
|
2012-12-14 00:16:56 -05:00
|
|
|
|
2021-06-23 02:14:21 -04:00
|
|
|
@orig_envs = %w[
|
|
|
|
GEM_VENDOR
|
|
|
|
GEMRC
|
|
|
|
XDG_CACHE_HOME
|
|
|
|
XDG_CONFIG_HOME
|
|
|
|
XDG_DATA_HOME
|
|
|
|
SOURCE_DATE_EPOCH
|
|
|
|
BUNDLER_VERSION
|
|
|
|
HOME
|
2021-06-23 05:57:39 -04:00
|
|
|
RDOCOPT
|
2021-06-23 02:14:21 -04:00
|
|
|
].map {|e| [e, ENV.delete(e)]}.to_h
|
|
|
|
ENV["HOME"] = @tempdir
|
|
|
|
|
2021-06-23 05:56:10 -04:00
|
|
|
Gem.configuration = nil
|
2021-06-23 05:46:16 -04:00
|
|
|
|
2021-06-17 20:51:23 -04:00
|
|
|
@a.instance_variable_set(:@doc_dir, File.join(@tempdir, "doc"))
|
|
|
|
@a.instance_variable_set(:@gem_dir, File.join(@tempdir, "a-2"))
|
|
|
|
@a.instance_variable_set(:@full_gem_path, File.join(@tempdir, "a-2"))
|
2021-06-18 00:13:27 -04:00
|
|
|
@a.loaded_from = File.join(@tempdir, 'a-2', 'a-2.gemspec')
|
2012-12-14 00:16:56 -05:00
|
|
|
|
2021-06-17 20:51:23 -04:00
|
|
|
FileUtils.mkdir_p File.join(@tempdir, 'a-2', 'lib')
|
|
|
|
FileUtils.touch File.join(@tempdir, 'a-2', 'lib', 'a.rb')
|
|
|
|
FileUtils.touch File.join(@tempdir, 'a-2', 'README')
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
@hook = RDoc::RubygemsHook.new @a
|
2011-06-16 00:59:24 -04:00
|
|
|
|
|
|
|
begin
|
|
|
|
RDoc::RubygemsHook.load_rdoc
|
|
|
|
rescue Gem::DocumentError => e
|
2021-06-27 23:53:52 -04:00
|
|
|
omit e.message
|
2011-06-16 00:59:24 -04:00
|
|
|
end
|
2021-06-18 00:13:27 -04:00
|
|
|
@old_ui = Gem::DefaultUserInteraction.ui
|
|
|
|
Gem::DefaultUserInteraction.ui = Gem::SilentUI.new
|
2021-06-17 20:51:23 -04:00
|
|
|
end
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2021-06-17 20:51:23 -04:00
|
|
|
def teardown
|
2021-06-22 23:52:32 -04:00
|
|
|
ui = Gem::DefaultUserInteraction.ui
|
2021-06-18 00:13:27 -04:00
|
|
|
Gem::DefaultUserInteraction.ui = @old_ui
|
2021-06-23 01:15:54 -04:00
|
|
|
FileUtils.rm_rf @tempdir
|
2021-06-22 23:52:32 -04:00
|
|
|
ui.close
|
2021-06-23 02:14:21 -04:00
|
|
|
ENV.update(@orig_envs)
|
2011-06-16 00:59:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_initialize
|
2012-12-14 00:16:56 -05:00
|
|
|
refute @hook.generate_rdoc
|
2012-11-27 01:01:41 -05:00
|
|
|
assert @hook.generate_ri
|
2011-06-16 00:59:24 -04:00
|
|
|
|
|
|
|
rdoc = RDoc::RubygemsHook.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-11-27 01:01:41 -05:00
|
|
|
@hook.delete_legacy_args args
|
2011-06-16 00:59:24 -04:00
|
|
|
|
|
|
|
assert_empty args
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_document
|
|
|
|
options = RDoc::Options.new
|
|
|
|
options.files = []
|
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
rdoc = @hook.new_rdoc
|
|
|
|
rdoc.store = RDoc::Store.new
|
|
|
|
@hook.instance_variable_set :@rdoc, rdoc
|
|
|
|
@hook.instance_variable_set :@file_info, []
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
@hook.document 'darkfish', options, @a.doc_dir('rdoc')
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
assert @hook.rdoc_installed?
|
2015-04-12 04:36:37 -04:00
|
|
|
end
|
2011-06-16 00:59:24 -04:00
|
|
|
|
|
|
|
def test_generate
|
|
|
|
FileUtils.mkdir_p @a.doc_dir
|
|
|
|
FileUtils.mkdir_p File.join(@a.gem_dir, 'lib')
|
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
@hook.generate
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2012-12-14 00:16:56 -05:00
|
|
|
refute @hook.rdoc_installed?
|
|
|
|
assert @hook.ri_installed?
|
|
|
|
|
|
|
|
rdoc = @hook.instance_variable_get :@rdoc
|
|
|
|
|
|
|
|
refute rdoc.options.hyperlink_all
|
|
|
|
assert_equal Pathname(@a.full_gem_path), rdoc.options.root
|
|
|
|
assert_equal %w[README lib], rdoc.options.files.sort
|
|
|
|
|
|
|
|
assert_equal 'MyTitle', rdoc.store.main
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_generate_all
|
|
|
|
@hook.generate_rdoc = true
|
|
|
|
@hook.generate_ri = true
|
|
|
|
|
|
|
|
FileUtils.mkdir_p @a.doc_dir
|
|
|
|
FileUtils.mkdir_p File.join(@a.gem_dir, 'lib')
|
|
|
|
|
|
|
|
@hook.generate
|
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
assert @hook.rdoc_installed?
|
|
|
|
assert @hook.ri_installed?
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
rdoc = @hook.instance_variable_get :@rdoc
|
2011-06-16 00:59:24 -04:00
|
|
|
|
|
|
|
refute rdoc.options.hyperlink_all
|
2012-12-14 00:16:56 -05:00
|
|
|
assert_equal Pathname(@a.full_gem_path), rdoc.options.root
|
|
|
|
assert_equal %w[README lib], rdoc.options.files.sort
|
|
|
|
|
|
|
|
assert_equal 'MyTitle', rdoc.store.main
|
2015-04-12 04:36:37 -04:00
|
|
|
end
|
2011-06-16 00:59:24 -04:00
|
|
|
|
|
|
|
def test_generate_configuration_rdoc_array
|
|
|
|
Gem.configuration[:rdoc] = %w[-A]
|
|
|
|
|
|
|
|
FileUtils.mkdir_p @a.doc_dir
|
|
|
|
FileUtils.mkdir_p File.join(@a.gem_dir, 'lib')
|
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
@hook.generate
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
rdoc = @hook.instance_variable_get :@rdoc
|
2011-06-16 00:59:24 -04:00
|
|
|
|
|
|
|
assert rdoc.options.hyperlink_all
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_generate_configuration_rdoc_string
|
|
|
|
Gem.configuration[:rdoc] = '-A'
|
|
|
|
|
|
|
|
FileUtils.mkdir_p @a.doc_dir
|
|
|
|
FileUtils.mkdir_p File.join(@a.gem_dir, 'lib')
|
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
@hook.generate
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
rdoc = @hook.instance_variable_get :@rdoc
|
2011-06-16 00:59:24 -04:00
|
|
|
|
|
|
|
assert rdoc.options.hyperlink_all
|
|
|
|
end
|
|
|
|
|
2012-11-29 18:34:29 -05:00
|
|
|
def test_generate_default_gem
|
2019-07-30 22:45:28 -04:00
|
|
|
Gem::Deprecate.skip_during do
|
2019-08-08 12:43:51 -04:00
|
|
|
if Gem.respond_to?(:default_specifications_dir)
|
|
|
|
klass = Gem
|
|
|
|
else
|
|
|
|
klass = Gem::Specification
|
|
|
|
end
|
|
|
|
@a.loaded_from = File.join klass.default_specifications_dir, 'a.gemspec'
|
2019-07-30 22:45:28 -04:00
|
|
|
end
|
2012-11-29 18:34:29 -05:00
|
|
|
|
|
|
|
@hook.generate
|
|
|
|
|
|
|
|
refute @hook.rdoc_installed?
|
|
|
|
refute @hook.ri_installed?
|
|
|
|
end
|
|
|
|
|
2011-06-16 00:59:24 -04:00
|
|
|
def test_generate_disabled
|
2012-11-27 01:01:41 -05:00
|
|
|
@hook.generate_rdoc = false
|
|
|
|
@hook.generate_ri = false
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
@hook.generate
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
refute @hook.rdoc_installed?
|
|
|
|
refute @hook.ri_installed?
|
2011-06-16 00:59:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_generate_force
|
|
|
|
FileUtils.mkdir_p @a.doc_dir 'ri'
|
|
|
|
FileUtils.mkdir_p @a.doc_dir 'rdoc'
|
|
|
|
FileUtils.mkdir_p File.join(@a.gem_dir, 'lib')
|
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
@hook.force = true
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
@hook.generate
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2021-05-14 12:08:33 -04:00
|
|
|
assert_path_not_exist File.join(@a.doc_dir('rdoc'), 'index.html')
|
|
|
|
assert_path_exist File.join(@a.doc_dir('ri'), 'cache.ri')
|
2011-06-16 00:59:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_generate_no_overwrite
|
|
|
|
FileUtils.mkdir_p @a.doc_dir 'ri'
|
|
|
|
FileUtils.mkdir_p @a.doc_dir 'rdoc'
|
|
|
|
FileUtils.mkdir_p File.join(@a.gem_dir, 'lib')
|
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
@hook.generate
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2021-05-14 12:08:33 -04:00
|
|
|
assert_path_not_exist File.join(@a.doc_dir('rdoc'), 'index.html')
|
|
|
|
assert_path_not_exist File.join(@a.doc_dir('ri'), 'cache.ri')
|
2011-06-16 00:59:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_new_rdoc
|
2012-11-27 01:01:41 -05:00
|
|
|
assert_kind_of RDoc::RDoc, @hook.new_rdoc
|
2011-06-16 00:59:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_rdoc_installed?
|
2012-11-27 01:01:41 -05:00
|
|
|
refute @hook.rdoc_installed?
|
2011-06-16 00:59:24 -04:00
|
|
|
|
|
|
|
FileUtils.mkdir_p @a.doc_dir 'rdoc'
|
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
assert @hook.rdoc_installed?
|
2011-06-16 00:59:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_remove
|
|
|
|
FileUtils.mkdir_p @a.doc_dir 'rdoc'
|
|
|
|
FileUtils.mkdir_p @a.doc_dir 'ri'
|
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
@hook.remove
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
refute @hook.rdoc_installed?
|
|
|
|
refute @hook.ri_installed?
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2021-05-14 12:08:33 -04:00
|
|
|
assert_path_exist @a.doc_dir
|
2011-06-16 00:59:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_remove_unwritable
|
2021-06-27 23:53:52 -04:00
|
|
|
omit 'chmod not supported' if Gem.win_platform?
|
|
|
|
omit "assumes that euid is not root" if Process.euid == 0
|
2018-12-26 01:01:18 -05:00
|
|
|
|
2011-06-16 00:59:24 -04:00
|
|
|
FileUtils.mkdir_p @a.base_dir
|
|
|
|
FileUtils.chmod 0, @a.base_dir
|
|
|
|
|
2021-05-12 03:01:49 -04:00
|
|
|
e = assert_raise Gem::FilePermissionError do
|
2012-11-27 01:01:41 -05:00
|
|
|
@hook.remove
|
2011-06-16 00:59:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal @a.base_dir, e.directory
|
|
|
|
ensure
|
2012-12-14 00:16:56 -05:00
|
|
|
FileUtils.chmod(0755, @a.base_dir) if File.directory?(@a.base_dir)
|
2011-06-16 00:59:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_ri_installed?
|
2012-11-27 01:01:41 -05:00
|
|
|
refute @hook.ri_installed?
|
2011-06-16 00:59:24 -04:00
|
|
|
|
|
|
|
FileUtils.mkdir_p @a.doc_dir 'ri'
|
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
assert @hook.ri_installed?
|
2011-06-16 00:59:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_setup
|
2012-11-27 01:01:41 -05:00
|
|
|
@hook.setup
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2021-05-14 12:08:33 -04:00
|
|
|
assert_path_exist @a.doc_dir
|
2011-06-16 00:59:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_setup_unwritable
|
2021-06-27 23:53:52 -04:00
|
|
|
omit 'chmod not supported' if Gem.win_platform?
|
|
|
|
omit "assumes that euid is not root" if Process.euid == 0
|
2018-12-26 01:01:18 -05:00
|
|
|
|
2012-12-14 00:16:56 -05:00
|
|
|
FileUtils.mkdir_p @a.doc_dir
|
|
|
|
FileUtils.chmod 0, @a.doc_dir
|
|
|
|
|
2021-05-12 03:01:49 -04:00
|
|
|
e = assert_raise Gem::FilePermissionError do
|
2012-12-14 00:16:56 -05:00
|
|
|
@hook.setup
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal @a.doc_dir, e.directory
|
|
|
|
ensure
|
|
|
|
if File.exist? @a.doc_dir
|
|
|
|
FileUtils.chmod 0755, @a.doc_dir
|
|
|
|
FileUtils.rm_r @a.doc_dir
|
2011-06-16 00:59:24 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
end
|