X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F25-copy.t;h=46e324141653d2298c32b85ad5a3b4ce948e379e;hb=9ad970e109ea4caa9767db1bda9d475444920c7a;hp=a18022f057488ca669b7375f790fe95387dc2bcd;hpb=3bc98bdbdb230943e7fb3135e325f10013acac2d;p=perl%2Fmodules%2FVariable-Magic.git diff --git a/t/25-copy.t b/t/25-copy.t index a18022f..46e3241 100644 --- a/t/25-copy.t +++ b/t/25-copy.t @@ -5,13 +5,12 @@ use warnings; use Test::More; -use Variable::Magic qw; +use lib 't/lib'; +use VPIT::TestHelpers; -if (MGf_COPY) { - plan tests => 2 + ((2 * 5 + 3) + (2 * 2 + 1)) + (2 * 9 + 6) + 1; -} else { - plan skip_all => 'No copy magic for this perl'; -} +use Variable::Magic qw; + +plan tests => 2 + ((2 * 5 + 3) + (2 * 2 + 1)) + (2 * 9 + 6) + 3 + 1; use lib 't/lib'; use Variable::Magic::TestWatcher; @@ -20,10 +19,7 @@ use Variable::Magic::TestValue; my $wiz = init_watcher 'copy', 'copy'; SKIP: { - eval "use Tie::Array"; - skip 'Tie::Array required to test copy magic on arrays' - => (2 * 5 + 3) + (2 * 2 + 1) if $@; - defined and diag "Using Tie::Array $_" for $Tie::Array::VERSION; + load_or_skip('Tie::Array', undef, undef, (2 * 5 + 3) + (2 * 2 + 1)); tie my @a, 'Tie::StdArray'; @a = (1 .. 10); @@ -55,9 +51,7 @@ SKIP: { } SKIP: { - eval "use Tie::Hash"; - skip 'Tie::Hash required to test copy magic on hashes' => 2 * 9 + 6 if $@; - defined and diag "Using Tie::Hash $_" for $Tie::Hash::VERSION; + load_or_skip('Tie::Hash', undef, undef, 2 * 9 + 6); tie my %h, 'Tie::StdHash'; %h = (a => 1, b => 2, c => 3); @@ -86,3 +80,23 @@ SKIP: { watch { undef %h } { }, 'tied hash undef'; } + +SKIP: { + skip 'copy magic not called for cloned prototypes before perl 5.17.0' => 3 + unless VMG_COMPAT_CODE_COPY_CLONE; + my $w = wizard copy => sub { + is ref($_[0]), 'CODE', 'first arg in copy on clone is a code ref'; + is $_[2], undef, 'third arg in copy on clone is undef'; + is ref($_[3]), 'CODE', 'fourth arg in copy on clone is a code ref'; + }; + eval <<'TEST_COPY'; + package X; + sub MODIFY_CODE_ATTRIBUTES { + my ($pkg, $sub) = @_; + &Variable::Magic::cast($sub, $w); + return; + } + my $i; + my $f = sub : Hello { $i }; +TEST_COPY +}