File: executable.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 (57 lines) | stat: -rw-r--r-- 1,452 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use strict;
use warnings;
use utf8;
use Test::More;
use File::Temp;

use Devel::CheckCompiler;

my $check;
my $extra_linker_flags;

my $code = <<'...';
int main(void)
{
    return maybe_not_defined_function12345678(0);
}
...

subtest 'generate only object file' => sub {
    my $tmpobj = File::Temp->new;
    make_stub($tmpobj->filename);
    ok(check_compile($code) && $check == 1);
};

subtest 'generate executable file' => sub {
    my $tmpobj = File::Temp->new;
    my $tmpexe = File::Temp->new;
    make_stub($tmpobj->filename, $tmpexe->filename);
    ok(check_compile($code, executable => 1) && $check == 2);
};

subtest 'generate executable file with linker option' => sub {
    my $tmpobj = File::Temp->new;
    my $tmpexe = File::Temp->new;
    make_stub($tmpobj->filename, $tmpexe->filename);
    ok(check_compile($code, executable => 1, extra_linker_flags => '-lm')
           && ($check == 2 && $extra_linker_flags eq '-lm'));
};

done_testing;

sub make_stub {
    my ($obj, $exe) = @_;

    no warnings 'redefine';
    no warnings 'once';
    *ExtUtils::CBuilder::new = sub { $check = 0; bless {}, shift };
    *ExtUtils::CBuilder::have_compiler = sub { 1 };
    *ExtUtils::CBuilder::compile = sub { $check = 1; $obj ? $obj : undef };
    *ExtUtils::CBuilder::link_executable = sub {
        my (undef, %args) = @_;
        $check = 2;
        $extra_linker_flags = $args{extra_linker_flags} || '';
        $exe ? $exe : undef;
    };
}