Skip to content

Conversation

@byroot
Copy link
Contributor

@byroot byroot commented Nov 3, 2025

power_assert 3.0 now uses pattern matching: ruby/power_assert#57.

This causes it to be half defined on Ruby 3.0 and older.

$ bundle exec ruby -Itest test/json/json_coder_test.rb
/Users/byroot/.gem/rubies/3.0.7/gems/test-unit-3.7.0/lib/test/unit/util/backtracefilter.rb:16:in `method': undefined method `start' for class `#<Class:PowerAssert>' (NameError)
	from /Users/byroot/.gem/rubies/3.0.7/gems/test-unit-3.7.0/lib/test/unit/util/backtracefilter.rb:16:in `<module:BacktraceFilter>'
	from /Users/byroot/.gem/rubies/3.0.7/gems/test-unit-3.7.0/lib/test/unit/util/backtracefilter.rb:9:in `<module:Util>'
	from /Users/byroot/.gem/rubies/3.0.7/gems/test-unit-3.7.0/lib/test/unit/util/backtracefilter.rb:8:in `<module:Unit>'
	from /Users/byroot/.gem/rubies/3.0.7/gems/test-unit-3.7.0/lib/test/unit/util/backtracefilter.rb:7:in `<module:Test>'
	from /Users/byroot/.gem/rubies/3.0.7/gems/test-unit-3.7.0/lib/test/unit/util/backtracefilter.rb:6:in `<top (required)>'
	from /Users/byroot/.gem/rubies/3.0.7/gems/test-unit-3.7.0/lib/test/unit/assertions.rb:7:in `require_relative'
	from /Users/byroot/.gem/rubies/3.0.7/gems/test-unit-3.7.0/lib/test/unit/assertions.rb:7:in `<top (required)>'
	from /Users/byroot/.gem/rubies/3.0.7/gems/test-unit-3.7.0/lib/test/unit/testcase.rb:12:in `require_relative'
	from /Users/byroot/.gem/rubies/3.0.7/gems/test-unit-3.7.0/lib/test/unit/testcase.rb:12:in `<top (required)>'
	from /Users/byroot/.gem/rubies/3.0.7/gems/test-unit-3.7.0/lib/test/unit.rb:3:in `require_relative'
	from /Users/byroot/.gem/rubies/3.0.7/gems/test-unit-3.7.0/lib/test/unit.rb:3:in `<top (required)>'
	from /Users/byroot/src/github.com/ruby/json/test/json/test_helper.rb:28:in `require'
	from /Users/byroot/src/github.com/ruby/json/test/json/test_helper.rb:28:in `<top (required)>'
	from test/json/json_coder_test.rb:4:in `require_relative'
	from test/json/json_coder_test.rb:4:in `<main>'

@byroot byroot changed the title Fix compatibility with power_assert 3.0 on olrder rubies Fix compatibility with power_assert 3.0 on older rubies Nov 3, 2025
power_assert 3.0 now use pattern matching: ruby/power_assert#57
This cause it to be half defined on Ruby 3.0 and older.
@byroot byroot force-pushed the fix-power-assert-3.0 branch from 12b8dad to 4e4b510 Compare November 3, 2025 08:34
byroot added a commit to ruby/json that referenced this pull request Nov 3, 2025
@kou kou merged commit dd28c55 into test-unit:master Nov 3, 2025
36 checks passed
@kou
Copy link
Member

kou commented Nov 3, 2025

Thanks!

@tikkss Could you release a new version?

@tikkss
Copy link
Contributor

tikkss commented Nov 3, 2025

Sure! I'll work on it in a few hours.

@Earlopain
Copy link

Is there a reason why power_assert has no required_ruby_version? This removes the power_assert module but requiring it seems to have other side effects. In the ruby/prism test suite on Ruby 2.7, a class new method is suddenly not defined anymore https://github.com/ruby/prism/actions/runs/19042061678/job/54381447951?pr=3704

I confirmed this locally, skipping the power_assert require entirely from test-unit resolves this error. Skipping power_assert 3.0.0 does fix this as well obviously.

Earlopain added a commit to Earlopain/prism that referenced this pull request Nov 4, 2025
It requires Ruby 3.1 but declares no `required_ruby_version`.
Ref: test-unit/test-unit#329 (comment)
@byroot
Copy link
Contributor Author

byroot commented Nov 4, 2025

Is there a reason why power_assert has no required_ruby_version?

It would be preferable, unfortunately that ship has sailed. Now that power_assert 3.0.0 has been released with no ruby version requirement, bundler will inevitably try to install it.

@Earlopain
Copy link

Well, yeah. It's unfortunate that bundler will always land on 3.0.0 in case of conflict but that at least makes it more obvious that something is not entirely right once more time has passed and new versions have been released.

I will open a PR.

Earlopain added a commit to Earlopain/power_assert that referenced this pull request Nov 4, 2025
This is only documented in the Readme.

3.0.0 now depends on pattern matching, which is invalid syntax on 2.7.
The `test-unit` gem depends on `power_assert` and tries to handle that by catching `SyntaxError`:
https://github.com/test-unit/test-unit/blob/edfa50cf4fef5521f34dca1995c1c8f3efe77d7b/lib/test/unit/assertions.rb#L12-L18
That seems to have worked ok previously but now it leaves the `PowerAssert` module behind,
among other things. `test-unit` cleans that up via test-unit/test-unit#329
but there are other side-effects it can do nothing about.

For example, an undefined `new` method:
> /Users/runner/hostedtoolcache/Ruby/2.7.8/arm64/lib/ruby/gems/2.7.0/gems/onigmo-0.1.0/lib/onigmo/node.rb:27:in `private_class_method': undefined method `new' for class `#<Class:Onigmo::Node>' (NameError)
> Did you mean?  next

Now, bundler will always fall back to 3.0.0 even if this gets released as 3.0.0.
But eventually it will help for future version bumps.
@Earlopain
Copy link

ruby/power_assert#61

@eregon
Copy link

eregon commented Nov 4, 2025

It would be preferable, unfortunately that ship has sailed. Now that power_assert 3.0.0 has been released with no ruby version requirement, bundler will inevitably try to install it.

Maybe this would be a good case to yank that version since it causes known problems? (after releasing 3.0.1 or so with the proper required_ruby_version of course)

@byroot
Copy link
Contributor Author

byroot commented Nov 4, 2025

I'm generally against yanking as it tend to cause even more issues.

@byroot byroot deleted the fix-power-assert-3.0 branch November 4, 2025 09:31
@Earlopain
Copy link

Yes, I hate yanking (as implemented). It causes problems for everyone that already upgraded and didn't have issues in the first place or already worked around it.

At one point you were able to still install even yanked gems which would be fine for this but I understand why they changed it. "soft-yanking" for cases like this would be great, I never encountered one where the gem had to actually be removed completely.

@eregon
Copy link

eregon commented Nov 5, 2025

Maybe it's time for test-unit to stop depending on power_assert: ruby/power_assert#61 (comment)
I think very few people use assert { ... } anyway (edited).

@Earlopain
Copy link

I think very few people use plain assert anyway.

plain assert with a block. I don't think it does anything otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants