This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Silence some diagnostic messages when running within the core tests.
[perl5.git] / lib / if.t
1 #!./perl
2
3 BEGIN {
4     chdir 't' and @INC = '../lib' if $ENV{PERL_CORE};
5 }
6
7 my $t = 1;
8 print "1..5\n";
9 sub ok {
10   print "not " unless shift;
11   print "ok $t # ", shift, "\n";
12   $t++;
13 }
14
15 my $v_plus = $] + 1;
16 my $v_minus = $] - 1;
17
18 unless (eval 'use open ":std"; 1') {
19   # pretend that open.pm is present
20   $INC{'open.pm'} = 'open.pm';
21   eval 'sub open::foo{}';               # Just in case...
22 }
23
24
25 ok( eval "use if ($v_minus > \$]), strict => 'subs'; \${'f'} = 12" eq 12,
26     '"use if" with a false condition, fake pragma');
27
28 ok( eval "use if ($v_minus > \$]), strict => 'refs'; \${'f'} = 12" eq 12,
29     '"use if" with a false condition and a pragma');
30
31 ok( eval "use if ($v_plus > \$]), strict => 'subs'; \${'f'} = 12" eq 12,
32     '"use if" with a true condition, fake pragma');
33
34 ok( (not defined eval "use if ($v_plus > \$]), strict => 'refs'; \${'f'} = 12"
35      and $@ =~ /while "strict refs" in use/),
36     '"use if" with a true condition and a pragma');
37
38 # Old version had problems with the module name `open', which is a keyword too
39 # Use 'open' =>, since pre-5.6.0 could interpret differently
40 ok( (eval "use if ($v_plus > \$]), 'open' => IN => ':crlf'; 12" || 0) eq 12,
41     '"use if" with open');