File: check_c99_or_exit.t

package info (click to toggle)
libdevel-checkcompiler-perl 0.07-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 124 kB
  • sloc: perl: 92; makefile: 2
file content (40 lines) | stat: -rw-r--r-- 811 bytes parent folder | download | duplicates (3)
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
use strict;
use warnings;
use utf8;
use Test::More;
use File::Temp;

my $exit_status;
BEGIN {
    *CORE::GLOBAL::exit = sub { $exit_status = $_[0] };
}

use Devel::CheckCompiler;

my $tmp = File::Temp->new;

subtest 'c99 is not available' => sub {
    undef $exit_status;
    make_stub(0, 0);
    check_c99_or_exit();
    is($exit_status, 0);
};

subtest 'c99 is available' => sub {
    undef $exit_status;
    make_stub(1, 1);
    check_c99_or_exit();
    is($exit_status, undef);
};

done_testing;

sub make_stub {
    my ($have_compiler, $compile) = @_;

    no warnings 'redefine';
    no warnings 'once';
    *ExtUtils::CBuilder::new = sub { bless {}, shift };
    *ExtUtils::CBuilder::have_compiler = sub { $have_compiler };
    *ExtUtils::CBuilder::compile = sub { $compile ? $tmp->filename : undef };
}