updated dependents test
[gitmo/Moo.git] / t / sub-defer.t
index a5309b0..5938dd8 100644 (file)
@@ -1,5 +1,6 @@
 use strictures 1;
 use Test::More;
+use Test::Fatal;
 use Sub::Defer;
 
 my %made;
@@ -29,6 +30,9 @@ is(Foo->one, 'one', 'one (undeferred) runs');
 
 is(my $two_made = undefer_sub($two_defer), $made{'Foo::two'}, 'make two');
 
+is exception { undefer_sub($two_defer) }, undef,
+  "repeated undefer doesn't regenerate";
+
 is($two_made, \&Foo::two, 'two installed');
 
 is($two_defer->(), 'two', 'two (deferred) still runs');
@@ -39,4 +43,19 @@ my $three = sub { 'three' };
 
 is(undefer_sub($three), $three, 'undefer non-deferred is a no-op');
 
+my $four_defer = defer_sub 'Foo::four' => sub {
+  sub { 'four' }
+};
+is($four_defer, \&Foo::four, 'four defer installed');
+
+# somebody somewhere wraps up around the deferred installer
+no warnings qw/redefine/;
+my $orig = Foo->can('four');
+*Foo::four = sub {
+  $orig->() . ' with a twist';
+};
+
+is(Foo->four, 'four with a twist', 'around works');
+is(Foo->four, 'four with a twist', 'around has not been destroyed by first invocation');
+
 done_testing;