1#!perl -Tw 2 3package Foo; 4 5sub new { my $class = shift; return bless [@_], $class; } 6 7package main; 8 9use warnings; 10use strict; 11 12use Test::More tests => 11; 13 14use Carp::Assert::More; 15 16use Test::Exception; 17 18my $FAILED = qr/Assertion failed/; 19 20# {} is not an arrayref. 21throws_ok( sub { assert_arrayref_nonempty( {} ) }, $FAILED ); 22 23# A ref to a hash with stuff in it is not an arrayref. 24my $ref = { foo => 'foo', bar => 'bar' }; 25throws_ok( sub { assert_arrayref_nonempty( $ref ) }, $FAILED ); 26 27# 3 is not an arrayref. 28throws_ok( sub { assert_arrayref_nonempty( 3 ) }, $FAILED ); 29 30# [] is a nonempty arrayref. 31lives_ok( sub { assert_arrayref_nonempty( [ 3 ] ) } ); 32lives_ok( sub { assert_arrayref_nonempty( [ undef ] ) } ); 33 34# [] is an empty arrayref. 35throws_ok( sub { assert_arrayref_nonempty( [] ) }, $FAILED ); 36 37# A ref to a list with stuff in it is an arrayref. 38my @ary = ('foo', 'bar', 'baaz'); 39lives_ok( sub { assert_arrayref_nonempty( \@ary ) } ); 40 41my @empty_ary = (); 42throws_ok( sub { assert_arrayref_nonempty( \@empty_ary ) }, $FAILED ); 43 44# A coderef is not an arrayref. 45my $coderef = sub {}; 46throws_ok( sub { assert_arrayref_nonempty( $coderef ) }, $FAILED ); 47 48# Foo->new->isa("ARRAY") returns true, but check emptiness. 49lives_ok( sub { assert_arrayref_nonempty( Foo->new( 14 ) ) } ); 50throws_ok( sub { assert_arrayref_nonempty( Foo->new ) }, $FAILED ); 51 52exit 0; 53