diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 14a1962..793fd85 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,9 +2,9 @@ name: CI on: push: - branches: [ "master" ] + branches: [ "main" ] pull_request: - branches: [ "master" ] + branches: [ "main" ] permissions: contents: read @@ -15,10 +15,10 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - ruby-version: ['2.7', '3.0', '3.1'] + ruby-version: ['3.2', '3.3', '3.4'] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: diff --git a/Gemfile.lock b/Gemfile.lock index 90136a8..7fdf1e1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -6,10 +6,10 @@ PATH GEM remote: https://rubygems.org/ specs: - minitest (5.16.3) - power_assert (2.0.1) - rake (13.0.6) - test-unit (3.5.5) + minitest (5.25.5) + power_assert (2.0.5) + rake (13.2.1) + test-unit (3.6.8) power_assert PLATFORMS @@ -23,4 +23,4 @@ DEPENDENCIES test-unit (~> 3.0) BUNDLED WITH - 2.3.7 + 2.6.2 diff --git a/README.md b/README.md index 4c46449..e5264c5 100644 --- a/README.md +++ b/README.md @@ -33,24 +33,9 @@ Or install it yourself as: ## Compatibility -`structured_warnings` aims to work with all Ruby interpreters. Please file a bug -for any incompatibilities. - - -Versions of `structured_warnings` before `v0.3.0` are incompatible with Ruby -2.4+. Please upgrade accordingly, if you need Ruby 2.4 compatibility. Please -note on the otherhand, that many class names changed in an incompatible way -with `structured_warnings` `v0.3.0`. This was done to avoid future name clashes. - -Here's a table which should ease upgrading. - -| v0.2.0 and before | v0.3.0 and after | -|------------------------------|--------------------------------------------------| -| `Warning` | `StructuredWarnings::Base` | -| `StandardWarning` | `StructuredWarnings::StandardWarning` | -| `DeprecationWarning` | `StructuredWarnings::DeprecationWarning` | -| `DeprecatedMethodWarning` | `StructuredWarnings::DeprecatedMethodWarning` | -| `DeprecatedSignatureWarning` | `StructuredWarnings::DeprecatedSignatureWarning` | +`structured_warnings` aims to work with all stable, maintained Ruby versions. At +the time of this writing this is Ruby 3.2, 3.3, and 3.4. Please file a bug for +any incompatibilities. ### Test framework support diff --git a/lib/structured_warnings.rb b/lib/structured_warnings.rb index ad70348..12c8a92 100644 --- a/lib/structured_warnings.rb +++ b/lib/structured_warnings.rb @@ -1,8 +1,5 @@ require 'structured_warnings/version' -# Compatibility layer -require 'warning' unless defined? ::Warning - require 'dynamic' module StructuredWarnings diff --git a/lib/structured_warnings/kernel.rb b/lib/structured_warnings/kernel.rb index 1419977..359c505 100644 --- a/lib/structured_warnings/kernel.rb +++ b/lib/structured_warnings/kernel.rb @@ -1,6 +1,6 @@ module StructuredWarnings::Kernel - def warn(*args) - Warning.warn(*args) + def warn(*args, **opts) + Warning.warn(*args, **opts) end end diff --git a/lib/structured_warnings/warning.rb b/lib/structured_warnings/warning.rb index 591114f..06e5c2a 100644 --- a/lib/structured_warnings/warning.rb +++ b/lib/structured_warnings/warning.rb @@ -36,7 +36,7 @@ module StructuredWarnings::Warning # # warn StructuredWarnings::Base.new("The least specific warning you can get") # - def warn(*args) + def warn(*args, **options) first = args.shift if first.is_a? Class and first <= StructuredWarnings::Base warning = first @@ -52,11 +52,9 @@ def warn(*args) else warning = StructuredWarnings::BuiltInWarning - message = first.to_s.split(':', 4).last[1..-2] + message = first.to_s.split(':', 4).last.strip end - options = args.first.is_a?(Hash) ? args.shift : {} - # If args is not empty, user passed an incompatible set of arguments. # Maybe somebody else is overriding warn as well and knows, what to do. # Better do nothing in this case. See #5 diff --git a/lib/warning.rb b/lib/warning.rb deleted file mode 100644 index 9eab49b..0000000 --- a/lib/warning.rb +++ /dev/null @@ -1,9 +0,0 @@ -module Warning - KERNEL_WARN = Kernel.instance_method(:warn).bind(self) - - def warn(*args) - KERNEL_WARN.call(*args) - end - - extend self -end diff --git a/structured_warnings.gemspec b/structured_warnings.gemspec index 684ad85..fca07c1 100644 --- a/structured_warnings.gemspec +++ b/structured_warnings.gemspec @@ -18,6 +18,8 @@ Gem::Specification.new do |spec| spec.require_paths = ['lib'] + spec.required_ruby_version = '>= 3.2.0' + spec.add_development_dependency 'bundler', '~> 2.1' spec.add_development_dependency 'rake', '~> 13.0' spec.add_development_dependency 'minitest', '~> 5.0' diff --git a/test/structured_warnings_test.rb b/test/structured_warnings_test.rb index 86b98ed..d663b81 100644 --- a/test/structured_warnings_test.rb +++ b/test/structured_warnings_test.rb @@ -25,6 +25,22 @@ def method_using_incompatible_warn_api end end + def opening_quote + if RUBY_VERSION < '3.4' + '`' + else + "'" + end + end + + def classname_in_message + if RUBY_VERSION < '3.4' + '' + else + 'StructuredWarningsTest#' + end + end + def test_fork_in_thread return unless supports_fork? @@ -128,8 +144,6 @@ def test_base_is_default_warning end def test_builtin_warnings - return unless supports_core_warnings? - with_verbose_warnings do assert_warn(StructuredWarnings::BuiltInWarning, /method redefined; discarding old name/) do class << Object.new @@ -213,7 +227,7 @@ def test_formatting_of_warn expected_warning = "#{__FILE__}:#{__LINE__ - 4}:" + - "in `block in test_formatting_of_warn': " + + "in #{opening_quote}block in #{classname_in_message}test_formatting_of_warn': " + "do not blink " + "(StructuredWarnings::StandardWarning)\n" @@ -230,16 +244,8 @@ def test_formatting_of_warn_with_uplevel end expected_warning = - "#{__FILE__}:#{__LINE__ - 4}:" - - expected_warning += - if RUBY_VERSION < '2.3' - "in `call': " - else - "in `block in test_formatting_of_warn_with_uplevel': " - end - - expected_warning += + "#{__FILE__}:#{__LINE__ - 4}:" + + "in #{opening_quote}block in #{classname_in_message}test_formatting_of_warn_with_uplevel': " + "do not blink " + "(StructuredWarnings::StandardWarning)\n" @@ -247,8 +253,6 @@ def test_formatting_of_warn_with_uplevel end def test_formatting_of_builtin_warn - return unless supports_core_warnings? - actual_warning = capture_strderr do class << Object.new attr_accessor :name @@ -261,13 +265,27 @@ def name expected_warning = "#{__FILE__}:#{__LINE__ - 7}:" + - "in `singleton class': " + + "in #{opening_quote}singleton class': " + "method redefined; discarding old name " + "(StructuredWarnings::BuiltInWarning)\n" assert_equal expected_warning, actual_warning end + def test_formatting_of_manual_warn + actual_warning = capture_strderr do + Warning.warn("This is a test warning.") + end + + expected_warning = + "#{__FILE__}:#{__LINE__ - 4}:" + + "in #{opening_quote}block in #{classname_in_message}test_formatting_of_manual_warn': " + + "This is a test warning. " + + "(StructuredWarnings::BuiltInWarning)\n" + + assert_equal expected_warning, actual_warning + end + protected def supports_fork? @@ -280,10 +298,6 @@ def supports_fork? false end - def supports_core_warnings? - Warning.instance_method(:warn).source_location.nil? - end - def with_verbose_warnings verbose, $VERBOSE = $VERBOSE, true