Repository navigation
Introduce RaaP for testing of signature - #1810
Conversation
| # has been modified while an element in the set. | ||
| # | ||
| class Set[unchecked out A] | ||
| class Set[unchecked out A < Object] |
There was a problem hiding this comment.
Does Set not support BasicObjects, or does RaaP not support them?
| # has been modified while an element in the set. | ||
| # | ||
| class Set[unchecked out A] | ||
| class Set[unchecked out A < Object] |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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| # Set[1, 2, 3].intersect? [3, 4] #=> true | ||
| # | ||
| def intersect?: (_Each[A]) -> bool | ||
| def intersect?: (Set[A] | Enumerable[A]) -> bool |
There was a problem hiding this comment.
| def subset?: (self) -> bool | ||
|
|
||
| def proper_subst?: (self) -> bool | ||
| def proper_subset?: (self) -> bool |
| # By prefixing with `!`, you can skip testing a method. | ||
| # Lines beginning with `#` are comments. | ||
|
|
||
| Set[Integer] |
There was a problem hiding this comment.
We can add more testing.
There was a problem hiding this comment.
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
| Set[Integer] | |
| Set |
There was a problem hiding this comment.
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.
01d8bd2 to
edd4ef5
Compare
|
I removed |
🆙. Non critical changes to the RBS are better scoped for another PR (or after some adjustments to the |
Problem
Currently, signature testing is conducted by rbs/unit_test.
However, there are the following issues:
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
Setas an exampleThis PR covers
Set.Many of the
Setsignatures 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.