]> git.vpit.fr Git - perl/modules/indirect.git/blobdiff - t/20-bad.t
Test 'package A; sub foo; foo A->new' that gets deparsed as 'A->foo->new'
[perl/modules/indirect.git] / t / 20-bad.t
index 5c57ebed84a6a2b65e26ee44470402101e460b6b..0a61cd1917454c16db0c84054042650389d4a6c3 100644 (file)
@@ -1,9 +1,15 @@
 #!perl -T
 
+package Dongs;
+
+sub new;
+
+package main;
+
 use strict;
 use warnings;
 
-use Test::More tests => 30 * 2 + 2;
+use Test::More tests => 33 * 4 + 2;
 
 my ($obj, $x);
 
@@ -11,18 +17,28 @@ my ($obj, $x);
  local $/ = "####\n";
  while (<DATA>) {
   chomp;
+  local $SIG{__WARN__} = sub { die 'warn:' . join(' ', @_) };
+  {
+   use indirect;
+   eval "die qq{ok\\n}; $_";
+  }
+  is($@, "ok\n", "use indirect: $_");
+  {
+   no indirect;
+   eval "die qq{the code compiled but it shouldn't have\n}; $_";
+  }
+  like($@, qr/^warn:Indirect\s+call\s+of\s+method\s+"(?:new|meh|HlaghHlagh)"\s+on\s+object\s+"(?:Hlagh|newnew|\$x|\$_)"/, "no indirect: $_");
+  s/Hlagh/Dongs/g;
   {
    use indirect;
-   local $SIG{__WARN__} = sub { die 'warn:' . join(' ', @_) };
    eval "die qq{ok\\n}; $_";
   }
-  is($@, "ok\n", $_);
+  is($@, "ok\n", "use indirect, defined: $_");
   {
    no indirect;
-   local $SIG{__WARN__} = sub { die 'warn:' . join(' ', @_) };
    eval "die qq{the code compiled but it shouldn't have\n}; $_";
   }
-  like($@, qr/^warn:Indirect\s+call\s+of\s+method\s+"(?:new|meh|HlaghHlagh)"\s+on\s+object\s+"(?:Hlagh|newnew|\$x|\$_)"/, $_);
+  like($@, qr/^warn:Indirect\s+call\s+of\s+method\s+"(?:new|meh|DongsDongs)"\s+on\s+object\s+"(?:Dongs|newnew|\$x|\$_)"/, "no indirect, defined: $_");
  }
 }
 
@@ -98,6 +114,12 @@ meh $x;
 ####
 meh $x, 1, 2;
 ####
+new Hlagh->wut;
+####
+new Hlagh->wut();
+####
+new Hlagh->wut, "Wut";
+####
 $obj = HlaghHlagh Hlagh;
 ####
 $obj = HlaghHlagh Hlagh; # HlaghHlagh Hlagh