File: 114-blurt_death_Warn.t

package info (click to toggle)
perl 5.20.2-3%2Bdeb8u11
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 102,964 kB
  • sloc: perl: 555,553; ansic: 214,041; sh: 38,121; pascal: 8,783; cpp: 3,895; makefile: 2,393; xml: 2,325; yacc: 1,741
file content (129 lines) | stat: -rw-r--r-- 2,836 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/perl
use strict;
use warnings;
$| = 1;
use Test::More tests =>  7;
use File::Spec;
use lib (-d 't' ? File::Spec->catdir(qw(t lib)) : 'lib');
use ExtUtils::ParseXS;
use ExtUtils::ParseXS::Utilities qw(
    Warn
    blurt
    death
);
use PrimitiveCapture;

my $self = ExtUtils::ParseXS->new;
$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->report_error_count, 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");