Skip to content

Commit

Permalink
Merge pull request #918 from haarg/is_deeply_lvalue
Browse files Browse the repository at this point in the history
is_deeply: fix handling of VSTRING and LVALUE refs
  • Loading branch information
exodist authored Oct 24, 2023
2 parents 68cad46 + 3fbf766 commit ee07627
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
19 changes: 17 additions & 2 deletions lib/Test/More.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1206,13 +1206,28 @@ sub _format_stack {
return $out;
}

my %_types = (
(map +($_ => $_), qw(
Regexp
ARRAY
HASH
SCALAR
REF
GLOB
CODE
)),
'LVALUE' => 'SCALAR',
'REF' => 'SCALAR',
'VSTRING' => 'SCALAR',
);

sub _type {
my $thing = shift;

return '' if !ref $thing;

for my $type (qw(Regexp ARRAY HASH REF SCALAR GLOB CODE VSTRING)) {
return $type if UNIVERSAL::isa( $thing, $type );
for my $type (keys %_types) {
return $_types{$type} if UNIVERSAL::isa( $thing, $type );
}

return '';
Expand Down
30 changes: 29 additions & 1 deletion t/Legacy/is_deeply_fail.t
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ package main;


my $TB = Test::Builder->create;
$TB->plan(tests => 102);
$TB->plan(tests => 110);

# Utility testing functions.
sub ok ($;$) {
Expand Down Expand Up @@ -428,3 +428,31 @@ ERR
ok !is_deeply( [\\$version1], [\\$version2], "version objects");
is( $out, "not ok 42 - version objects\n" );
}

{
my $version1 = v1.2.3;
my $version2 = '' . v1.2.3;
ok is_deeply( [\$version1], [\$version2], "version objects");
is( $out, "ok 43 - version objects\n" );
}

{
my $version1 = v1.2.3;
my $version2 = v1.2.3;
ok !is_deeply( [$version1], [\$version2], "version objects");
is( $out, "not ok 44 - version objects\n" );
}

{
my $string = "abc";
my $string2 = "b";
ok is_deeply( [\substr($string, 1, 1)], [\$string2], "lvalue ref");
is( $out, "ok 45 - lvalue ref\n" );
}

{
my $string = "b";
my $string2 = "b";
ok !is_deeply( [\substr($string, 1, 1)], ["b"], "lvalue ref");
is( $out, "not ok 46 - lvalue ref\n" );
}

0 comments on commit ee07627

Please sign in to comment.