2012-11-26 23:28:14 -05:00
|
|
|
require 'rdoc/test_case'
|
2010-12-19 22:22:49 -05:00
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
class TestRDocGeneratorDarkfish < RDoc::TestCase
|
2010-12-19 22:22:49 -05:00
|
|
|
|
|
|
|
def setup
|
2012-11-26 23:28:14 -05:00
|
|
|
super
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
@lib_dir = "#{@pwd}/lib"
|
|
|
|
$LOAD_PATH.unshift @lib_dir # ensure we load from this RDoc
|
|
|
|
|
|
|
|
@options = RDoc::Options.new
|
|
|
|
@options.option_parser = OptionParser.new
|
|
|
|
|
|
|
|
@tmpdir = File.join Dir.tmpdir, "test_rdoc_generator_darkfish_#{$$}"
|
|
|
|
FileUtils.mkdir_p @tmpdir
|
|
|
|
Dir.chdir @tmpdir
|
|
|
|
@options.op_dir = @tmpdir
|
|
|
|
@options.generator = RDoc::Generator::Darkfish
|
|
|
|
|
|
|
|
$LOAD_PATH.each do |path|
|
2012-11-26 23:28:14 -05:00
|
|
|
darkfish_dir = File.join path, 'rdoc/generator/template/darkfish/'
|
2010-12-19 22:22:49 -05:00
|
|
|
next unless File.directory? darkfish_dir
|
|
|
|
@options.template_dir = darkfish_dir
|
|
|
|
break
|
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
@rdoc.options = @options
|
|
|
|
|
|
|
|
@g = @options.generator.new @store, @options
|
|
|
|
@rdoc.generator = @g
|
|
|
|
|
|
|
|
@top_level = @store.add_file 'file.rb'
|
|
|
|
@top_level.parser = RDoc::Parser::Ruby
|
|
|
|
@klass = @top_level.add_class RDoc::NormalClass, 'Klass'
|
2010-12-19 22:22:49 -05:00
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
@alias_constant = RDoc::Constant.new 'A', nil, ''
|
|
|
|
@alias_constant.record_location @top_level
|
2010-12-19 22:22:49 -05:00
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
@top_level.add_constant @alias_constant
|
2010-12-19 22:22:49 -05:00
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
@klass.add_module_alias @klass, 'A', @top_level
|
2011-07-30 20:19:00 -04:00
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
@meth = RDoc::AnyMethod.new nil, 'method'
|
|
|
|
@meth_bang = RDoc::AnyMethod.new nil, 'method!'
|
|
|
|
@attr = RDoc::Attr.new nil, 'attr', 'RW', ''
|
|
|
|
|
|
|
|
@klass.add_method @meth
|
|
|
|
@klass.add_method @meth_bang
|
|
|
|
@klass.add_attribute @attr
|
2011-07-30 20:19:00 -04:00
|
|
|
|
|
|
|
@ignored = @top_level.add_class RDoc::NormalClass, 'Ignored'
|
|
|
|
@ignored.ignore
|
2012-11-26 23:28:14 -05:00
|
|
|
|
|
|
|
@store.complete :private
|
|
|
|
|
|
|
|
@object = @store.find_class_or_module 'Object'
|
|
|
|
@klass_alias = @store.find_class_or_module 'Klass::A'
|
2010-12-19 22:22:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
2012-11-26 23:28:14 -05:00
|
|
|
super
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
$LOAD_PATH.shift
|
|
|
|
Dir.chdir @pwd
|
|
|
|
FileUtils.rm_rf @tmpdir
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_generate
|
2012-11-26 23:28:14 -05:00
|
|
|
top_level = @store.add_file 'file.rb'
|
2010-12-19 22:22:49 -05:00
|
|
|
top_level.add_class @klass.class, @klass.name
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
@g.generate
|
2010-12-19 22:22:49 -05:00
|
|
|
|
|
|
|
assert_file 'index.html'
|
|
|
|
assert_file 'Object.html'
|
2012-11-26 23:28:14 -05:00
|
|
|
assert_file 'table_of_contents.html'
|
|
|
|
assert_file 'js/search_index.js'
|
2010-12-19 22:22:49 -05:00
|
|
|
|
2014-12-06 20:22:37 -05:00
|
|
|
assert_hard_link 'css/rdoc.css'
|
|
|
|
assert_hard_link 'css/fonts.css'
|
2013-09-18 19:33:36 -04:00
|
|
|
|
|
|
|
assert_hard_link 'fonts/SourceCodePro-Bold.ttf'
|
|
|
|
assert_hard_link 'fonts/SourceCodePro-Regular.ttf'
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
encoding = if Object.const_defined? :Encoding then
|
2012-11-27 02:09:21 -05:00
|
|
|
Regexp.escape Encoding::UTF_8.name
|
2010-12-19 22:22:49 -05:00
|
|
|
else
|
|
|
|
Regexp.escape 'UTF-8'
|
|
|
|
end
|
|
|
|
|
2013-09-18 19:33:36 -04:00
|
|
|
assert_match %r%<meta charset="#{encoding}">%, File.read('index.html')
|
|
|
|
assert_match %r%<meta charset="#{encoding}">%, File.read('Object.html')
|
2011-07-30 20:19:00 -04:00
|
|
|
|
|
|
|
refute_match(/Ignored/, File.read('index.html'))
|
2010-12-19 22:22:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_generate_dry_run
|
2012-11-26 23:28:14 -05:00
|
|
|
@g.dry_run = true
|
|
|
|
top_level = @store.add_file 'file.rb'
|
2010-12-19 22:22:49 -05:00
|
|
|
top_level.add_class @klass.class, @klass.name
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
@g.generate
|
2010-12-19 22:22:49 -05:00
|
|
|
|
|
|
|
refute_file 'index.html'
|
|
|
|
refute_file 'Object.html'
|
2012-11-26 23:28:14 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_generate_static
|
|
|
|
FileUtils.mkdir_p 'dir/images'
|
|
|
|
FileUtils.touch 'dir/images/image.png'
|
|
|
|
FileUtils.mkdir_p 'file'
|
|
|
|
FileUtils.touch 'file/file.txt'
|
|
|
|
|
|
|
|
@options.static_path = [
|
|
|
|
File.expand_path('dir'),
|
|
|
|
File.expand_path('file/file.txt'),
|
|
|
|
]
|
|
|
|
|
|
|
|
@g.generate
|
|
|
|
|
|
|
|
assert_file 'images/image.png'
|
|
|
|
assert_file 'file.txt'
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_generate_static_dry_run
|
|
|
|
FileUtils.mkdir 'static'
|
|
|
|
FileUtils.touch 'static/image.png'
|
|
|
|
|
|
|
|
@options.static_path = [File.expand_path('static')]
|
|
|
|
@g.dry_run = true
|
|
|
|
|
|
|
|
@g.generate
|
|
|
|
|
|
|
|
refute_file 'image.png'
|
|
|
|
end
|
|
|
|
|
2013-09-18 19:33:36 -04:00
|
|
|
def test_install_rdoc_static_file
|
|
|
|
src = Pathname(__FILE__)
|
|
|
|
dst = File.join @tmpdir, File.basename(src)
|
|
|
|
options = {}
|
|
|
|
|
|
|
|
@g.install_rdoc_static_file src, dst, options
|
|
|
|
|
|
|
|
assert_file dst
|
|
|
|
|
|
|
|
begin
|
|
|
|
assert_hard_link dst
|
|
|
|
rescue MiniTest::Assertion
|
|
|
|
return # hard links are not supported, no further tests needed
|
|
|
|
end
|
|
|
|
|
|
|
|
@g.install_rdoc_static_file src, dst, options
|
|
|
|
|
|
|
|
assert_hard_link dst
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_install_rdoc_static_file_missing
|
|
|
|
src = Pathname(__FILE__) + 'nonexistent'
|
|
|
|
dst = File.join @tmpdir, File.basename(src)
|
|
|
|
options = {}
|
|
|
|
|
|
|
|
@g.install_rdoc_static_file src, dst, options
|
|
|
|
|
|
|
|
refute_file dst
|
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
def test_setup
|
|
|
|
@g.setup
|
|
|
|
|
|
|
|
assert_equal [@klass_alias, @ignored, @klass, @object],
|
|
|
|
@g.classes.sort_by { |klass| klass.full_name }
|
|
|
|
assert_equal [@top_level], @g.files
|
|
|
|
assert_equal [@meth, @meth, @meth_bang, @meth_bang], @g.methods
|
|
|
|
assert_equal [@klass_alias, @klass, @object], @g.modsort
|
2010-12-19 22:22:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_template_for
|
2012-11-26 23:28:14 -05:00
|
|
|
classpage = Pathname.new @options.template_dir + 'class.rhtml'
|
2010-12-19 22:22:49 -05:00
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
template = @g.send(:template_for, classpage, true, RDoc::ERBIO)
|
2010-12-19 22:22:49 -05:00
|
|
|
assert_kind_of RDoc::ERBIO, template
|
|
|
|
|
|
|
|
assert_same template, @g.send(:template_for, classpage)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_template_for_dry_run
|
2012-11-26 23:28:14 -05:00
|
|
|
classpage = Pathname.new @options.template_dir + 'class.rhtml'
|
2010-12-19 22:22:49 -05:00
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
template = @g.send(:template_for, classpage, true, ERB)
|
2010-12-19 22:22:49 -05:00
|
|
|
assert_kind_of ERB, template
|
|
|
|
|
|
|
|
assert_same template, @g.send(:template_for, classpage)
|
|
|
|
end
|
|
|
|
|
2013-02-07 23:12:56 -05:00
|
|
|
def test_template_for_partial
|
|
|
|
partial = Pathname.new @options.template_dir + '_sidebar_classes.rhtml'
|
|
|
|
|
|
|
|
template = @g.send(:template_for, partial, false, RDoc::ERBPartial)
|
|
|
|
|
|
|
|
assert_kind_of RDoc::ERBPartial, template
|
|
|
|
|
|
|
|
assert_same template, @g.send(:template_for, partial)
|
|
|
|
end
|
|
|
|
|
2013-09-18 19:33:36 -04:00
|
|
|
##
|
|
|
|
# Asserts that +filename+ has a link count greater than 1 if hard links to
|
|
|
|
# @tmpdir are supported.
|
|
|
|
|
|
|
|
def assert_hard_link filename
|
|
|
|
assert_file filename
|
|
|
|
|
|
|
|
src = @g.template_dir + '_head.rhtml'
|
|
|
|
dst = File.join @tmpdir, 'hardlinktest'
|
|
|
|
|
|
|
|
begin
|
|
|
|
FileUtils.ln src, dst
|
2013-11-19 09:34:20 -05:00
|
|
|
nlink = File.stat(dst).nlink if File.identical? src, dst
|
2013-09-18 19:33:36 -04:00
|
|
|
FileUtils.rm dst
|
2013-11-19 09:34:20 -05:00
|
|
|
return if nlink == 1
|
2013-09-18 19:33:36 -04:00
|
|
|
rescue SystemCallError
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-11-18 19:47:33 -05:00
|
|
|
assert_operator File.stat(filename).nlink, :>, 1,
|
|
|
|
"#{filename} is not hard-linked"
|
2013-09-18 19:33:36 -04:00
|
|
|
end
|
|
|
|
|
2015-04-12 04:36:37 -04:00
|
|
|
end
|
|
|
|
|