use strict; use warnings; use Test::More; my ($pos1,$pos2)=("a","a"); # *** Those should pass suite(\$pos1,\$pos1); # *** Those should fail suite(\$pos1,\$pos2); done_testing; # --- my tests for various scalar refs sub suite { my ($ref1,$ref2) = @_; is_deeply( scr($ref1), scr($ref2), "is_deeply"); is_deeply( scr([$ref1]), scr([$ref2]), "is_deeply ARRAY"); is_deeply( scr({t=> $ref1}), scr({t=>$ref2}), "is_deeply HASH"); is_deeply( scr({t => [$ref1]}), scr({t => [$ref2]}), "is_deeply HoA"); is_deeply( scr({t => [$ref1,$ref1], t2 => [$ref1]}), scr({t => [$ref2,$ref2], t2 => [$ref2]}), "is_deeply HoA multiple refs"); } # --- stringify_scalar_refs sub scr { my ($ref) = @_; my $reftype = ref $ref; if( $reftype eq 'SCALAR') { $$ref = "$ref"; } elsif ( $reftype eq 'ARRAY') { for my $el (@$ref) { scr($el); } } elsif ( $reftype eq 'HASH') { while (my ($key,$val) = each %$ref ){ scr($val); } } else { ... # dunno yet } return $ref }
-*- mode: compilation; default-directory: "d:/exp/" -*- Compilation started at Thu Jul 23 22:28:14 C:/Perl_524/bin\perl.exe -w d:/exp/pm_is_deeply.pl ok 1 - is_deeply ok 2 - is_deeply ARRAY ok 3 - is_deeply HASH ok 4 - is_deeply HoA ok 5 - is_deeply HoA multiple refs not ok 6 - is_deeply # Failed test 'is_deeply' # at d:/exp/pm_is_deeply.pl line 28. # Structures begin differing at: # ${ $got} = 'SCALAR(0x26589e8)' # ${$expected} = 'SCALAR(0x2650480)' not ok 7 - is_deeply ARRAY # Failed test 'is_deeply ARRAY' # at d:/exp/pm_is_deeply.pl line 32. # Structures begin differing at: # ${ $got->[0]} = 'SCALAR(0x26589e8)' # ${$expected->[0]} = 'SCALAR(0x2650480)' not ok 8 - is_deeply HASH # Failed test 'is_deeply HASH' # at d:/exp/pm_is_deeply.pl line 36. # Structures begin differing at: # ${ $got->{t}} = 'SCALAR(0x26589e8)' # ${$expected->{t}} = 'SCALAR(0x2650480)' not ok 9 - is_deeply HoA # Failed test 'is_deeply HoA' # at d:/exp/pm_is_deeply.pl line 40. # Structures begin differing at: # ${ $got->{t}[0]} = 'SCALAR(0x26589e8)' # ${$expected->{t}[0]} = 'SCALAR(0x2650480)' not ok 10 - is_deeply HoA multiple refs # Failed test 'is_deeply HoA multiple refs' # at d:/exp/pm_is_deeply.pl line 44. # Structures begin differing at: # ${ $got->{t2}[0]} = 'SCALAR(0x26589e8)' # ${$expected->{t2}[0]} = 'SCALAR(0x2650480)' 1..10 # Looks like you failed 5 tests of 10. Compilation exited abnormally with code 5 at Thu Jul 23 22:28:14
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
In reply to Re: Test scalar refs (not values) in deeply nested structure (workaround)
by LanX
in thread Test scalar refs (not values) in deeply nested structure
by LanX
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |