7 use File::Temp qw( tempdir );
8 use Test::More tests => 13;
9 use lib qw( lib t/lib );
10 use ExtUtils::ParseXS;
11 use ExtUtils::ParseXS::Utilities qw(
12 check_conditional_preprocessor_statements
16 my $self = bless({} => 'ExtUtils::ParseXS');
18 $self->{XSStack} = [];
19 $self->{XSStack}->[0] = {};
23 "#if this_is_an_if_statement",
24 "Alpha this is not an if/elif/elsif/endif",
25 "#elif this_is_an_elif_statement",
26 "Beta this is not an if/elif/elsif/endif",
27 "#else this_is_an_else_statement",
28 "Gamma this is not an if/elif/elsif/endif",
29 "#endif this_is_an_endif_statement",
31 $self->{line_no} = [ 17 .. 23 ];
32 $self->{XSStack}->[-1]{type} = 'if';
33 $self->{filename} = 'myfile1';
36 my $stderr = PrimitiveCapture::capture_stderr(sub {
37 $rv = check_conditional_preprocessor_statements($self);
40 is( $rv, 0, "Basic case: returned 0: all ifs resolved" );
41 ok( ! $stderr, "No warnings captured, as expected" );
46 "#if this_is_an_if_statement",
47 "Alpha this is not an if/elif/elsif/endif",
48 "#if this_is_a_different_if_statement",
49 "Beta this is not an if/elif/elsif/endif",
50 "#endif this_is_a_different_endif_statement",
51 "Gamma this is not an if/elif/elsif/endif",
52 "#endif this_is_an_endif_statement",
54 $self->{line_no} = [ 17 .. 23 ];
55 $self->{XSStack}->[-1]{type} = 'if';
56 $self->{filename} = 'myfile1';
59 my $stderr = PrimitiveCapture::capture_stderr(sub {
60 $rv = check_conditional_preprocessor_statements($self);
62 is( $rv, 0, "One nested if case: returned 0: all ifs resolved" );
63 ok( ! $stderr, "No warnings captured, as expected" );
68 "Alpha this is not an if/elif/elsif/endif",
69 "#elif this_is_an_elif_statement",
70 "Beta this is not an if/elif/elsif/endif",
71 "#else this_is_an_else_statement",
72 "Gamma this is not an if/elif/elsif/endif",
73 "#endif this_is_an_endif_statement",
75 $self->{line_no} = [ 17 .. 22 ];
76 $self->{XSStack}->[-1]{type} = 'if';
77 $self->{filename} = 'myfile1';
80 my $stderr = PrimitiveCapture::capture_stderr(sub {
81 $rv = check_conditional_preprocessor_statements($self);
84 "Missing 'if' case: returned undef: all ifs resolved" );
86 qr/Warning: #else\/elif\/endif without #if in this function/,
87 "Got expected warning: lack of #if"
90 qr/precede it with a blank line/s,
91 "Got expected warning: advice re blank line"
97 "Alpha this is not an if/elif/elsif/endif",
98 "#elif this_is_an_elif_statement",
99 "Beta this is not an if/elif/elsif/endif",
100 "#else this_is_an_else_statement",
101 "Gamma this is not an if/elif/elsif/endif",
102 "#endif this_is_an_endif_statement",
104 $self->{line_no} = [ 17 .. 22 ];
105 $self->{XSStack}->[-1]{type} = 'file';
106 $self->{filename} = 'myfile1';
109 my $stderr = PrimitiveCapture::capture_stderr(sub {
110 $rv = check_conditional_preprocessor_statements($self);
113 "Missing 'if' case: returned undef: all ifs resolved" );
115 qr/Warning: #else\/elif\/endif without #if in this function/,
116 "Got expected warning: lack of #if"
119 qr/precede it with a blank line/s,
120 "Did not get unexpected stderr"
126 "#if this_is_an_if_statement",
127 "Alpha this is not an if/elif/elsif/endif",
128 "#elif this_is_an_elif_statement",
129 "Beta this is not an if/elif/elsif/endif",
130 "#else this_is_an_else_statement",
131 "Gamma this is not an if/elif/elsif/endif",
133 $self->{line_no} = [ 17 .. 22 ];
134 $self->{XSStack}->[-1]{type} = 'if';
135 $self->{filename} = 'myfile1';
138 my $stderr = PrimitiveCapture::capture_stderr(sub {
139 $rv = check_conditional_preprocessor_statements($self);
142 "Missing 'endif' case: returned non-zero as expected" );
144 qr/Warning: #if without #endif in this function/s,
145 "Got expected warning: lack of #endif"
149 pass("Passed all tests in $0");