File: 30-compiler-unixy.t

package info (click to toggle)
libextutils-builder-compiler-perl 0.032-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 252 kB
  • sloc: perl: 1,252; makefile: 2
file content (55 lines) | stat: -rw-r--r-- 2,415 bytes parent folder | download
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
#! perl

use strict;
use warnings;

use Test::More 0.89;
BEGIN {
	*eq_or_diff = eval { require Test::Differences } ? \&Test::Differences::eq_or_diff : \&Test::More::is_deeply;
}


use ExtUtils::Builder::Compiler::Unixy;

{
	my $compiler = ExtUtils::Builder::Compiler::Unixy->new(cc => 'cc', cccdlflags => [ '-fPIC' ], type => 'loadable-object');
	my $obj = $compiler->compile('file.c', 'file.o');
	eq_or_diff([ $obj->to_command ], [[qw/cc -fPIC -o file.o -c file.c/]], 'Got "cc -fPIC -o file.o -c file.c"') or diag explain $obj;
}

{
	my $compiler = ExtUtils::Builder::Compiler::Unixy->new(cc => [ 'cc' ], cccdlflags => [ '-fPIC' ], type => 'executable');
	eq_or_diff([ $compiler->compile('file.c', 'file.o')->to_command ], [[qw/cc -o file.o -c file.c/]], 'Got "cc -o file.o -c file.c"');
}

{
	my $compiler = ExtUtils::Builder::Compiler::Unixy->new(cc => 'cc', cccdlflags => [ ], type => 'loadable-object');
	eq_or_diff([ $compiler->compile('file.c', 'file.o')->to_command ], [[qw/cc -o file.o -c file.c/]], 'Got "cc -o file.o -c file.c" 2');
}

{
	my $compiler = ExtUtils::Builder::Compiler::Unixy->new(cc => [ 'cc' ], cccdlflags => [ ], type => 'loadable-object');
	$compiler->add_include_dirs([ 'headers' ]);
	eq_or_diff([ $compiler->compile('file.c', 'file.o')->to_command ], [[qw/cc -Iheaders -o file.o -c file.c/]], 'Got "cc -Iheaders -o file.o -c file.c"');
}

{
	my $compiler = ExtUtils::Builder::Compiler::Unixy->new(cc => 'cc89', cccdlflags => [ '-fPIC' ], type => 'executable');
	$compiler->add_include_dirs([ 'headers' ]);
	$compiler->add_defines({ foo => 'bar' });
	eq_or_diff([ $compiler->compile('file.c', 'file.o')->to_command ], [[qw/cc89 -Iheaders -Dfoo=bar -o file.o -c file.c/]], 'Got "cc -Iheaders -Dfoo=bar -o file.o -c file.c"');
}

{
	my $compiler = ExtUtils::Builder::Compiler::Unixy->new(cc => [ qw/cc -std=c89/ ], cccdlflags => [ ], type => 'loadable-object');
	$compiler->add_defines({ foo => '' });
	eq_or_diff([ $compiler->compile('file.c', 'file.o')->to_command ], [[qw/cc -std=c89 -Dfoo -o file.o -c file.c/]], 'Got "cc -Dfoo -o file.o -c file.c"');
}

{
	my $compiler = ExtUtils::Builder::Compiler::Unixy->new(cc => [ 'cc' ], cccdlflags => [ '-fPIC' ], type => 'executable');
	$compiler->add_defines({ foo => undef });
	eq_or_diff([ $compiler->compile('file.c', 'file.o')->to_command ], [[qw/cc -Ufoo -o file.o -c file.c/]], 'Got "cc -Ufoo -o file.o -c file.c"');
}

done_testing;