From e10554b7fe0f8e069485970e16ab8b3628ba66c1 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Tue, 24 Dec 2024 18:12:20 +0900 Subject: [PATCH] Separate patterns by `--exclude` option from defaults --- lib/rdoc/options.rb | 31 ++++++++++++++++++++++++------- test/rdoc/test_rdoc_options.rb | 26 +++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/lib/rdoc/options.rb b/lib/rdoc/options.rb index f35467e312..5e2d320c73 100644 --- a/lib/rdoc/options.rb +++ b/lib/rdoc/options.rb @@ -355,18 +355,24 @@ class RDoc::Options # +--[no-]embed-mixins+ (Default is +false+.) attr_accessor :embed_mixins + ## + # Exclude the default patterns as well if true. + attr_reader :apply_default_exclude + def initialize loaded_options = nil # :nodoc: init_ivars override loaded_options if loaded_options end + DEFAULT_EXCLUDE = %w[ + ~\z \.orig\z \.rej\z \.bak\z + \.gemspec\z + ] + def init_ivars # :nodoc: @dry_run = false @embed_mixins = false - @exclude = %w[ - ~\z \.orig\z \.rej\z \.bak\z - \.gemspec\z - ] + @exclude = [] @files = nil @force_output = false @force_update = true @@ -405,6 +411,7 @@ def init_ivars # :nodoc: @encoding = Encoding::UTF_8 @charset = @encoding.name @skip_tests = true + @apply_default_exclude = true end def init_with map # :nodoc: @@ -430,6 +437,7 @@ def init_with map # :nodoc: @title = map['title'] @visibility = map['visibility'] @webcvs = map['webcvs'] + @apply_default_exclude = map['apply_default_exclude'] @rdoc_include = sanitize_path map['rdoc_include'] @static_path = sanitize_path map['static_path'] @@ -463,6 +471,7 @@ def override map # :nodoc: @title = map['title'] if map.has_key?('title') @visibility = map['visibility'] if map.has_key?('visibility') @webcvs = map['webcvs'] if map.has_key?('webcvs') + @apply_default_exclude = map['apply_default_exclude'] if map.has_key?('apply_default_exclude') @warn_missing_rdoc_ref = map['warn_missing_rdoc_ref'] if map.has_key?('warn_missing_rdoc_ref') @@ -493,7 +502,8 @@ def == other # :nodoc: @template == other.template and @title == other.title and @visibility == other.visibility and - @webcvs == other.webcvs + @webcvs == other.webcvs and + @apply_default_exclude == other.apply_default_exclude end ## @@ -564,10 +574,12 @@ def exclude if @exclude.nil? or Regexp === @exclude then # done, #finish is being re-run @exclude - elsif @exclude.empty? then + elsif !@apply_default_exclude and @exclude.empty? then nil else - Regexp.new(@exclude.join("|")) + exclude = @exclude + exclude |= DEFAULT_EXCLUDE if @apply_default_exclude + Regexp.new(exclude.join("|")) end end @@ -801,6 +813,11 @@ def parse argv @exclude << value end + opt.on("--[no-]apply-default-exclude", + "Use default PATTERN to exclude.") do |value| + @apply_default_exclude = value + end + opt.separator nil opt.on("--no-skipping-tests", nil, diff --git a/test/rdoc/test_rdoc_options.rb b/test/rdoc/test_rdoc_options.rb index eb8477483c..e658d4b314 100644 --- a/test/rdoc/test_rdoc_options.rb +++ b/test/rdoc/test_rdoc_options.rb @@ -66,7 +66,7 @@ def test_to_yaml 'charset' => 'UTF-8', 'encoding' => encoding, 'embed_mixins' => false, - 'exclude' => %w[~\z \.orig\z \.rej\z \.bak\z \.gemspec\z], + 'exclude' => [], 'hyperlink_all' => false, 'line_numbers' => false, 'locale_dir' => 'locale', @@ -85,6 +85,7 @@ def test_to_yaml 'warn_missing_rdoc_ref' => false, 'webcvs' => nil, 'skip_tests' => true, + 'apply_default_exclude' => true, } assert_equal expected, coder @@ -939,6 +940,29 @@ def test_no_skip_test_value assert_equal false, @options.skip_tests end + def test_apply_default_exclude_option + @options.parse %w[] + exclude = @options.exclude + assert_kind_of Regexp, exclude + assert_match exclude, "foo~" + assert_match exclude, "foo.orig" + assert_match exclude, "foo.rej" + assert_match exclude, "foo.bak" + assert_match exclude, "foo.gemspec" + end + + def test_no_apply_default_exclude_option + @options.parse %w[--no-apply-default-exclude] + assert_nil @options.exclude + end + + def test_exclude_option_without_default + @options.parse %w[--no-apply-default-exclude --exclude=\.old\z] + exclude = @options.exclude + assert_match exclude, "foo.old" + assert_not_match exclude, "foo~" + end + class DummyCoder < Hash alias add :[]= def tag=(tag)