This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
if.pm: Better failure message for 'no if'
[perl5.git] / dist / if / t / if.t
CommitLineData
cd16c24c
IZ
1#!./perl
2
80b774e4 3use strict;
14735530 4use Test::More tests => 10;
cd16c24c
IZ
5
6my $v_plus = $] + 1;
7my $v_minus = $] - 1;
8
2f761939
NC
9unless (eval 'use open ":std"; 1') {
10 # pretend that open.pm is present
11 $INC{'open.pm'} = 'open.pm';
12 eval 'sub open::foo{}'; # Just in case...
13}
14
80b774e4 15no strict;
cd16c24c 16
80b774e4 17is( eval "use if ($v_minus > \$]), strict => 'subs'; \${'f'} = 12", 12,
cd16c24c 18 '"use if" with a false condition, fake pragma');
80b774e4 19is( eval "use if ($v_minus > \$]), strict => 'refs'; \${'f'} = 12", 12,
cd16c24c
IZ
20 '"use if" with a false condition and a pragma');
21
80b774e4 22is( eval "use if ($v_plus > \$]), strict => 'subs'; \${'f'} = 12", 12,
cd16c24c
IZ
23 '"use if" with a true condition, fake pragma');
24
80b774e4 25is( eval "use if ($v_plus > \$]), strict => 'refs'; \${'f'} = 12", undef,
cd16c24c 26 '"use if" with a true condition and a pragma');
80b774e4 27like( $@, qr/while "strict refs" in use/, 'expected error message'),
cd16c24c 28
882ce583 29# Old version had problems with the module name 'open', which is a keyword too
2f761939 30# Use 'open' =>, since pre-5.6.0 could interpret differently
80b774e4 31is( (eval "use if ($v_plus > \$]), 'open' => IN => ':crlf'; 12" || 0), 12,
2f761939 32 '"use if" with open');
14735530
KW
33
34is(eval "use if ($v_plus > \$])", undef,
35 "Too few args to 'use if' returns <undef>");
36like($@, qr/Too few arguments to 'use if'/, " ... and returns correct error");
37
38is(eval "no if ($v_plus > \$])", undef,
39 "Too few args to 'no if' returns <undef>");
40like($@, qr/Too few arguments to 'no if'/, " ... and returns correct error");