]> git.vpit.fr Git - perl/modules/indirect.git/blobdiff - t/10-args.t
Forbid passing 'hook' and 'fatal' at the same time
[perl/modules/indirect.git] / t / 10-args.t
index d7352955b295e46478be1e971a951d0711639e0c..444c730f49334bf0f726c50ca3894ff88652fcfe 100644 (file)
@@ -3,7 +3,9 @@
 use strict;
 use warnings;
 
-use Test::More tests => 4 + 1 + 1;
+use Test::More tests => 4 + 3 + 1 + 2;
+
+BEGIN { delete $ENV{PERL_INDIRECT_PM_DISABLE} }
 
 sub expect {
  my ($pkg) = @_;
@@ -29,17 +31,17 @@ sub expect {
  is_deeply \@warns, [ ],             'no more warnings without arguments';
 }
 
-{
+for my $fatal (':fatal', 'FATAL', ':Fatal') {
  {
   local $SIG{__WARN__} = sub { die "warn:@_" };
-  eval <<'  HERE';
+  eval <<"  HERE";
    die qq{shouldn't even compile\n};
-   no indirect ':fatal', hook => sub { die 'should not be called' };
-   my $x = new Croaked;
-   $x = new NotReached;
+   no indirect '$fatal';
+   my \$x = new Croaked;
+   \$x = new NotReached;
   HERE
  }
- like $@, expect('Croaked'), 'croaks when :fatal is specified';
+ like $@, expect('Croaked'), "croaks when $fatal is specified";
 }
 
 {
@@ -47,10 +49,34 @@ sub expect {
   local $SIG{__WARN__} = sub { "warn:@_" };
   eval <<'  HERE';
    die qq{shouldn't even compile\n};
-   no indirect 'whatever', hook => sub { die 'hook:' . join(':', @_) . "\n" }, ':fatal';
+   no indirect 'whatever', hook => sub { die 'hook:' . join(':', @_) . "\n" };
    my $x = new Hooked;
    $x = new AlsoNotReached;
   HERE
  }
  like $@, qr/^hook:Hooked:new:\(eval\s+\d+\):\d+$/, 'calls the specified hook';
 }
+
+{
+ my $no_hook_and_fatal = qr/^The 'fatal' and 'hook' options are mutually exclusive at \(eval \d+\) line \d+/;
+
+ {
+  local $SIG{__WARN__} = sub { die "warn:@_" };
+  eval <<'  HERE';
+   die qq{shouldn't even compile\n};
+   no indirect 'fatal', hook => sub { };
+   new NotReached;
+  HERE
+ }
+ like $@, $no_hook_and_fatal, '"no indirect qw<fatal hook>" croaks';
+
+ {
+  local $SIG{__WARN__} = sub { die "warn:@_" };
+  eval <<'  HERE';
+   die qq{shouldn't even compile\n};
+   no indirect hook => sub { }, 'fatal';
+   new NotReached;
+  HERE
+ }
+ like $@, $no_hook_and_fatal, '"no indirect qw<hook fatal>" croaks';
+}