2010-04-01 03:45:16 -04:00
|
|
|
require 'rubygems'
|
|
|
|
require 'minitest/autorun'
|
|
|
|
require 'rdoc/rdoc'
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
require 'fileutils'
|
|
|
|
require 'tempfile'
|
|
|
|
require 'tmpdir'
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
class TestRDocRDoc < MiniTest::Unit::TestCase
|
|
|
|
|
|
|
|
def setup
|
2011-02-01 19:32:30 -05:00
|
|
|
RDoc::TopLevel.reset
|
|
|
|
|
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
|
|
|
|
|
|
|
|
@stats = RDoc::Stats.new 0, 0
|
|
|
|
@rdoc.instance_variable_set :@stats, @stats
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
2011-06-16 00:59:24 -04:00
|
|
|
def test_class_reset
|
|
|
|
tl = RDoc::TopLevel.new 'file.rb'
|
|
|
|
tl.add_class RDoc::NormalClass, 'C'
|
|
|
|
tl.add_class RDoc::NormalModule, 'M'
|
|
|
|
|
|
|
|
c = RDoc::Parser::C
|
|
|
|
enclosure_classes = c.send :class_variable_get, :@@enclosure_classes
|
|
|
|
enclosure_classes['A'] = 'B'
|
|
|
|
known_bodies = c.send :class_variable_get, :@@known_bodies
|
|
|
|
known_bodies['A'] = 'B'
|
|
|
|
|
|
|
|
RDoc::RDoc.reset
|
|
|
|
|
|
|
|
assert_empty RDoc::TopLevel.all_classes_hash
|
|
|
|
assert_empty RDoc::TopLevel.all_files_hash
|
|
|
|
assert_empty RDoc::TopLevel.all_modules_hash
|
|
|
|
|
|
|
|
assert_empty c.send :class_variable_get, :@@enclosure_classes
|
|
|
|
assert_empty c.send :class_variable_get, :@@known_bodies
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_gather_files
|
2010-04-10 02:36:13 -04:00
|
|
|
file = File.expand_path __FILE__
|
|
|
|
assert_equal [file], @rdoc.gather_files([file, file])
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
2010-04-10 21:34:28 -04:00
|
|
|
def test_normalized_file_list
|
|
|
|
files = @rdoc.normalized_file_list [__FILE__]
|
|
|
|
|
|
|
|
files = files.map { |file| File.expand_path file }
|
|
|
|
|
|
|
|
assert_equal [File.expand_path(__FILE__)], files
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_normalized_file_list_not_modified
|
|
|
|
files = [__FILE__]
|
|
|
|
|
|
|
|
@rdoc.last_modified[__FILE__] = File.stat(__FILE__).mtime
|
|
|
|
|
|
|
|
files = @rdoc.normalized_file_list [__FILE__]
|
|
|
|
|
|
|
|
assert_empty files
|
|
|
|
end
|
|
|
|
|
2011-06-16 00:59:24 -04:00
|
|
|
def test_parse_file_encoding
|
|
|
|
skip "Encoding not implemented" unless Object.const_defined? :Encoding
|
|
|
|
@rdoc.options.encoding = Encoding::ISO_8859_1
|
|
|
|
|
|
|
|
Tempfile.open 'test.txt' do |io|
|
|
|
|
io.write 'hi'
|
|
|
|
io.rewind
|
|
|
|
|
|
|
|
top_level = @rdoc.parse_file io.path
|
|
|
|
|
|
|
|
assert_equal Encoding::ISO_8859_1, top_level.absolute_name.encoding
|
|
|
|
end
|
|
|
|
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
|
|
|
|
blah.ttf
|
|
|
|
blah.yml
|
|
|
|
]
|
|
|
|
|
|
|
|
assert_empty @rdoc.remove_unparseable file_list
|
|
|
|
end
|
|
|
|
|
2010-04-10 21:34:28 -04:00
|
|
|
def test_setup_output_dir
|
2010-04-26 23:45:22 -04:00
|
|
|
skip "No Dir::mktmpdir, upgrade your ruby" unless Dir.respond_to? :mktmpdir
|
2010-04-10 21:34:28 -04:00
|
|
|
|
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
|
|
|
|
skip "No Dir::mktmpdir, upgrade your ruby" unless Dir.respond_to? :mktmpdir
|
|
|
|
|
|
|
|
@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
|
|
|
skip "No Dir::mktmpdir, upgrade your ruby" unless Dir.respond_to? :mktmpdir
|
2010-04-10 21:34:28 -04:00
|
|
|
|
2010-04-26 23:45:22 -04:00
|
|
|
Dir.mktmpdir {|path|
|
|
|
|
open @rdoc.output_flag_file(path), 'w' do |io|
|
|
|
|
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
|
|
|
skip "No Dir::mktmpdir, upgrade your ruby" unless Dir.respond_to? :mktmpdir
|
2010-04-10 21:34:28 -04:00
|
|
|
|
2010-04-26 23:45:22 -04:00
|
|
|
Dir.mktmpdir {|path|
|
|
|
|
open @rdoc.output_flag_file(path), 'w' do end
|
2010-04-10 21:34:28 -04:00
|
|
|
|
2010-04-26 23:45:22 -04:00
|
|
|
e = assert_raises RDoc::Error do
|
|
|
|
@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
|
2011-06-16 00:59:24 -04:00
|
|
|
Tempfile.open 'test_rdoc_rdoc' do |tempfile|
|
|
|
|
path = tempfile.path
|
2010-04-10 21:34:28 -04:00
|
|
|
|
2011-06-16 00:59:24 -04:00
|
|
|
e = assert_raises RDoc::Error do
|
|
|
|
@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)
|
|
|
|
end
|
2010-04-10 21:34:28 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_setup_output_dir_exists_not_rdoc
|
|
|
|
skip "No Dir::mktmpdir, upgrade your ruby" unless Dir.respond_to? :mktmpdir
|
|
|
|
|
|
|
|
Dir.mktmpdir do |dir|
|
|
|
|
e = assert_raises RDoc::Error do
|
|
|
|
@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
|
|
|
|
skip "No Dir::mktmpdir, upgrade your ruby" unless Dir.respond_to? :mktmpdir
|
|
|
|
|
|
|
|
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
|
|
|
|
skip "No Dir::mktmpdir, upgrade your ruby" unless Dir.respond_to? :mktmpdir
|
|
|
|
|
|
|
|
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
|
|
|
|
skip "No Dir::mktmpdir, upgrade your ruby" unless Dir.respond_to? :mktmpdir
|
|
|
|
|
|
|
|
Dir.mktmpdir do |d|
|
|
|
|
@rdoc.options.dry_run = true
|
|
|
|
@rdoc.update_output_dir d, Time.now, {}
|
|
|
|
|
|
|
|
refute File.exist? "#{d}/created.rid"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|