From 29eda518c227258fd2cf4a132d646969f92fe58b Mon Sep 17 00:00:00 2001 From: Sven Riedel Date: Sun, 16 Jun 2019 10:42:08 +0200 Subject: [PATCH 1/5] Add --no-skipping-tests option --- lib/rdoc/options.rb | 12 ++++++++++++ test/rdoc/test_rdoc_options.rb | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/rdoc/options.rb b/lib/rdoc/options.rb index 55994c9dcc..912d8accdf 100644 --- a/lib/rdoc/options.rb +++ b/lib/rdoc/options.rb @@ -339,6 +339,10 @@ class RDoc::Options attr_reader :visibility + ## + # Indicates if files of test suites should be skipped + attr_reader :skip_tests + def initialize loaded_options = nil # :nodoc: init_ivars override loaded_options if loaded_options @@ -386,6 +390,7 @@ def init_ivars # :nodoc: @write_options = false @encoding = Encoding::UTF_8 @charset = @encoding.name + @skip_tests = true end def init_with map # :nodoc: @@ -778,6 +783,13 @@ def parse argv 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", "Treat files ending with .new as if they", "ended with .old. Using '-E cgi=rb' will", diff --git a/test/rdoc/test_rdoc_options.rb b/test/rdoc/test_rdoc_options.rb index 009dcdd998..c71ee25cef 100644 --- a/test/rdoc/test_rdoc_options.rb +++ b/test/rdoc/test_rdoc_options.rb @@ -83,6 +83,7 @@ def test_to_yaml 'title' => nil, 'visibility' => :protected, 'webcvs' => nil, + 'skip_tests' => true, } assert_equal expected, coder @@ -871,6 +872,16 @@ def test_load_options_no_file 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 alias add :[]= def tag=(tag) From f9a9eb5b4e8227c623fbdaeffc3765e50cef8cad Mon Sep 17 00:00:00 2001 From: Sven Riedel Date: Sun, 16 Jun 2019 10:57:04 +0200 Subject: [PATCH 2/5] Make skip_test option writeable for ease of testing --- lib/rdoc/options.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rdoc/options.rb b/lib/rdoc/options.rb index 912d8accdf..eed0f6b39b 100644 --- a/lib/rdoc/options.rb +++ b/lib/rdoc/options.rb @@ -341,7 +341,7 @@ class RDoc::Options ## # Indicates if files of test suites should be skipped - attr_reader :skip_tests + attr_accessor :skip_tests def initialize loaded_options = nil # :nodoc: init_ivars From 92d92ed2285783ce749b5171f4a477cfc4929e55 Mon Sep 17 00:00:00 2001 From: Sven Riedel Date: Sun, 16 Jun 2019 10:57:38 +0200 Subject: [PATCH 3/5] Skip gathering files in test directories --- lib/rdoc/rdoc.rb | 1 + test/rdoc/test_rdoc_rdoc.rb | 42 +++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/lib/rdoc/rdoc.rb b/lib/rdoc/rdoc.rb index 400f9b5bc3..d583de5490 100644 --- a/lib/rdoc/rdoc.rb +++ b/lib/rdoc/rdoc.rb @@ -281,6 +281,7 @@ def normalized_file_list(relative_files, force_doc = false, end when "directory" then next if rel_file_name == "CVS" || rel_file_name == ".svn" + next if options.skip_tests && %w[spec test].include?(File.basename(rel_file_name)) created_rid = File.join rel_file_name, "created.rid" next if File.file? created_rid diff --git a/test/rdoc/test_rdoc_rdoc.rb b/test/rdoc/test_rdoc_rdoc.rb index e958e5f2f6..13bfec535a 100644 --- a/test/rdoc/test_rdoc_rdoc.rb +++ b/test/rdoc/test_rdoc_rdoc.rb @@ -213,6 +213,48 @@ def test_normalized_file_list_with_dot_doc_overridden_by_exclude_option assert_equal expected_files, files 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 [@test_file, @spec_file, @a], files + end + def test_parse_file @rdoc.store = RDoc::Store.new From c11ddd95cbdb9ca52f1bb81ef720051a59bf144c Mon Sep 17 00:00:00 2001 From: Sven Riedel Date: Sun, 16 Jun 2019 11:01:45 +0200 Subject: [PATCH 4/5] Extract directory names to contants, add .git --- lib/rdoc/rdoc.rb | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/rdoc/rdoc.rb b/lib/rdoc/rdoc.rb index d583de5490..2d8a9dea8c 100644 --- a/lib/rdoc/rdoc.rb +++ b/lib/rdoc/rdoc.rb @@ -35,6 +35,17 @@ class RDoc::RDoc 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 @@ -280,8 +291,10 @@ def normalized_file_list(relative_files, force_doc = false, file_list[rel_file_name] = mtime end when "directory" then - next if rel_file_name == "CVS" || rel_file_name == ".svn" - next if options.skip_tests && %w[spec test].include?(File.basename(rel_file_name)) + 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" next if File.file? created_rid From 3cd4bfdc056b7b05a63e48788e307ba16f8945b5 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Mon, 28 Nov 2022 13:11:42 +0900 Subject: [PATCH 5/5] Fix tests `RDoc::RDoc#normalized_file_list` returns a filenames-to-mtime `Hash`, and the order is indeterminable. --- test/rdoc/test_rdoc_rdoc.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/rdoc/test_rdoc_rdoc.rb b/test/rdoc/test_rdoc_rdoc.rb index 13bfec535a..853d7dad22 100644 --- a/test/rdoc/test_rdoc_rdoc.rb +++ b/test/rdoc/test_rdoc_rdoc.rb @@ -230,7 +230,7 @@ def test_normalized_file_list_with_skipping_tests_enabled @rdoc.normalized_file_list [File.realpath(dir)] end - files = files.map { |file| File.expand_path file } + files = files.map { |file, *| File.expand_path file } assert_equal [@a], files end @@ -251,8 +251,8 @@ def test_normalized_file_list_with_skipping_tests_disabled @rdoc.normalized_file_list [File.realpath(dir)] end - files = files.map { |file| File.expand_path file } - assert_equal [@test_file, @spec_file, @a], files + files = files.map { |file, *| File.expand_path file } + assert_equal [@a, @spec_file, @test_file], files.sort end def test_parse_file