From 71b4ecb3d3068c23809983e1ce556056c0d2172a Mon Sep 17 00:00:00 2001 From: drbrain Date: Fri, 18 Jul 2008 21:10:47 +0000 Subject: Import RDoc r104. Various test fixes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18131 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/rdoc/test_rdoc_info_sections.rb | 99 ++++++++++++++++++++++++++---------- 1 file changed, 71 insertions(+), 28 deletions(-) (limited to 'test/rdoc/test_rdoc_info_sections.rb') diff --git a/test/rdoc/test_rdoc_info_sections.rb b/test/rdoc/test_rdoc_info_sections.rb index 2b6ff6adcb..4cc982613e 100644 --- a/test/rdoc/test_rdoc_info_sections.rb +++ b/test/rdoc/test_rdoc_info_sections.rb @@ -1,33 +1,38 @@ -$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib/' require 'fileutils' +require 'tempfile' require 'test/unit' +require 'tmpdir' + require 'rdoc/generator/texinfo' -require 'yaml' # give us access to check this stuff before it's rendered class RDoc::Generator::Texinfo; attr_reader :files, :classes; end class RDoc::RDoc; attr_reader :options; attr_reader :gen; end class TestRdocInfoSections < Test::Unit::TestCase - OUTPUT_DIR = "/tmp/rdoc-#{$$}" def setup - # supress stdout - $stdout = File.new('/dev/null','w') - $stderr = File.new('/dev/null','w') + @output_dir = File.join Dir.tmpdir, "test_rdoc_info_sections_#{$$}" + @output_file = File.join @output_dir, 'rdoc.texinfo' + + @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.document(['--fmt=texinfo', - File.expand_path(File.dirname(__FILE__) + '/../lib/rdoc/generator/texinfo.rb'), - File.expand_path(File.dirname(__FILE__) + '/../README.txt'), - "--op=#{OUTPUT_DIR}"]) - @text = File.read(OUTPUT_DIR + '/rdoc.texinfo') + @rdoc.document(['--fmt=texinfo', '--quiet', @input_file.path, + "--op=#{@output_dir}"]) + + @text = File.read @output_file end def teardown - $stdout = STDOUT - $stderr = STDERR - FileUtils.rm_rf OUTPUT_DIR + @input_file.close + FileUtils.rm_rf @output_dir end def test_output_exists @@ -35,34 +40,37 @@ class TestRdocInfoSections < Test::Unit::TestCase end def test_each_class_has_a_chapter - assert_section "Class RDoc::Generator::Texinfo", '@chapter' - assert_section "Class RDoc::Generator::TexinfoTemplate", '@chapter' + assert_section "Class MyClass", '@chapter' end 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 def test_included_modules_are_given - assert_match(/Includes.* Generator::MarkUp/m, @text) + assert_match(/Includes.* MyModule/m, @text) end def test_class_methods_are_given - assert_match(/new\(options\)/, @text) + assert_match(/my_class_method\(my_first_argument\)/, @text) end def test_classes_instance_methods_are_given - assert_section 'Class RDoc::Generator::Texinfo#generate' - assert_match(/generate\(toplevels\)/, @text) + assert_section 'Class MyClass#my_method' + assert_match(/my_method\(my_first_argument\)/, @text) end def test_each_module_has_a_chapter - assert_section "RDoc", '@chapter' - assert_section "Generator", '@chapter' + assert_section 'MyModule', '@chapter' end 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 end @@ -82,12 +90,47 @@ class TestRdocInfoSections < Test::Unit::TestCase # def test_oh_yeah_dont_forget_files # end - private def assert_section(name, command = '@section') assert_match Regexp.new("^#{command}.*#{Regexp.escape name}"), @text, "Could not find a #{command} #{name}" end -# def puts(*args) -# @real_stdout.puts(*args) -# end + TEST_DOC = <<-DOC +## +# 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 -- cgit v1.2.3