Skip to content

Introduce RaaP for testing of signature - #1810

Merged
soutaro merged 3 commits into
ruby:masterfrom
ksss:set-with-raap
May 29, 2024
Merged

soutaro merged 3 commits into
ruby:masterfrom
ksss:set-with-raap

Conversation

@ksss

@ksss ksss commented Apr 23, 2024

Copy link
Copy Markdown
Collaborator

Problem

Currently, signature testing is conducted by rbs/unit_test.
However, there are the following issues:

  • Many methods exist that have not been tested.
  • There is a pattern that has not been tested.
  • It takes time to cover the pattern.

Solution: RaaP

raap is a testing tool for RBS signature.
RaaP can materialize objects and execute methods as long as there is an RBS signature, and it can verify whether the return type matches.

The effectiveness of RaaP can be explained by this PR.

Take Set as an example

This PR covers Set.
Many of the Set signatures have not been tested and RaaP has been able to find some errors.
The ability to verify many test cases without writing test code is one of the advantages of using RaaP.

Comment thread core/set.rbs Outdated
# has been modified while an element in the set.
#
class Set[unchecked out A]
class Set[unchecked out A < Object]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does Set not support BasicObjects, or does RaaP not support them?

Comment thread core/set.rbs Outdated
# has been modified while an element in the set.
#
class Set[unchecked out A]
class Set[unchecked out A < Object]

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Set#initialize use #hash, and Set#flatten use #is_a?.
These are not so much interfaces, but rather it seems that BasicObject has simply not been considered as an element.

Set.new([BasicObject.new])
#=> undefined method `hash' for #<BasicObject:0x000000013b09d350> (NoMethodError)

https://github.com/ruby/set/blob/4e95d55294f0e577529ca8702c4d2c3ae90247e7/lib/set.rb#L358

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One of us should rather send a PR to support BasicObject.
Else it’d be a sign that Set isn’t stable enough for the highly-requested Set literal.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Are you suggesting that we should make modifications to support BasicObject in ruby/set as much as possible?
I do not have the motivation to do so myself, but it would certainly be a contribution to the community.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

FWIW… neither does Array#inspect

[BasicObject.new].inspect #=! undefined method `inspect' for an instance of BasicObject (NoMethodError)

For this situation, IIRC @sampersand had the idea of adding a RBS syntax for additional fine-grained bounds on the method level, e.g.,

class Set[unchecked out E] # & class Array[unchecked out E]
  …
  def inspect: [E < _Inspect] () -> String
  …
end

Comment thread core/set.rbs Resolved
Comment thread core/set.rbs Resolved
Comment thread core/set.rbs Resolved
Comment thread core/set.rbs Resolved
Comment thread core/set.rbs
# Set[1, 2, 3].intersect? [3, 4] #=> true
#
def intersect?: (_Each[A]) -> bool
def intersect?: (Set[A] | Enumerable[A]) -> bool

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Comment thread core/set.rbs
def subset?: (self) -> bool

def proper_subst?: (self) -> bool
def proper_subset?: (self) -> bool

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

typo

Comment thread core/set.rbs Resolved
Comment thread core/set.rbs Resolved
Comment thread test/raap.txt
# By prefixing with `!`, you can skip testing a method.
# Lines beginning with `#` are comments.

Set[Integer]

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We can add more testing.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ideally, RaaP should be able to automatically test with the given bound (Object at this writing), and maybe also a variety of other sample classes.
Then, this file would simply be

Suggested change
Set[Integer]
Set

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The minimal condition to satisfy the upper bound is Object, but using Object in Set makes it harder to visually interpret the reproducible code, so I use Integer instead.

@ksss
ksss force-pushed the set-with-raap branch 2 times, most recently from 01d8bd2 to edd4ef5 Compare April 26, 2024 01:46
@ksss
ksss marked this pull request as ready for review April 26, 2024 01:54
@ksss
ksss force-pushed the set-with-raap branch from edd4ef5 to 8def573 Compare May 8, 2024 10:10
@ksss

ksss commented May 8, 2024

Copy link
Copy Markdown
Collaborator Author

I removed Object & and made adjustments to minimize changes.

@ParadoxV5

ParadoxV5 commented May 8, 2024 •

Copy link
Copy Markdown
Contributor

I removed Object & and made adjustments to minimize changes.

🆙. Non critical changes to the RBS are better scoped for another PR (or after some adjustments to the .rb itself)

@soutaro
soutaro enabled auto-merge May 28, 2024 08:11
@soutaro
soutaro added this pull request to the merge queue May 29, 2024
Merged via the queue into ruby:master with commit 1d42c1c May 29, 2024
@ksss
ksss deleted the set-with-raap branch May 29, 2024 01:52
@ksss ksss mentioned this pull request May 29, 2024
@soutaro soutaro added this to the RBS 3.5 milestone Jun 6, 2024
@soutaro soutaro added the Released PRs already included in the released version label Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Released PRs already included in the released version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants