diff options
Diffstat (limited to 'dist/ExtUtils-ParseXS/t/114-blurt_death_Warn.t')
-rw-r--r-- | dist/ExtUtils-ParseXS/t/114-blurt_death_Warn.t | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/dist/ExtUtils-ParseXS/t/114-blurt_death_Warn.t b/dist/ExtUtils-ParseXS/t/114-blurt_death_Warn.t new file mode 100644 index 0000000000..955b29b65b --- /dev/null +++ b/dist/ExtUtils-ParseXS/t/114-blurt_death_Warn.t @@ -0,0 +1,132 @@ +#!/usr/bin/perl +use strict; +use warnings; +$| = 1; +use Carp; +use Cwd; +use File::Spec; +use File::Temp qw( tempdir ); +use Test::More tests => 7; +use lib qw( lib t/lib ); +use ExtUtils::ParseXS; +use ExtUtils::ParseXS::Utilities qw( + Warn + blurt + death +); +use PrimitiveCapture; + +my $self = bless({} => 'ExtUtils::ParseXS'); +$self->{line} = []; +$self->{line_no} = []; + +{ + $self->{line} = [ + 'Alpha', + 'Beta', + 'Gamma', + 'Delta', + ]; + $self->{line_no} = [ 17 .. 20 ]; + $self->{filename} = 'myfile1'; + + my $message = 'Warning: Ignoring duplicate alias'; + + my $stderr = PrimitiveCapture::capture_stderr(sub { + Warn( $self, $message); + }); + like( $stderr, + qr/$message in $self->{filename}, line 20/, + "Got expected Warn output", + ); +} + +{ + $self->{line} = [ + 'Alpha', + 'Beta', + 'Gamma', + 'Delta', + 'Epsilon', + ]; + $self->{line_no} = [ 17 .. 20 ]; + $self->{filename} = 'myfile2'; + + my $message = 'Warning: Ignoring duplicate alias'; + my $stderr = PrimitiveCapture::capture_stderr(sub { + Warn( $self, $message); + }); + like( $stderr, + qr/$message in $self->{filename}, line 19/, + "Got expected Warn output", + ); +} + +{ + $self->{line} = [ + 'Alpha', + 'Beta', + 'Gamma', + 'Delta', + ]; + $self->{line_no} = [ 17 .. 21 ]; + $self->{filename} = 'myfile1'; + + my $message = 'Warning: Ignoring duplicate alias'; + my $stderr = PrimitiveCapture::capture_stderr(sub { + Warn( $self, $message); + }); + like( $stderr, + qr/$message in $self->{filename}, line 17/, + "Got expected Warn output", + ); +} + +{ + $self->{line} = [ + 'Alpha', + 'Beta', + 'Gamma', + 'Delta', + ]; + $self->{line_no} = [ 17 .. 20 ]; + $self->{filename} = 'myfile1'; + $self->{errors} = 0; + + + my $message = 'Error: Cannot parse function definition'; + my $stderr = PrimitiveCapture::capture_stderr(sub { + blurt( $self, $message); + }); + like( $stderr, + qr/$message in $self->{filename}, line 20/, + "Got expected blurt output", + ); + is( $self->{errors}, 1, "Error count incremented correctly" ); +} + +SKIP: { + skip "death() not testable as long as it contains hard-coded 'exit'", 1; + + $self->{line} = [ + 'Alpha', + 'Beta', + 'Gamma', + 'Delta', + ]; + $self->{line_no} = [ 17 .. 20 ]; + $self->{filename} = 'myfile1'; + + my $message = "Code is not inside a function"; + eval { + my $stderr = PrimitiveCapture::capture_stderr(sub { + death( $self, $message); + }); + like( $stderr, + qr/$message in $self->{filename}, line 20/, + "Got expected death output", + ); + }; +} + +pass("Passed all tests in $0"); |