]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blobdiff - t/15-self.t
Move the global destruction logic of t/15-self.t out in an helper module
[perl/modules/Variable-Magic.git] / t / 15-self.t
index 6f6d9a469b99c9df35389bb1f4965fb5be1eff56..1491dfe372b294a9f72457e3e173c7f12f858fbe 100644 (file)
@@ -3,9 +3,12 @@
 use strict;
 use warnings;
 
-use Test::More tests => 16;
+use Test::More tests => 17;
 
-use Variable::Magic qw/wizard cast dispell getdata getsig/;
+use Variable::Magic qw<wizard cast dispell getdata>;
+
+use lib 't/lib';
+use Variable::Magic::TestGlobalDestruction;
 
 my $c = 0;
 
@@ -15,39 +18,42 @@ my $c = 0;
          get  => sub { ++$c },
          free => sub { --$c }
  };
ok(!$@, "wizard creation error ($@)");
- ok(defined $wiz, 'wizard is defined');
ok(ref $wiz eq 'SCALAR', 'wizard is a scalar ref');
is($@, '',             'wizard creation error doesn\'t croak');
+ ok(defined $wiz,       'wizard is defined');
is(ref $wiz, 'SCALAR', 'wizard is a scalar ref');
 
  my $res = eval { cast $wiz, $wiz };
ok(!$@, "cast on self croaks ($@)");
- ok($res, 'cast on self invalid');
is($@, '', 'cast on self doesn\'t croak');
+ ok($res,   'cast on self is valid');
 
  my $w = $wiz;
ok($c == 1, 'magic works correctly on self');
is($c, 1, 'magic works correctly on self');
 
  $res = eval { dispell $wiz, $wiz };
ok(!$@, "dispell on self croaks ($@)");
- ok($res, 'dispell on self invalid');
is($@, '', 'dispell on self doesn\'t croak');
+ ok($res,   'dispell on self is valid');
 
  $w = $wiz;
ok($c == 1, 'magic is no longer invoked on self when dispelled');
is($c, 1, 'magic is no longer invoked on self when dispelled');
 
  $res = eval { cast $wiz, $wiz, $wiz };
ok(!$@, "re-cast on self croaks ($@)");
- ok($res, 're-cast on self invalid');
is($@, '', 're-cast on self doesn\'t croak');
+ ok($res,   're-cast on self is valid');
 
  $w = getdata $wiz, $wiz;
- ok($c == 1, 'getdata on magical self doesn\'t trigger callbacks');
- # ok(getsig($w) == getsig($wiz), 'getdata returns the correct wizard');
+ is($c, 1, 'getdata on magical self doesn\'t trigger callbacks');
 
  $res = eval { dispell $wiz, $wiz };
ok(!$@, "re-dispell on self croaks ($@)");
- ok($res, 're-dispell on self invalid');
is($@, '', 're-dispell on self doesn\'t croak');
+ ok($res,   're-dispell on self is valid');
 
  $res = eval { cast $wiz, $wiz };
ok(!$@, "re-re-cast on self croaks ($@)");
- ok($res, 're-re-cast on self invalid');
is($@, '', 're-re-cast on self doesn\'t croak');
+ ok($res,   're-re-cast on self is valid');
 }
 
-# ok($c == 0, 'magic destructor is called');
+eval q[
+ use lib 't/lib';
+ BEGIN { require Variable::Magic::TestDestroyRequired; }
+];
+is $@, '', 'wizard destruction at the end of BEGIN-time require doesn\'t panic';