petdance / carp-assert-more Goto Github PK
View Code? Open in Web Editor NEWCarp::Assert::More, handy assertion functions for Perl
Carp::Assert::More, handy assertion functions for Perl
assert_all_in( \@domains, [ 'A', 'B' ], 'all domains are valid' );
So for assert_all_in( $x, $y, $msg )
, each value in $x is one of the values in $y.
Add assert_aoh
to verify arrays of hashes.
by @petek
Carp::Assert allows its use as "no Carp::Assert" in code to disable assertions, so that assertions are disabled when desired. Since Carp::Assert::More bills itself as an extension of Carp::Assert, it needs the same functionality.
Consider
my $monolith = { h => 9, w => 4, d => 1 };
assert_keys_are( $monolith, [( h x q )] );
The output of the failed assertion should say both that d
and w
are not represented in the key list, and that both x
and q
not in the hash.
For this case:
assert_all_keys_in( $monolith, [( h x q )] );
it should saw that both x
and q
are not in the hash.
In both cases, they stop at the first failure. All should be listed.
We have assert_arrayref_nonempty
The current implementation is optimized for the author of Carp::Assert::More, not the users who have to deal with the stacks of assertion calls.
Assertion (Could not find a row of test data) failed!
at /var/perl5.20.3/lib/site_perl/5.20.3/Carp/Assert/More.pm line 199.
Carp::Assert::More::assert_defined(undef, "Could not find a row of test data") called at /var/perl5.20.3/lib/site_perl/5.20.3/Carp/Assert/More.pm line 454
Carp::Assert::More::assert_isa(undef, "HASH", "Could not find a row of test data") called at /var/perl5.20.3/lib/site_perl/5.20.3/Carp/Assert/More.pm line 622
Carp::Assert::More::assert_hashref(undef, "Could not find a row of test data") called at test.t line 141
That should just be a single call to assert_hashref
. It will be some replicated code, but that's OK. It will also speed things up.
Carp::Assert::More uses Carp::Assert::_fail_msg(), tempting fate if the underlying Carp::Assert changes. Bring it into Carp::Assert::More.
v2.0.0 is much faster than the 1.x series. See what other improvements we can eke out.
Carp::Assert::More::assert_in("X", ARRAY(0x7ed8068), "Must be a solrtype")
isn't very helpful.
Repeated calls to assert_in
makes tons more assertions than is necessary.
Sometimes you want exactly a set number of keys, and no others, like
assert_keys_are( $image_spec, [qw( height width )] );
The POD for assert_integer has a wrong example. -14 should pass, not FAIL.
=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
Remove Carp::Assert as a requirement. Add our own assert
so that the user doesn't have to use Carp::Assert
if they just want a simple assert
.
assert_listref() should have been called assert_arrayref(). Include them both.
The bugtracker in the meta.yml points at RT. Point it to GitHub.
Right now you have to do
assert_all_keys_in( \%hash, \@list_of_valid_keys );
but you should also be able to do
assert_all_keys_in( \%hash, \%hash_of_valid_keys );
In the most recent release of this module you
added a small change to the code which requires Perl 5.10+ (the
defined or operator). Here's the line as on Metacpan:
https://metacpan.org/source/PETDANCE/Carp-Assert-More-1.20/More.pm#L695
I know the Perl community needs to learn to love newer Perl but I
would like to ask if you would reconsider this change and use a
slightly longer version of this line which could eliminate the defined
or op and restore compatibility with Perl 5.8. I only ask because
Catalyst is very committed to supporting our legacy users, many of
which are at companies where upgrading Perl is not going to happen.
Since the change I'm asking for is trivial and I see nothing else in
the code that is greatly benefiting from Perl 5.10+ I would hope this
is something you could consider. Our only alternative would be to
scour Catalyst and a number of its more important plugins (such as the
Authentication plugin which nearly everyone uses) to remove
Carp::Assert::More and work around as best we can. It's already been
a lot of hours of volunteer time compared to what I hope would be just
a few minutes of your effort.
All I think we need to do is change:
(line => https://metacpan.org/source/PETDANCE/Carp-Assert-More-1.20/More.pm#L695)
my $desc = shift // 'Must be a DateTime object';
my $desc = defined($_[0]) ? shift(@_) : 'Must be a DateTime object';
change to
I'll also send a PR against master with the change. Thanks!
Allow this:
assert_in( $foo, [ undef, 1, 2, 'x' ] );
This is so common it should be a single call:
assert_arrayref( $foo );
assert_nonempty( $foo );
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.