Carp-Assert-More-1.14/0000755000076400007640000000000012044251705013143 5ustar andyandyCarp-Assert-More-1.14/MANIFEST0000644000076400007640000000140212044251705014271 0ustar andyandyChanges INSTALL MANIFEST Makefile.PL More.pm README t/00-load.t t/assert_defined.t t/assert_exists.t t/assert_fail.t t/assert_hashref.t t/assert_in.t t/assert_integer.t t/assert_is.t t/assert_isa.t t/assert_isnt.t t/assert_lacks.t t/assert_like.t t/assert_listref.t t/assert_negative_integer.t t/assert_negative.t t/assert_nonblank.t t/assert_nonempty.t t/assert_nonnegative_integer.t t/assert_nonnegative.t t/assert_nonref.t t/assert_nonzero_integer.t t/assert_nonzero.t t/assert_positive_integer.t t/assert_positive.t t/assert_undefined.t t/assert_unlike.t t/pod.t t/pod-coverage.t t/test-coverage.t META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) Carp-Assert-More-1.14/Makefile.PL0000644000076400007640000000252412044235602015116 0ustar andyandypackage main; use 5.006001; use strict; use warnings; use ExtUtils::MakeMaker; my %parms = ( NAME => 'Carp::Assert::More', VERSION_FROM => 'More.pm', # finds $VERSION PM => { 'More.pm' => '$(INST_LIB)/Carp/Assert/More.pm', }, PREREQ_PM => { Carp => 0, 'Carp::Assert' => 0, 'Scalar::Util' => 0, 'Test::Exception' => 0, 'Test::More' => 0.18, }, dist => { COMPRESS => 'gzip -9', SUFFIX => '.gz', DIST_DEFAULT => 'all tardist', }, ); if ( $ExtUtils::MakeMaker::VERSION =~ /^\d\.\d\d$/ and $ExtUtils::MakeMaker::VERSION > 6.30 ) { $parms{LICENSE} = 'artistic_2'; } if ( $ExtUtils::MakeMaker::VERSION ge '6.46' ) { $parms{META_MERGE} = { resources => { bugtracker => 'https://rt.cpan.org/Public/Dist/Display.html?Name=Carp-Assert-More', repository => 'http://github.com/petdance/carp-assert-more/tree/master', license => 'http://www.opensource.org/licenses/artistic-license-2.0.php', } }; } WriteMakefile( %parms ); package MY; sub MY::postamble { my $postamble = <<'MAKE_FRAG'; .PHONY: critic critic: perlcritic -1 -q -profile perlcriticrc More.pm t/*.t MAKE_FRAG return $postamble; } 1; Carp-Assert-More-1.14/README0000644000076400007640000000036212044226333014023 0ustar andyandy# Carp::Assert::More Carp::Assert::More is a set of handy assertion functions for Perl. For example, instead of writing assert( $foo ne '', '$foo cannot be blank' ); you can write assert_nonblank( $foo, '$foo cannot be blank' ); Carp-Assert-More-1.14/t/0000755000076400007640000000000012044251704013405 5ustar andyandyCarp-Assert-More-1.14/t/assert_negative_integer.t0000644000076400007640000000114710323762253020501 0ustar andyandy#!perl -Tw use warnings; use strict; use Test::More tests=>8; BEGIN { use_ok( 'Carp::Assert::More' ); } use constant PASS => 1; use constant FAIL => 2; my @cases = ( [ 5, FAIL ], [ 0, FAIL ], [ 0.4, FAIL ], [ -10, PASS ], [ -97.9, FAIL ], [ "dog", FAIL ], [ "14.", FAIL ], ); for my $case ( @cases ) { my ($val,$status) = @$case; my $desc = "Checking \"$val\""; eval { assert_negative_integer( $val ) }; if ( $status eq FAIL ) { like( $@, qr/Assertion.+failed/, $desc ); } else { is( $@, "", $desc ); } } Carp-Assert-More-1.14/t/assert_fail.t0000644000076400007640000000031112044250723016061 0ustar andyandy#!perl -Tw use warnings; use strict; use Test::More tests=>2; BEGIN { use_ok( 'Carp::Assert::More' ); } eval { assert_fail( "Everything is broken!" ); }; like( $@, qr/Everything is broken!/ ); Carp-Assert-More-1.14/t/assert_nonnegative.t0000644000076400007640000000111210323762253017467 0ustar andyandy#!perl -Tw use warnings; use strict; use Test::More tests=>7; BEGIN { use_ok( 'Carp::Assert::More' ); } use constant PASS => 1; use constant FAIL => 2; my @cases = ( [ 5, PASS ], [ 0, PASS ], [ 0.4, PASS ], [ -10, FAIL ], [ "dog", PASS ], [ "14.", PASS ], ); for my $case ( @cases ) { my ($val,$status) = @$case; my $desc = "Checking \"$val\""; eval { assert_nonnegative( $val ) }; if ( $status eq FAIL ) { like( $@, qr/Assertion.+failed/, $desc ); } else { is( $@, "", $desc ); } } Carp-Assert-More-1.14/t/assert_lacks.t0000644000076400007640000000112612044251310016241 0ustar andyandy#!perl -Tw use warnings; use strict; use Test::More tests => 6; use Carp::Assert::More; use Test::Exception; my %foo = ( name => 'Andy Lester', phone => '578-3338', wango => undef, ); lives_ok( sub { assert_lacks( \%foo, 'Name' ) } ); throws_ok( sub { assert_lacks( \%foo, 'name' ); }, qr/Assert.+failed/ ); lives_ok( sub { assert_lacks( \%foo, [qw( Wango )] ); } ); lives_ok( sub { assert_lacks( \%foo, [qw( Wango Tango )] ); } ); throws_ok( sub { assert_lacks( \%foo, [qw( Wango Tango name )] ); }, qr/Assertion.+failed/ ); lives_ok( sub { assert_lacks( \%foo, [qw()] ) } ); Carp-Assert-More-1.14/t/assert_isa.t0000644000076400007640000000130112044251015015715 0ustar andyandy#!perl -Tw use warnings; use strict; use Test::More tests => 4; use Carp::Assert::More; use IO::File; # just for creating objects local $@; $@ = ''; eval { my $fh = new IO::File; assert_isa( $fh, 'IO::File', 'Created an IO::File object' ); assert_isa( $fh, 'GLOB', 'Created an IO::File object, which is a GLOB' ); }; is( $@, '' ); eval { my $random = 2112; assert_isa( $random, 'IO::File', 'Created an IO::File object' ); }; like( $@, qr/Assertion.*failed/ ); eval { my @array; assert_isa( \@array, 'HASH', 'An array is not a hash' ); }; like( $@, qr/Assertion.*failed/ ); eval { my %hash; assert_isa( \%hash, 'HASH', 'Created a hash' ); }; is( $@, '' ); Carp-Assert-More-1.14/t/assert_nonempty.t0000644000076400007640000000242612044234373017033 0ustar andyandy#!perl -Tw use warnings; use strict; use Test::More tests => 12; use Test::Exception; use Carp::Assert::More; use constant PASS => 1; use constant FAIL => 0; my @cases = ( [ 0 => FAIL ], [ 'foo' => FAIL ], [ undef => FAIL ], [ {} => FAIL ], [ [] => FAIL ], [ {foo=>1} => PASS ], [ [1,2,3] => PASS ], ); for my $case ( @cases ) { my ($val,$expected_status) = @$case; eval { assert_nonempty( $val ) }; $val = "undef" if !defined($val); my $desc = "Checking \"$val\""; if ( $expected_status eq FAIL ) { like( $@, qr/Assertion.+failed/, $desc ); } else { is( $@, "", $desc ); } } throws_ok( sub { assert_nonempty( 27 ) }, qr/Not an array or hash reference/ ); BLESSED_ARRAY: { my $array_object = bless( [], 'WackyPackage' ); throws_ok( sub { assert_nonempty( $array_object, 'Flooble' ) }, qr/\QAssertion (Flooble) failed!/ ); push( @{$array_object}, 14 ); lives_ok( sub { assert_nonempty( $array_object ) } ); } BLESSED_HASH: { my $hash_object = bless( {}, 'WackyPackage' ); throws_ok( sub { assert_nonempty( $hash_object, 'Flargle' ) }, qr/\QAssertion (Flargle) failed!/ ); $hash_object->{foo} = 14; lives_ok( sub { assert_nonempty( $hash_object ) } ); } Carp-Assert-More-1.14/t/assert_nonzero.t0000644000076400007640000000110610323762253016647 0ustar andyandy#!perl -Tw use warnings; use strict; use Test::More tests=>7; BEGIN { use_ok( 'Carp::Assert::More' ); } use constant PASS => 1; use constant FAIL => 2; my @cases = ( [ 5, PASS ], [ 0, FAIL ], [ 0.4, PASS ], [ -10, PASS ], [ "dog", FAIL ], [ "14.", PASS ], ); for my $case ( @cases ) { my ($val,$status) = @$case; my $desc = "Checking \"$val\""; eval { assert_nonzero( $val ) }; if ( $status eq FAIL ) { like( $@, qr/Assertion.+failed/, $desc ); } else { is( $@, "", $desc ); } } Carp-Assert-More-1.14/t/assert_unlike.t0000644000076400007640000000155512044244643016454 0ustar andyandy#!/usr/bin/perl use warnings; use strict; use Test::More tests => 6; use Test::Exception; use Carp::Assert::More; throws_ok( sub { assert_unlike( 'unlikely', qr/like/, 'Wango' ); }, qr/\QAssertion (Wango) failed!/, 'Testing simple matching' ); throws_ok( sub { assert_unlike( 'tempest', qr/te.*st/, 'Tango' ); }, qr/\QAssertion (Tango) failed!/, 'Testing simple matching' ); lives_ok( sub { assert_unlike( 'passing', qr/fa.*il/, 'Flargle' ); }, 'Simple non-matching' ); lives_ok( sub { assert_unlike( undef, qr/anything/ ); }, 'undef string is always unlike' ); throws_ok( sub { assert_unlike( 'Blah blah', undef, 'Bingo' ); }, qr/\QAssertion (Bingo) failed!/, 'undef regex always fails' ); throws_ok( sub { my $string = 'Blah blah'; my $ref = \$string; assert_unlike( $string, $ref, 'Dingo' ); }, qr/\QAssertion (Dingo) failed/, 'bad reference fails' ); Carp-Assert-More-1.14/t/pod-coverage.t0000644000076400007640000000040312044235775016154 0ustar andyandy#!perl -T use strict; use warnings; use Test::More; my $module = 'Test::Pod::Coverage 1.04'; if ( eval "use $module; 1;" ) { ## no critic (ProhibitStringyEval) all_pod_coverage_ok(); } else { plan skip_all => "$module required for testing POD"; } Carp-Assert-More-1.14/t/assert_like.t0000644000076400007640000000150612044251312016074 0ustar andyandy#!/usr/bin/perl use warnings; use strict; use Test::More tests => 7; use Test::Exception; use Carp::Assert::More; lives_ok( sub { assert_like('unlikely', qr/like/ ); } ); lives_ok( sub { assert_like( 'tempest', qr/te.*st/ ); } ); lives_ok( sub { assert_like( 'quality inn', qr/qu.*inn/ ); } ); throws_ok( sub { assert_like( 'passing', qr/fa.*il/, 'Flargle' ); }, qr/\QAssertion (Flargle) failed!/ ); throws_ok( sub { assert_like( undef, qr/anything/, 'Bongo' ); }, qr/\QAssertion (Bongo) failed!/, 'undef string always fails' ); throws_ok( sub { assert_like( 'Blah blah', undef, 'Bingo' ); }, qr/\QAssertion (Bingo) failed!/, 'undef regex always fails' ); throws_ok( sub { my $string = 'Blah blah'; my $ref = \$string; assert_like( $string, $ref, 'Dingo' ); }, qr/\QAssertion (Dingo) failed/, 'bad reference fails' ); Carp-Assert-More-1.14/t/assert_nonblank.t0000644000076400007640000000146412044230665016765 0ustar andyandy#!perl -Tw use warnings; use strict; use Test::More tests => 7; use Test::Exception; use Carp::Assert::More; lives_ok( sub { assert_nonblank( 3 ) } ); lives_ok( sub { assert_nonblank( 0 ) } ); throws_ok( sub { assert_nonblank( '' ) }, qr/Assertion failed!/, q{'' is blank, with no message} ); throws_ok( sub { assert_nonblank( '', 'flooble' ) }, qr/\QAssertion (flooble) failed!/, q{'' is blank, with message} ); throws_ok( sub { assert_nonblank( undef ) }, qr/Assertion failed!/, q{undef is blank, with no message} ); throws_ok( sub { assert_nonblank( undef, 'bargle' ) }, qr/\QAssertion (bargle) failed!/, q{undef is blank, with message} ); throws_ok( sub { my $scalar = "Blah blah"; my $ref = \$scalar; assert_nonblank( $ref, 'wango' ); }, qr/\QAssertion (wango) failed!/, 'Testing scalar ref' ); Carp-Assert-More-1.14/t/assert_hashref.t0000644000076400007640000000144712044250743016603 0ustar andyandy#!perl -Tw package Foo; sub new { my $class = shift; return bless {@_}, $class; } package main; use warnings; use strict; use Test::More tests => 6; use Carp::Assert::More; local $@; $@ = ''; # {} is a hashref eval { assert_hashref( {} ); }; is( $@, '' ); # a ref to a hash with stuff in it is a hashref my %hash = ( foo => 'foo', bar => 'bar' ); eval { assert_hashref( \%hash ); }; is( $@, '' ); # 3 is not a hashref eval { assert_hashref( 3 ); }; like( $@, qr/Assertion.*failed/ ); # [] is not a hashref eval { assert_hashref( [] ); }; like( $@, qr/Assertion.*failed/ ); # sub {} is not a hashref eval { assert_hashref( sub {} ); }; like( $@, qr/Assertion.*failed/ ); # Foo->new->isa("HASH") returns true, so do we eval { assert_hashref( Foo->new ); }; is( $@, '' ); Carp-Assert-More-1.14/t/00-load.t0000644000076400007640000000031512044227403014724 0ustar andyandy#!perl -Tw use Test::More tests => 1; use Carp::Assert::More; diag( "Testing Carp::Assert::More $Carp::Assert::More::VERSION, Test::More $Test::More::VERSION, Perl $], $^X" ); pass( 'Module loaded' ); Carp-Assert-More-1.14/t/assert_positive_integer.t0000644000076400007640000000114710323762253020541 0ustar andyandy#!perl -Tw use warnings; use strict; use Test::More tests=>8; BEGIN { use_ok( 'Carp::Assert::More' ); } use constant PASS => 1; use constant FAIL => 2; my @cases = ( [ 5, PASS ], [ 0, FAIL ], [ 0.4, FAIL ], [ -10, FAIL ], [ "dog", FAIL ], [ "14.", FAIL ], [ "14", PASS ], ); for my $case ( @cases ) { my ($val,$status) = @$case; my $desc = "Checking \"$val\""; eval { assert_positive_integer( $val ) }; if ( $status eq FAIL ) { like( $@, qr/Assertion.+failed/, $desc ); } else { is( $@, "", $desc ); } } Carp-Assert-More-1.14/t/assert_nonnegative_integer.t0000644000076400007640000000112210323762253021205 0ustar andyandy#!perl -Tw use warnings; use strict; use Test::More tests=>7; BEGIN { use_ok( 'Carp::Assert::More' ); } use constant PASS => 1; use constant FAIL => 2; my @cases = ( [ 5, PASS ], [ 0, PASS ], [ 0.4, FAIL ], [ -10, FAIL ], [ "dog", FAIL ], [ "14.", FAIL ], ); for my $case ( @cases ) { my ($val,$status) = @$case; my $desc = "Checking \"$val\""; eval { assert_nonnegative_integer( $val ) }; if ( $status eq FAIL ) { like( $@, qr/Assertion.+failed/, $desc ); } else { is( $@, "", $desc ); } } Carp-Assert-More-1.14/t/assert_negative.t0000644000076400007640000000110710323762253016760 0ustar andyandy#!perl -Tw use warnings; use strict; use Test::More tests=>7; BEGIN { use_ok( 'Carp::Assert::More' ); } use constant PASS => 1; use constant FAIL => 2; my @cases = ( [ 5, FAIL ], [ 0, FAIL ], [ 0.4, FAIL ], [ -10, PASS ], [ "dog", FAIL ], [ "14.", FAIL ], ); for my $case ( @cases ) { my ($val,$status) = @$case; my $desc = "Checking \"$val\""; eval { assert_negative( $val ) }; if ( $status eq FAIL ) { like( $@, qr/Assertion.+failed/, $desc ); } else { is( $@, "", $desc ); } } Carp-Assert-More-1.14/t/assert_in.t0000644000076400007640000000236312044251357015571 0ustar andyandy#!/usr/bin/perl use warnings; use strict; use Test::More tests => 9; use Carp::Assert::More; local $@; $@ = ''; # one element in arrayref eval { assert_in('one', [ 'one' ] ); }; is( $@, '' ); # separate string, two elements eval { my $string = 'B'; assert_in( $string, [ 'A', 'B' ] ); }; is( $@, '' ); # separate string and manual arrayref eval { my $string = 'delta'; my @array = ('alpha','beta','delta'); assert_in( $string, \@array ); }; is( $@, '' ); # separate string and arrayref eval { my $string = 'tres'; my $ref = [ 'uno', 'dos', 'tres', 'quatro' ]; assert_in( $string, $ref ); }; is( $@, '' ); # not found fails eval { assert_in( 'F', [ 'A', 'B', 'C', 'D', 'E' ] ); }; like( $@, qr/Assertion.*failed/ ); # undef string fa6yyils eval { assert_in( undef, [ 'fail' ] ); }; like( $@, qr/Assertion.*failed/ ); # empty array fails eval { assert_in( 'empty', [ ] ); }; like( $@, qr/Assertion.*failed/ ); # undef for the arrayref fails eval { my $string = 'zippo'; assert_in( $string, undef ); }; like( $@, qr/Assertion.*failed/ ); # A bad reference should also fail. eval { my $string = 'nil'; my $ref = \$string; assert_in( $string, $ref ); }; like( $@, qr/Assertion.*failed/ ); Carp-Assert-More-1.14/t/assert_integer.t0000644000076400007640000000121612044251500016602 0ustar andyandy#!perl -Tw use warnings; use strict; use Test::More tests => 6; use Carp::Assert::More; use Test::Exception; use constant PASS => 1; use constant FAIL => 2; my @cases = ( [ 5, PASS ], [ 0, PASS ], [ 0.4, FAIL ], [ -10, PASS ], [ 'dog', FAIL ], [ '14.', FAIL ], ); for my $case ( @cases ) { my ($val,$status) = @$case; my $desc = "Checking \"$val\""; eval { assert_integer( $val ) }; if ( $status eq FAIL ) { throws_ok( sub { assert_integer( $val ) }, qr/Assertion.+failed/, $desc ); } else { lives_ok( sub { assert_integer( $val ) }, $desc ); } } Carp-Assert-More-1.14/t/assert_nonref.t0000644000076400007640000000114710323762253016451 0ustar andyandy#!perl -Tw use warnings; use strict; use Test::More tests => 6; BEGIN { use_ok( 'Carp::Assert::More' ); } local $@; $@ = ''; # 3 is nonref eval { assert_nonref( 3 ); }; is( $@, '' ); # 0 is nonref eval { assert_nonref( 0 ); }; is( $@, '' ); # '' is nonref eval { assert_nonref( 0 ); }; is( $@, '' ); # undef is not a reference, but it also fails by my rules eval { assert_nonref( undef ); }; like( $@, qr/Assertion.*failed/ ); # A reference is not a non-reference eval { my $scalar = "Blah blah"; my $ref = \$scalar; assert_nonref( $ref ); }; like( $@, qr/Assertion.*failed/ ); Carp-Assert-More-1.14/t/assert_undefined.t0000644000076400007640000000076612044242743017130 0ustar andyandy#!perl -T use warnings; use strict; use Test::More tests => 4; use Carp::Assert::More; use Test::Exception; throws_ok( sub { assert_undefined( 3, 'Fleegle' ); }, qr/\QAssertion (Fleegle) failed!/, '3 is defined' ); throws_ok( sub { assert_undefined( 0, 'Drooper' ); }, qr/\QAssertion (Drooper) failed!/, '0 is defined' ); throws_ok( sub { assert_undefined( '', 'Snork' ); }, qr/\QAssertion (Snork) failed!/, 'blank is defined' ); lives_ok( sub { assert_undefined( undef ); }, '0 is undefined' ); Carp-Assert-More-1.14/t/test-coverage.t0000644000076400007640000000057112044244501016342 0ustar andyandy#!perl -Tw use Test::More tests => 26; use Carp::Assert::More; my @funcs = ( @Carp::Assert::More::EXPORT, @Carp::Assert::More::EXPORT_OK ); my %deduped; $deduped{$_}++ for @funcs; @funcs = sort keys %deduped; isnt( scalar @funcs, 0, 'There are no function names!' ); for my $func ( @funcs ) { my $filename = "t/$func.t"; ok( -e $filename, "$filename exists" ); } Carp-Assert-More-1.14/t/assert_exists.t0000644000076400007640000000136712044250717016504 0ustar andyandy#!perl -T use warnings; use strict; use Test::More tests=>8; BEGIN { use_ok( 'Carp::Assert::More' ); } my %foo = ( name => 'Andy Lester', phone => '578-3338', wango => undef, ); eval { assert_exists( \%foo, 'name' ); }; is( $@, '' ); eval { assert_exists( \%foo, 'wango' ); }; is( $@, '' ); eval { assert_exists( \%foo, 'Nonexistent' ); }; like( $@, qr/Assert.+failed/ ); eval { assert_exists( \%foo, [qw( name )] ); }; is( $@, '' ); eval { assert_exists( \%foo, [qw( name social-security-number )] ); }; like( $@, qr/Assertion.+failed/ ); eval { assert_exists( \%foo, [qw( name phone )] ); }; is( $@, '' ); eval { assert_exists( \%foo, ['name','Nonexistent'] ); }; like( $@, qr/Assert.+failed/ ); Carp-Assert-More-1.14/t/assert_listref.t0000644000076400007640000000170512044251324016624 0ustar andyandy#!perl -Tw package Foo; sub new { my $class = shift; return bless [@_], $class; } package main; use warnings; use strict; use Test::More tests => 7; use Carp::Assert::More; local $@; $@ = ''; # {} is not a listref eval { assert_listref( {} ); }; like( $@, qr/Assertion.*failed/ ); # a ref to a hash with stuff in it is not a listref my $ref = { foo => 'foo', bar => 'bar' }; eval { assert_listref( $ref ); }; like( $@, qr/Assertion.*failed/ ); # 3 is not a listref eval { assert_listref( 3 ); }; like( $@, qr/Assertion.*failed/ ); # [] is a listref eval { assert_listref( [] ); }; is( $@, '' ); # a ref to a list with stuff in it is a listref my @ary = ('foo', 'bar', 'baaz'); eval { assert_listref( \@ary ); }; is( $@, '' ); # sub {} is not a listref eval { assert_listref( sub {} ); }; like( $@, qr/Assertion.*failed/ ); # Foo->new->isa("ARRAY") returns true, so do we eval { assert_listref( Foo->new ); }; is( $@, '' ); Carp-Assert-More-1.14/t/assert_defined.t0000644000076400007640000000065512044250670016560 0ustar andyandy#!perl -T use warnings; use strict; use Test::More tests => 4; use Carp::Assert::More; use Test::Exception; lives_ok( sub { assert_defined( 3 ); }, '3 is defined' ); lives_ok( sub { assert_defined( 0 ); }, '0 is false but defined' ); lives_ok( sub { assert_defined( '' ); }, 'blank is false but defined' ); throws_ok( sub { assert_defined( undef, 'Flargle' ); }, qr/\QAssertion (Flargle) failed!/, 'undef is not defined' ); Carp-Assert-More-1.14/t/assert_nonzero_integer.t0000644000076400007640000000111610323762253020365 0ustar andyandy#!perl -Tw use warnings; use strict; use Test::More tests=>7; BEGIN { use_ok( 'Carp::Assert::More' ); } use constant PASS => 1; use constant FAIL => 2; my @cases = ( [ 5, PASS ], [ 0, FAIL ], [ 0.4, FAIL ], [ -10, PASS ], [ "dog", FAIL ], [ "14.", FAIL ], ); for my $case ( @cases ) { my ($val,$status) = @$case; my $desc = "Checking \"$val\""; eval { assert_nonzero_integer( $val ) }; if ( $status eq FAIL ) { like( $@, qr/Assertion.+failed/, $desc ); } else { is( $@, "", $desc ); } } Carp-Assert-More-1.14/t/pod.t0000644000076400007640000000036612044236014014356 0ustar andyandy#!perl -T use strict; use warnings; use Test::More; my $module = 'Test::Pod 1.14'; if ( eval "use $module; 1;" ) { ## no critic (ProhibitStringyEval) all_pod_files_ok(); } else { plan skip_all => "$module required for testing POD"; } Carp-Assert-More-1.14/t/assert_isnt.t0000644000076400007640000000134612044251076016136 0ustar andyandy#!perl -Tw use warnings; use strict; use Test::More tests => 8; use Carp::Assert::More; use Test::Exception; lives_ok { assert_isnt( 4, 3 ) } "4 is not 3"; lives_ok { assert_isnt( undef, "" ) } "Undef is not space"; lives_ok { assert_isnt( "", undef ) } "Space is not undef"; throws_ok { assert_isnt( undef, undef ) } qr/Assertion.+failed/, "Undef only matches undef"; throws_ok { assert_isnt( "a", "a" ) } qr/Assertion.+failed/, "a is a"; throws_ok { assert_isnt( 4, 4 ) } qr/Assertion.+failed/, "4 is 4"; throws_ok { assert_isnt( "", "" ) } qr/Assertion.+failed/, "space is space"; throws_ok { assert_isnt( "14", 14 ) } qr/Assertion.+failed/, "14 is 14 as strings"; Carp-Assert-More-1.14/t/assert_positive.t0000644000076400007640000000111312044250661017012 0ustar andyandy#!perl -Tw use warnings; use strict; use Test::More tests=>7; BEGIN { use_ok( 'Carp::Assert::More' ); } use constant PASS => 1; use constant FAIL => 2; my @cases = ( [ 5, PASS ], [ 0, FAIL ], [ 0.4, PASS ], [ -10, FAIL ], [ 'dog', FAIL ], [ '14.', PASS ], ); for my $case ( @cases ) { my ($val,$status) = @$case; my $desc = "Checking \"$val\""; eval { assert_positive( $val ) }; if ( $status eq FAIL ) { like( $@, qr/Assertion.+failed/, $desc ); } else { is( $@, '', $desc ); } } Carp-Assert-More-1.14/t/assert_is.t0000644000076400007640000000123712044251124015565 0ustar andyandy#!perl -Tw use warnings; use strict; use Test::More tests => 8; use Carp::Assert::More; use Test::Exception; throws_ok { assert_is( 4, 3 ) } qr/Assertion.*failed/, "4 is not 3"; throws_ok { assert_is( undef, "" ) } qr/Assertion.*failed/, "Undef is not space"; throws_ok { assert_is( "", undef ) } qr/Assertion.*failed/, "Space is not undef"; lives_ok { assert_is( undef, undef ) } "Undef only matches undef"; lives_ok { assert_is( "a", "a" ) } "a is a"; lives_ok { assert_is( 4, 4 ) } "4 is 4"; lives_ok { assert_is( "", "" ) } "space is space"; lives_ok { assert_is( "14", 14 ) } "14 is 14 as strings"; Carp-Assert-More-1.14/META.yml0000664000076400007640000000135712044251704014423 0ustar andyandy--- abstract: unknown author: - unknown build_requires: ExtUtils::MakeMaker: 0 configure_requires: ExtUtils::MakeMaker: 0 dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.112621' license: artistic_2 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Carp-Assert-More no_index: directory: - t - inc requires: Carp: 0 Carp::Assert: 0 Scalar::Util: 0 Test::Exception: 0 Test::More: 0.18 resources: bugtracker: https://rt.cpan.org/Public/Dist/Display.html?Name=Carp-Assert-More license: http://www.opensource.org/licenses/artistic-license-2.0.php repository: http://github.com/petdance/carp-assert-more/tree/master version: 1.14 Carp-Assert-More-1.14/META.json0000664000076400007640000000243512044251705014572 0ustar andyandy{ "abstract" : "unknown", "author" : [ "unknown" ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.112621", "license" : [ "artistic_2" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Carp-Assert-More", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : 0 } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : 0 } }, "runtime" : { "requires" : { "Carp" : 0, "Carp::Assert" : 0, "Scalar::Util" : 0, "Test::Exception" : 0, "Test::More" : "0.18" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://rt.cpan.org/Public/Dist/Display.html?Name=Carp-Assert-More" }, "license" : [ "http://www.opensource.org/licenses/artistic-license-2.0.php" ], "repository" : { "url" : "http://github.com/petdance/carp-assert-more/tree/master" } }, "version" : "1.14" } Carp-Assert-More-1.14/More.pm0000644000076400007640000003454112044247620014413 0ustar andyandypackage Carp::Assert::More; use warnings; use strict; use Exporter; use Carp::Assert; use vars qw( $VERSION @ISA @EXPORT ); *_fail_msg = *Carp::Assert::_fail_msg; =head1 NAME Carp::Assert::More - convenience wrappers around Carp::Assert =head1 VERSION Version 1.14 =cut BEGIN { $VERSION = '1.14'; @ISA = qw(Exporter); @EXPORT = qw( assert_defined assert_exists assert_fail assert_hashref assert_in assert_integer assert_is assert_isa assert_isnt assert_lacks assert_like assert_listref assert_negative assert_negative_integer assert_nonblank assert_nonempty assert_nonnegative assert_nonnegative_integer assert_nonref assert_nonzero assert_nonzero_integer assert_positive assert_positive_integer assert_undefined assert_unlike ); } =head1 SYNOPSIS A set of convenience functions for common assertions. use Carp::Assert::More; my $obj = My::Object; assert_isa( $obj, 'My::Object', 'Got back a correct object' ); =head1 DESCRIPTION Carp::Assert::More is a set of wrappers around the L functions to make the habit of writing assertions even easier. Everything in here is effectively syntactic sugar. There's no technical reason to use assert_isa( $foo, 'HTML::Lint' ); instead of assert( defined $foo ); assert( ref($foo) eq 'HTML::Lint' ); other than readability and simplicity of the code. My intent here is to make common assertions easy so that we as programmers have no excuse to not use them. =head1 CAVEATS I haven't specifically done anything to make Carp::Assert::More be backwards compatible with anything besides Perl 5.6.1, much less back to 5.004. Perhaps someone with better testing resources in that area can help me out here. =head1 SIMPLE ASSERTIONS =head2 assert_is( $string, $match [,$name] ) Asserts that I<$string> matches I<$match>. =cut sub assert_is($$;$) { my $string = shift; my $match = shift; my $name = shift; # undef only matches undef return if !defined($string) && !defined($match); assert_defined( $string, $name ); assert_defined( $match, $name ); return if $string eq $match; require Carp; &Carp::confess( _fail_msg($name) ); } =head2 assert_isnt( $string, $unmatch [,$name] ) Asserts that I<$string> does NOT match I<$unmatch>. =cut sub assert_isnt($$;$) { my $string = shift; my $unmatch = shift; my $name = shift; # undef only matches undef return if defined($string) xor defined($unmatch); return if defined($string) && defined($unmatch) && ($string ne $unmatch); require Carp; &Carp::confess( _fail_msg($name) ); } =head2 assert_like( $string, qr/regex/ [,$name] ) Asserts that I<$string> matches I. The assertion fails either the string or the regex are undef. =cut sub assert_like($$;$) { my $string = shift; my $regex = shift; my $name = shift; assert_nonref( $string, $name ); assert_isa( $regex, 'Regexp', $name ); return if $string =~ $regex; require Carp; &Carp::confess( _fail_msg($name) ); } =head2 assert_unlike( $string, qr/regex/ [,$name] ) Asserts that I<$string> matches I. The assertion fails if the regex is undef. =cut sub assert_unlike($$;$) { my $string = shift; my $regex = shift; my $name = shift; return if !defined($string); assert_nonref( $string, $name ); assert_isa( $regex, 'Regexp', $name ); return if $string !~ $regex; require Carp; &Carp::confess( _fail_msg($name) ); } =head2 assert_defined( $this [, $name] ) Asserts that I<$this> is defined. =cut sub assert_defined($;$) { return if defined( $_[0] ); require Carp; &Carp::confess( _fail_msg($_[1]) ); } =head2 assert_undefined( $this [, $name] ) Asserts that I<$this> is not defined. =cut sub assert_undefined($;$) { return unless defined( $_[0] ); require Carp; &Carp::confess( _fail_msg($_[1]) ); } =head2 assert_nonblank( $this [, $name] ) Asserts that I<$this> is not blank and not a reference. =cut sub assert_nonblank($;$) { my $this = shift; my $name = shift; assert_nonref( $this, $name ); return if $this ne ""; require Carp; &Carp::confess( _fail_msg($name) ); } =head1 NUMERIC ASSERTIONS =head2 assert_integer( $this [, $name ] ) Asserts that I<$this> is an integer, which may be zero or negative. assert_integer( 0 ); # pass assert_integer( 14 ); # pass assert_integer( -14 ); # FAIL assert_integer( '14.' ); # FAIL =cut sub assert_integer($;$) { my $this = shift; my $name = shift; assert_nonref( $this, $name ); return if $this =~ /^-?\d+$/; require Carp; &Carp::confess( _fail_msg($name) ); } =head2 assert_nonzero( $this [, $name ] ) Asserts that the numeric value of I<$this> is not zero. assert_nonzero( 0 ); # FAIL assert_nonzero( -14 ); # pass assert_nonzero( '14.' ); # pass Asserts that the numeric value of I<$this> is not zero. =cut sub assert_nonzero($;$) { my $this = shift; my $name = shift; no warnings; return if $this+0 != 0; require Carp; &Carp::confess( _fail_msg($name) ); } =head2 assert_positive( $this [, $name ] ) Asserts that the numeric value of I<$this> is greater than zero. assert_positive( 0 ); # FAIL assert_positive( -14 ); # FAIL assert_positive( '14.' ); # pass =cut sub assert_positive($;$) { my $this = shift; my $name = shift; no warnings; return if $this+0 > 0; require Carp; &Carp::confess( _fail_msg($name) ); } =head2 assert_nonnegative( $this [, $name ] ) Asserts that the numeric value of I<$this> is greater than or equal to zero. Since non-numeric strings evaluate to zero, this means that any non-numeric string will pass. assert_nonnegative( 0 ); # pass assert_nonnegative( -14 ); # FAIL assert_nonnegative( '14.' ); # pass assert_nonnegative( 'dog' ); # pass =cut sub assert_nonnegative($;$) { my $this = shift; my $name = shift; no warnings; return if $this+0 >= 0; require Carp; &Carp::confess( _fail_msg($name) ); } =head2 assert_negative( $this [, $name ] ) Asserts that the numeric value of I<$this> is less than zero. assert_negative( 0 ); # FAIL assert_negative( -14 ); # pass assert_negative( '14.' ); # FAIL =cut sub assert_negative($;$) { my $this = shift; my $name = shift; no warnings; return if $this+0 < 0; require Carp; &Carp::confess( _fail_msg($name) ); } =head2 assert_nonzero_integer( $this [, $name ] ) Asserts that the numeric value of I<$this> is not zero, and that I<$this> is an integer. assert_nonzero_integer( 0 ); # FAIL assert_nonzero_integer( -14 ); # pass assert_nonzero_integer( '14.' ); # FAIL =cut sub assert_nonzero_integer($;$) { my $this = shift; my $name = shift; assert_nonzero( $this, $name ); assert_integer( $this, $name ); } =head2 assert_positive_integer( $this [, $name ] ) Asserts that the numeric value of I<$this> is greater than zero, and that I<$this> is an integer. assert_positive_integer( 0 ); # FAIL assert_positive_integer( -14 ); # FAIL assert_positive_integer( '14.' ); # FAIL assert_positive_integer( '14' ); # pass =cut sub assert_positive_integer($;$) { my $this = shift; my $name = shift; assert_positive( $this, $name ); assert_integer( $this, $name ); } =head2 assert_nonnegative_integer( $this [, $name ] ) Asserts that the numeric value of I<$this> is not less than zero, and that I<$this> is an integer. assert_nonnegative_integer( 0 ); # pass assert_nonnegative_integer( -14 ); # pass assert_nonnegative_integer( '14.' ); # FAIL =cut sub assert_nonnegative_integer($;$) { my $this = shift; my $name = shift; assert_nonnegative( $this, $name ); assert_integer( $this, $name ); } =head2 assert_negative_integer( $this [, $name ] ) Asserts that the numeric value of I<$this> is less than zero, and that I<$this> is an integer. assert_negative_integer( 0 ); # FAIL assert_negative_integer( -14 ); # pass assert_negative_integer( '14.' ); # FAIL =cut sub assert_negative_integer($;$) { my $this = shift; my $name = shift; assert_negative( $this, $name ); assert_integer( $this, $name ); } =head1 REFERENCE ASSERTIONS =head2 assert_isa( $this, $type [, $name ] ) Asserts that I<$this> is an object of type I<$type>. =cut sub assert_isa($$;$) { my $this = shift; my $type = shift; my $name = shift; assert_defined( $this, $name ); # The assertion is true if # 1) For objects, $this is of class $type or of a subclass of $type # 2) For non-objects, $this is a reference to a HASH, SCALAR, ARRAY, etc. require Scalar::Util; return if Scalar::Util::blessed( $this ) && $this->isa( $type ); return if ref($this) eq $type; require Carp; &Carp::confess( _fail_msg($name) ); } =head2 assert_nonempty( $this [, $name ] ) I<$this> must be a ref to either a hash or an array. Asserts that that collection contains at least 1 element. Will assert (with its own message, not I<$name>) unless given a hash or array ref. It is OK if I<$this> has been blessed into objecthood, but the semantics of checking an object to see if it has keys (for a hashref) or returns >0 in scalar context (for an array ref) may not be what you want. assert_nonempty( 0 ); # FAIL assert_nonempty( 'foo' ); # FAIL assert_nonempty( undef ); # FAIL assert_nonempty( {} ); # FAIL assert_nonempty( [] ); # FAIL assert_nonempty( {foo=>1} );# pass assert_nonempty( [1,2,3] ); # pass =cut sub assert_nonempty($;$) { my $ref = shift; my $name = shift; require Scalar::Util; my $underlying_type; if ( Scalar::Util::blessed( $ref ) ) { $underlying_type = Scalar::Util::reftype( $ref ); } else { $underlying_type = ref( $ref ); } if ( $underlying_type eq 'HASH' ) { assert_positive( scalar keys %{$ref}, $name ); } elsif ( $underlying_type eq 'ARRAY' ) { assert_positive( scalar @{$ref}, $name ); } else { assert_fail( 'Not an array or hash reference' ); } } =head2 assert_nonref( $this [, $name ] ) Asserts that I<$this> is not undef and not a reference. =cut sub assert_nonref($;$) { my $this = shift; my $name = shift; assert_defined( $this, $name ); return unless ref( $this ); require Carp; &Carp::confess( _fail_msg($name) ); } =head2 assert_hashref( $ref [,$name] ) Asserts that I<$ref> is defined, and is a reference to a (possibly empty) hash. B This method returns I for objects, even those whose underlying data is a hashref. This is as it should be, under the assumptions that: =over 4 =item (a) you shouldn't rely on the underlying data structure of a particular class, and =item (b) you should use C instead. =back =cut sub assert_hashref($;$) { my $ref = shift; my $name = shift; return assert_isa( $ref, 'HASH', $name ); } =head2 assert_listref( $ref [,$name] ) Asserts that I<$ref> is defined, and is a reference to a (possibly empty) list. B The same caveat about objects whose underlying structure is a hash (see C) applies here; this method returns false even for objects whose underlying structure is an array. =cut sub assert_listref($;$) { my $ref = shift; my $name = shift; return assert_isa( $ref, 'ARRAY', $name ); } =head1 SET AND HASH MEMBERSHIP =head2 assert_in( $string, \@inlist [,$name] ); Asserts that I<$string> is defined and matches one of the elements of I<\@inlist>. I<\@inlist> must be an array reference of defined strings. =cut sub assert_in($$;$) { my $string = shift; my $arrayref = shift; my $name = shift; assert_nonref( $string, $name ); assert_isa( $arrayref, 'ARRAY', $name ); foreach my $element (@{$arrayref}) { assert_nonref( $element, $name ); return if $string eq $element; } require Carp; &Carp::confess( _fail_msg($name) ); } =head2 assert_exists( \%hash, $key [,$name] ) =head2 assert_exists( \%hash, \@keylist [,$name] ) Asserts that I<%hash> is indeed a hash, and that I<$key> exists in I<%hash>, or that all of the keys in I<@keylist> exist in I<%hash>. assert_exists( \%custinfo, 'name', 'Customer has a name field' ); assert_exists( \%custinfo, [qw( name addr phone )], 'Customer has name, address and phone' ); =cut sub assert_exists($$;$) { my $hash = shift; my $key = shift; my $name = shift; assert_isa( $hash, 'HASH', $name ); my @list = ref($key) ? @$key : ($key); for ( @list ) { if ( !exists( $hash->{$_} ) ) { require Carp; &Carp::confess( _fail_msg($name) ); } } } =head2 assert_lacks( \%hash, $key [,$name] ) =head2 assert_lacks( \%hash, \@keylist [,$name] ) Asserts that I<%hash> is indeed a hash, and that I<$key> does NOT exist in I<%hash>, or that none of the keys in I<@keylist> exist in I<%hash>. assert_lacks( \%users, 'root', 'Root is not in the user table' ); assert_lacks( \%users, [qw( root admin nobody )], 'No bad usernames found' ); =cut sub assert_lacks($$;$) { my $hash = shift; my $key = shift; my $name = shift; assert_isa( $hash, 'HASH', $name ); my @list = ref($key) ? @$key : ($key); for ( @list ) { if ( exists( $hash->{$_} ) ) { require Carp; &Carp::confess( _fail_msg($name) ); } } } =head1 UTILITY ASSERTIONS =head2 assert_fail( [$name] ) Assertion that always fails. C is exactly the same as calling C, but it eliminates that case where you accidentally use C, which of course never fires. =cut sub assert_fail(;$) { require Carp; &Carp::confess( _fail_msg($_[0]) ); } =head1 COPYRIGHT & LICENSE Copyright 2005-2012 Andy Lester. This program is free software; you can redistribute it and/or modify it under the terms of the Artistic License version 2.0. =head1 ACKNOWLEDGEMENTS Thanks to Bob Diss, Pete Krawczyk, David Storrs, Dan Friedman, Allard Hoeve, Thomas L. Shinnick, and Leland Johnson for code and fixes. =cut "I stood on the porch in a tie." Carp-Assert-More-1.14/Changes0000644000076400007640000000417312044251664014447 0ustar andyandyRevision history for Perl extension Carp::Assert::More. 1.14 Wed Oct 31 11:37:04 CDT 2012 [ENHANCEMENTS] Added assert_undefined() for Ben Hengst. Added assert_unlike(). [FIXES] assert_nonblank() wasn't using the correct message. Thanks to Leland Johnson. assert_nonempty() wouldn't work on blessed arrays and refs. Now it will. 1.12 Oct 14 2005 [ENHANCEMENTS] * Added assert_nonnegative() and assert_nonnegative_integer(). * Added assert_lacks(). Thanks to Bob Diss. 1.10 Wed Feb 16 12:52:16 CST 2005 [FIXES] * Fixed assert_positive_integer() to not pass "14.". 1.08 Wed Nov 24 11:44:34 CST 2004 [ENHANCEMENTS] * Added assert_is() and assert_isnt() * Organized the functions into logical groupings. [INTERNALS] * Now requires Test::Exception. * Added t/pod.t and t/pod-coverage.t 1.06 Sat Oct 30 23:50:45 CDT 2004 * No functionality changes. Just added a Copyright notice to so we can put it in Debian. 1.04 Mon Oct 18 10:21:37 CDT 2004 [ENHANCEMENTS] * assert_isa() is now aware of subclasses. [FIXES] * $names weren't getting passed to sub-assertions. Now they are. [DOCUMENTATION] * Documentation fix. This is the "all thanks to Allard Hoeve" release. 1.02 Tue Oct 5 17:31:56 CDT 2004 [ENHANCEMENTS] * Added assert_hashref() and assert_listref(). Thanks to Dan Friedman. 1.00 Wed Sep 22 10:14:28 CDT 2004 * First real official version. I'm not sure what's different between this and 0.04. * Added a bunch of new assert_* functions. Thanks David Storrs and Pete Krawczyk. 0.04 August 21, 2002 - Added assert_integer - Added assert_nonzero - Added assert_nonzero_integer - Added assert_exists 0.03 August 15, 2002 - Added assert_fail 0.02 August 8, 2002 - Added assert_nonblank and assert_nonref 0.01 August 8, 2002 - Original version, stolen from Carp::Assert Carp-Assert-More-1.14/INSTALL0000644000076400007640000000104010323752376014177 0ustar andyandyWHAT IS THIS? This is Carp::Assert::More, a perl module. Please see the README that comes with this distribution. HOW DO I INSTALL IT? To install this module, cd to the directory that contains this README file and type the following: perl Makefile.PL make make test make install To install this module into a specific directory, do: perl Makefile.PL PREFIX=/name/of/the/directory ...the rest is the same... Please also read the perlmodinstall man page, if available. WHAT MODULES DO I NEED? Carp and Carp::Assert