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

is_refcount() doesn't support check objects #938

Open
leonerd opened this issue Mar 22, 2023 · 3 comments
Open

is_refcount() doesn't support check objects #938

leonerd opened this issue Mar 22, 2023 · 3 comments

Comments

@leonerd
Copy link
Contributor

leonerd commented Mar 22, 2023

It appears to be using plain numerical == comparison.

   is_refcount( $cb, Test2::Tools::Compare::validator( sub { $_ > 1 } ),
      '$cb has refcount > 1 captured by followed_by callback' );

causes:

# Failed test '$cb has refcount > 1 captured by followed_by callback'
# at ./t/06followed_by.pl line 29.
#   expected Test2::Compare::Custom=HASH(0x55604b89b340) references, found 2

It'd be handy to support proper use of check objects - especially when combined with Test-More/Test2-Suite#258 - as this would permit

is_refcount( $cb, number_gt(1), '$cb has refcount > 1 captured by followed_by callback' );
@exodist
Copy link
Member

exodist commented Apr 28, 2023

The idea here is that you would use is or like for that:

is(get_ref_count($thing), 2);
is(get_ref_count($thing), greater_than(2));

Adding more tools that emulate is() makes little sense. Though under the hood you could wrap the is() code in refcount_is() to support refcount_is($thing, $check) that opens the door for checking that the refcount is a hash or has a deeply nested structure.

@exodist
Copy link
Member

exodist commented Apr 28, 2023

We talked in person and decided on this interface:

is($thing, refcnt(5), "refcount is 5");
is($thing, refcnt(5,10), "refcount is between 5 and 10");
is($thing, refcnt($check), "refcount  matches the specified check");

refcnt() is not necessarily the name to use, but similar.

@rabbiveesh
Copy link

wouldn't you want to put that refcnt check as a prop inside of a meta check? Meaning

is $thing, meta {
  prop refcount => $check;
}, 'refcount matches the check'

@exodist exodist transferred this issue from Test-More/Test2-Suite Aug 4, 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

No branches or pull requests

3 participants