From 0e2d96d6321504ef2240aa4e4e162a0dad6d7ec3 Mon Sep 17 00:00:00 2001 From: nick evans Date: Tue, 18 Feb 2025 18:35:58 -0500 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Update=20versioned=20defau?= =?UTF-8?q?lt=20configs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reorganizes the creation of `Config.version_defaults` to make it easier to cherry-pick backported config changes to stable branches: * Sets `Config[0.4]` as a diff from the previous versioned default, just like the other versioned defaults. * Sets `Config[:current] = Config[VERSION.to_f]`, so it will not need to be updated for any x.y.0 release. Likewise, sets `Config[:next]` to `Config[VERSION.to_f + 0.1]` which only rarely needs to be changed. * Because `Config[:default]` and `Config[:current]` are now derived two different ways, both a warning and a test have been added to ensure they remain synchronized. * A few other `Config.version_defaults` tests were added or updated. --- lib/net/imap/config.rb | 30 +++++++++++++++++++++++------- test/net/imap/test_config.rb | 36 ++++++++++++++++++++++++++++-------- 2 files changed, 51 insertions(+), 15 deletions(-) diff --git a/lib/net/imap/config.rb b/lib/net/imap/config.rb index 79f81355..aea07b89 100644 --- a/lib/net/imap/config.rb +++ b/lib/net/imap/config.rb @@ -408,9 +408,9 @@ def defaults_hash @global = default.new - version_defaults[0.4] = Config[default.send(:defaults_hash)] + version_defaults[:default] = Config[default.send(:defaults_hash)] - version_defaults[0] = Config[0.4].dup.update( + version_defaults[0] = Config[:default].dup.update( sasl_ir: false, parser_use_deprecated_uidplus_data: true, parser_max_deprecated_uidplus_data_size: 10_000, @@ -420,24 +420,40 @@ def defaults_hash version_defaults[0.2] = Config[0] version_defaults[0.3] = Config[0] + version_defaults[0.4] = Config[0.3].dup.update( + sasl_ir: true, + parser_max_deprecated_uidplus_data_size: 1000, + ).freeze + version_defaults[0.5] = Config[0.4].dup.update( responses_without_block: :warn, parser_use_deprecated_uidplus_data: :up_to_max_size, parser_max_deprecated_uidplus_data_size: 100, ).freeze - version_defaults[:default] = Config[0.4] - version_defaults[:current] = Config[0.4] - version_defaults[:next] = Config[0.5] - version_defaults[0.6] = Config[0.5].dup.update( responses_without_block: :frozen_dup, parser_use_deprecated_uidplus_data: false, parser_max_deprecated_uidplus_data_size: 0, ).freeze - version_defaults[:future] = Config[0.6] + + version_defaults[0.7] = Config[0.6].dup.update( + ).freeze + + current = VERSION.to_f + version_defaults[:original] = Config[0] + version_defaults[:current] = Config[current] + version_defaults[:next] = Config[current + 0.1] + version_defaults[:future] = Config[0.7] version_defaults.freeze + + if ($VERBOSE || $DEBUG) && self[:current].to_h != self[:default].to_h + warn "Misconfigured Net::IMAP::Config[:current] => %p,\n" \ + " not equal to Net::IMAP::Config[:default] => %p" % [ + self[:current].to_h, self[:default].to_h + ] + end end end end diff --git a/test/net/imap/test_config.rb b/test/net/imap/test_config.rb index 7a2cd174..0b0009a0 100644 --- a/test/net/imap/test_config.rb +++ b/test/net/imap/test_config.rb @@ -5,6 +5,9 @@ class ConfigTest < Test::Unit::TestCase Config = Net::IMAP::Config + THIS_VERSION = Net::IMAP::VERSION.to_f + NEXT_VERSION = THIS_VERSION + 0.1 + FUTURE_VERSION = 0.7 setup do Config.global.reset @@ -141,10 +144,26 @@ class ConfigTest < Test::Unit::TestCase assert_kind_of Config, config assert config.frozen?, "#{name} isn't frozen" assert config.inherited?(:debug), "#{name} doesn't inherit debug" + keys = config.to_h.keys - [:debug] + keys.each do |key| + refute config.inherited?(key) + end assert_same Config.global, config.parent end end + test "Config[:default] and Config[:current] both hold default config" do + defaults = Config.default.to_h + assert_equal(defaults, Config[:default].to_h) + assert_equal(defaults, Config[:current].to_h) + end + + test ".[] for all version_defaults" do + Config.version_defaults.each do |version, config| + assert_same Config[version], config + end + end + test ".[] for all x.y versions" do original = Config[0] assert_kind_of Config, original @@ -152,8 +171,9 @@ class ConfigTest < Test::Unit::TestCase assert_same original, Config[0.1] assert_same original, Config[0.2] assert_same original, Config[0.3] - assert_kind_of Config, Config[0.4] - assert_kind_of Config, Config[0.5] + ((0.4r..FUTURE_VERSION.to_r) % 0.1r).each do |version| + assert_kind_of Config, Config[version.to_f] + end end test ".[] range errors" do @@ -169,10 +189,10 @@ class ConfigTest < Test::Unit::TestCase end test ".[] with symbol names" do - assert_same Config[0.4], Config[:current] - assert_same Config[0.4], Config[:default] - assert_same Config[0.5], Config[:next] - assert_kind_of Config, Config[:future] + assert_equal Config[THIS_VERSION].to_h, Config[:default].to_h + assert_same Config[THIS_VERSION], Config[:current] + assert_same Config[NEXT_VERSION], Config[:next] + assert_same Config[FUTURE_VERSION], Config[:future] end test ".[] with a hash" do @@ -190,8 +210,8 @@ class ConfigTest < Test::Unit::TestCase assert_same Config.default, Config.new(Config.default).parent assert_same Config.global, Config.new(Config.global).parent assert_same Config[0.4], Config.new(0.4).parent - assert_same Config[0.5], Config.new(:next).parent - assert_same Config[0.6], Config.new(:future).parent + assert_same Config[NEXT_VERSION], Config.new(:next).parent + assert_same Config[FUTURE_VERSION], Config.new(:future).parent assert_equal true, Config.new({debug: true}, debug: false).parent.debug? assert_equal true, Config.new({debug: true}, debug: false).parent.frozen? end