This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Undo io_linenum.t part of #34148. It was io_multihomed.t that I meant
[perl5.git] / t / op / wantarray.t
CommitLineData
1d0ef875
NA
1#!./perl
2
cc37eb0b 3print "1..12\n";
1d0ef875
NA
4sub context {
5 my ( $cona, $testnum ) = @_;
6 my $conb = (defined wantarray) ? ( wantarray ? 'A' : 'S' ) : 'V';
7 unless ( $cona eq $conb ) {
8 print "# Context $conb should be $cona\nnot ";
9 }
10 print "ok $testnum\n";
11}
12
13context('V',1);
14$a = context('S',2);
15@a = context('A',3);
d6483035
GS
16scalar context('S',4);
17$a = scalar context('S',5);
18($a) = context('A',6);
19($a) = scalar context('S',7);
d2ccd3cb
HS
20
21{
22 # [ID 20020626.011] incorrect wantarray optimisation
23 sub simple { wantarray ? 1 : 2 }
24 sub inline {
25 my $a = wantarray ? simple() : simple();
26 $a;
27 }
28 my @b = inline();
29 my $c = inline();
30 print +(@b == 1 && "@b" eq "2") ? "ok 8\n" : "not ok 8\t# <@b>\n";
31 print +($c == 2) ? "ok 9\n" : "not ok 9\t# <$c>\n";
32}
33
cc37eb0b
RGS
34my $qcontext = q{
35 $q = (defined wantarray) ? ( wantarray ? 'A' : 'S' ) : 'V';
36};
37eval $qcontext;
38print $q eq 'V' ? "ok 10\n" : "not ok 10\n";
39$a = eval $qcontext;
40print $q eq 'S' ? "ok 11\n" : "not ok 11\n";
41@a = eval $qcontext;
42print $q eq 'A' ? "ok 12\n" : "not ok 12\n";
43
1d0ef875 441;