Alt-Sub-Delete-NewPackageSeparator
view release on metacpan or search on metacpan
t/Test/More.pm view on Meta::CPAN
$module = qq['$module'] unless _is_module_name($module);
local($!, $@); # eval sometimes interferes with $!
eval <<REQUIRE;
package $pack;
require $module;
REQUIRE
my $ok = $tb->ok( !$@, "require $module;" );
unless( $ok ) {
chomp $@;
$tb->diag(<<DIAGNOSTIC);
Tried to require '$module'.
Error: $@
DIAGNOSTIC
}
return $ok;
}
sub _is_module_name {
my $module = shift;
# Module names start with a letter.
# End with an alphanumeric.
# The rest is an alphanumeric or ::
$module =~ s/\b::\b//g;
$module =~ /^[a-zA-Z]\w*$/;
}
=back
=head2 Complex data structures
Not everything is a simple eq check or regex. There are times you
need to see if two data structures are equivalent. For these
instances Test::More provides a handful of useful functions.
B<NOTE> I'm not quite sure what will happen with filehandles.
=over 4
=item B<is_deeply>
is_deeply( $this, $that, $test_name );
Similar to is(), except that if $this and $that are references, it
does a deep comparison walking each data structure to see if they are
equivalent. If the two structures are different, it will display the
place where they start differing.
is_deeply() compares the dereferenced values of references, the
references themselves (except for their type) are ignored. This means
aspects such as blessing and ties are not considered "different".
is_deeply() current has very limited handling of function reference
and globs. It merely checks if they have the same referent. This may
improve in the future.
Test::Differences and Test::Deep provide more in-depth functionality
along these lines.
=cut
use vars qw(@Data_Stack %Refs_Seen);
my $DNE = bless [], 'Does::Not::Exist';
sub is_deeply {
my $tb = Test::More->builder;
unless( @_ == 2 or @_ == 3 ) {
my $msg = <<WARNING;
is_deeply() takes two or three args, you gave %d.
This usually means you passed an array or hash instead
of a reference to it
WARNING
chop $msg; # clip off newline so carp() will put in line/file
_carp sprintf $msg, scalar @_;
return $tb->ok(0);
}
my($this, $that, $name) = @_;
$tb->_unoverload_str(\$that, \$this);
my $ok;
if( !ref $this and !ref $that ) { # neither is a reference
$ok = $tb->is_eq($this, $that, $name);
}
elsif( !ref $this xor !ref $that ) { # one's a reference, one isn't
$ok = $tb->ok(0, $name);
$tb->diag( _format_stack({ vals => [ $this, $that ] }) );
}
else { # both references
local @Data_Stack = ();
if( _deep_check($this, $that) ) {
$ok = $tb->ok(1, $name);
}
else {
$ok = $tb->ok(0, $name);
$tb->diag(_format_stack(@Data_Stack));
}
}
return $ok;
}
sub _format_stack {
my(@Stack) = @_;
my $var = '$FOO';
my $did_arrow = 0;
foreach my $entry (@Stack) {
my $type = $entry->{type} || '';
my $idx = $entry->{'idx'};
if( $type eq 'HASH' ) {
( run in 3.681 seconds using v1.01-cache-2.11-cpan-f56aa216473 )