[ruby/rdoc] Add --no-skipping-tests option

https://github.com/ruby/rdoc/commit/33925f885f
This commit is contained in:
Sven Riedel 2022-11-28 05:36:26 +01:00 committed by git
parent 745dcf5326
commit e0901f46b7
4 changed files with 80 additions and 1 deletions

View File

@ -339,6 +339,10 @@ class RDoc::Options
attr_reader :visibility attr_reader :visibility
##
# Indicates if files of test suites should be skipped
attr_accessor :skip_tests
def initialize loaded_options = nil # :nodoc: def initialize loaded_options = nil # :nodoc:
init_ivars init_ivars
override loaded_options if loaded_options override loaded_options if loaded_options
@ -386,6 +390,7 @@ class RDoc::Options
@write_options = false @write_options = false
@encoding = Encoding::UTF_8 @encoding = Encoding::UTF_8
@charset = @encoding.name @charset = @encoding.name
@skip_tests = true
end end
def init_with map # :nodoc: def init_with map # :nodoc:
@ -778,6 +783,13 @@ Usage: #{opt.program_name} [options] [names...]
opt.separator nil opt.separator nil
opt.on("--no-skipping-tests", nil,
"Don't skip generating documentation for test and spec files") do |value|
@skip_tests = false
end
opt.separator nil
opt.on("--extension=NEW=OLD", "-E", opt.on("--extension=NEW=OLD", "-E",
"Treat files ending with .new as if they", "Treat files ending with .new as if they",
"ended with .old. Using '-E cgi=rb' will", "ended with .old. Using '-E cgi=rb' will",

View File

@ -35,6 +35,17 @@ class RDoc::RDoc
GENERATORS = {} GENERATORS = {}
##
# List of directory names always skipped
UNCONDITIONALLY_SKIPPED_DIRECTORIES = %w[CVS .svn .git].freeze
##
# List of directory names skipped if test suites should be skipped
TEST_SUITE_DIRECTORY_NAMES = %w[spec test].freeze
## ##
# Generator instance used for creating output # Generator instance used for creating output
@ -280,7 +291,10 @@ option)
file_list[rel_file_name] = mtime file_list[rel_file_name] = mtime
end end
when "directory" then when "directory" then
next if rel_file_name == "CVS" || rel_file_name == ".svn" next if UNCONDITIONALLY_SKIPPED_DIRECTORIES.include?(rel_file_name)
basename = File.basename(rel_file_name)
next if options.skip_tests && TEST_SUITE_DIRECTORY_NAMES.include?(basename)
created_rid = File.join rel_file_name, "created.rid" created_rid = File.join rel_file_name, "created.rid"
next if File.file? created_rid next if File.file? created_rid

View File

@ -83,6 +83,7 @@ class TestRDocOptions < RDoc::TestCase
'title' => nil, 'title' => nil,
'visibility' => :protected, 'visibility' => :protected,
'webcvs' => nil, 'webcvs' => nil,
'skip_tests' => true,
} }
assert_equal expected, coder assert_equal expected, coder
@ -871,6 +872,16 @@ rdoc_include:
end end
end end
def test_skip_test_default_value
@options.parse %w[]
assert_equal true, @options.skip_tests
end
def test_no_skip_test_value
@options.parse %w[--no-skipping-tests]
assert_equal false, @options.skip_tests
end
class DummyCoder < Hash class DummyCoder < Hash
alias add :[]= alias add :[]=
def tag=(tag) def tag=(tag)

View File

@ -213,6 +213,48 @@ class TestRDocRDoc < RDoc::TestCase
assert_equal expected_files, files assert_equal expected_files, files
end end
def test_normalized_file_list_with_skipping_tests_enabled
files = temp_dir do |dir|
@a = File.expand_path('a.rb')
spec_dir = File.expand_path('spec')
spec_file = File.expand_path(File.join('spec', 'my_spec.rb'))
test_dir = File.expand_path('test')
test_file = File.expand_path(File.join('test', 'my_test.rb'))
FileUtils.touch @a
FileUtils.mkdir_p spec_dir
FileUtils.touch spec_file
FileUtils.mkdir_p test_dir
FileUtils.touch test_file
@rdoc.options.skip_tests = true
@rdoc.normalized_file_list [File.realpath(dir)]
end
files = files.map { |file, *| File.expand_path file }
assert_equal [@a], files
end
def test_normalized_file_list_with_skipping_tests_disabled
files = temp_dir do |dir|
@a = File.expand_path('a.rb')
spec_dir = File.expand_path('spec')
@spec_file = File.expand_path(File.join('spec', 'my_spec.rb'))
test_dir = File.expand_path('test')
@test_file = File.expand_path(File.join('test', 'my_test.rb'))
FileUtils.touch @a
FileUtils.mkdir_p spec_dir
FileUtils.touch @spec_file
FileUtils.mkdir_p test_dir
FileUtils.touch @test_file
@rdoc.options.skip_tests = false
@rdoc.normalized_file_list [File.realpath(dir)]
end
files = files.map { |file, *| File.expand_path file }
assert_equal [@a, @spec_file, @test_file], files.sort
end
def test_parse_file def test_parse_file
@rdoc.store = RDoc::Store.new @rdoc.store = RDoc::Store.new