ruby-changes:18789
From: drbrain <ko1@a...>
Date: Mon, 7 Feb 2011 16:07:21 +0900 (JST)
Subject: [ruby-changes:18789] Ruby:r30815 (trunk): Upgrade to RDoc 3.5.3. Fixes [Bug #4376]
drbrain 2011-02-07 16:07:12 +0900 (Mon, 07 Feb 2011) New Revision: 30815 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=30815 Log: Upgrade to RDoc 3.5.3. Fixes [Bug #4376] Modified files: trunk/ChangeLog trunk/NEWS trunk/lib/rdoc/encoding.rb trunk/lib/rdoc/generator/darkfish.rb trunk/lib/rdoc/markup/pre_process.rb trunk/lib/rdoc/text.rb trunk/lib/rdoc.rb trunk/test/rdoc/test_rdoc_encoding.rb trunk/test/rdoc/test_rdoc_markup_pre_process.rb trunk/test/rdoc/test_rdoc_options.rb trunk/test/rdoc/test_rdoc_text.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 30814) +++ ChangeLog (revision 30815) @@ -1,3 +1,7 @@ +Mon Feb 7 16:05:32 2011 Eric Hodel <drbrain@s...> + + * lib/rdoc: Upgrade to RDoc 3.5.3 Fixes [Bug #4376] + Mon Feb 7 11:46:59 2011 NARUSE, Yui <naruse@r...> * common.mk (rdoc): add --encoding=UTF-8; ruby's rdoc must be UTF-8. Index: lib/rdoc.rb =================================================================== --- lib/rdoc.rb (revision 30814) +++ lib/rdoc.rb (revision 30815) @@ -95,7 +95,7 @@ ## # RDoc version you are using - VERSION = '3.5.2' + VERSION = '3.5.3' ## # Method visibilities Index: lib/rdoc/generator/darkfish.rb =================================================================== --- lib/rdoc/generator/darkfish.rb (revision 30814) +++ lib/rdoc/generator/darkfish.rb (revision 30815) @@ -46,7 +46,7 @@ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# + class RDoc::Generator::Darkfish RDoc::RDoc.add_generator self @@ -162,9 +162,9 @@ generate_class_files generate_file_files - rescue StandardError => err + rescue => e debug_msg "%s: %s\n %s" % [ - err.class.name, err.message, err.backtrace.join("\n ") + e.class.name, e.message, e.backtrace.join("\n ") ] raise @@ -208,6 +208,12 @@ out_file = @basedir + @options.op_dir + 'index.html' render_template template_file, out_file do |io| binding end + rescue => e + error = RDoc::Error.new \ + "error generating index.html: #{e.message} (#{e.class})" + error.set_backtrace e.backtrace + + raise error end ## @@ -216,9 +222,12 @@ def generate_class_files template_file = @template_dir + 'classpage.rhtml' return unless template_file.exist? - debug_msg "Generating class documentation in #@outputdir" + debug_msg "Generating class documentation in #{@outputdir}" + current = nil + @classes.each do |klass| + current = klass debug_msg " working on %s (%s)" % [klass.full_name, klass.path] out_file = @outputdir + klass.path # suppress 1.9.3 warning @@ -228,6 +237,12 @@ debug_msg " rendering #{out_file}" render_template template_file, out_file do |io| binding end end + rescue => e + error = RDoc::Error.new \ + "error generating #{current.path}: #{e.message} (#{e.class})" + error.set_backtrace e.backtrace + + raise error end ## @@ -236,17 +251,25 @@ def generate_file_files template_file = @template_dir + 'filepage.rhtml' return unless template_file.exist? - debug_msg "Generating file documentation in #@outputdir" + debug_msg "Generating file documentation in #{@outputdir}" + out_file = nil + @files.each do |file| out_file = @outputdir + file.path - debug_msg " working on %s (%s)" % [ file.full_name, out_file ] + debug_msg " working on %s (%s)" % [file.full_name, out_file] # suppress 1.9.3 warning rel_prefix = rel_prefix = @outputdir.relative_path_from(out_file.dirname) debug_msg " rendering #{out_file}" render_template template_file, out_file do |io| binding end end + rescue => e + error = + RDoc::Error.new "error generating #{out_file}: #{e.message} (#{e.class})" + error.set_backtrace e.backtrace + + raise error end ## Index: lib/rdoc/markup/pre_process.rb =================================================================== --- lib/rdoc/markup/pre_process.rb (revision 30814) +++ lib/rdoc/markup/pre_process.rb (revision 30815) @@ -120,7 +120,7 @@ return '' end - content = RDoc::Encoding.read_file full_name, encoding + content = RDoc::Encoding.read_file full_name, encoding, true # strip magic comment content = content.sub(/\A# .*coding[=:].*$/, '').lstrip Index: lib/rdoc/text.rb =================================================================== --- lib/rdoc/text.rb (revision 30814) +++ lib/rdoc/text.rb (revision 30815) @@ -46,7 +46,9 @@ text.each_line do |line| line.gsub!(/^(.{8}*?)([^\t\r\n]{0,7})\t/) do - "#{$1}#{$2}#{' ' * (8 - $2.size)}" + r = "#{$1}#{$2}#{' ' * (8 - $2.size)}" + r.force_encoding text.encoding if Object.const_defined? :Encoding + r end until line !~ /\t/ expanded << line @@ -69,8 +71,11 @@ flush = [] + empty = '' + empty.force_encoding text.encoding if Object.const_defined? :Encoding + text.each_line do |line| - line[/^ {0,#{indent}}/] = '' + line[/^ {0,#{indent}}/] = empty flush << line end @@ -158,11 +163,20 @@ # Strips /* */ style comments def strip_stars text + encoding = text.encoding if Object.const_defined? :Encoding + text = text.gsub %r%Document-method:\s+[\w:.#]+%, '' - text.sub! %r%/\*+% do " " * $&.length end - text.sub! %r%\*+/% do " " * $&.length end - text.gsub! %r%^[ \t]*\*%m do " " * $&.length end - text.gsub(/^\s+$/, '') + + space = ' ' + space.force_encoding encoding if encoding + + text.sub! %r%/\*+% do space * $&.length end + text.sub! %r%\*+/% do space * $&.length end + text.gsub! %r%^[ \t]*\*%m do space * $&.length end + + empty = '' + empty.force_encoding encoding if encoding + text.gsub(/^\s+$/, empty) end ## Index: lib/rdoc/encoding.rb =================================================================== --- lib/rdoc/encoding.rb (revision 30814) +++ lib/rdoc/encoding.rb (revision 30815) @@ -12,8 +12,11 @@ # # The content will be converted to the +encoding+. If the file cannot be # converted a warning will be printed and nil will be returned. + # + # If +force_transcode+ is true the document will be transcoded and any + # unknown character in the target encoding will be replaced with '?' - def self.read_file filename, encoding + def self.read_file filename, encoding, force_transcode = false content = open filename, "rb" do |f| f.read end utf8 = content.sub!(/\A\xef\xbb\xbf/, '') @@ -50,8 +53,14 @@ warn "unknown encoding name \"#{$1}\" for #{filename}, skipping" nil rescue Encoding::UndefinedConversionError => e - warn "unable to convert #{e.message} for #{filename}, skipping" - nil + if force_transcode then + content.force_encoding orig_encoding + content.encode! encoding, :undef => :replace, :replace => '?' + content + else + warn "unable to convert #{e.message} for #{filename}, skipping" + nil + end rescue Errno::EISDIR, Errno::ENOENT nil end Index: NEWS =================================================================== --- NEWS (revision 30814) +++ NEWS (revision 30815) @@ -92,7 +92,7 @@ * support for bash/zsh completion. * RDoc - * RDoc has been upgraded to RDoc 3.5.2. For full release notes see + * RDoc has been upgraded to RDoc 3.5.3. For full release notes see http://docs.seattlerb.org/rdoc/History_txt.html * rexml Index: test/rdoc/test_rdoc_markup_pre_process.rb =================================================================== --- test/rdoc/test_rdoc_markup_pre_process.rb (revision 30814) +++ test/rdoc/test_rdoc_markup_pre_process.rb (revision 30815) @@ -1,3 +1,5 @@ +# coding: utf-8 + require 'tempfile' require 'rubygems' require 'minitest/autorun' @@ -46,6 +48,30 @@ assert_equal expected, content end + def test_include_file_encoding_incompatible + skip "Encoding not implemented" unless Object.const_defined? :Encoding + + @tempfile.write <<-INCLUDE +# -*- mode: rdoc; coding: utf-8; fill-column: 74; -*- + + + INCLUDE + + @tempfile.flush + @tempfile.rewind + + content = @pp.include_file @file_name, '', Encoding::US_ASCII + + expected = "?\n" + + # FIXME 1.9 fix on windoze + # preprocessor uses binread, so line endings are \r\n + expected.gsub!("\n", "\r\n") if + RUBY_VERSION =~ /^1.9/ && RUBY_PLATFORM =~ /mswin|mingw/ + + assert_equal expected, content + end + def test_handle text = "# :x: y\n" out = @pp.handle text Index: test/rdoc/test_rdoc_text.rb =================================================================== --- test/rdoc/test_rdoc_text.rb (revision 30814) +++ test/rdoc/test_rdoc_text.rb (revision 30815) @@ -55,6 +55,18 @@ expand_tabs(".\t\t."), 'dot tab tab dot') end + def test_expand_tabs_encoding + skip "Encoding not implemented" unless Object.const_defined? :Encoding + + inn = "hello\ns\tdave" + inn.force_encoding Encoding::BINARY + + out = expand_tabs inn + + assert_equal "hello\ns dave", out + assert_equal Encoding::BINARY, out.encoding + end + def test_flush_left text = <<-TEXT @@ -73,6 +85,31 @@ assert_equal expected, flush_left(text) end + def test_flush_left_encoding + skip "Encoding not implemented" unless Object.const_defined? :Encoding + + text = <<-TEXT + + we don't worry too much. + + The comments associated with + TEXT + + text.force_encoding Encoding::US_ASCII + + expected = <<-EXPECTED + +we don't worry too much. + +The comments associated with + EXPECTED + + result = flush_left text + + assert_equal expected, result + assert_equal Encoding::US_ASCII, result.encoding + end + def test_markup def formatter() RDoc::Markup::ToHtml.new end @@ -223,10 +260,38 @@ The comments associated with EXPECTED - assert_equal expected, strip_stars(text) - assert_equal Encoding::CP852, text.encoding + result = strip_stars text + + assert_equal expected, result + assert_equal Encoding::CP852, result.encoding end + def test_strip_stars_encoding2 + skip "Encoding not implemented" unless Object.const_defined? :Encoding + + text = <<-TEXT +/* + * * we don't worry too much. + * + * The comments associated with + */ + TEXT + + text.force_encoding Encoding::BINARY + + expected = <<-EXPECTED + + * we don't worry too much. + + The comments associated with + EXPECTED + + result = strip_stars text + + assert_equal expected, result + assert_equal Encoding::BINARY, result.encoding + end + def test_to_html_apostrophe assert_equal '', to_html("'a") assert_equal 'a, to_html("a'") Index: test/rdoc/test_rdoc_encoding.rb =================================================================== --- test/rdoc/test_rdoc_encoding.rb (revision 30814) +++ test/rdoc/test_rdoc_encoding.rb (revision 30815) @@ -49,6 +49,26 @@ assert_equal "hi \u00e9verybody", contents.sub("\r", '') end + def test_class_read_file_encoding_fail + skip "Encoding not implemented" unless Object.const_defined? :Encoding + + @tempfile.write "# coding: utf-8\n\317\200" # pi + @tempfile.flush + + # FIXME 1.9 fix on windoze + expected.gsub!("\n", "\r\n") if RUBY_VERSION =~ /^1.9/ && RUBY_PLATFORM =~ /mswin|mingw/ + + contents = :junk + + _, err = capture_io do + contents = RDoc::Encoding.read_file @tempfile.path, Encoding::US_ASCII + end + + assert_nil contents + + assert_match %r%^unable to convert%, err + end + def test_class_read_file_encoding_fancy skip "Encoding not implemented" unless Object.const_defined? :Encoding @@ -66,6 +86,21 @@ assert_equal Encoding::UTF_8, contents.encoding end + def test_class_read_file_encoding_force_transcode + skip "Encoding not implemented" unless Object.const_defined? :Encoding + + @tempfile.write "# coding: utf-8\n\317\200" # pi + @tempfile.flush + + # FIXME 1.9 fix on windoze + expected.gsub!("\n", "\r\n") if RUBY_VERSION =~ /^1.9/ && RUBY_PLATFORM =~ /mswin|mingw/ + + contents = RDoc::Encoding.read_file @tempfile.path, Encoding::US_ASCII, true + + assert_equal '?', contents + assert_equal Encoding::US_ASCII, contents.encoding + end + def test_class_read_file_encoding_guess skip "Encoding not implemented" unless Object.const_defined? :Encoding Index: test/rdoc/test_rdoc_options.rb =================================================================== --- test/rdoc/test_rdoc_options.rb (revision 30814) +++ test/rdoc/test_rdoc_options.rb (revision 30815) @@ -17,28 +17,17 @@ end def test_check_files - expected = '' + skip "assumes UNIX permission model" if /mswin|mingw/ =~ RUBY_PLATFORM out, err = capture_io do Dir.mktmpdir do |dir| - if RUBY_PLATFORM =~ /mswin|mingw/ then - @options.files = %w[nonexistent] - - expected = <<-EXPECTED -file 'nonexistent' not found - EXPECTED - else + Dir.chdir dir do FileUtils.touch 'unreadable' FileUtils.chmod 0, 'unreadable' @options.files = %w[nonexistent unreadable] - expected = <<-EXPECTED -file 'nonexistent' not found -file 'unreadable' not readable - EXPECTED + @options.check_files end - - @options.check_files end end @@ -46,6 +35,11 @@ assert_equal '', out + expected = <<-EXPECTED +file 'nonexistent' not found +file 'unreadable' not readable + EXPECTED + assert_equal expected, err end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/
-> 18789 2011-02-07 16:07 [ko1@a... ] Ruby:r30815 (trunk): Upgrade to RDoc 3.5.3. Fixes [Bug #4376] 18798 2011-02-08 16:45 ┗[kosaki.motohiro@g...]