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
CommitLineData
1d0ef875
NA
1#!./perl
2
dab34d0f
NC
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6 require './test.pl';
7}
8
9use strict;
10
11plan 13;
12
1d0ef875 13sub context {
dab34d0f 14 local $::Level = $::Level + 1;
1d0ef875
NA
15 my ( $cona, $testnum ) = @_;
16 my $conb = (defined wantarray) ? ( wantarray ? 'A' : 'S' ) : 'V';
dab34d0f 17 is $cona, $conb;
1d0ef875
NA
18}
19
dab34d0f
NC
20context('V');
21my $a = context('S');
22my @a = context('A');
23scalar context('S');
24$a = scalar context('S');
25($a) = context('A');
26($a) = scalar context('S');
d2ccd3cb
HS
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();
dab34d0f
NC
37 is @b, 1;
38 is "@b", "2";
39 is $c, 2;
d2ccd3cb
HS
40}
41
dab34d0f
NC
42my $q;
43
cc37eb0b
RGS
44my $qcontext = q{
45 $q = (defined wantarray) ? ( wantarray ? 'A' : 'S' ) : 'V';
46};
47eval $qcontext;
dab34d0f 48is $q, 'V';
cc37eb0b 49$a = eval $qcontext;
dab34d0f 50is $q, 'S';
cc37eb0b 51@a = eval $qcontext;
dab34d0f 52is $q, 'A';
cc37eb0b 53
1d0ef875 541;