Skip to content

Commit b82ef3e

Browse files
authored
Update Rubys and Gems (#20)
Update required Rubys to a maintained version. If anybody wants to use an older version of Ruby, they'll have to use an older version of structured warnings. Cleaning up and removing older compatibility layers. Also adding @NobodysNightmare's changes from #19 to improve cooperation with other gems overriding the default warning behavior.
1 parent fe5c8d1 commit b82ef3e

9 files changed

Lines changed: 52 additions & 65 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: CI
22

33
on:
44
push:
5-
branches: [ "master" ]
5+
branches: [ "main" ]
66
pull_request:
7-
branches: [ "master" ]
7+
branches: [ "main" ]
88

99
permissions:
1010
contents: read
@@ -15,10 +15,10 @@ jobs:
1515
runs-on: ubuntu-latest
1616
strategy:
1717
matrix:
18-
ruby-version: ['2.7', '3.0', '3.1']
18+
ruby-version: ['3.2', '3.3', '3.4']
1919

2020
steps:
21-
- uses: actions/checkout@v3
21+
- uses: actions/checkout@v4
2222
- name: Set up Ruby
2323
uses: ruby/setup-ruby@v1
2424
with:

Gemfile.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ PATH
66
GEM
77
remote: https://rubygems.org/
88
specs:
9-
minitest (5.16.3)
10-
power_assert (2.0.1)
11-
rake (13.0.6)
12-
test-unit (3.5.5)
9+
minitest (5.25.5)
10+
power_assert (2.0.5)
11+
rake (13.2.1)
12+
test-unit (3.6.8)
1313
power_assert
1414

1515
PLATFORMS
@@ -23,4 +23,4 @@ DEPENDENCIES
2323
test-unit (~> 3.0)
2424

2525
BUNDLED WITH
26-
2.3.7
26+
2.6.2

README.md

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,9 @@ Or install it yourself as:
3333

3434
## Compatibility
3535

36-
`structured_warnings` aims to work with all Ruby interpreters. Please file a bug
37-
for any incompatibilities.
38-
39-
40-
Versions of `structured_warnings` before `v0.3.0` are incompatible with Ruby
41-
2.4+. Please upgrade accordingly, if you need Ruby 2.4 compatibility. Please
42-
note on the otherhand, that many class names changed in an incompatible way
43-
with `structured_warnings` `v0.3.0`. This was done to avoid future name clashes.
44-
45-
Here's a table which should ease upgrading.
46-
47-
| v0.2.0 and before | v0.3.0 and after |
48-
|------------------------------|--------------------------------------------------|
49-
| `Warning` | `StructuredWarnings::Base` |
50-
| `StandardWarning` | `StructuredWarnings::StandardWarning` |
51-
| `DeprecationWarning` | `StructuredWarnings::DeprecationWarning` |
52-
| `DeprecatedMethodWarning` | `StructuredWarnings::DeprecatedMethodWarning` |
53-
| `DeprecatedSignatureWarning` | `StructuredWarnings::DeprecatedSignatureWarning` |
36+
`structured_warnings` aims to work with all stable, maintained Ruby versions. At
37+
the time of this writing this is Ruby 3.2, 3.3, and 3.4. Please file a bug for
38+
any incompatibilities.
5439

5540

5641
### Test framework support

lib/structured_warnings.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
require 'structured_warnings/version'
22

3-
# Compatibility layer
4-
require 'warning' unless defined? ::Warning
5-
63
require 'dynamic'
74

85
module StructuredWarnings

lib/structured_warnings/kernel.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module StructuredWarnings::Kernel
2-
def warn(*args)
3-
Warning.warn(*args)
2+
def warn(*args, **opts)
3+
Warning.warn(*args, **opts)
44
end
55
end
66

lib/structured_warnings/warning.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module StructuredWarnings::Warning
3636
#
3737
# warn StructuredWarnings::Base.new("The least specific warning you can get")
3838
#
39-
def warn(*args)
39+
def warn(*args, **options)
4040
first = args.shift
4141
if first.is_a? Class and first <= StructuredWarnings::Base
4242
warning = first
@@ -52,11 +52,9 @@ def warn(*args)
5252

5353
else
5454
warning = StructuredWarnings::BuiltInWarning
55-
message = first.to_s.split(':', 4).last[1..-2]
55+
message = first.to_s.split(':', 4).last.strip
5656
end
5757

58-
options = args.first.is_a?(Hash) ? args.shift : {}
59-
6058
# If args is not empty, user passed an incompatible set of arguments.
6159
# Maybe somebody else is overriding warn as well and knows, what to do.
6260
# Better do nothing in this case. See #5

lib/warning.rb

Lines changed: 0 additions & 9 deletions
This file was deleted.

structured_warnings.gemspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
1818

1919
spec.require_paths = ['lib']
2020

21+
spec.required_ruby_version = '>= 3.2.0'
22+
2123
spec.add_development_dependency 'bundler', '~> 2.1'
2224
spec.add_development_dependency 'rake', '~> 13.0'
2325
spec.add_development_dependency 'minitest', '~> 5.0'

test/structured_warnings_test.rb

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,22 @@ def method_using_incompatible_warn_api
2525
end
2626
end
2727

28+
def opening_quote
29+
if RUBY_VERSION < '3.4'
30+
'`'
31+
else
32+
"'"
33+
end
34+
end
35+
36+
def classname_in_message
37+
if RUBY_VERSION < '3.4'
38+
''
39+
else
40+
'StructuredWarningsTest#'
41+
end
42+
end
43+
2844
def test_fork_in_thread
2945
return unless supports_fork?
3046

@@ -128,8 +144,6 @@ def test_base_is_default_warning
128144
end
129145

130146
def test_builtin_warnings
131-
return unless supports_core_warnings?
132-
133147
with_verbose_warnings do
134148
assert_warn(StructuredWarnings::BuiltInWarning, /method redefined; discarding old name/) do
135149
class << Object.new
@@ -213,7 +227,7 @@ def test_formatting_of_warn
213227

214228
expected_warning =
215229
"#{__FILE__}:#{__LINE__ - 4}:" +
216-
"in `block in test_formatting_of_warn': " +
230+
"in #{opening_quote}block in #{classname_in_message}test_formatting_of_warn': " +
217231
"do not blink " +
218232
"(StructuredWarnings::StandardWarning)\n"
219233

@@ -230,25 +244,15 @@ def test_formatting_of_warn_with_uplevel
230244
end
231245

232246
expected_warning =
233-
"#{__FILE__}:#{__LINE__ - 4}:"
234-
235-
expected_warning +=
236-
if RUBY_VERSION < '2.3'
237-
"in `call': "
238-
else
239-
"in `block in test_formatting_of_warn_with_uplevel': "
240-
end
241-
242-
expected_warning +=
247+
"#{__FILE__}:#{__LINE__ - 4}:" +
248+
"in #{opening_quote}block in #{classname_in_message}test_formatting_of_warn_with_uplevel': " +
243249
"do not blink " +
244250
"(StructuredWarnings::StandardWarning)\n"
245251

246252
assert_equal expected_warning, actual_warning
247253
end
248254

249255
def test_formatting_of_builtin_warn
250-
return unless supports_core_warnings?
251-
252256
actual_warning = capture_strderr do
253257
class << Object.new
254258
attr_accessor :name
@@ -261,13 +265,27 @@ def name
261265

262266
expected_warning =
263267
"#{__FILE__}:#{__LINE__ - 7}:" +
264-
"in `singleton class': " +
268+
"in #{opening_quote}singleton class': " +
265269
"method redefined; discarding old name " +
266270
"(StructuredWarnings::BuiltInWarning)\n"
267271

268272
assert_equal expected_warning, actual_warning
269273
end
270274

275+
def test_formatting_of_manual_warn
276+
actual_warning = capture_strderr do
277+
Warning.warn("This is a test warning.")
278+
end
279+
280+
expected_warning =
281+
"#{__FILE__}:#{__LINE__ - 4}:" +
282+
"in #{opening_quote}block in #{classname_in_message}test_formatting_of_manual_warn': " +
283+
"This is a test warning. " +
284+
"(StructuredWarnings::BuiltInWarning)\n"
285+
286+
assert_equal expected_warning, actual_warning
287+
end
288+
271289
protected
272290

273291
def supports_fork?
@@ -280,10 +298,6 @@ def supports_fork?
280298
false
281299
end
282300

283-
def supports_core_warnings?
284-
Warning.instance_method(:warn).source_location.nil?
285-
end
286-
287301
def with_verbose_warnings
288302
verbose, $VERBOSE = $VERBOSE, true
289303

0 commit comments

Comments
 (0)