X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2Findirect.git;a=blobdiff_plain;f=t%2F33-compilation-errors.t;fp=t%2F33-compilation-errors.t;h=be01768a99c07a1af6a155c49723c40d9773a9f2;hp=0000000000000000000000000000000000000000;hb=4f7c4a9fe4fd2332dd2a748b17171f9d45129e4f;hpb=b05f4291bec38d550b98e45a9e6f2320403905d3 diff --git a/t/33-compilation-errors.t b/t/33-compilation-errors.t new file mode 100644 index 0000000..be01768 --- /dev/null +++ b/t/33-compilation-errors.t @@ -0,0 +1,60 @@ +#!perl + +use strict; +use warnings; + +use Test::More tests => 4; + +use lib 't/lib'; +use VPIT::TestHelpers 'capture'; + +BEGIN { delete $ENV{PERL_INDIRECT_PM_DISABLE} } + +sub compile_err_code { + my ($fatal) = @_; + + if ($fatal) { + $fatal = 'no indirect q[fatal]; sub foo { \$bar }'; + } else { + $fatal = 'no indirect;'; + } + + return "use strict; use warnings; $fatal; baz \$_; sub qux { \$ook }"; +} + +my $indirect_msg = qr/Indirect call of method "baz" on object "\$_"/; +my $core_err1 = qr/Global symbol "\$bar"/; +my $core_err2 = qr/Global symbol "\$ook"/; +my $aborted = qr/Execution of -e aborted due to compilation errors\./; +my $line_end = qr/[^\n]*\n/; +my $compile_err_warn_exp = qr/$indirect_msg$line_end$core_err2$line_end/o; +my $compile_err_fatal_exp = qr/$core_err1$line_end$indirect_msg$line_end/o; + +SKIP: { + my ($stat, $out, $err) = capture_perl compile_err_code(0); + skip CAPTURE_PERL_FAILED($out) => 1 unless defined $stat; + like $err, qr/\A$compile_err_warn_exp$aborted$line_end\z/o, + 'no indirect warn does not hide compilation errors outside of eval'; +} + +SKIP: { + my $code = compile_err_code(0); + my ($stat, $out, $err) = capture_perl "eval q[$code]; die \$@ if \$@"; + skip CAPTURE_PERL_FAILED($out) => 1 unless defined $stat; + like $err, qr/\A$compile_err_warn_exp\z/o, + 'no indirect warn does not hide compilation errors inside of eval'; +} + +SKIP: { + my ($stat, $out, $err) = capture_perl compile_err_code(1); + skip CAPTURE_PERL_FAILED($out) => 1 unless defined $stat; + like $err, qr/\A$compile_err_fatal_exp\z/o, + 'no indirect fatal does not hide compilation errors outside of eval'; +} + +{ + local $@; + eval compile_err_code(1); + like $@, qr/\A$compile_err_fatal_exp\z/o, + 'no indirect fatal does not hide compilation errors inside of eval'; +}