Dist::Zilla::Tester::DieHard - Die hard Dist::Zilla, but save the messages
Version 0.002_01, released on 2015-08-29 17:12 UTC. This is a trial release.
Dist-Zilla-Tester-DieHard (or shortly DieHard) is a Dist::Zilla testing tool, a replacement for standard Dist::Zilla::Tester. If Dist::Zilla dies in construction, DieHard survives itself and saves the logger to let you analyze the messages.
Dist-Zilla-Tester-DieHard
DieHard
Dist::Zilla
Dist::Zilla::Tester
Use Dist::Zilla::Tester::DieHard instead of Dist::Zilla::Tester:
Dist::Zilla::Tester::DieHard
use Dist::Zilla::Tester::DieHard; # instead of Dist::Zilla::Tester use Test::Deep qw{ cmp_deeply }; use Test::Fatal; use Test::More; my $tzil = Builder->from_config( … ); my $ex = exception { $tzil->build(); }; is( $ex, $expected_exception, 'check status' ); cmd_deeply( $tzil->log_messages, $expected_messages, 'check log messages' );
Dist::Zilla::Tester::DieHard (or, for brevity just DieHard), is a replacement for Dist::Zilla::Tester. If Dist::Zilla dies in construction, DieHard catches the exception, saves the exception and Dist::Zilla logger, and returns a "survivor" object.
Th returned survivor will fail in build method: it just rethrows the saved exception. However, such "delayed death" saves log messages for analysis:
build
my $tzil = Builder->from_config( … ); # ^ Construction never fails, # it always returns an object, # either builder or survivor. my $ex = exception { $tzil->build(); }; # ^ Builder does build, # survivor rethrows the saved exception. is( $ex, $expected_exception, 'check status' ); cmd_deeply( $tzil->log_messages, $expected_messages, 'check log messages' ); # ^ In *any* case we can check log messages.
Usually I test my Dist::Zilla plugins in such a way:
… use Dist::Zilla::Tester; use Test::Deep qw{ cmp_deeply }; use Test::Fatal; use Test::More; my $tzil = Builder->from_config( … ); my $exception = exception { $tzil->build(); }; if ( $expected_success ) { is( $exception, undef, 'status' ); } else { like( $exception, qr{…}, 'status' ); }; cmd_deeply( $tzil->log_messages, $expected_messages, 'log messages' ); …
The approach works well, until Dist::Zilla dies in from_config (e. g. if a plugin throws an exception in its construction).
from_config
A straightforward attempt to catch exception thrown in from_config:
my $tzil; my $exception = exception { $tzil = Builder->from_config( … ); }; if ( $expected_success ) { is( $exception, undef, 'status' ); } else { like( $exception, qr{…}, 'status' ); };
works but… from_config dies leaving $tzil undefined, and log_messages method call on undefined value will definitely fail:
$tzil
log_messages
cmd_deeply( $tzil->log_messages, $expected_messages, 'log messages' ); # ^^^^^^^^^^^^^^^^^^^ Oops: $tzil undefined.
Dist::Zilla dies, and all the messages logged by either Dist::Zilla or its plugins die too.
Using Dist::Zilla::Tester::DieHard instead of regular Dist::Zilla::Tester solves this problem: even if a plugin throws an exception in constructor, Builder->from_config does not die but returns a "survivor" object which can be used to retrieve log messages.
Builder->from_config
Regular Dist::Zilla::Tester (as of v5.039) is not documented, so and I have to study its sources to find out features it provides.
I have implemented only part of Dist::Zilla::Tester features, shown in "SYNOPSIS" and "DESCRIPTION". Minter is not (yet?) implemented — I do not need it (yet?). Probably there are other not (yet?) implemented features I am not aware of.
Minter
Van de Bugger <van.de.bugger@gmail.com>
Copyright © 2015 Van de Bugger
This file is part of perl-Dist-Zilla-Tester-DieHard.
perl-Dist-Zilla-Tester-DieHard is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
perl-Dist-Zilla-Tester-DieHard is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with perl-Dist-Zilla-Tester-DieHard. If not, see <http://www.gnu.org/licenses/>.
To install Dist::Zilla::Tester::DieHard, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Dist::Zilla::Tester::DieHard
CPAN shell
perl -MCPAN -e shell install Dist::Zilla::Tester::DieHard
For more information on module installation, please visit the detailed CPAN module installation guide.