]> git.vpit.fr Git - perl/modules/indirect.git/blob - t/33-compilation-errors.t
be01768a99c07a1af6a155c49723c40d9773a9f2
[perl/modules/indirect.git] / t / 33-compilation-errors.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 4;
7
8 use lib 't/lib';
9 use VPIT::TestHelpers 'capture';
10
11 BEGIN { delete $ENV{PERL_INDIRECT_PM_DISABLE} }
12
13 sub compile_err_code {
14  my ($fatal) = @_;
15
16  if ($fatal) {
17   $fatal = 'no indirect q[fatal]; sub foo { \$bar }';
18  } else {
19   $fatal = 'no indirect;';
20  }
21
22  return "use strict; use warnings; $fatal; baz \$_; sub qux { \$ook }";
23 }
24
25 my $indirect_msg = qr/Indirect call of method "baz" on object "\$_"/;
26 my $core_err1    = qr/Global symbol "\$bar"/;
27 my $core_err2    = qr/Global symbol "\$ook"/;
28 my $aborted      = qr/Execution of -e aborted due to compilation errors\./;
29 my $line_end     = qr/[^\n]*\n/;
30 my $compile_err_warn_exp  = qr/$indirect_msg$line_end$core_err2$line_end/o;
31 my $compile_err_fatal_exp = qr/$core_err1$line_end$indirect_msg$line_end/o;
32
33 SKIP: {
34  my ($stat, $out, $err) = capture_perl compile_err_code(0);
35  skip CAPTURE_PERL_FAILED($out) => 1 unless defined $stat;
36  like $err, qr/\A$compile_err_warn_exp$aborted$line_end\z/o,
37             'no indirect warn does not hide compilation errors outside of eval';
38 }
39
40 SKIP: {
41  my $code = compile_err_code(0);
42  my ($stat, $out, $err) = capture_perl "eval q[$code]; die \$@ if \$@";
43  skip CAPTURE_PERL_FAILED($out) => 1 unless defined $stat;
44  like $err, qr/\A$compile_err_warn_exp\z/o,
45              'no indirect warn does not hide compilation errors inside of eval';
46 }
47
48 SKIP: {
49  my ($stat, $out, $err) = capture_perl compile_err_code(1);
50  skip CAPTURE_PERL_FAILED($out) => 1 unless defined $stat;
51  like $err, qr/\A$compile_err_fatal_exp\z/o,
52            'no indirect fatal does not hide compilation errors outside of eval';
53 }
54
55 {
56  local $@;
57  eval compile_err_code(1);
58  like $@, qr/\A$compile_err_fatal_exp\z/o,
59             'no indirect fatal does not hide compilation errors inside of eval';
60 }