]> git.vpit.fr Git - perl/modules/indirect.git/blobdiff - t/10-args.t
Only enable the pragma during compile time
[perl/modules/indirect.git] / t / 10-args.t
index 6b7b61c2b0d97a3cf90954a027fbdbcb0803e50c..bb44e978fb1e346c02e01bd9db1f01f7c171e884 100644 (file)
@@ -1,17 +1,50 @@
-#!perl
+#!perl -T
 
 use strict;
 use warnings;
 
-use Test::More tests => 1;
+use Test::More tests => 4 + 1 + 1;
+
+sub expect {
+ my ($pkg) = @_;
+ return qr/^Indirect\s+call\s+of\s+method\s+"new"\s+on\s+object\s+"$pkg"\s+at\s+\(eval\s+\d+\)\s+line\s+\d+/;
+}
+
+{
+ my @warns;
+ local $SIG{__WARN__} = sub { push @warns, "@_" };
+ eval <<'HERE';
+  die qq{ok\n};
+  no indirect;
+  my $x = new Warn1;
+  $x = new Warn2;
+HERE
+ my $w1 = shift @warns;
+ my $w2 = shift @warns;
+ is             $@, "ok\n",          'didn\'t croak without arguments';
+ like          $w1, expect('Warn1'), 'first warning caught without arguments';
+ like          $w2, expect('Warn2'), 'second warning caught without arguments';
+ is_deeply \@warns, [ ],             'no more warnings without arguments';
+}
+
+{
+ local $SIG{__WARN__} = sub { die "warn:@_" };
+ eval <<'HERE';
+  die qq{shouldn't even compile\n};
+  no indirect ':fatal', hook => sub { die 'should not be called' };
+  my $x = new Fatal;
+  $x = new NotReached;
+HERE
+ like $@, expect('Fatal'), 'croaks when :fatal is specified';
+}
 
 {
- local $SIG{__WARN__} = sub { die 'warn:' . join(' ', @_) };
- eval <<HERE;
-die qq{shouldn't even compile\n};
-no indirect ':fatal';
-my \$x = new Hlagh;
-\$x = new Fail;
+ local $SIG{__WARN__} = sub { "warn:@_" };
+ eval <<'HERE';
+  die qq{shouldn't even compile\n};
+  no indirect 'whatever', hook => sub { die 'hook:' . join(':', @_) . "\n" }, ':fatal';
+  my $x = new Hooked;
+  $x = new AlsoNotReached;
 HERE
- like($@, qr/^Indirect\s+call\s+of\s+method\s+"new"\s+on\s+object\s+"Hlagh"/, 'croak when :fatal is specified');
+ like $@, qr/^hook:Hooked:new:\(eval\s+\d+\):\d+$/, 'calls the specified hook';
 }