2017-11-27 05:45:24 -05:00
|
|
|
# frozen_string_literal: true
|
2019-08-08 10:09:24 -04:00
|
|
|
require_relative 'helper'
|
2010-04-01 03:45:16 -04:00
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
class TestRDocRDoc < RDoc::TestCase
|
2010-04-01 03:45:16 -04:00
|
|
|
|
|
|
|
def setup
|
2012-11-26 23:28:14 -05:00
|
|
|
super
|
2011-02-01 19:32:30 -05:00
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
@rdoc = RDoc::RDoc.new
|
2010-12-19 22:22:49 -05:00
|
|
|
@rdoc.options = RDoc::Options.new
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
@stats = RDoc::Stats.new @store, 0, 0
|
2010-12-19 22:22:49 -05:00
|
|
|
@rdoc.instance_variable_set :@stats, @stats
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
def test_document # functional test
|
|
|
|
options = RDoc::Options.new
|
2013-01-04 01:16:13 -05:00
|
|
|
options.files = [File.expand_path('../xref_data.rb', __FILE__)]
|
2012-11-26 23:28:14 -05:00
|
|
|
options.setup_generator 'ri'
|
|
|
|
options.main_page = 'MAIN_PAGE.rdoc'
|
2013-01-04 01:16:13 -05:00
|
|
|
options.root = Pathname File.expand_path('..', __FILE__)
|
2012-11-26 23:28:14 -05:00
|
|
|
options.title = 'title'
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
rdoc = RDoc::RDoc.new
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
temp_dir do
|
2013-01-04 01:16:13 -05:00
|
|
|
options.op_dir = 'ri'
|
|
|
|
|
2019-08-10 17:12:46 -04:00
|
|
|
capture_output do
|
2012-11-26 23:28:14 -05:00
|
|
|
rdoc.document options
|
|
|
|
end
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2013-01-04 01:16:13 -05:00
|
|
|
assert File.directory? 'ri'
|
2012-11-26 23:28:14 -05:00
|
|
|
assert_equal rdoc, rdoc.store.rdoc
|
|
|
|
end
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
store = rdoc.store
|
|
|
|
|
|
|
|
assert_equal 'MAIN_PAGE.rdoc', store.main
|
|
|
|
assert_equal 'title', store.title
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
2017-11-27 05:45:24 -05:00
|
|
|
def test_document_with_dry_run # functional test
|
|
|
|
options = RDoc::Options.new
|
|
|
|
options.files = [File.expand_path('../xref_data.rb', __FILE__)]
|
|
|
|
options.setup_generator 'darkfish'
|
|
|
|
options.main_page = 'MAIN_PAGE.rdoc'
|
|
|
|
options.root = Pathname File.expand_path('..', __FILE__)
|
|
|
|
options.title = 'title'
|
|
|
|
options.dry_run = true
|
|
|
|
|
|
|
|
rdoc = RDoc::RDoc.new
|
|
|
|
|
|
|
|
out = nil
|
|
|
|
temp_dir do
|
2019-08-10 17:12:46 -04:00
|
|
|
out, = capture_output do
|
2017-11-27 05:45:24 -05:00
|
|
|
rdoc.document options
|
|
|
|
end
|
|
|
|
|
|
|
|
refute File.directory? 'doc'
|
|
|
|
assert_equal rdoc, rdoc.store.rdoc
|
|
|
|
end
|
|
|
|
assert_includes out, '100%'
|
|
|
|
|
|
|
|
store = rdoc.store
|
|
|
|
|
|
|
|
assert_equal 'MAIN_PAGE.rdoc', store.main
|
|
|
|
assert_equal 'title', store.title
|
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
def test_gather_files
|
2012-11-26 23:28:14 -05:00
|
|
|
a = File.expand_path __FILE__
|
|
|
|
b = File.expand_path '../test_rdoc_text.rb', __FILE__
|
|
|
|
|
|
|
|
assert_equal [a, b], @rdoc.gather_files([b, a, b])
|
2019-09-28 01:45:44 -04:00
|
|
|
|
|
|
|
assert_empty @rdoc.gather_files([b, a, b])
|
|
|
|
|
|
|
|
@rdoc.last_modified[a] -= 10
|
|
|
|
assert_equal [a, b], @rdoc.gather_files([b, a, b])
|
2012-11-26 23:28:14 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_handle_pipe
|
|
|
|
$stdin = StringIO.new "hello"
|
|
|
|
|
2019-08-10 17:12:46 -04:00
|
|
|
out, = capture_output do
|
2012-11-26 23:28:14 -05:00
|
|
|
@rdoc.handle_pipe
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal "\n<p>hello</p>\n", out
|
|
|
|
ensure
|
|
|
|
$stdin = STDIN
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_handle_pipe_rd
|
|
|
|
$stdin = StringIO.new "=begin\nhello\n=end"
|
|
|
|
|
|
|
|
@rdoc.options.markup = 'rd'
|
|
|
|
|
2019-08-10 17:12:46 -04:00
|
|
|
out, = capture_output do
|
2012-11-26 23:28:14 -05:00
|
|
|
@rdoc.handle_pipe
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal "\n<p>hello</p>\n", out
|
|
|
|
ensure
|
|
|
|
$stdin = STDIN
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_load_options
|
|
|
|
temp_dir do
|
|
|
|
options = RDoc::Options.new
|
|
|
|
options.markup = 'tomdoc'
|
|
|
|
options.write_options
|
|
|
|
|
|
|
|
options = @rdoc.load_options
|
|
|
|
|
|
|
|
assert_equal 'tomdoc', options.markup
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_load_options_invalid
|
|
|
|
temp_dir do
|
2018-03-26 01:56:26 -04:00
|
|
|
File.open '.rdoc_options', 'w' do |io|
|
2012-11-26 23:28:14 -05:00
|
|
|
io.write "a: !ruby.yaml.org,2002:str |\nfoo"
|
|
|
|
end
|
|
|
|
|
2019-08-15 17:45:36 -04:00
|
|
|
e = assert_raise RDoc::Error do
|
2012-11-26 23:28:14 -05:00
|
|
|
@rdoc.load_options
|
|
|
|
end
|
|
|
|
|
|
|
|
options_file = File.expand_path '.rdoc_options'
|
|
|
|
assert_equal "#{options_file} is not a valid rdoc options file", e.message
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-07 16:14:03 -05:00
|
|
|
def test_load_options_empty_file
|
|
|
|
temp_dir do
|
|
|
|
File.open '.rdoc_options', 'w' do |io|
|
|
|
|
end
|
|
|
|
|
|
|
|
options = @rdoc.load_options
|
|
|
|
|
|
|
|
assert_equal 'rdoc', options.markup
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-06 20:13:14 -05:00
|
|
|
def test_load_options_partial_override
|
|
|
|
temp_dir do
|
|
|
|
File.open '.rdoc_options', 'w' do |io|
|
|
|
|
io.write "markup: Markdown"
|
|
|
|
end
|
|
|
|
|
|
|
|
options = @rdoc.load_options
|
|
|
|
|
|
|
|
assert_equal 'Markdown', options.markup
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
def load_options_no_file
|
|
|
|
temp_dir do
|
|
|
|
options = @rdoc.load_options
|
|
|
|
|
|
|
|
assert_kind_of RDoc::Options, options
|
|
|
|
end
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
2010-04-10 21:34:28 -04:00
|
|
|
def test_normalized_file_list
|
2017-11-27 05:45:24 -05:00
|
|
|
test_path = File.expand_path(__FILE__)
|
2013-09-18 19:33:36 -04:00
|
|
|
files = temp_dir do |dir|
|
|
|
|
flag_file = @rdoc.output_flag_file dir
|
|
|
|
|
|
|
|
FileUtils.touch flag_file
|
|
|
|
|
2017-11-27 05:45:24 -05:00
|
|
|
@rdoc.normalized_file_list [test_path, flag_file]
|
2013-09-18 19:33:36 -04:00
|
|
|
end
|
2010-04-10 21:34:28 -04:00
|
|
|
|
2019-09-28 01:45:44 -04:00
|
|
|
files = files.map { |file, *| File.expand_path file }
|
2010-04-10 21:34:28 -04:00
|
|
|
|
2017-11-27 05:45:24 -05:00
|
|
|
assert_equal [test_path], files
|
2010-04-10 21:34:28 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_normalized_file_list_not_modified
|
|
|
|
@rdoc.last_modified[__FILE__] = File.stat(__FILE__).mtime
|
|
|
|
|
|
|
|
files = @rdoc.normalized_file_list [__FILE__]
|
|
|
|
|
2019-09-28 01:45:44 -04:00
|
|
|
files = files.collect {|file, mtime| file if mtime}.compact
|
|
|
|
|
|
|
|
assert_empty(files)
|
2010-04-10 21:34:28 -04:00
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
def test_normalized_file_list_non_file_directory
|
2016-11-05 05:18:10 -04:00
|
|
|
dev = File::NULL
|
2019-10-29 00:16:31 -04:00
|
|
|
omit "#{dev} is not a character special" unless
|
2012-12-12 02:08:06 -05:00
|
|
|
File.chardev? dev
|
2012-11-26 23:28:14 -05:00
|
|
|
|
|
|
|
files = nil
|
|
|
|
|
2019-08-10 17:12:46 -04:00
|
|
|
out, err = verbose_capture_output do
|
2012-12-12 02:08:06 -05:00
|
|
|
files = @rdoc.normalized_file_list [dev]
|
2012-11-26 23:28:14 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
files = files.map { |file| File.expand_path file }
|
|
|
|
|
|
|
|
assert_empty files
|
|
|
|
|
|
|
|
assert_empty out
|
2012-12-12 02:08:06 -05:00
|
|
|
assert_match %r"^rdoc can't parse", err
|
|
|
|
assert_match %r"#{dev}$", err
|
2012-11-26 23:28:14 -05:00
|
|
|
end
|
|
|
|
|
2018-03-26 01:56:26 -04:00
|
|
|
def test_normalized_file_list_with_dot_doc
|
|
|
|
expected_files = []
|
|
|
|
files = temp_dir do |dir|
|
|
|
|
a = File.expand_path('a.rb')
|
|
|
|
b = File.expand_path('b.rb')
|
|
|
|
c = File.expand_path('c.rb')
|
|
|
|
FileUtils.touch a
|
|
|
|
FileUtils.touch b
|
|
|
|
FileUtils.touch c
|
2019-10-28 00:39:37 -04:00
|
|
|
# Use Dir.glob to convert short path of Dir.tmpdir to long path.
|
|
|
|
a = Dir.glob(a).first
|
|
|
|
b = Dir.glob(b).first
|
|
|
|
c = Dir.glob(c).first
|
2018-03-26 01:56:26 -04:00
|
|
|
|
|
|
|
dot_doc = File.expand_path('.document')
|
|
|
|
FileUtils.touch dot_doc
|
|
|
|
open(dot_doc, 'w') do |f|
|
|
|
|
f.puts 'a.rb'
|
|
|
|
f.puts 'b.rb'
|
|
|
|
end
|
|
|
|
expected_files << a
|
|
|
|
expected_files << b
|
|
|
|
|
|
|
|
@rdoc.normalized_file_list [File.realpath(dir)]
|
|
|
|
end
|
|
|
|
|
2019-09-28 01:45:44 -04:00
|
|
|
files = files.map { |file, *| File.expand_path file }
|
2018-03-26 01:56:26 -04:00
|
|
|
|
|
|
|
assert_equal expected_files, files
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_normalized_file_list_with_dot_doc_overridden_by_exclude_option
|
|
|
|
expected_files = []
|
|
|
|
files = temp_dir do |dir|
|
|
|
|
a = File.expand_path('a.rb')
|
|
|
|
b = File.expand_path('b.rb')
|
|
|
|
c = File.expand_path('c.rb')
|
|
|
|
FileUtils.touch a
|
|
|
|
FileUtils.touch b
|
|
|
|
FileUtils.touch c
|
2019-10-28 00:39:37 -04:00
|
|
|
# Use Dir.glob to convert short path of Dir.tmpdir to long path.
|
|
|
|
a = Dir.glob(a).first
|
|
|
|
b = Dir.glob(b).first
|
|
|
|
c = Dir.glob(c).first
|
2018-03-26 01:56:26 -04:00
|
|
|
|
|
|
|
dot_doc = File.expand_path('.document')
|
|
|
|
FileUtils.touch dot_doc
|
|
|
|
open(dot_doc, 'w') do |f|
|
|
|
|
f.puts 'a.rb'
|
|
|
|
f.puts 'b.rb'
|
|
|
|
end
|
|
|
|
expected_files << a
|
|
|
|
|
|
|
|
@rdoc.options.exclude = Regexp.new(['b.rb'].join('|'))
|
|
|
|
@rdoc.normalized_file_list [File.realpath(dir)]
|
|
|
|
end
|
|
|
|
|
2019-09-28 01:45:44 -04:00
|
|
|
files = files.map { |file, *| File.expand_path file }
|
2018-03-26 01:56:26 -04:00
|
|
|
|
|
|
|
assert_equal expected_files, files
|
|
|
|
end
|
|
|
|
|
2012-11-27 03:54:03 -05:00
|
|
|
def test_parse_file
|
|
|
|
@rdoc.store = RDoc::Store.new
|
|
|
|
|
|
|
|
temp_dir do |dir|
|
|
|
|
@rdoc.options.root = Pathname(Dir.pwd)
|
|
|
|
|
2018-03-26 01:56:26 -04:00
|
|
|
File.open 'test.txt', 'w' do |io|
|
2012-11-27 03:54:03 -05:00
|
|
|
io.puts 'hi'
|
|
|
|
end
|
|
|
|
|
|
|
|
top_level = @rdoc.parse_file 'test.txt'
|
|
|
|
|
|
|
|
assert_equal 'test.txt', top_level.absolute_name
|
|
|
|
assert_equal 'test.txt', top_level.relative_name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-09-18 19:33:36 -04:00
|
|
|
def test_parse_file_binary
|
|
|
|
@rdoc.store = RDoc::Store.new
|
|
|
|
|
|
|
|
root = File.dirname __FILE__
|
|
|
|
|
|
|
|
@rdoc.options.root = Pathname root
|
|
|
|
|
2019-08-10 17:12:46 -04:00
|
|
|
out, err = capture_output do
|
2013-09-18 19:33:36 -04:00
|
|
|
Dir.chdir root do
|
|
|
|
assert_nil @rdoc.parse_file 'binary.dat'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_empty out
|
|
|
|
assert_empty err
|
|
|
|
end
|
|
|
|
|
2013-07-31 15:06:21 -04:00
|
|
|
def test_parse_file_include_root
|
|
|
|
@rdoc.store = RDoc::Store.new
|
|
|
|
|
2017-11-27 05:45:24 -05:00
|
|
|
test_path = File.expand_path('..', __FILE__)
|
2013-07-31 15:06:21 -04:00
|
|
|
top_level = nil
|
|
|
|
temp_dir do |dir|
|
2017-11-27 05:45:24 -05:00
|
|
|
@rdoc.options.parse %W[--root #{test_path}]
|
2013-07-31 15:06:21 -04:00
|
|
|
|
2018-03-26 01:56:26 -04:00
|
|
|
File.open 'include.txt', 'w' do |io|
|
2013-07-31 15:06:21 -04:00
|
|
|
io.puts ':include: test.txt'
|
|
|
|
end
|
|
|
|
|
2019-08-10 17:12:46 -04:00
|
|
|
out, err = capture_output do
|
2013-07-31 15:06:21 -04:00
|
|
|
top_level = @rdoc.parse_file 'include.txt'
|
|
|
|
end
|
|
|
|
assert_empty out
|
|
|
|
assert_empty err
|
|
|
|
end
|
|
|
|
assert_equal "test file", top_level.comment.text
|
|
|
|
end
|
|
|
|
|
2012-12-11 02:44:56 -05:00
|
|
|
def test_parse_file_page_dir
|
|
|
|
@rdoc.store = RDoc::Store.new
|
|
|
|
|
|
|
|
temp_dir do |dir|
|
|
|
|
FileUtils.mkdir 'pages'
|
|
|
|
@rdoc.options.page_dir = Pathname('pages')
|
|
|
|
@rdoc.options.root = Pathname(Dir.pwd)
|
|
|
|
|
2018-03-26 01:56:26 -04:00
|
|
|
File.open 'pages/test.txt', 'w' do |io|
|
2012-12-11 02:44:56 -05:00
|
|
|
io.puts 'hi'
|
|
|
|
end
|
|
|
|
|
|
|
|
top_level = @rdoc.parse_file 'pages/test.txt'
|
|
|
|
|
|
|
|
assert_equal 'pages/test.txt', top_level.absolute_name
|
|
|
|
assert_equal 'test.txt', top_level.relative_name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-11-27 03:54:03 -05:00
|
|
|
def test_parse_file_relative
|
|
|
|
pwd = Dir.pwd
|
|
|
|
|
|
|
|
@rdoc.store = RDoc::Store.new
|
|
|
|
|
|
|
|
temp_dir do |dir|
|
|
|
|
@rdoc.options.root = Pathname(dir)
|
|
|
|
|
2018-03-26 01:56:26 -04:00
|
|
|
File.open 'test.txt', 'w' do |io|
|
2012-11-27 03:54:03 -05:00
|
|
|
io.puts 'hi'
|
|
|
|
end
|
|
|
|
|
|
|
|
test_txt = File.join dir, 'test.txt'
|
|
|
|
|
|
|
|
Dir.chdir pwd do
|
|
|
|
top_level = @rdoc.parse_file test_txt
|
|
|
|
|
|
|
|
assert_equal test_txt, top_level.absolute_name
|
|
|
|
assert_equal 'test.txt', top_level.relative_name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-16 00:59:24 -04:00
|
|
|
def test_parse_file_encoding
|
|
|
|
@rdoc.options.encoding = Encoding::ISO_8859_1
|
2012-11-26 23:28:14 -05:00
|
|
|
@rdoc.store = RDoc::Store.new
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2020-08-29 06:49:20 -04:00
|
|
|
tf = Tempfile.open 'test.txt' do |io|
|
2011-06-16 00:59:24 -04:00
|
|
|
io.write 'hi'
|
|
|
|
io.rewind
|
|
|
|
|
|
|
|
top_level = @rdoc.parse_file io.path
|
|
|
|
|
|
|
|
assert_equal Encoding::ISO_8859_1, top_level.absolute_name.encoding
|
2020-08-29 06:49:20 -04:00
|
|
|
io
|
2011-06-16 00:59:24 -04:00
|
|
|
end
|
2020-08-29 06:49:20 -04:00
|
|
|
tf.close!
|
2011-06-16 00:59:24 -04:00
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
def test_parse_file_forbidden
|
2019-10-29 00:16:31 -04:00
|
|
|
omit 'chmod not supported' if Gem.win_platform?
|
|
|
|
omit "assumes that euid is not root" if Process.euid == 0
|
2012-11-27 02:09:21 -05:00
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
@rdoc.store = RDoc::Store.new
|
|
|
|
|
2020-08-29 06:49:20 -04:00
|
|
|
tf = Tempfile.open 'test.txt' do |io|
|
2012-11-26 23:28:14 -05:00
|
|
|
io.write 'hi'
|
|
|
|
io.rewind
|
|
|
|
|
|
|
|
File.chmod 0000, io.path
|
|
|
|
|
|
|
|
begin
|
|
|
|
top_level = :bug
|
|
|
|
|
2019-08-10 17:12:46 -04:00
|
|
|
_, err = capture_output do
|
2012-11-26 23:28:14 -05:00
|
|
|
top_level = @rdoc.parse_file io.path
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match "Unable to read #{io.path},", err
|
|
|
|
|
|
|
|
assert_nil top_level
|
|
|
|
ensure
|
|
|
|
File.chmod 0400, io.path
|
|
|
|
end
|
2020-08-29 06:49:20 -04:00
|
|
|
io
|
2012-11-26 23:28:14 -05:00
|
|
|
end
|
2020-08-29 06:49:20 -04:00
|
|
|
tf.close!
|
2012-11-26 23:28:14 -05:00
|
|
|
end
|
|
|
|
|
2011-02-01 19:32:30 -05:00
|
|
|
def test_remove_unparseable
|
2010-04-01 03:45:16 -04:00
|
|
|
file_list = %w[
|
|
|
|
blah.class
|
|
|
|
blah.eps
|
|
|
|
blah.erb
|
|
|
|
blah.scpt.txt
|
2016-09-05 06:35:30 -04:00
|
|
|
blah.svg
|
2010-04-01 03:45:16 -04:00
|
|
|
blah.ttf
|
|
|
|
blah.yml
|
|
|
|
]
|
|
|
|
|
|
|
|
assert_empty @rdoc.remove_unparseable file_list
|
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
def test_remove_unparseable_tags_emacs
|
|
|
|
temp_dir do
|
2018-03-26 01:56:26 -04:00
|
|
|
File.open 'TAGS', 'wb' do |io| # emacs
|
2012-11-26 23:28:14 -05:00
|
|
|
io.write "\f\nlib/foo.rb,43\n"
|
|
|
|
end
|
|
|
|
|
|
|
|
file_list = %w[
|
|
|
|
TAGS
|
|
|
|
]
|
|
|
|
|
|
|
|
assert_empty @rdoc.remove_unparseable file_list
|
|
|
|
end
|
|
|
|
end
|
2010-04-10 21:34:28 -04:00
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
def test_remove_unparseable_tags_vim
|
|
|
|
temp_dir do
|
2018-03-26 01:56:26 -04:00
|
|
|
File.open 'TAGS', 'w' do |io| # emacs
|
2012-11-26 23:28:14 -05:00
|
|
|
io.write "!_TAG_"
|
|
|
|
end
|
|
|
|
|
|
|
|
file_list = %w[
|
|
|
|
TAGS
|
|
|
|
]
|
|
|
|
|
|
|
|
assert_empty @rdoc.remove_unparseable file_list
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_setup_output_dir
|
2010-04-26 23:45:22 -04:00
|
|
|
Dir.mktmpdir {|d|
|
2011-02-01 19:32:30 -05:00
|
|
|
path = File.join d, 'testdir'
|
2010-04-10 21:34:28 -04:00
|
|
|
|
2010-04-26 23:45:22 -04:00
|
|
|
last = @rdoc.setup_output_dir path, false
|
2010-04-10 21:34:28 -04:00
|
|
|
|
2010-04-26 23:45:22 -04:00
|
|
|
assert_empty last
|
|
|
|
|
|
|
|
assert File.directory? path
|
2011-02-01 19:32:30 -05:00
|
|
|
assert File.exist? @rdoc.output_flag_file path
|
2010-04-26 23:45:22 -04:00
|
|
|
}
|
2010-04-10 21:34:28 -04:00
|
|
|
end
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
def test_setup_output_dir_dry_run
|
|
|
|
@rdoc.options.dry_run = true
|
|
|
|
|
|
|
|
Dir.mktmpdir do |d|
|
|
|
|
path = File.join d, 'testdir'
|
|
|
|
|
|
|
|
@rdoc.setup_output_dir path, false
|
|
|
|
|
|
|
|
refute File.exist? path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-04-10 21:34:28 -04:00
|
|
|
def test_setup_output_dir_exists
|
2010-04-26 23:45:22 -04:00
|
|
|
Dir.mktmpdir {|path|
|
2018-03-26 01:56:26 -04:00
|
|
|
File.open @rdoc.output_flag_file(path), 'w' do |io|
|
2010-04-26 23:45:22 -04:00
|
|
|
io.puts Time.at 0
|
|
|
|
io.puts "./lib/rdoc.rb\t#{Time.at 86400}"
|
|
|
|
end
|
2010-04-10 21:34:28 -04:00
|
|
|
|
2010-04-26 23:45:22 -04:00
|
|
|
last = @rdoc.setup_output_dir path, false
|
2010-04-10 21:34:28 -04:00
|
|
|
|
2010-04-26 23:45:22 -04:00
|
|
|
assert_equal 1, last.size
|
|
|
|
assert_equal Time.at(86400), last['./lib/rdoc.rb']
|
|
|
|
}
|
2010-04-10 21:34:28 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_setup_output_dir_exists_empty_created_rid
|
2010-04-26 23:45:22 -04:00
|
|
|
Dir.mktmpdir {|path|
|
2018-03-26 01:56:26 -04:00
|
|
|
File.open @rdoc.output_flag_file(path), 'w' do end
|
2010-04-10 21:34:28 -04:00
|
|
|
|
2019-08-15 17:45:36 -04:00
|
|
|
e = assert_raise RDoc::Error do
|
2010-04-26 23:45:22 -04:00
|
|
|
@rdoc.setup_output_dir path, false
|
|
|
|
end
|
2010-04-10 21:34:28 -04:00
|
|
|
|
2010-04-26 23:45:22 -04:00
|
|
|
assert_match %r%Directory #{Regexp.escape path} already exists%, e.message
|
|
|
|
}
|
2010-04-10 21:34:28 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_setup_output_dir_exists_file
|
2020-08-29 06:49:20 -04:00
|
|
|
tf = Tempfile.open 'test_rdoc_rdoc' do |tempfile|
|
2011-06-16 00:59:24 -04:00
|
|
|
path = tempfile.path
|
2010-04-10 21:34:28 -04:00
|
|
|
|
2019-08-15 17:45:36 -04:00
|
|
|
e = assert_raise RDoc::Error do
|
2011-06-16 00:59:24 -04:00
|
|
|
@rdoc.setup_output_dir path, false
|
|
|
|
end
|
2010-04-10 21:34:28 -04:00
|
|
|
|
2011-06-16 00:59:24 -04:00
|
|
|
assert_match(%r%#{Regexp.escape path} exists and is not a directory%,
|
|
|
|
e.message)
|
2020-08-29 06:49:20 -04:00
|
|
|
tempfile
|
2011-06-16 00:59:24 -04:00
|
|
|
end
|
2020-08-29 06:49:20 -04:00
|
|
|
tf.close!
|
2010-04-10 21:34:28 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_setup_output_dir_exists_not_rdoc
|
|
|
|
Dir.mktmpdir do |dir|
|
2019-08-15 17:45:36 -04:00
|
|
|
e = assert_raise RDoc::Error do
|
2010-04-10 21:34:28 -04:00
|
|
|
@rdoc.setup_output_dir dir, false
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match %r%Directory #{Regexp.escape dir} already exists%, e.message
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
def test_update_output_dir
|
|
|
|
Dir.mktmpdir do |d|
|
|
|
|
@rdoc.update_output_dir d, Time.now, {}
|
|
|
|
|
|
|
|
assert File.exist? "#{d}/created.rid"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-02-01 19:32:30 -05:00
|
|
|
def test_update_output_dir_dont
|
|
|
|
Dir.mktmpdir do |d|
|
|
|
|
@rdoc.options.update_output_dir = false
|
|
|
|
@rdoc.update_output_dir d, Time.now, {}
|
|
|
|
|
|
|
|
refute File.exist? "#{d}/created.rid"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
def test_update_output_dir_dry_run
|
|
|
|
Dir.mktmpdir do |d|
|
|
|
|
@rdoc.options.dry_run = true
|
|
|
|
@rdoc.update_output_dir d, Time.now, {}
|
|
|
|
|
|
|
|
refute File.exist? "#{d}/created.rid"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-26 01:56:26 -04:00
|
|
|
def test_update_output_dir_with_reproducible_time
|
|
|
|
Dir.mktmpdir do |d|
|
|
|
|
backup_epoch = ENV['SOURCE_DATE_EPOCH']
|
|
|
|
ruby_birthday = Time.parse 'Wed, 24 Feb 1993 21:00:00 +0900'
|
|
|
|
ENV['SOURCE_DATE_EPOCH'] = ruby_birthday.to_i.to_s
|
|
|
|
|
|
|
|
@rdoc.update_output_dir d, Time.now, {}
|
|
|
|
|
|
|
|
assert File.exist? "#{d}/created.rid"
|
|
|
|
|
|
|
|
f = File.open("#{d}/created.rid", 'r')
|
|
|
|
head_timestamp = Time.parse f.gets.chomp
|
|
|
|
f.close
|
|
|
|
assert_equal ruby_birthday, head_timestamp
|
|
|
|
|
|
|
|
ENV['SOURCE_DATE_EPOCH'] = backup_epoch
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-04 21:41:25 -04:00
|
|
|
def test_normalized_file_list_removes_created_rid_dir
|
|
|
|
temp_dir do |d|
|
|
|
|
FileUtils.mkdir "doc"
|
|
|
|
flag_file = @rdoc.output_flag_file "doc"
|
|
|
|
file = File.join "doc", "test"
|
|
|
|
FileUtils.touch flag_file
|
|
|
|
FileUtils.touch file
|
|
|
|
|
|
|
|
file_list = ["doc"]
|
|
|
|
|
|
|
|
output = @rdoc.normalized_file_list file_list
|
|
|
|
|
|
|
|
assert_empty output
|
|
|
|
end
|
|
|
|
end
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|