r1435 - in
packages/libcarp-assert-more-perl/branches/upstream/current: . t
Gunnar Wolf
gwolf at costa.debian.org
Mon Oct 24 16:34:51 UTC 2005
Author: gwolf
Date: 2005-10-24 16:34:50 +0000 (Mon, 24 Oct 2005)
New Revision: 1435
Added:
packages/libcarp-assert-more-perl/branches/upstream/current/t/assert_lacks.t
packages/libcarp-assert-more-perl/branches/upstream/current/t/assert_nonnegative.t
packages/libcarp-assert-more-perl/branches/upstream/current/t/assert_nonnegative_integer.t
Modified:
packages/libcarp-assert-more-perl/branches/upstream/current/Changes
packages/libcarp-assert-more-perl/branches/upstream/current/MANIFEST
packages/libcarp-assert-more-perl/branches/upstream/current/META.yml
packages/libcarp-assert-more-perl/branches/upstream/current/More.pm
packages/libcarp-assert-more-perl/branches/upstream/current/t/00-load.t
packages/libcarp-assert-more-perl/branches/upstream/current/t/test-coverage.t
Log:
Load /tmp/tmp.vTQgsQ/libcarp-assert-more-perl-1.12 into
packages/libcarp-assert-more-perl/branches/upstream/current.
Modified: packages/libcarp-assert-more-perl/branches/upstream/current/Changes
===================================================================
--- packages/libcarp-assert-more-perl/branches/upstream/current/Changes 2005-10-24 16:34:36 UTC (rev 1434)
+++ packages/libcarp-assert-more-perl/branches/upstream/current/Changes 2005-10-24 16:34:50 UTC (rev 1435)
@@ -1,6 +1,11 @@
Revision history for Perl extension Carp::Assert::More.
-1.10
+1.12
+ [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.".
Modified: packages/libcarp-assert-more-perl/branches/upstream/current/MANIFEST
===================================================================
--- packages/libcarp-assert-more-perl/branches/upstream/current/MANIFEST 2005-10-24 16:34:36 UTC (rev 1434)
+++ packages/libcarp-assert-more-perl/branches/upstream/current/MANIFEST 2005-10-24 16:34:50 UTC (rev 1435)
@@ -4,9 +4,7 @@
Makefile.PL
More.pm
README
-META.yml Module meta-data (added by MakeMaker)
-t/01.load.t
-t/02.coverage.t
+t/00-load.t
t/assert_defined.t
t/assert_exists.t
t/assert_fail.t
@@ -16,12 +14,15 @@
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
@@ -29,3 +30,5 @@
t/assert_positive.t
t/pod.t
t/pod-coverage.t
+t/test-coverage.t
+META.yml Module meta-data (added by MakeMaker)
Modified: packages/libcarp-assert-more-perl/branches/upstream/current/META.yml
===================================================================
--- packages/libcarp-assert-more-perl/branches/upstream/current/META.yml 2005-10-24 16:34:36 UTC (rev 1434)
+++ packages/libcarp-assert-more-perl/branches/upstream/current/META.yml 2005-10-24 16:34:50 UTC (rev 1435)
@@ -1,7 +1,7 @@
# http://module-build.sourceforge.net/META-spec.html
#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
name: Carp-Assert-More
-version: 1.10
+version: 1.12
version_from: More.pm
installdirs: site
requires:
@@ -12,4 +12,4 @@
Test::More: 0.18
distribution_type: module
-generated_by: ExtUtils::MakeMaker version 6.24
+generated_by: ExtUtils::MakeMaker version 6.30
Modified: packages/libcarp-assert-more-perl/branches/upstream/current/More.pm
===================================================================
--- packages/libcarp-assert-more-perl/branches/upstream/current/More.pm 2005-10-24 16:34:36 UTC (rev 1434)
+++ packages/libcarp-assert-more-perl/branches/upstream/current/More.pm 2005-10-24 16:34:50 UTC (rev 1435)
@@ -16,12 +16,12 @@
=head1 VERSION
-Version 1.10
+Version 1.12
=cut
BEGIN {
- $VERSION = '1.10';
+ $VERSION = '1.12';
@ISA = qw(Exporter);
@EXPORT = qw(
assert_defined
@@ -33,12 +33,15 @@
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
@@ -241,6 +244,30 @@
&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.
@@ -301,6 +328,25 @@
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
@@ -375,9 +421,11 @@
my $type = ref $ref;
if ( $type eq "HASH" ) {
assert_positive( scalar keys %$ref, $name );
- } elsif ( $type eq "ARRAY" ) {
+ }
+ elsif ( $type eq "ARRAY" ) {
assert_positive( scalar @$ref, $name );
- } else {
+ }
+ else {
assert_fail( "Not an array or hash reference" );
}
}
@@ -474,8 +522,8 @@
=head2 assert_exists( \%hash, \@keylist [,$name] )
-Asserts that I<$key> exists in I<%hash>, or that all of the keys in
-I<@keylist> exist in I<%this>.
+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' );
@@ -500,6 +548,35 @@
}
}
+=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] )
@@ -525,6 +602,7 @@
=head1 ACKNOWLEDGEMENTS
Thanks to
+Bob Diss,
Pete Krawczyk,
David Storrs,
Dan Friedman,
Modified: packages/libcarp-assert-more-perl/branches/upstream/current/t/00-load.t
===================================================================
--- packages/libcarp-assert-more-perl/branches/upstream/current/t/00-load.t 2005-10-24 16:34:36 UTC (rev 1434)
+++ packages/libcarp-assert-more-perl/branches/upstream/current/t/00-load.t 2005-10-24 16:34:50 UTC (rev 1435)
@@ -5,3 +5,5 @@
BEGIN {
use_ok( 'Carp::Assert::More' );
}
+
+diag( "Testing Carp::Assert::More $Carp::Assert::More::VERSION under Perl $] and Test::More $Test::More::VERSION" );
Added: packages/libcarp-assert-more-perl/branches/upstream/current/t/assert_lacks.t
===================================================================
--- packages/libcarp-assert-more-perl/branches/upstream/current/t/assert_lacks.t 2005-10-24 16:34:36 UTC (rev 1434)
+++ packages/libcarp-assert-more-perl/branches/upstream/current/t/assert_lacks.t 2005-10-24 16:34:50 UTC (rev 1435)
@@ -0,0 +1,50 @@
+#!perl -Tw
+
+use warnings;
+use strict;
+
+use Test::More tests=>7;
+
+BEGIN {
+ use_ok( 'Carp::Assert::More' );
+}
+
+my %foo = (
+ name => "Andy Lester",
+ phone => "578-3338",
+ wango => undef,
+);
+
+
+eval {
+ assert_lacks( \%foo, 'Name' );
+};
+is( $@, "" );
+
+
+eval {
+ assert_lacks( \%foo, 'name' );
+};
+like( $@, qr/Assert.+failed/ );
+
+
+eval {
+ assert_lacks( \%foo, [qw( Wango )] );
+};
+is( $@, "" );
+
+eval {
+ assert_lacks( \%foo, [qw( Wango Tango )] );
+};
+is( $@, "" );
+
+eval {
+ assert_lacks( \%foo, [qw( Wango Tango name )] );
+};
+like( $@, qr/Assertion.+failed/ );
+
+eval {
+ assert_lacks( \%foo, [qw()] );
+};
+is( $@, "" );
+
Added: packages/libcarp-assert-more-perl/branches/upstream/current/t/assert_nonnegative.t
===================================================================
--- packages/libcarp-assert-more-perl/branches/upstream/current/t/assert_nonnegative.t 2005-10-24 16:34:36 UTC (rev 1434)
+++ packages/libcarp-assert-more-perl/branches/upstream/current/t/assert_nonnegative.t 2005-10-24 16:34:50 UTC (rev 1435)
@@ -0,0 +1,34 @@
+#!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 );
+ }
+}
+
Added: packages/libcarp-assert-more-perl/branches/upstream/current/t/assert_nonnegative_integer.t
===================================================================
--- packages/libcarp-assert-more-perl/branches/upstream/current/t/assert_nonnegative_integer.t 2005-10-24 16:34:36 UTC (rev 1434)
+++ packages/libcarp-assert-more-perl/branches/upstream/current/t/assert_nonnegative_integer.t 2005-10-24 16:34:50 UTC (rev 1435)
@@ -0,0 +1,34 @@
+#!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 );
+ }
+}
+
Modified: packages/libcarp-assert-more-perl/branches/upstream/current/t/test-coverage.t
===================================================================
--- packages/libcarp-assert-more-perl/branches/upstream/current/t/test-coverage.t 2005-10-24 16:34:36 UTC (rev 1434)
+++ packages/libcarp-assert-more-perl/branches/upstream/current/t/test-coverage.t 2005-10-24 16:34:50 UTC (rev 1435)
@@ -1,8 +1,10 @@
#!perl -Tw
-use Test::More tests => 22;
+use Test::More tests => 25;
-use_ok( 'Carp::Assert::More' );
+BEGIN {
+ use_ok( 'Carp::Assert::More' );
+}
my @funcs = ( @Carp::Assert::More::EXPORT, @Carp::Assert::More::EXPORT_OK );
More information about the Pkg-perl-cvs-commits
mailing list