This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Get t/uni/cache.t working under minitest
[perl5.git] / t / op / wantarray.t
1 #!./perl
2
3 BEGIN {
4     chdir 't' if -d 't';
5     @INC = '../lib';
6     require './test.pl';
7 }
8
9 use strict;
10
11 plan 13;
12
13 sub context {
14   local $::Level = $::Level + 1;
15   my ( $cona, $testnum ) = @_;
16   my $conb = (defined wantarray) ? ( wantarray ? 'A' : 'S' ) : 'V';
17   is $cona, $conb;
18 }
19
20 context('V');
21 my $a = context('S');
22 my @a = context('A');
23 scalar context('S');
24 $a = scalar context('S');
25 ($a) = context('A');
26 ($a) = scalar context('S');
27
28 {
29   # [ID 20020626.011] incorrect wantarray optimisation
30   sub simple { wantarray ? 1 : 2 }
31   sub inline {
32     my $a = wantarray ? simple() : simple();
33     $a;
34   }
35   my @b = inline();
36   my $c = inline();
37   is @b, 1;
38   is "@b", "2";
39   is $c, 2;
40 }
41
42 my $q;
43
44 my $qcontext = q{
45   $q = (defined wantarray) ? ( wantarray ? 'A' : 'S' ) : 'V';
46 };
47 eval $qcontext;
48 is $q, 'V';
49 $a = eval $qcontext;
50 is $q, 'S';
51 @a = eval $qcontext;
52 is $q, 'A';
53
54 1;