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 => 10;
13
14use Carp::Assert::More;
15
16use Test::Exception;
17
18my $FAILED = qr/Assertion failed/;
19
20# {} is a hashref
21lives_ok( sub { assert_hashref_nonempty( { foo => 'bar' } ) } );
22throws_ok( sub { assert_hashref_nonempty( {} ) }, $FAILED );
23
24# A ref to a hash with stuff in it is a hashref.
25my %hash = ( foo => 'foo', bar => 'bar' );
26lives_ok( sub { assert_hashref_nonempty( \%hash ) } );
27
28my %hash_empty;
29throws_ok( sub { assert_hashref_nonempty( \%hash_empty ) }, $FAILED );
30
31# 3 is not a hashref.
32throws_ok( sub { assert_hashref_nonempty( 3 ) }, $FAILED );
33
34# A ref to 3 is not a hashref.
35throws_ok( sub { assert_hashref_nonempty( \3 ) }, $FAILED );
36
37# [] is not a hashref
38throws_ok( sub { assert_hashref_nonempty( [] ) }, $FAILED );
39
40# sub {} is not a hashref
41my $coderef = sub {};
42throws_ok( sub { assert_hashref_nonempty( $coderef ) }, $FAILED );
43
44# Foo->new->isa("HASH") returns true, so do we
45throws_ok( sub { assert_hashref_nonempty( Foo->new ) }, $FAILED );
46
47lives_ok( sub { assert_hashref_nonempty( Foo->new( foo => 'bar' ) ) } );
48
49exit 0;
50