2017-11-27 13:45:24 +03:00
|
|
|
# frozen_string_literal: true
|
2019-08-08 17:09:24 +03:00
|
|
|
require_relative 'helper'
|
2010-04-01 11:45:16 +04:00
|
|
|
|
2012-11-27 08:28:14 +04:00
|
|
|
class TestRDocRIPaths < RDoc::TestCase
|
2010-04-01 11:45:16 +04:00
|
|
|
|
|
|
|
def setup
|
2012-11-27 08:28:14 +04:00
|
|
|
super
|
|
|
|
|
2019-09-26 16:57:25 +03:00
|
|
|
@orig_env = ENV.to_hash
|
2012-11-27 08:28:14 +04:00
|
|
|
@orig_gem_path = Gem.path
|
|
|
|
|
|
|
|
@tempdir = File.join Dir.tmpdir, "test_rdoc_ri_paths_#{$$}"
|
|
|
|
Gem.use_paths @tempdir
|
|
|
|
Gem.ensure_gem_subdirectories @tempdir
|
|
|
|
|
|
|
|
specs = [
|
|
|
|
@rake_10 = Gem::Specification.new('rake', '10.0.1'),
|
|
|
|
@rdoc_4_0 = Gem::Specification.new('rdoc', '4.0'),
|
|
|
|
@rdoc_3_12 = Gem::Specification.new('rdoc', '3.12'),
|
|
|
|
@nodoc = Gem::Specification.new('nodoc', '1.0'),
|
|
|
|
]
|
|
|
|
|
|
|
|
specs.each do |spec|
|
2012-11-27 11:29:00 +04:00
|
|
|
spec.loaded_from = spec.spec_file
|
2012-11-27 08:28:14 +04:00
|
|
|
|
2018-03-26 08:56:26 +03:00
|
|
|
File.open spec.spec_file, 'w' do |file|
|
2012-11-27 08:28:14 +04:00
|
|
|
file.write spec.to_ruby_for_cache
|
|
|
|
end
|
|
|
|
|
|
|
|
FileUtils.mkdir_p File.join(spec.doc_dir, 'ri') unless
|
|
|
|
spec.name == 'nodoc'
|
|
|
|
end
|
|
|
|
|
|
|
|
Gem::Specification.reset
|
|
|
|
Gem::Specification.all = specs
|
2010-04-01 11:45:16 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
2012-11-27 08:28:14 +04:00
|
|
|
Gem.use_paths(*@orig_gem_path)
|
|
|
|
Gem::Specification.reset
|
|
|
|
FileUtils.rm_rf @tempdir
|
2019-09-26 16:57:25 +03:00
|
|
|
ENV.replace(@orig_env)
|
2020-04-24 18:19:01 +03:00
|
|
|
|
|
|
|
super
|
2012-11-27 08:28:14 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_each
|
|
|
|
enum = RDoc::RI::Paths.each true, true, true, :all
|
|
|
|
|
|
|
|
path = enum.map { |dir,| dir }
|
|
|
|
|
|
|
|
assert_equal RDoc::RI::Paths.system_dir, path.shift
|
|
|
|
assert_equal RDoc::RI::Paths.site_dir, path.shift
|
2020-04-26 10:14:14 +03:00
|
|
|
assert_equal RDoc::RI::Paths.home_dir, path.shift if RDoc::RI::Paths.home_dir
|
2012-11-27 08:28:14 +04:00
|
|
|
assert_equal File.join(@nodoc.doc_dir, 'ri'), path.shift
|
|
|
|
assert_equal File.join(@rake_10.doc_dir, 'ri'), path.shift
|
|
|
|
assert_equal File.join(@rdoc_4_0.doc_dir, 'ri'), path.shift
|
|
|
|
assert_equal File.join(@rdoc_3_12.doc_dir, 'ri'), path.shift
|
|
|
|
assert_empty path
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_gemdirs_latest
|
|
|
|
Dir.chdir @tempdir do
|
|
|
|
gemdirs = RDoc::RI::Paths.gemdirs :latest
|
|
|
|
|
|
|
|
expected = [
|
|
|
|
File.join(@rake_10.doc_dir, 'ri'),
|
|
|
|
File.join(@rdoc_4_0.doc_dir, 'ri'),
|
|
|
|
]
|
|
|
|
|
|
|
|
assert_equal expected, gemdirs
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_gemdirs_legacy
|
|
|
|
Dir.chdir @tempdir do
|
|
|
|
gemdirs = RDoc::RI::Paths.gemdirs true
|
|
|
|
|
|
|
|
expected = [
|
|
|
|
File.join(@rake_10.doc_dir, 'ri'),
|
|
|
|
File.join(@rdoc_4_0.doc_dir, 'ri'),
|
|
|
|
]
|
|
|
|
|
|
|
|
assert_equal expected, gemdirs
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_gemdirs_all
|
|
|
|
Dir.chdir @tempdir do
|
|
|
|
gemdirs = RDoc::RI::Paths.gemdirs :all
|
|
|
|
|
|
|
|
expected = [
|
|
|
|
File.join(@nodoc.doc_dir, 'ri'),
|
|
|
|
File.join(@rake_10.doc_dir, 'ri'),
|
|
|
|
File.join(@rdoc_4_0.doc_dir, 'ri'),
|
|
|
|
File.join(@rdoc_3_12.doc_dir, 'ri'),
|
|
|
|
]
|
|
|
|
|
|
|
|
assert_equal expected, gemdirs
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_gem_dir
|
|
|
|
dir = RDoc::RI::Paths.gem_dir 'rake', '10.0.1'
|
|
|
|
|
|
|
|
expected = File.join @rake_10.doc_dir, 'ri'
|
|
|
|
|
|
|
|
assert_equal expected, dir
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_home_dir
|
|
|
|
dir = RDoc::RI::Paths.home_dir
|
|
|
|
|
|
|
|
assert_equal RDoc::RI::Paths::HOMEDIR, dir
|
2010-04-01 11:45:16 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_path_nonexistent
|
2012-11-27 08:28:14 +04:00
|
|
|
temp_dir do |dir|
|
|
|
|
nonexistent = File.join dir, 'nonexistent'
|
|
|
|
dir = RDoc::RI::Paths.path true, true, true, true, nonexistent
|
2010-04-01 11:45:16 +04:00
|
|
|
|
2012-11-27 08:28:14 +04:00
|
|
|
refute_includes dir, nonexistent
|
|
|
|
end
|
2010-04-01 11:45:16 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_raw_path
|
|
|
|
path = RDoc::RI::Paths.raw_path true, true, true, true
|
|
|
|
|
2012-11-27 08:28:14 +04:00
|
|
|
assert_equal RDoc::RI::Paths.system_dir, path.shift
|
|
|
|
assert_equal RDoc::RI::Paths.site_dir, path.shift
|
2020-04-26 10:14:14 +03:00
|
|
|
assert_equal RDoc::RI::Paths.home_dir, path.shift if RDoc::RI::Paths.home_dir
|
2012-11-27 08:28:14 +04:00
|
|
|
assert_equal File.join(@rake_10.doc_dir, 'ri'), path.shift
|
2010-04-01 11:45:16 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_raw_path_extra_dirs
|
|
|
|
path = RDoc::RI::Paths.raw_path true, true, true, true, '/nonexistent'
|
|
|
|
|
2012-11-27 08:28:14 +04:00
|
|
|
assert_equal '/nonexistent', path.shift
|
|
|
|
assert_equal RDoc::RI::Paths.system_dir, path.shift
|
|
|
|
assert_equal RDoc::RI::Paths.site_dir, path.shift
|
2020-04-26 10:14:14 +03:00
|
|
|
assert_equal RDoc::RI::Paths.home_dir, path.shift if RDoc::RI::Paths.home_dir
|
2012-11-27 08:28:14 +04:00
|
|
|
assert_equal File.join(@rake_10.doc_dir, 'ri'), path.shift
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_site_dir
|
|
|
|
dir = RDoc::RI::Paths.site_dir
|
|
|
|
|
|
|
|
assert_equal File.join(RDoc::RI::Paths::BASE, 'site'), dir
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_system_dir
|
|
|
|
dir = RDoc::RI::Paths.system_dir
|
|
|
|
|
|
|
|
assert_equal File.join(RDoc::RI::Paths::BASE, 'system'), dir
|
2010-04-01 11:45:16 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|