1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/rdoc] Relative loading for easier development (https://github.com/ruby/rdoc/pull/821)

This patch makes sure we only load relative code. Hence when coding or
testing rdoc, we'll be sure to always be using the correct code.

Discussion started at https://github.com/ruby/rdoc/pull/817.

Signed-off-by: Ulysse Buonomo <buonomo.ulysse@gmail.com>

https://github.com/ruby/rdoc/commit/aa41bd48eb

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
This commit is contained in:
Ulysse Buonomo 2022-02-10 03:31:06 +01:00 committed by Nobuyoshi Nakada
parent 08137c5dd9
commit 5348a34504
41 changed files with 161 additions and 162 deletions

View file

@ -62,7 +62,7 @@ module RDoc
class Error < RuntimeError; end
require 'rdoc/version'
require_relative 'rdoc/version'
##
# Method visibilities
@ -141,61 +141,61 @@ module RDoc
end
end
autoload :RDoc, 'rdoc/rdoc'
autoload :RDoc, "#{__dir__}/rdoc/rdoc"
autoload :CrossReference, 'rdoc/cross_reference'
autoload :ERBIO, 'rdoc/erbio'
autoload :ERBPartial, 'rdoc/erb_partial'
autoload :Encoding, 'rdoc/encoding'
autoload :Generator, 'rdoc/generator'
autoload :Options, 'rdoc/options'
autoload :Parser, 'rdoc/parser'
autoload :Servlet, 'rdoc/servlet'
autoload :RI, 'rdoc/ri'
autoload :Stats, 'rdoc/stats'
autoload :Store, 'rdoc/store'
autoload :Task, 'rdoc/task'
autoload :Text, 'rdoc/text'
autoload :CrossReference, "#{__dir__}/rdoc/cross_reference"
autoload :ERBIO, "#{__dir__}/rdoc/erbio"
autoload :ERBPartial, "#{__dir__}/rdoc/erb_partial"
autoload :Encoding, "#{__dir__}/rdoc/encoding"
autoload :Generator, "#{__dir__}/rdoc/generator"
autoload :Options, "#{__dir__}/rdoc/options"
autoload :Parser, "#{__dir__}/rdoc/parser"
autoload :Servlet, "#{__dir__}/rdoc/servlet"
autoload :RI, "#{__dir__}/rdoc/ri"
autoload :Stats, "#{__dir__}/rdoc/stats"
autoload :Store, "#{__dir__}/rdoc/store"
autoload :Task, "#{__dir__}/rdoc/task"
autoload :Text, "#{__dir__}/rdoc/text"
autoload :Markdown, 'rdoc/markdown'
autoload :Markup, 'rdoc/markup'
autoload :RD, 'rdoc/rd'
autoload :TomDoc, 'rdoc/tom_doc'
autoload :Markdown, "#{__dir__}/rdoc/markdown"
autoload :Markup, "#{__dir__}/rdoc/markup"
autoload :RD, "#{__dir__}/rdoc/rd"
autoload :TomDoc, "#{__dir__}/rdoc/tom_doc"
autoload :KNOWN_CLASSES, 'rdoc/known_classes'
autoload :KNOWN_CLASSES, "#{__dir__}/rdoc/known_classes"
autoload :TokenStream, 'rdoc/token_stream'
autoload :TokenStream, "#{__dir__}/rdoc/token_stream"
autoload :Comment, 'rdoc/comment'
autoload :Comment, "#{__dir__}/rdoc/comment"
require 'rdoc/i18n'
require_relative 'rdoc/i18n'
# code objects
#
# We represent the various high-level code constructs that appear in Ruby
# programs: classes, modules, methods, and so on.
autoload :CodeObject, 'rdoc/code_object'
autoload :CodeObject, "#{__dir__}/rdoc/code_object"
autoload :Context, 'rdoc/context'
autoload :TopLevel, 'rdoc/top_level'
autoload :Context, "#{__dir__}/rdoc/context"
autoload :TopLevel, "#{__dir__}/rdoc/top_level"
autoload :AnonClass, 'rdoc/anon_class'
autoload :ClassModule, 'rdoc/class_module'
autoload :NormalClass, 'rdoc/normal_class'
autoload :NormalModule, 'rdoc/normal_module'
autoload :SingleClass, 'rdoc/single_class'
autoload :AnonClass, "#{__dir__}/rdoc/anon_class"
autoload :ClassModule, "#{__dir__}/rdoc/class_module"
autoload :NormalClass, "#{__dir__}/rdoc/normal_class"
autoload :NormalModule, "#{__dir__}/rdoc/normal_module"
autoload :SingleClass, "#{__dir__}/rdoc/single_class"
autoload :Alias, 'rdoc/alias'
autoload :AnyMethod, 'rdoc/any_method'
autoload :MethodAttr, 'rdoc/method_attr'
autoload :GhostMethod, 'rdoc/ghost_method'
autoload :MetaMethod, 'rdoc/meta_method'
autoload :Attr, 'rdoc/attr'
autoload :Alias, "#{__dir__}/rdoc/alias"
autoload :AnyMethod, "#{__dir__}/rdoc/any_method"
autoload :MethodAttr, "#{__dir__}/rdoc/method_attr"
autoload :GhostMethod, "#{__dir__}/rdoc/ghost_method"
autoload :MetaMethod, "#{__dir__}/rdoc/meta_method"
autoload :Attr, "#{__dir__}/rdoc/attr"
autoload :Constant, 'rdoc/constant'
autoload :Mixin, 'rdoc/mixin'
autoload :Include, 'rdoc/include'
autoload :Extend, 'rdoc/extend'
autoload :Require, 'rdoc/require'
autoload :Constant, "#{__dir__}/rdoc/constant"
autoload :Mixin, "#{__dir__}/rdoc/mixin"
autoload :Include, "#{__dir__}/rdoc/include"
autoload :Extend, "#{__dir__}/rdoc/extend"
autoload :Require, "#{__dir__}/rdoc/require"
end

View file

@ -2,5 +2,4 @@
# This file was used to load all the RDoc::CodeObject subclasses at once. Now
# autoload handles this.
require 'rdoc'
require_relative '../rdoc'

View file

@ -1261,6 +1261,6 @@ class RDoc::Context < RDoc::CodeObject
klass
end
autoload :Section, 'rdoc/context/section'
autoload :Section, "#{__dir__}/context/section"
end

View file

@ -41,11 +41,11 @@
module RDoc::Generator
autoload :Markup, 'rdoc/generator/markup'
autoload :Markup, "#{__dir__}/generator/markup"
autoload :Darkfish, 'rdoc/generator/darkfish'
autoload :JsonIndex, 'rdoc/generator/json_index'
autoload :RI, 'rdoc/generator/ri'
autoload :POT, 'rdoc/generator/pot'
autoload :Darkfish, "#{__dir__}/generator/darkfish"
autoload :JsonIndex, "#{__dir__}/generator/json_index"
autoload :RI, "#{__dir__}/generator/ri"
autoload :POT, "#{__dir__}/generator/pot"
end

View file

@ -4,7 +4,7 @@
module RDoc::I18n
autoload :Locale, 'rdoc/i18n/locale'
autoload :Locale, "#{__dir__}/i18n/locale"
require_relative 'i18n/text'
end

View file

@ -199,6 +199,7 @@ class RDoc::Markdown
@result = nil
@failed_rule = nil
@failing_rule_offset = -1
@line_offsets = nil
setup_foreign_grammar
end
@ -215,17 +216,32 @@ class RDoc::Markdown
target + 1
end
def current_line(target=pos)
cur_offset = 0
cur_line = 0
if [].respond_to? :bsearch_index
def current_line(target=pos)
unless @line_offsets
@line_offsets = []
total = 0
string.each_line do |line|
total += line.size
@line_offsets << total
end
end
string.each_line do |line|
cur_line += 1
cur_offset += line.size
return cur_line if cur_offset >= target
@line_offsets.bsearch_index {|x| x >= target } + 1 || -1
end
else
def current_line(target=pos)
cur_offset = 0
cur_line = 0
-1
string.each_line do |line|
cur_line += 1
cur_offset += line.size
return cur_line if cur_offset >= target
end
-1
end
end
def lines
@ -533,11 +549,11 @@ class RDoc::Markdown
require 'rdoc'
require 'rdoc/markup/to_joined_paragraph'
require 'rdoc/markdown/entities'
require_relative '../rdoc'
require_relative 'markup/to_joined_paragraph'
require_relative 'markdown/entities'
require 'rdoc/markdown/literals'
require_relative 'markdown/literals'
##
# Supported extensions

View file

@ -822,46 +822,45 @@ https://github.com/ruby/rdoc/issues
document.accept formatter
end
autoload :Parser, 'rdoc/markup/parser'
autoload :PreProcess, 'rdoc/markup/pre_process'
autoload :Parser, "#{__dir__}/markup/parser"
autoload :PreProcess, "#{__dir__}/markup/pre_process"
# Inline markup classes
autoload :AttrChanger, 'rdoc/markup/attr_changer'
autoload :AttrSpan, 'rdoc/markup/attr_span'
autoload :Attributes, 'rdoc/markup/attributes'
autoload :AttributeManager, 'rdoc/markup/attribute_manager'
autoload :RegexpHandling, 'rdoc/markup/regexp_handling'
autoload :AttrChanger, "#{__dir__}/markup/attr_changer"
autoload :AttrSpan, "#{__dir__}/markup/attr_span"
autoload :Attributes, "#{__dir__}/markup/attributes"
autoload :AttributeManager, "#{__dir__}/markup/attribute_manager"
autoload :RegexpHandling, "#{__dir__}/markup/regexp_handling"
# RDoc::Markup AST
autoload :BlankLine, 'rdoc/markup/blank_line'
autoload :BlockQuote, 'rdoc/markup/block_quote'
autoload :Document, 'rdoc/markup/document'
autoload :HardBreak, 'rdoc/markup/hard_break'
autoload :Heading, 'rdoc/markup/heading'
autoload :Include, 'rdoc/markup/include'
autoload :IndentedParagraph, 'rdoc/markup/indented_paragraph'
autoload :List, 'rdoc/markup/list'
autoload :ListItem, 'rdoc/markup/list_item'
autoload :Paragraph, 'rdoc/markup/paragraph'
autoload :Table, 'rdoc/markup/table'
autoload :Raw, 'rdoc/markup/raw'
autoload :Rule, 'rdoc/markup/rule'
autoload :Verbatim, 'rdoc/markup/verbatim'
autoload :BlankLine, "#{__dir__}/markup/blank_line"
autoload :BlockQuote, "#{__dir__}/markup/block_quote"
autoload :Document, "#{__dir__}/markup/document"
autoload :HardBreak, "#{__dir__}/markup/hard_break"
autoload :Heading, "#{__dir__}/markup/heading"
autoload :Include, "#{__dir__}/markup/include"
autoload :IndentedParagraph, "#{__dir__}/markup/indented_paragraph"
autoload :List, "#{__dir__}/markup/list"
autoload :ListItem, "#{__dir__}/markup/list_item"
autoload :Paragraph, "#{__dir__}/markup/paragraph"
autoload :Table, "#{__dir__}/markup/table"
autoload :Raw, "#{__dir__}/markup/raw"
autoload :Rule, "#{__dir__}/markup/rule"
autoload :Verbatim, "#{__dir__}/markup/verbatim"
# Formatters
autoload :Formatter, 'rdoc/markup/formatter'
autoload :Formatter, "#{__dir__}/markup/formatter"
autoload :ToAnsi, 'rdoc/markup/to_ansi'
autoload :ToBs, 'rdoc/markup/to_bs'
autoload :ToHtml, 'rdoc/markup/to_html'
autoload :ToHtmlCrossref, 'rdoc/markup/to_html_crossref'
autoload :ToHtmlSnippet, 'rdoc/markup/to_html_snippet'
autoload :ToLabel, 'rdoc/markup/to_label'
autoload :ToMarkdown, 'rdoc/markup/to_markdown'
autoload :ToRdoc, 'rdoc/markup/to_rdoc'
autoload :ToTableOfContents, 'rdoc/markup/to_table_of_contents'
autoload :ToTest, 'rdoc/markup/to_test'
autoload :ToTtOnly, 'rdoc/markup/to_tt_only'
autoload :ToAnsi, "#{__dir__}/markup/to_ansi"
autoload :ToBs, "#{__dir__}/markup/to_bs"
autoload :ToHtml, "#{__dir__}/markup/to_html"
autoload :ToHtmlCrossref, "#{__dir__}/markup/to_html_crossref"
autoload :ToHtmlSnippet, "#{__dir__}/markup/to_html_snippet"
autoload :ToLabel, "#{__dir__}/markup/to_label"
autoload :ToMarkdown, "#{__dir__}/markup/to_markdown"
autoload :ToRdoc, "#{__dir__}/markup/to_rdoc"
autoload :ToTableOfContents, "#{__dir__}/markup/to_table_of_contents"
autoload :ToTest, "#{__dir__}/markup/to_test"
autoload :ToTtOnly, "#{__dir__}/markup/to_tt_only"
end

View file

@ -263,8 +263,8 @@ class RDoc::Parser
@preprocess.options = @options
end
autoload :RubyTools, 'rdoc/parser/ruby_tools'
autoload :Text, 'rdoc/parser/text'
autoload :RubyTools, "#{__dir__}/parser/ruby_tools"
autoload :Text, "#{__dir__}/parser/text"
end

View file

@ -92,9 +92,8 @@ class RDoc::RD
document
end
autoload :BlockParser, 'rdoc/rd/block_parser'
autoload :InlineParser, 'rdoc/rd/inline_parser'
autoload :Inline, 'rdoc/rd/inline'
autoload :BlockParser, "#{__dir__}/rd/block_parser"
autoload :InlineParser, "#{__dir__}/rd/inline_parser"
autoload :Inline, "#{__dir__}/rd/inline"
end

View file

@ -1,5 +1,5 @@
# frozen_string_literal: true
require 'rdoc'
require_relative '../rdoc'
require 'find'
require 'fileutils'

View file

@ -1,5 +1,5 @@
# frozen_string_literal: true
require 'rdoc'
require_relative '../rdoc'
##
# Namespace for the ri command line tool's implementation.
@ -13,9 +13,8 @@ module RDoc::RI
class Error < RDoc::Error; end
autoload :Driver, 'rdoc/ri/driver'
autoload :Paths, 'rdoc/ri/paths'
autoload :Store, 'rdoc/ri/store'
autoload :Driver, "#{__dir__}/ri/driver"
autoload :Paths, "#{__dir__}/ri/paths"
autoload :Store, "#{__dir__}/ri/store"
end

View file

@ -12,7 +12,7 @@ begin
rescue LoadError
end
require 'rdoc'
require_relative '../../rdoc'
##
# For RubyGems backwards compatibility

View file

@ -1,7 +1,7 @@
# frozen_string_literal: true
require 'rubygems/user_interaction'
require 'fileutils'
require 'rdoc'
require_relative '../rdoc'
##
# Gem::RDoc provides methods to generate RDoc and ri data for installed gems

View file

@ -1,5 +1,5 @@
# frozen_string_literal: true
require 'rdoc'
require_relative '../rdoc'
require 'erb'
require 'time'
require 'json'

View file

@ -454,9 +454,8 @@ class RDoc::Stats
[params.length, undoc]
end
autoload :Quiet, 'rdoc/stats/quiet'
autoload :Normal, 'rdoc/stats/normal'
autoload :Verbose, 'rdoc/stats/verbose'
autoload :Quiet, "#{__dir__}/stats/quiet"
autoload :Normal, "#{__dir__}/stats/normal"
autoload :Verbose, "#{__dir__}/stats/verbose"
end

View file

@ -32,7 +32,7 @@ begin
rescue Gem::LoadError
end unless defined?(Rake)
require 'rdoc'
require_relative '../rdoc'
require 'rake'
require 'rake/tasklib'

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module RDoc
##

View file

@ -41,4 +41,3 @@ rescue Exception => e
exit 1
end

View file

@ -1,5 +1,5 @@
# frozen_string_literal: true
require_relative './support/test_case'
require_relative './support/formatter_test_case'
require_relative './support/text_formatter_test_case'
require_relative 'support/test_case'
require_relative 'support/formatter_test_case'
require_relative 'support/text_formatter_test_case'

View file

@ -13,7 +13,7 @@ require 'tempfile'
require 'tmpdir'
require 'stringio'
require 'rdoc'
require_relative '../../../lib/rdoc'
##
# RDoc::TestCase is an abstract TestCase to provide common setup and teardown

View file

@ -1,5 +1,5 @@
# frozen_string_literal: true
require File.expand_path '../xref_test_case', __FILE__
require_relative 'xref_test_case'
class TestRDocAlias < XrefTestCase
@ -11,4 +11,3 @@ class TestRDocAlias < XrefTestCase
end
end

View file

@ -1,5 +1,5 @@
# frozen_string_literal: true
require File.expand_path '../xref_test_case', __FILE__
require_relative 'xref_test_case'
class TestRDocAnyMethod < XrefTestCase

View file

@ -1,5 +1,5 @@
# frozen_string_literal: true
require File.expand_path '../xref_test_case', __FILE__
require_relative 'xref_test_case'
class TestRDocClassModule < XrefTestCase
@ -1501,4 +1501,3 @@ class TestRDocClassModule < XrefTestCase
end
end

View file

@ -1,7 +1,7 @@
# coding: US-ASCII
# frozen_string_literal: true
require File.expand_path '../xref_test_case', __FILE__
require_relative 'xref_test_case'
class TestRDocCodeObject < XrefTestCase

View file

@ -1,5 +1,5 @@
# frozen_string_literal: true
require File.expand_path '../xref_test_case', __FILE__
require_relative 'xref_test_case'
class TestRDocConstant < XrefTestCase

View file

@ -1,5 +1,5 @@
# frozen_string_literal: true
require File.expand_path '../xref_test_case', __FILE__
require_relative 'xref_test_case'
class TestRDocContext < XrefTestCase

View file

@ -1,5 +1,5 @@
# frozen_string_literal: true
require File.expand_path '../xref_test_case', __FILE__
require_relative 'xref_test_case'
class TestRDocCrossReference < XrefTestCase
OPERATOR_METHODS = %w'== === != =~ !~ < > <= >= <=> [] []= << >> -@ +@ ! - + * / % ** !@ ` | & ^ ~'
@ -215,4 +215,3 @@ class TestRDocCrossReference < XrefTestCase
end
end

View file

@ -1,5 +1,5 @@
# frozen_string_literal: true
require File.expand_path '../xref_test_case', __FILE__
require_relative 'xref_test_case'
class TestRDocExtend < XrefTestCase
@ -92,4 +92,3 @@ class TestRDocExtend < XrefTestCase
end
end

View file

@ -1,5 +1,5 @@
# frozen_string_literal: true
require File.expand_path '../xref_test_case', __FILE__
require_relative 'xref_test_case'
class TestRDocInclude < XrefTestCase
@ -107,4 +107,3 @@ class TestRDocInclude < XrefTestCase
end
end

View file

@ -2,8 +2,8 @@
# frozen_string_literal: true
require_relative 'helper'
require 'rdoc/markup/block_quote'
require 'rdoc/markdown'
require_relative '../../lib/rdoc/markup/block_quote'
require_relative '../../lib/rdoc/markdown'
class TestRDocMarkdown < RDoc::TestCase
@ -1068,4 +1068,3 @@ and an extra note.[^2]
end
end

View file

@ -2,8 +2,8 @@
require_relative 'helper'
require 'pp'
require 'rdoc'
require 'rdoc/markdown'
require_relative '../../lib/rdoc'
require_relative '../../lib/rdoc/markdown'
class TestRDocMarkdownTest < RDoc::TestCase

View file

@ -1,5 +1,5 @@
# frozen_string_literal: true
require File.expand_path '../xref_test_case', __FILE__
require_relative 'xref_test_case'
class TestRDocMarkupToHtmlCrossref < XrefTestCase
@ -260,4 +260,3 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase
end
end

View file

@ -1,5 +1,5 @@
# frozen_string_literal: true
require File.expand_path '../xref_test_case', __FILE__
require_relative 'xref_test_case'
class TestRDocMethodAttr < XrefTestCase
@ -191,4 +191,3 @@ class TestRDocMethodAttr < XrefTestCase
end
end

View file

@ -1,5 +1,5 @@
# frozen_string_literal: true
require File.expand_path '../xref_test_case', __FILE__
require_relative 'xref_test_case'
class TestRDocNormalClass < XrefTestCase
@ -45,4 +45,3 @@ class TestRDocNormalClass < XrefTestCase
end
end

View file

@ -1,5 +1,5 @@
# frozen_string_literal: true
require File.expand_path '../xref_test_case', __FILE__
require_relative 'xref_test_case'
class TestRDocNormalModule < XrefTestCase
@ -40,4 +40,3 @@ class TestRDocNormalModule < XrefTestCase
end
end

View file

@ -1,5 +1,5 @@
# frozen_string_literal: true
require File.expand_path '../xref_test_case', __FILE__
require_relative 'xref_test_case'
class TestRDocRequire < XrefTestCase
@ -23,4 +23,3 @@ class TestRDocRequire < XrefTestCase
end
end

View file

@ -32,8 +32,8 @@ class TestRDocRIDriver < RDoc::TestCase
end
def teardown
ENV['RI'] = @orig_ri
FileUtils.rm_rf @tmpdir
defined?(@orig_ri) and ENV['RI'] = @orig_ri
defined?(@tmpdir) and FileUtils.rm_rf @tmpdir
super
end

View file

@ -1,9 +1,9 @@
# frozen_string_literal: true
require "rubygems"
require "fileutils"
require "tmpdir"
require 'rdoc/rubygems_hook'
require "test/unit"
require 'rubygems'
require 'fileutils'
require 'tmpdir'
require_relative '../../lib/rdoc/rubygems_hook'
require 'test/unit'
class TestRDocRubygemsHook < Test::Unit::TestCase
def setup

View file

@ -1,5 +1,5 @@
# frozen_string_literal: true
require File.expand_path '../xref_test_case', __FILE__
require_relative 'xref_test_case'
class TestRDocStore < XrefTestCase

View file

@ -171,4 +171,3 @@ class TestRDocTask < RDoc::TestCase
end
end if defined?(Rake::Task)

View file

@ -1,5 +1,5 @@
# frozen_string_literal: true
require File.expand_path '../xref_test_case', __FILE__
require_relative 'xref_test_case'
class TestRDocTopLevel < XrefTestCase
@ -288,4 +288,3 @@ class TestRDocTopLevel < XrefTestCase
end
end