]> git.vpit.fr Git - perl/modules/indirect.git/blobdiff - t/20-good.t
Partially revert 502e3aac.
[perl/modules/indirect.git] / t / 20-good.t
index 0f482a55cf0a3bce2d3026b11fa39457e8215261..d57de4f0cc009fe71835634ebbfa3f1790c410ff 100644 (file)
@@ -9,12 +9,26 @@ package main;
 use strict;
 use warnings;
 
-use Test::More tests => 56 * 4;
+use Test::More tests => 112 * 8 + 10;
+
+BEGIN { delete $ENV{PERL_INDIRECT_PM_DISABLE} }
 
 my ($obj, $pkg, $cb, $x, @a);
-our $y;
+our ($y, $meth);
 sub meh;
-sub try (&);
+sub zap (&);
+
+my @warns;
+
+sub try {
+ my ($code) = @_;
+
+ @warns = ();
+ {
+  local $SIG{__WARN__} = sub { push @warns, @_ };
+  eval $code;
+ }
+}
 
 {
  local $/ = "####";
@@ -29,27 +43,126 @@ sub try (&);
 
 SKIP:
   {
-   skip "$_: $skip" => 4 if eval $skip;
-
-   local $SIG{__WARN__} = sub { die 'warn:' . join(' ', @_) };
+   skip "$_: $skip" => 8 if eval $skip;
 
-   eval "die qq{ok\\n}; $prefix; use indirect; $_";
-   is($@, "ok\n", "use indirect: $_");
+   {
+    try "return; $prefix; use indirect; $_";
+    is $@,     '', "use indirect: $_";
+    is @warns, 0,  'no reports';
 
-   eval "die qq{ok\n}; $prefix; no indirect; $_";
-   is($@, "ok\n", "no indirect: $_");
+    try "return; $prefix; no indirect; $_";
+    is $@,     '', "no indirect: $_";
+    is @warns, 0,  'no reports';
+   }
 
-   s/Hlagh/Dongs/g;
+   {
+    local $_ = $_;
+    s/Hlagh/Dongs/g;
 
-   eval "die qq{ok\\n}; $prefix; use indirect; $_";
-   is($@, "ok\n", "use indirect, defined: $_");
+    try "return; $prefix; use indirect; $_";
+    is $@,     '', "use indirect, defined: $_";
+    is @warns, 0,  'no reports';
 
-   eval "die qq{ok\\n}; $prefix; no indirect; $_";
-   is($@, "ok\n", "no indirect, defined: $_");
+    try "return; $prefix; no indirect; $_";
+    is $@,     '', "no indirect, defined: $_";
+    is @warns, 0,  'no reports';
+   }
   }
  }
 }
 
+# These tests must be run outside of eval to be meaningful.
+{
+ sub Zlott::Owww::new { }
+
+ my (@warns, $hook, $desc, $id);
+ BEGIN {
+  $hook = sub { push @warns, indirect::msg(@_) };
+  $desc = "test sort and line endings %d: no indirect construct";
+  $id   = 1;
+ }
+
+ BEGIN { @warns = () }
+ {
+  no indirect hook => $hook;
+  my @stuff = sort Zlott::Owww
+          ->new;
+ }
+ BEGIN { is_deeply \@warns, [ ], sprintf $desc, $id++ }
+
+ BEGIN { @warns = () }
+ {
+  no indirect hook => $hook;
+  my @stuff = sort Zlott::Owww
+               ->new;
+ };
+ BEGIN { is_deeply \@warns, [ ], sprintf $desc, $id++ }
+
+ BEGIN { @warns = () }
+ {
+  no indirect hook => $hook;
+  my @stuff = sort Zlott::Owww
+                 ->new;
+ }
+ BEGIN { is_deeply \@warns, [ ], sprintf $desc, $id++ }
+
+ BEGIN { @warns = () }
+ {
+  no indirect hook => $hook;
+  my @stuff = sort Zlott::Owww
+                  ->new;
+ }
+ BEGIN { is_deeply \@warns, [ ], sprintf $desc, $id++ }
+
+ BEGIN { @warns = () }
+ {
+  no indirect hook => $hook;
+  my @stuff = sort Zlott::Owww
+                   ->new;
+ }
+ BEGIN { is_deeply \@warns, [ ], sprintf $desc, $id++ }
+
+ BEGIN { @warns = () }
+ {
+  no indirect hook => $hook;
+  my @stuff = sort Zlott::Owww
+                     ->new;
+ }
+ BEGIN { is_deeply \@warns, [ ], sprintf $desc, $id++ }
+
+ BEGIN { @warns = () }
+ {
+  no indirect hook => $hook;
+  my @stuff = sort Zlott::Owww
+                       ->new;
+ }
+ BEGIN { is_deeply \@warns, [ ], sprintf $desc, $id++ }
+
+ BEGIN { @warns = () }
+ {
+  no indirect hook => $hook;
+  my @stuff = sort Zlott::Owww
+                          ->new;
+ }
+ BEGIN { is_deeply \@warns, [ ], sprintf $desc, $id++ }
+
+ BEGIN { @warns = () }
+ {
+  no indirect hook => $hook;
+  my @stuff = sort Zlott::Owww
+                            ->new;
+ }
+ BEGIN { is_deeply \@warns, [ ], sprintf $desc, $id++ }
+
+ BEGIN { @warns = () }
+ {
+  no indirect hook => $hook;
+  my @stuff = sort Zlott::Owww
+                             ->new;
+ }
+ BEGIN { is_deeply \@warns, [ ], sprintf $desc, $id++ }
+}
+
 __DATA__
 
 $obj = Hlagh->new;
@@ -103,6 +216,12 @@ $obj = Hlagh->$cb($pkg);
 ####
 $obj = Hlagh->$cb(sub { 'foo' },  bar => $obj);
 ####
+$obj = Hlagh->$meth;
+####
+$obj =   Hlagh
+   -> 
+          $meth   ( 1,   2   );
+####
 $obj = $pkg->new   ;
 ####
 $obj = $pkg  ->   new  (   );
@@ -128,7 +247,31 @@ $obj = $pkg    ->   ($cb)   ();
 ####
 $obj = $pkg->$cb( $obj  );
 ####
-$obj = $pkg->$cb(qw/foo bar baz/);
+$obj = $pkg->$cb(qw<foo bar baz>);
+####
+$obj = $pkg->$meth;
+####
+$obj 
+ =
+    $pkg
+          ->
+              $meth
+  ( 1 .. 10 );
+####
+$obj = $y->$cb;
+####
+$obj =  $y
+  ->          $cb   (
+  'foo', 1, 2, 'bar'
+);
+####
+$obj = $y->$meth;
+####
+$obj =
+  $y->
+      $meth   (
+ qr(hello),
+);
 ####
 meh;
 ####
@@ -141,9 +284,9 @@ meh $x, 1, 2;
 meh $y;
 ####
 meh $y, 1, 2;
-#### $] < 5.010 # use feature 'state'; state $z
+#### "$]" < 5.010 # use feature 'state'; state $z
 meh $z;
-#### $] < 5.010 # use feature 'state'; state $z
+#### "$]" < 5.010 # use feature 'state'; state $z
 meh $z, 1, 2;
 ####
 print;
@@ -157,18 +300,92 @@ print $x "oh hai\n";
 print $y;
 ####
 print $y "dongs\n";
-#### $] < 5.010 # use feature 'state'; state $z
+#### "$]" < 5.010 # use feature 'state'; state $z
 print $z;
-#### $] < 5.010 # use feature 'state'; state $z
+#### "$]" < 5.010 # use feature 'state'; state $z
 print $z "hlagh\n";
 ####
 print STDOUT "bananananananana\n";
 ####
 $x->foo($pkg->$cb)
 ####
-$obj = "apple ${\(new Hlagh)} pear"
+$obj = "apple ${\($x->new)} pear"
+####
+$obj = "apple @{[$x->new]} pear"
+####
+$obj = "apple ${\($y->new)} pear"
+####
+$obj = "apple @{[$y->new]} pear"
+####
+$obj = "apple ${\($x->$cb)} pear"
+####
+$obj = "apple @{[$x->$cb]} pear"
+####
+$obj = "apple ${\($y->$cb)} pear"
+####
+$obj = "apple @{[$y->$cb]} pear"
+####
+$obj = "apple ${\($x->$meth)} pear"
+####
+$obj = "apple @{[$x->$meth]} pear"
+####
+$obj = "apple ${\($y->$meth)} pear"
+####
+$obj = "apple @{[$y->$meth]} pear"
+#### # local $_ = "foo";
+s/foo/return; Hlagh->new/e;
+#### # local $_ = "bar";
+s/foo/return; Hlagh->new/e;
+#### # local $_ = "foo";
+s/foo/return; Hlagh->$cb/e;
+#### # local $_ = "bar";
+s/foo/return; Hlagh->$cb/e;
+#### # local $_ = "foo";
+s/foo/return; Hlagh->$meth/e;
+#### # local $_ = "bar";
+s/foo/return; Hlagh->$meth/e;
+#### # local $_ = "foo";
+s/foo/return; $x->new/e;
+#### # local $_ = "bar";
+s/foo/return; $x->new/e;
+#### # local $_ = "foo";
+s/foo/return; $x->$cb/e;
+#### # local $_ = "bar";
+s/foo/return; $x->$cb/e;
+#### # local $_ = "foo";
+s/foo/return; $x->$meth/e;
+#### # local $_ = "bar";
+s/foo/return; $x->$meth/e;
+#### # local $_ = "foo";
+s/foo/return; $y->new/e;
+#### # local $_ = "bar";
+s/foo/return; $y->new/e;
+#### # local $_ = "foo";
+s/foo/return; $y->$cb/e;
+#### # local $_ = "bar";
+s/foo/return; $y->$cb/e;
+#### # local $_ = "foo";
+s/foo/return; $y->$meth/e;
+#### # local $_ = "bar";
+s/foo/return; $y->$meth/e;
+####
+"foo" =~ /(?{Hlagh->new})/;
+####
+"foo" =~ /(?{Hlagh->$cb})/;
+####
+"foo" =~ /(?{Hlagh->$meth})/;
+####
+"foo" =~ /(?{$x->new})/;
 ####
-$obj = "apple @{[new Hlagh]} pear"
+"foo" =~ /(?{$x->$cb})/;
+####
+"foo" =~ /(?{$x->$meth})/;
+####
+"foo" =~ /(?{$y->new})/;
+####
+"foo" =~ /(?{$y->$cb})/;
+####
+"foo" =~ /(?{$y->$meth})/;
 ####
 exec $x $x, @a;
 ####
@@ -178,10 +395,49 @@ system $x $x, @a;
 ####
 system { $a[0] } @a;
 ####
-try { };
+zap { };
+####
+zap { 1; };
+####
+zap { 1; 1; };
+####
+zap { zap { }; 1; };
+####
+my @stuff = sort Hlagh
+     ->new;
+####
+my @stuff = sort Hlagh
+              ->new;
 ####
-try { 1; };
+my @stuff = sort Hlagh
+               ->new;
 ####
-try { 1; 1; };
+my @stuff = sort Hlagh
+                ->new;
 ####
-try { try { }; 1; };
+my @stuff = sort Hlagh
+                 ->new;
+####
+my @stuff = sort Hlagh
+                   ->new;
+####
+my @stuff = sort Hlagh
+                     ->new;
+####
+my @stuff = sort Hlagh
+                        ->new;
+####
+sub {
+ my $self = shift;
+ return $self->new ? $self : undef;
+}
+####
+sub {
+ my $self = shift;
+ return $self ? $self->new : undef;
+}
+####
+sub {
+ my $self = shift;
+ return $_[0] ? undef : $self->new;
+}