Test::Carp(3pm)

πŸ“¦
version 0.2 Β· 5 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

🌸 NAME 🌸

Test::Carp β€” test your code for calls to Carp functions πŸ’… bestie this is the one that checks whether your code is out here carping, croaking, clucking and confessing like it's supposed to.


✨ VERSION ✨

This document describes Test::Carp version 0.2 πŸŽ€


πŸŽ€ 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/);

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so here's the tea β˜• β€” you call some given code (with whatever arguments you handed over), and this module tests whether the given Carp function (or their imported versions πŸ‘€) actually gets called, with a given value, or nah. That's literally it. That's the whole plot.


πŸ‘‘ INTERFACE πŸ‘‘

Every function gets yeeted straight into the caller's namespace during import() 🫢. But if you would rather use their full namespace and not clutter up your current package with a bunch of extra functions, do this instead:

require Test::Carp;

or

use Test::Carp ();

and not this:

use Test::Carp;

🧚 being ok() w/ ok()

Under the hood, Test::Carp uses Test::More::ok() (require()ing in Test::More if it needs to) whenever it needs an ok() function. No cap.

If you want it to use a different one, just supply a coderef in the use statement:

use Test::Carp \&Test::Foo::ok;

That function should take the same args as Test::More::ok() and probably behave the same way too. Like, it's giving ok() energy, so it should act like ok(), iykyk πŸ’œ

πŸ“ carp()/cluck() functions

πŸ’– does_carp()

Tests whether the given code ref, when executed, actually calls carp().

The test fails if carp() is not called 😭 There are 2 forms:

Without arguments to the coderef:

does_carp(sub {...});

With args to the coderef:

does_carp(sub {...},"first arg to coderef", "second arg to coderef", ...);

πŸ’– does_carp_that_matches()

Tests 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 a Regexp ref (i.e. qr//) to match the message against πŸ”

There are 2 forms:

Without arguments passed to the coderef:

does_carp(sub {...}, $match_me)

With arguments passed to the coderef:

does_carp(sub {...},"first arg to coderef", "second arg to coderef", ..., $match_me);

πŸ’– does_cluck

Same vibe as does_carp(), but for cluck() πŸ”

πŸ’– does_cluck_that_matches

Same vibe as does_carp_that_matches(), but for cluck() πŸ”

🌈 croak()/confess() functions

Heads up bestie β€” these functions stop running at the point where it calls the [croak|cluck]() , just like in normal code. Not a drill, it really does halt πŸ’€

πŸ’– does_croak()

Like does_carp() but for croak() πŸ’…

πŸ’– does_croak_that_matches()

Like does_carp_that_matches() but for croak() πŸ’…

πŸ’– does_confess()

Like does_carp() but for confess() πŸ™ˆ

πŸ’– does_confess_that_matches()

Like does_carp_that_matches() but for confess() πŸ™ˆ


πŸ” DIAGNOSTICS πŸ”

Throws no warnings or errors of its own. Clean. Flawless. Not a single peep ✨


βš™οΈ CONFIGURATION AND ENVIRONMENT βš™οΈ

Test::Carp requires no configuration files and no environment variables. Zero setup, we love a low-maintenance icon 🫢


πŸ“¦ DEPENDENCIES πŸ“¦

Test::More for ok(), unless you define a different ok() for it to use.

It uses Carp in order to ensure carp and croak are defined before it does what it does 🐟


🚫 INCOMPATIBILITIES 🚫

None reported. Green flags only πŸ’š


πŸ’€ BUGS AND LIMITATIONS πŸ’€

No bugs have been reported πŸ‘‘

Please report any bugs or feature requests to bug-test-carp@rt.cpan.org, or through the web interface at <http://rt.cpan.org>.


πŸ“ 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 ?

🌟 AUTHOR 🌟

Daniel Muey <http://drmuey.com/cpan_contact.pl> πŸ’–


Copyright (c) 2010, Daniel Muey <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 perlartistic.


⚠️ DISCLAIMER OF WARRANTY ⚠️

Okay bestie, legal text incoming and I am not touching a single word of it, because lawyers do not appreciate our vibe. Reproducing it verbatim, all caps and all, exactly as it appears 🫑

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.

and that's the whole page, periodt πŸ’… This one was baked up on 2022-10-13, shipped alongside perl v5.36.0, and it lives under the manual name Test::Carp(3pm) πŸŽ€ go forth and test your carps, queen πŸ‘‘

πŸ“¦ where this page comes from