/usr/share/perl5/Test/Carp.pm is in libtest-carp-perl 0.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | package Test::Carp;
use strict;
use warnings;
use Carp;
$Test::Carp::VERSION = '0.2';
# Prototype mismatch: sub Test::Carp::_ok: none vs ($;$) at .../Test/Carp.pm line ...
# perl -MTest::More -e 'print prototype("Test::More::ok");'
# sub _ok($;$) {
sub _ok {
require Test::More;
# no warnings 'redefine';
# *_ok = \&Test::More::ok; # make subsequent calls not do all of this ferdiddling
goto &Test::More::ok;
}
sub import {
my $caller = caller();
use Data::Dumper;
if ( ref( $_[1] ) eq 'CODE' ) {
no warnings 'redefine';
*_ok = $_[1];
}
no strict 'refs';
for my $func (qw(
does_carp does_cluck
does_croak does_confess
does_carp_that_matches does_cluck_that_matches
does_croak_that_matches does_confess_that_matches
)) {
*{ $caller . "::$func" } = *{$func};
};
}
sub _does {
my $caller = caller();
my $func = shift;
my $code = shift;
no strict 'refs';
my ( $carp_orig, $caller_orig ) = ( \&{"Carp::$func"}, \&{"${caller}::$func"} );
no warnings 'redefine';
my $called = 0;
*{"Carp::$func"} = sub {
return if $called++;
_ok( 1, "$func() was called (@_)" );
if ( $func eq 'croak' || $func eq 'confess' ) {
local $Carp::CarpLevel = $Carp::CarpLevel + 2;
$carp_orig->( $_[0] );
}
};
*{"${caller}::$func"} = \&{"Carp::$func"};
( $func eq 'croak' || $func eq 'confess' ) ? eval { $code->(@_) } : $code->(@_);
_ok( 0, "$func() was called" ) if !$called;
*{"Carp::$func"} = $carp_orig;
*{"${caller}::$func"} = $caller_orig;
}
sub does_carp {
unshift @_, 'carp';
goto &_does;
}
sub does_cluck {
unshift @_, 'cluck';
goto &_does;
}
sub does_croak {
unshift @_, 'croak';
goto &_does;
}
sub does_confess {
unshift @_, 'confess';
goto &_does;
}
sub _does_and_matches {
my $caller = caller();
my $func = shift;
my $code = shift;
my $match = pop;
no strict 'refs';
my ( $carp_orig, $caller_orig ) = ( \&{"Carp::$func"}, \&{"${caller}::$func"} );
no warnings 'redefine';
my $called = 0;
if ( !defined $match ) {
$match = 'undef()'; # so you don't get "Use of uninitialized value" when used in the test name during
# t/02.functions.t oddity (look for 'to test that these are working we need to reverse ok()')
*{"Carp::$func"} = sub {
return if @_ && grep { defined $_ } @_;
return if $called++;
_ok( 1, "$func() was called w/ undefined argument" );
if ( $func eq 'croak' || $func eq 'confess' ) {
local $Carp::CarpLevel = $Carp::CarpLevel + 2;
$carp_orig->(); # do not pass @_ or you get: Use of uninitialized value in join or string at .../Carp/Heavy.pm at line ...
}
};
}
elsif ( $match eq '' ) {
*{"Carp::$func"} = sub {
return if "@_" ne '';
return if $called++;
_ok( 1, "$func() was called w/ empty string argument" );
if ( $func eq 'croak' || $func eq 'confess' ) {
local $Carp::CarpLevel = $Carp::CarpLevel + 2;
$carp_orig->(@_);
}
};
}
elsif ( ref($match) eq 'Regexp' ) {
*{"Carp::$func"} = sub {
return if "@_" !~ $match;
return if $called++;
_ok( 1, "$func() was called (w/ '@_') and matches '$match'" );
if ( $func eq 'croak' || $func eq 'confess' ) {
local $Carp::CarpLevel = $Carp::CarpLevel + 2;
$carp_orig->(@_);
}
};
}
else {
# On some odd setups qr() is not available
if ( eval { $match = qr/$match/; ref($match) eq 'Regexp' ? 1 : 0 } ) {
*{"Carp::$func"} = sub {
return if "@_" !~ $match;
return if $called++;
_ok( 1, "$func() was called (w/ '@_') and matches '$match'" );
if ( $func eq 'croak' || $func eq 'confess' ) {
local $Carp::CarpLevel = $Carp::CarpLevel + 2;
$carp_orig->(@_);
}
};
}
else {
$match = quotemeta($match); # use this instead of \Q\E so that it will be escaped in the test label
*{"Carp::$func"} = sub {
return if "@_" !~ m/$match/;
return if $called++;
_ok( 1, "$func() was called (w/ '@_') and matches '$match'" );
if ( $func eq 'croak' || $func eq 'confess' ) {
local $Carp::CarpLevel = $Carp::CarpLevel + 2;
$carp_orig->(@_);
}
};
}
}
*{"${caller}::$func"} = *{"Carp::$func"};
( $func eq 'croak' || $func eq 'confess' ) ? eval { $code->(@_) } : $code->(@_);
_ok( 0, "$func() was called and matches '$match'" ) if !$called;
*{"Carp::$func"} = $carp_orig;
*{"${caller}::$func"} = $caller_orig;
}
sub does_carp_that_matches {
unshift @_, 'carp';
goto &_does_and_matches;
}
sub does_cluck_that_matches {
unshift @_, 'cluck';
goto &_does_and_matches;
}
sub does_croak_that_matches {
unshift @_, 'croak';
goto &_does_and_matches;
}
sub does_confess_that_matches {
unshift @_, 'confess';
goto &_does_and_matches;
}
1;
__END__
=head1 NAME
Test::Carp - test your code for calls to Carp functions
=head1 VERSION
This document describes Test::Carp version 0.2
=head1 SYNOPSIS
use Test::More tests => 42;
use Test::Carp;
ok($x eq $y, "X does equal Y");
does_carp(\&function);
does_croak(\&function, 1, 2, 3);
does_carp_that_matches(\&function, qr/whoopsy/);
does_croak_that_matches(\&function, 1, 2, 3, qr/a likely story/);
=head1 DESCRIPTION
Call given code (with given arguments) and tests whether the given Carp function (or their imported versions) are called (with a given value) or not.
=head1 INTERFACE
All functions are put in the caller's name space during import(). If you'd rather use their full name space and not clutter up the current package with functions just:
require Test::Carp;
or
use Test::Carp ();
instead of
use Test::Carp;
=head2 being ok() w/ ok()
Internally, Test::Carp uses Test::More::ok() (require()ing in Test::More if needed) when it needs to use an ok() function.
If you want to specify a different one for it to use simply supply a coderef in the use statement.
use Test::Carp \&Test::Foo::ok;
The function should take the same args as Test::More::ok() and probably behave the same as well.
=head2 carp()/cluck() functions
=over 4
=item does_carp()
Test whether the given code ref, when executed, calls carp().
Test fails if carp() is not called. There are 2 forms:
Without arguments to codreref:
does_carp(sub {...});
With arge to coderef:
does_carp(sub {...},"first arg to coderef", "second arg to coderef", ...);
=item does_carp_that_matches()
Test whether the given code ref, when executed, calls carp() with a specific message.
The test fails if carp() is not called with the given message.
The last argument should be a string or Regexp ref (i.e. qr//) to match the message against.
There are 2 forms:
Without arguments passed to codreref:
does_carp(sub {...}, $match_me)
With arguments passed to coderef:
does_carp(sub {...},"first arg to coderef", "second arg to coderef", ..., $match_me);
=item does_cluck
Like does_carp() but for cluck()
=item does_cluck_that_matches
Like does_carp_that_matches() but for cluck()
=back
=head2 croak()/confess() functions
These functions stop running at the point it calls the [croak|cluck]() just like in normal code.
=over 4
=item does_croak()
Like does_carp() but for croak()
=item does_croak_that_matches()
Like does_carp_that_matches() but for croak()
=item does_confess()
Like does_carp() but for confess()
=item does_confess_that_matches()
Like does_carp_that_matches() but for confess()
=back
=head1 DIAGNOSTICS
Throws no warnings or errors of it's own.
=head1 CONFIGURATION AND ENVIRONMENT
Test::Carp requires no configuration files or environment variables.
=head1 DEPENDENCIES
L<Test::More> for ok() unless you define a different ok() for it to use.
It uses Carp in order to ensure carp and corak are defined before it does what it does.
=head1 INCOMPATIBILITIES
None reported.
=head1 BUGS AND LIMITATIONS
No bugs have been reported.
Please report any bugs or feature requests to
C<bug-test-carp@rt.cpan.org>, or through the web interface at
L<http://rt.cpan.org>.
=head1 TODO
Corresponding does_not_* functions. (v0.2)
TODOs in 02.functions.t (v0.2)
Maybe count and overall call info type functions, depending on demand ?
Determine [what needs done/if it should be done/etc] to make the test syntax not require a codref ?
Add mostly-internal Carp functions like (short|long)mess[_heavy](), etc ?
=head1 AUTHOR
Daniel Muey C<< <http://drmuey.com/cpan_contact.pl> >>
=head1 LICENCE AND COPYRIGHT
Copyright (c) 2010, Daniel Muey C<< <http://drmuey.com/cpan_contact.pl> >>. All rights reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself. See L<perlartistic>.
=head1 DISCLAIMER OF WARRANTY
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE
LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
|