Iterator-Flex

 view release on metacpan or  search on metacpan

t/lib/MyTest/Utils.pm  view on Meta::CPAN

package MyTest::Utils;

use Test2::V0;
use Test2::API qw[ context ];

use Exporter 'import';

our @EXPORT_OK = qw( drain );

sub drain {
    my ( $iter, $max, $sentinel ) = @_;

    my $cnt = 0;
    eval {
        if ( defined $sentinel ) {
            1 while $sentinel != <$iter> && ++$cnt < $max + 1;
        }
        else {
            1 while defined <$iter> && ++$cnt < $max + 1;
        }
    };

    my $err = $@;

    my $ctx = context();

    is( $cnt, $max, 'not enough or too few iterations' );

    $ctx->release;

    die $@ if $@;
}

1;



( run in 0.584 second using v1.01-cache-2.11-cpan-71847e10f99 )