Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ap/test-lives
decorate tests with a no-exceptions assertion
https://github.com/ap/test-lives
developer-tools perl testing testing-library
Last synced: 14 days ago
JSON representation
decorate tests with a no-exceptions assertion
- Host: GitHub
- URL: https://github.com/ap/test-lives
- Owner: ap
- Created: 2015-03-17T20:27:33.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2022-09-02T04:29:04.000Z (about 2 years ago)
- Last Synced: 2024-10-11T21:15:46.977Z (about 1 month ago)
- Topics: developer-tools, perl, testing, testing-library
- Language: Perl
- Homepage: https://metacpan.org/release/Test-Lives
- Size: 12.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.pod
- Changelog: Changes
Awesome Lists containing this project
README
use 5.006; use strict; use warnings;
package Test::Lives;
our $VERSION = '1.003';
use Carp ();
use Test::Builder ();my $Tester = Test::Builder->new;
sub lives_and (&;$) {
my ( $code, $name ) = @_;my $ok;
eval {
local $Carp::Internal{(__PACKAGE__)} = 1;
$ok = $code->() for $name;
1;
} or do {
my $e = "$@";
$ok = $Tester->ok( 0, $name );
$Tester->diag( $e );
};return $ok;
}sub import {
my $class = shift;
do { die "Unknown symbol: $_" if $_ ne 'lives_and' } for @_;
no strict 'refs';
*{ caller . '::lives_and' } = \&lives_and;
}1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Test::Lives - decorate tests with a no-exceptions assertion
=head1 SYNOPSIS
use Test::More;
use Test::Lives;use System::Under::Test 'might_die';
lives_and { is might_die, 'correct', $_ } 'system under test is correct';
=head1 DESCRIPTION
This module provides only one function, C, which works almost
exactly like the function of the same name in L. That is,
it allows you to test things that could (but shouldn't) throw an exception
without having to have
two separate tests with two separate results (and two separate descriptions).You pass it a block of code to run (which should contain one test assertion)
and a test description to give the assertion inside the block.The description will be available inside the block in the C<$_> variable.
(This is different from L, which employs hacky magic to
relieve you of having to pass the description to the decorated assertion.)If the block ends up throwing an exception, a test failure will be logged.
=cut