Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: CI

on:
push:
branches: [ "master" ]
branches: [ "main" ]
pull_request:
branches: [ "master" ]
branches: [ "main" ]

permissions:
contents: read
Expand All @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,4 +23,4 @@ DEPENDENCIES
test-unit (~> 3.0)

BUNDLED WITH
2.3.7
2.6.2
21 changes: 3 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions lib/structured_warnings.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
require 'structured_warnings/version'

# Compatibility layer
require 'warning' unless defined? ::Warning

require 'dynamic'

module StructuredWarnings
Expand Down
4 changes: 2 additions & 2 deletions lib/structured_warnings/kernel.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module StructuredWarnings::Kernel
def warn(*args)
Warning.warn(*args)
def warn(*args, **opts)
Warning.warn(*args, **opts)
end
end

Expand Down
6 changes: 2 additions & 4 deletions lib/structured_warnings/warning.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 0 additions & 9 deletions lib/warning.rb

This file was deleted.

2 changes: 2 additions & 0 deletions structured_warnings.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
54 changes: 34 additions & 20 deletions test/structured_warnings_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"

Expand All @@ -230,25 +244,15 @@ 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"

assert_equal expected_warning, actual_warning
end

def test_formatting_of_builtin_warn
return unless supports_core_warnings?

actual_warning = capture_strderr do
class << Object.new
attr_accessor :name
Expand All @@ -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?
Expand All @@ -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

Expand Down