2
# BioPerl module for Bio::Root::Test::Warn
4
# Please direct questions and support issues to <bioperl-l@bioperl.org>
6
# Cared for by Sendu Bala <bix@sendu.me.uk>
10
# You may distribute this module under the same terms as perl itself
12
# POD documentation - main docs before the code
16
Bio::Root::Test::Warn - Perl extension to test Bioperl methods for warnings
20
use Bio::Root::Test::Warn;
22
warning_is {$bio_object->method()} 'Must supply a parameter', "a missing parameter test";
23
warning_like {$bio_object->method()} qr/Must supply a parameter/i, "a missing parameter test";
27
This module provides a few convenience methods for testing warning based code.
29
See Test::Warn for details.
31
You will normally not use this module directly, but have it auto-loaded for you
38
User feedback is an integral part of the evolution of this and other
39
Bioperl modules. Send your comments and suggestions preferably to
40
the Bioperl mailing list. Your participation is much appreciated.
42
bioperl-l@bioperl.org - General discussion
43
http://bioperl.org/wiki/Mailing_lists - About the mailing lists
47
Please direct usage questions or support issues to the mailing list:
49
I<bioperl-l@bioperl.org>
51
rather than to the module maintainer directly. Many experienced and
52
reponsive experts will be able look at the problem and quickly
53
address it. Please include a thorough description of the problem
54
with code and data examples if at all possible.
58
Report bugs to the Bioperl bug tracking system to help us keep track
59
of the bugs and their resolution. Bug reports can be submitted via
62
https://redmine.open-bio.org/projects/bioperl/
64
=head1 AUTHOR - Sendu Bala
70
The rest of the documentation details each of the object methods.
71
Internal methods are usually preceded with a _
75
package Bio::Root::Test::Warn;
79
use Exporter qw(import);
84
our @EXPORT = qw(warning_is
90
my $Tester = Test::Builder->new;
92
no warnings 'redefine';
93
sub Test::Warn::_canonical_got_warning {
94
my ($called_from, $msg) = @_;
95
my $warn_kind = $called_from eq 'Carp' ? 'carped' : ($called_from =~ /Bio::/ ? 'Bioperl' : 'warn');
98
if ($warn_kind eq 'Bioperl') {
99
($warning) = $msg =~ /\n--------------------- WARNING ---------------------\nMSG: (.+)\n---------------------------------------------------\n$/m;
100
$warning ||= $msg; # shouldn't ever happen
103
my @warning_stack = split /\n/, $msg; # some stuff of uplevel is included
104
$warning = $warning_stack[0];
107
return {$warn_kind => $warning}; # return only the real message
110
sub Test::Warn::_diag_found_warning {
112
if (ref($_) eq 'HASH') {
113
${$_}{carped} ? $Tester->diag("found carped warning: ${$_}{carped}")
114
: (${$_}{Bioperl} ? $Tester->diag("found Bioperl warning: ${$_}{Bioperl}")
115
: $Tester->diag("found warning: ${$_}{warn}"));
117
$Tester->diag( "found warning: $_" );
120
$Tester->diag( "didn't find a warning" ) unless @_;
123
sub Test::Warn::_cmp_got_to_exp_warning {
124
my ($got_kind, $got_msg) = %{ shift() };
125
my ($exp_kind, $exp_msg) = %{ shift() };
126
return 0 if ($got_kind eq 'warn') && ($exp_kind eq 'carped');
129
if ($got_kind eq 'Bioperl') {
130
$cmp = $got_msg =~ /^\Q$exp_msg\E$/;
133
$cmp = $got_msg =~ /^\Q$exp_msg\E at \S+ line \d+\.?$/;