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

Refcount assertions #943

Open
leonerd opened this issue Aug 30, 2022 · 2 comments
Open

Refcount assertions #943

leonerd opened this issue Aug 30, 2022 · 2 comments

Comments

@leonerd
Copy link
Contributor

leonerd commented Aug 30, 2022

It'd be great if there were some test assertions for refcounts. A copy of those in Test::Refcount would be lovely:

{
  my $arr = [];
  is_oneref( $arr, "Array has one reference initially" );

  my $acopy = $arr;
  is_refcount( $arr, 2, "Array has two references now" );

  undef $acopy;
  is_oneref( $arr, "Array is back to one reference now" );
}

For docs you can just copy the ones out of Test::Refcount if required:

=head2 is_refcount

  is_refcount( $object, $count, $name )

Test that $object has $count references to it.

=head2 is_oneref

  is_oneref( $object, $name )

Assert that the $object has only 1 reference to it.

=cut
@leonerd
Copy link
Contributor Author

leonerd commented Aug 30, 2022

For an extra superspecial bonus I'd love it to also have the automatic integration with Devel::MAT::Dumper - you can just steal this code:

https://metacpan.org/dist/Test-Refcount/source/lib/Test/Refcount.pm#L121-132

@wolfsage
Copy link
Contributor

https://github.com/wolfsage/scratchpg has a conversion of the .pm file and one of the tests to show how it could be done. I could maybe do more later to make it into a Test2::Suite addon...

@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

2 participants