mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Import RDoc r104. Various test fixes.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18131 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
dbd68031e0
commit
71b4ecb3d3
5 changed files with 86 additions and 34 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
Sat Jul 19 06:08:43 2008 Eric Hodel <drbrain@segment7.net>
|
||||||
|
|
||||||
|
* lib/rdoc*: Import RDoc r104. Various make test-all fixes.
|
||||||
|
|
||||||
Sat Jul 19 00:27:58 2008 NAKAMURA Usaku <usa@ruby-lang.org>
|
Sat Jul 19 00:27:58 2008 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
* numeric.c (check_uint, rb_num2uint, rb_fix2uint): fixed wrong check
|
* numeric.c (check_uint, rb_num2uint, rb_fix2uint): fixed wrong check
|
||||||
|
|
|
@ -154,7 +154,7 @@ class RDoc::Options
|
||||||
|
|
||||||
attr_reader :webcvs
|
attr_reader :webcvs
|
||||||
|
|
||||||
def initialize(generators) # :nodoc:
|
def initialize(generators = {}) # :nodoc:
|
||||||
@op_dir = "doc"
|
@op_dir = "doc"
|
||||||
@op_name = nil
|
@op_name = nil
|
||||||
@show_all = false
|
@show_all = false
|
||||||
|
@ -613,8 +613,8 @@ Usage: #{opt.program_name} [options] [names...]
|
||||||
|
|
||||||
def check_files
|
def check_files
|
||||||
@files.each do |f|
|
@files.each do |f|
|
||||||
stat = File.stat f rescue abort("File not found: #{f}")
|
stat = File.stat f
|
||||||
abort("File '#{f}' not readable") unless stat.readable?
|
raise RDoc::Error, "file '#{f}' not readable" unless stat.readable?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -53,10 +53,13 @@ class RDoc::Parser
|
||||||
# "new_ext" will be parsed using the same parser as "old_ext"
|
# "new_ext" will be parsed using the same parser as "old_ext"
|
||||||
|
|
||||||
def self.alias_extension(old_ext, new_ext)
|
def self.alias_extension(old_ext, new_ext)
|
||||||
|
old_ext = old_ext.sub(/^\.(.*)/, '\1')
|
||||||
|
new_ext = new_ext.sub(/^\.(.*)/, '\1')
|
||||||
|
|
||||||
parser = can_parse "xxx.#{old_ext}"
|
parser = can_parse "xxx.#{old_ext}"
|
||||||
return false unless parser
|
return false unless parser
|
||||||
|
|
||||||
RDoc::Parser.parsers.unshift [/\.#{new_ext}$/, parser.last]
|
RDoc::Parser.parsers.unshift [/\.#{new_ext}$/, parser]
|
||||||
|
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
|
@ -540,8 +540,10 @@ class RDoc::RubyLex
|
||||||
begin
|
begin
|
||||||
tk = @OP.match(self)
|
tk = @OP.match(self)
|
||||||
@space_seen = TkSPACE === tk
|
@space_seen = TkSPACE === tk
|
||||||
rescue SyntaxError
|
rescue SyntaxError => e
|
||||||
abort if @exception_on_syntax_error
|
raise RDoc::Error, "syntax error: #{e.message}" if
|
||||||
|
@exception_on_syntax_error
|
||||||
|
|
||||||
tk = TkError.new(line_no, char_no)
|
tk = TkError.new(line_no, char_no)
|
||||||
end
|
end
|
||||||
end while @skip_space and TkSPACE === tk
|
end while @skip_space and TkSPACE === tk
|
||||||
|
|
|
@ -1,33 +1,38 @@
|
||||||
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib/'
|
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
|
require 'tempfile'
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
|
require 'tmpdir'
|
||||||
|
|
||||||
require 'rdoc/generator/texinfo'
|
require 'rdoc/generator/texinfo'
|
||||||
require 'yaml'
|
|
||||||
|
|
||||||
# give us access to check this stuff before it's rendered
|
# give us access to check this stuff before it's rendered
|
||||||
class RDoc::Generator::Texinfo; attr_reader :files, :classes; end
|
class RDoc::Generator::Texinfo; attr_reader :files, :classes; end
|
||||||
class RDoc::RDoc; attr_reader :options; attr_reader :gen; end
|
class RDoc::RDoc; attr_reader :options; attr_reader :gen; end
|
||||||
|
|
||||||
class TestRdocInfoSections < Test::Unit::TestCase
|
class TestRdocInfoSections < Test::Unit::TestCase
|
||||||
OUTPUT_DIR = "/tmp/rdoc-#{$$}"
|
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
# supress stdout
|
@output_dir = File.join Dir.tmpdir, "test_rdoc_info_sections_#{$$}"
|
||||||
$stdout = File.new('/dev/null','w')
|
@output_file = File.join @output_dir, 'rdoc.texinfo'
|
||||||
$stderr = File.new('/dev/null','w')
|
|
||||||
|
@input_file = Tempfile.new 'my_file.rb'
|
||||||
|
|
||||||
|
open @input_file.path, 'w' do |io|
|
||||||
|
io.write TEST_DOC
|
||||||
|
end
|
||||||
|
|
||||||
|
RDoc::Parser.alias_extension '.rb', File.extname(@input_file.path)
|
||||||
|
|
||||||
@rdoc = RDoc::RDoc.new
|
@rdoc = RDoc::RDoc.new
|
||||||
@rdoc.document(['--fmt=texinfo',
|
@rdoc.document(['--fmt=texinfo', '--quiet', @input_file.path,
|
||||||
File.expand_path(File.dirname(__FILE__) + '/../lib/rdoc/generator/texinfo.rb'),
|
"--op=#{@output_dir}"])
|
||||||
File.expand_path(File.dirname(__FILE__) + '/../README.txt'),
|
|
||||||
"--op=#{OUTPUT_DIR}"])
|
@text = File.read @output_file
|
||||||
@text = File.read(OUTPUT_DIR + '/rdoc.texinfo')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
$stdout = STDOUT
|
@input_file.close
|
||||||
$stderr = STDERR
|
FileUtils.rm_rf @output_dir
|
||||||
FileUtils.rm_rf OUTPUT_DIR
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_output_exists
|
def test_output_exists
|
||||||
|
@ -35,34 +40,37 @@ class TestRdocInfoSections < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_each_class_has_a_chapter
|
def test_each_class_has_a_chapter
|
||||||
assert_section "Class RDoc::Generator::Texinfo", '@chapter'
|
assert_section "Class MyClass", '@chapter'
|
||||||
assert_section "Class RDoc::Generator::TexinfoTemplate", '@chapter'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_class_descriptions_are_given
|
def test_class_descriptions_are_given
|
||||||
assert_match(/This generates .*Texinfo.* files for viewing with GNU Info or Emacs from .*RDoc.* extracted from Ruby source files/, @text.gsub("\n", ' '))
|
assert_match(/Documentation for my class/, @text.gsub("\n", ' '))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_included_modules_are_given
|
def test_included_modules_are_given
|
||||||
assert_match(/Includes.* Generator::MarkUp/m, @text)
|
assert_match(/Includes.* MyModule/m, @text)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_class_methods_are_given
|
def test_class_methods_are_given
|
||||||
assert_match(/new\(options\)/, @text)
|
assert_match(/my_class_method\(my_first_argument\)/, @text)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_classes_instance_methods_are_given
|
def test_classes_instance_methods_are_given
|
||||||
assert_section 'Class RDoc::Generator::Texinfo#generate'
|
assert_section 'Class MyClass#my_method'
|
||||||
assert_match(/generate\(toplevels\)/, @text)
|
assert_match(/my_method\(my_first_argument\)/, @text)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_each_module_has_a_chapter
|
def test_each_module_has_a_chapter
|
||||||
assert_section "RDoc", '@chapter'
|
assert_section 'MyModule', '@chapter'
|
||||||
assert_section "Generator", '@chapter'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_methods_are_shown_only_once
|
def test_methods_are_shown_only_once
|
||||||
methods = @rdoc.gen.classes.map { |c| c.methods.map{ |m| c.name + '#' + m.name } }.flatten
|
methods = @rdoc.gen.classes.map do |c|
|
||||||
|
c.methods.map do |m|
|
||||||
|
c.name + '#' + m.name
|
||||||
|
end
|
||||||
|
end.flatten
|
||||||
|
|
||||||
assert_equal methods, methods.uniq
|
assert_equal methods, methods.uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -82,12 +90,47 @@ class TestRdocInfoSections < Test::Unit::TestCase
|
||||||
# def test_oh_yeah_dont_forget_files
|
# def test_oh_yeah_dont_forget_files
|
||||||
# end
|
# end
|
||||||
|
|
||||||
private
|
|
||||||
def assert_section(name, command = '@section')
|
def assert_section(name, command = '@section')
|
||||||
assert_match Regexp.new("^#{command}.*#{Regexp.escape name}"), @text, "Could not find a #{command} #{name}"
|
assert_match Regexp.new("^#{command}.*#{Regexp.escape name}"), @text, "Could not find a #{command} #{name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# def puts(*args)
|
TEST_DOC = <<-DOC
|
||||||
# @real_stdout.puts(*args)
|
##
|
||||||
# end
|
# Documentation for my module
|
||||||
|
|
||||||
|
module MyModule
|
||||||
|
|
||||||
|
##
|
||||||
|
# Documentation for my included method
|
||||||
|
|
||||||
|
def my_included_method() end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Documentation for my class
|
||||||
|
|
||||||
|
class MyClass
|
||||||
|
|
||||||
|
include MyModule
|
||||||
|
|
||||||
|
##
|
||||||
|
# Documentation for my constant
|
||||||
|
|
||||||
|
MY_CONSTANT = 'my value'
|
||||||
|
|
||||||
|
##
|
||||||
|
# Documentation for my class method
|
||||||
|
|
||||||
|
def self.my_class_method(my_first_argument) end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Documentation for my method
|
||||||
|
|
||||||
|
def my_method(my_first_argument) end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
DOC
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue