Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A few small fixes for rubyspecs #192

Merged
merged 6 commits into from Mar 5, 2024
Merged

Conversation

headius
Copy link
Contributor

@headius headius commented Mar 5, 2024

Fixes 10 cases from rubyspec:

  • Size error cases
  • Enumerator.product rejects kwargs by name
  • Product#rewind rewinds in "direct order", not reverse

JRuby is using this impl for now, and this brings the failure count for the Enumerator::Product specs down to 10 (43 total, 20 failures without this PR).

headius added a commit to jruby/jruby that referenced this pull request Mar 5, 2024
See marcandre/backports#192 for a few
small additional fixes incorporated here.
@headius
Copy link
Contributor Author

headius commented Mar 5, 2024

Remaining failures (running in JRuby):

1)
Enumerator::Product#each returns self if given a block FAILED
Expected nil.equal? #<Enumerator::Product: nil:>
to be truthy but was false
/Users/headius/work/jruby/spec/ruby/core/enumerator/product/each_spec.rb:50:in `block in <main>'
org/jruby/RubyBasicObject.java:2620:in `instance_exec'
org/jruby/RubyArray.java:4912:in `all?'
org/jruby/RubyArray.java:1985:in `each'
/Users/headius/work/jruby/spec/ruby/core/enumerator/product/each_spec.rb:5:in `block in <main>'
/Users/headius/work/jruby/spec/ruby/core/enumerator/product/each_spec.rb:4:in `<main>'
org/jruby/RubyKernel.java:1211:in `load'
org/jruby/RubyBasicObject.java:2620:in `instance_exec'
org/jruby/RubyArray.java:1985:in `each'
                                                                                             
2)
Enumerator::Product#initialize_copy replaces content of the receiver with content of the other object FAILED
Expected [[true], [false]] == [[1, :a], [1, :b], [2, :a], [2, :b]]
to be truthy but was false
/Users/headius/work/jruby/spec/ruby/core/enumerator/product/initialize_copy_spec.rb:10:in `block in <main>'
org/jruby/RubyBasicObject.java:2620:in `instance_exec'
org/jruby/RubyArray.java:4912:in `all?'
org/jruby/RubyArray.java:1985:in `each'
/Users/headius/work/jruby/spec/ruby/core/enumerator/product/initialize_copy_spec.rb:4:in `block in <main>'
/Users/headius/work/jruby/spec/ruby/core/enumerator/product/initialize_copy_spec.rb:3:in `<main>'
org/jruby/RubyKernel.java:1211:in `load'
org/jruby/RubyBasicObject.java:2620:in `instance_exec'
org/jruby/RubyArray.java:1985:in `each'
                                                                                             
3)
Enumerator::Product#initialize_copy is a private method FAILED
Expected Enumerator::Product to have private instance method 'initialize_copy'
but it does not
/Users/headius/work/jruby/spec/ruby/core/enumerator/product/initialize_copy_spec.rb:21:in `block in <main>'
org/jruby/RubyBasicObject.java:2620:in `instance_exec'
org/jruby/RubyArray.java:4912:in `all?'
org/jruby/RubyArray.java:1985:in `each'
/Users/headius/work/jruby/spec/ruby/core/enumerator/product/initialize_copy_spec.rb:4:in `block in <main>'
/Users/headius/work/jruby/spec/ruby/core/enumerator/product/initialize_copy_spec.rb:3:in `<main>'
org/jruby/RubyKernel.java:1211:in `load'
org/jruby/RubyBasicObject.java:2620:in `instance_exec'
org/jruby/RubyArray.java:1985:in `each'
                                                                                             
4)
Enumerator::Product#initialize_copy raises ArgumentError if the argument is not initialized yet FAILED
Expected ArgumentError (uninitialized product)
but no exception was raised (#<Enumerator::Product: nil:> was returned)
/Users/headius/work/jruby/spec/ruby/core/enumerator/product/initialize_copy_spec.rb:51:in `block in <main>'
org/jruby/RubyBasicObject.java:2620:in `instance_exec'
org/jruby/RubyArray.java:4912:in `all?'
org/jruby/RubyArray.java:1985:in `each'
/Users/headius/work/jruby/spec/ruby/core/enumerator/product/initialize_copy_spec.rb:4:in `block in <main>'
/Users/headius/work/jruby/spec/ruby/core/enumerator/product/initialize_copy_spec.rb:3:in `<main>'
org/jruby/RubyKernel.java:1211:in `load'
org/jruby/RubyBasicObject.java:2620:in `instance_exec'
org/jruby/RubyArray.java:1985:in `each'
                                                                                             
5)
Enumerator::Product#initialize returns self FAILED
Expected [] to be identical to #<Enumerator::Product: nil:>
/Users/headius/work/jruby/spec/ruby/core/enumerator/product/initialize_spec.rb:14:in `block in <main>'
org/jruby/RubyBasicObject.java:2620:in `instance_exec'
org/jruby/RubyArray.java:4912:in `all?'
org/jruby/RubyArray.java:1985:in `each'
/Users/headius/work/jruby/spec/ruby/core/enumerator/product/initialize_spec.rb:4:in `block in <main>'
/Users/headius/work/jruby/spec/ruby/core/enumerator/product/initialize_spec.rb:3:in `<main>'
org/jruby/RubyKernel.java:1211:in `load'
org/jruby/RubyBasicObject.java:2620:in `instance_exec'
org/jruby/RubyArray.java:1985:in `each'
                                                                                             
6)
Enumerator::Product#initialize accepts many arguments FAILED
Expected [0..1, 2..3, 4..5] to be identical to #<Enumerator::Product: nil:>
/Users/headius/work/jruby/spec/ruby/core/enumerator/product/initialize_spec.rb:18:in `block in <main>'
org/jruby/RubyBasicObject.java:2620:in `instance_exec'
org/jruby/RubyArray.java:4912:in `all?'
org/jruby/RubyArray.java:1985:in `each'
/Users/headius/work/jruby/spec/ruby/core/enumerator/product/initialize_spec.rb:4:in `block in <main>'
/Users/headius/work/jruby/spec/ruby/core/enumerator/product/initialize_spec.rb:3:in `<main>'
org/jruby/RubyKernel.java:1211:in `load'
org/jruby/RubyBasicObject.java:2620:in `instance_exec'
org/jruby/RubyArray.java:1985:in `each'
                                                                                             
7)
Enumerator::Product#initialize accepts arguments that are not Enumerable nor responding to :each_entry FAILED
Expected [#<Object:0x731ab49b>] to be identical to #<Enumerator::Product: nil:>
/Users/headius/work/jruby/spec/ruby/core/enumerator/product/initialize_spec.rb:22:in `block in <main>'
org/jruby/RubyBasicObject.java:2620:in `instance_exec'
org/jruby/RubyArray.java:4912:in `all?'
org/jruby/RubyArray.java:1985:in `each'
/Users/headius/work/jruby/spec/ruby/core/enumerator/product/initialize_spec.rb:4:in `block in <main>'
/Users/headius/work/jruby/spec/ruby/core/enumerator/product/initialize_spec.rb:3:in `<main>'
org/jruby/RubyKernel.java:1211:in `load'
org/jruby/RubyBasicObject.java:2620:in `instance_exec'
org/jruby/RubyArray.java:1985:in `each'
                                                                                             
8)
Enumerator::Product#inspect returns a String including enumerators FAILED
Expected "#<Enumerator::Product: nil:>" == "#<Enumerator::Product: [[1, 2], [:a, :b]]>"
to be truthy but was false
/Users/headius/work/jruby/spec/ruby/core/enumerator/product/inspect_spec.rb:7:in `block in <main>'
org/jruby/RubyBasicObject.java:2620:in `instance_exec'
org/jruby/RubyArray.java:4912:in `all?'
org/jruby/RubyArray.java:1985:in `each'
/Users/headius/work/jruby/spec/ruby/core/enumerator/product/inspect_spec.rb:4:in `block in <main>'
/Users/headius/work/jruby/spec/ruby/core/enumerator/product/inspect_spec.rb:3:in `<main>'
org/jruby/RubyKernel.java:1211:in `load'
org/jruby/RubyBasicObject.java:2620:in `instance_exec'
org/jruby/RubyArray.java:1985:in `each'
                                                                                             
9)
Enumerator::Product#inspect represents a recursive element with '[...]' FAILED
Expected "#<Enumerator::Product: nil:>" == "#<Enumerator::Product: [[1, 2, #<Enumerator::Product: ...>]]>"
to be truthy but was false
/Users/headius/work/jruby/spec/ruby/core/enumerator/product/inspect_spec.rb:15:in `block in <main>'
org/jruby/RubyBasicObject.java:2620:in `instance_exec'
org/jruby/RubyArray.java:4912:in `all?'
org/jruby/RubyArray.java:1985:in `each'
/Users/headius/work/jruby/spec/ruby/core/enumerator/product/inspect_spec.rb:4:in `block in <main>'
/Users/headius/work/jruby/spec/ruby/core/enumerator/product/inspect_spec.rb:3:in `<main>'
org/jruby/RubyKernel.java:1211:in `load'
org/jruby/RubyBasicObject.java:2620:in `instance_exec'
org/jruby/RubyArray.java:1985:in `each'
                                                                                             
10)
Enumerator::Product#inspect returns a not initialized representation if #initialized is not called yet FAILED
Expected "#<Enumerator::Product: nil:>" == "#<Enumerator::Product: uninitialized>"
to be truthy but was false
/Users/headius/work/jruby/spec/ruby/core/enumerator/product/inspect_spec.rb:19:in `block in <main>'
org/jruby/RubyBasicObject.java:2620:in `instance_exec'
org/jruby/RubyArray.java:4912:in `all?'
org/jruby/RubyArray.java:1985:in `each'
/Users/headius/work/jruby/spec/ruby/core/enumerator/product/inspect_spec.rb:4:in `block in <main>'
/Users/headius/work/jruby/spec/ruby/core/enumerator/product/inspect_spec.rb:3:in `<main>'
org/jruby/RubyKernel.java:1211:in `load'
org/jruby/RubyBasicObject.java:2620:in `instance_exec'
org/jruby/RubyArray.java:1985:in `each'

Copy link
Owner

@marcandre marcandre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theses changes are great, thank you so much, except the one with -infinity.

lib/backports/3.2.0/enumerator/product.rb Outdated Show resolved Hide resolved
lib/backports/3.2.0/enumerator/product.rb Outdated Show resolved Hide resolved
@marcandre
Copy link
Owner

This PR made me realize there's a bug in Ruby, and missing specs. Feel free to address it now or I can do it later.
https://bugs.ruby-lang.org/issues/20325

* Size error cases
* Enumerator.product rejects kwargs by name
* Product#rewind rewinds in "direct order", not reverse
@headius
Copy link
Contributor Author

headius commented Mar 5, 2024

I re-pushed with some tweaks to the size checks. I did not make any changes related to Infinity so I'll leave that up to you to debate on the issue.

Let's not go out of our way to return senseless results.
See ruby/spec#1140
@marcandre marcandre merged commit 83904f5 into marcandre:master Mar 5, 2024
10 of 12 checks passed
@marcandre
Copy link
Owner

Merged, thank you again for this PR, much appreciated.

I've also fixed the case 0 * Infinity in a separate PR.

Released as 3.25.0 (along with other features I had forgotten to release!)

@headius headius deleted the spec_fixes branch March 5, 2024 22:15
headius added a commit to jruby/jruby that referenced this pull request Mar 5, 2024
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.

None yet

2 participants