This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Convert wantarray.t to use strict and test.pl
[perl5.git] / t / op / wantarray.t
... / ...
CommitLineData
1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6 require './test.pl';
7}
8
9use strict;
10
11plan 13;
12
13sub 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
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');
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
42my $q;
43
44my $qcontext = q{
45 $q = (defined wantarray) ? ( wantarray ? 'A' : 'S' ) : 'V';
46};
47eval $qcontext;
48is $q, 'V';
49$a = eval $qcontext;
50is $q, 'S';
51@a = eval $qcontext;
52is $q, 'A';
53
541;