This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update to ExtUtils::CBuilder 0.280226
[perl5.git] / dist / ExtUtils-CBuilder / t / 03-cplusplus.t
1 #! perl -w
2
3 use strict;
4 use Test::More;
5 BEGIN {
6   if ($^O eq 'VMS') {
7     # So we can get the return value of system()
8     require vmsish;
9     import vmsish;
10   }
11 }
12 use ExtUtils::CBuilder;
13 use File::Spec;
14
15 # TEST does not like extraneous output
16 my $quiet = $ENV{PERL_CORE} && !$ENV{HARNESS_ACTIVE};
17 my ($source_file, $object_file, $lib_file);
18
19 my $b = ExtUtils::CBuilder->new(quiet => $quiet);
20
21 # test plan
22 if ( ! $b->have_cplusplus ) {
23   plan skip_all => "no compiler available for testing";
24 }
25 else {
26   plan tests => 7;
27 }
28
29 ok $b, "created EU::CB object";
30
31 ok $b->have_cplusplus, "have_cplusplus";
32
33 $source_file = File::Spec->catfile('t', 'cplust.cc');
34 {
35   open my $FH, '>', $source_file or die "Can't create $source_file: $!";
36   print $FH "class Bogus { public: int boot_cplust() { return 1; } };\n";
37   close $FH;
38 }
39 ok -e $source_file, "source file '$source_file' created";
40
41 $object_file = $b->object_file($source_file);
42 ok 1;
43
44 is $object_file, $b->compile(source => $source_file, 'C++' => 1);
45
46 $lib_file = $b->lib_file($object_file, module_name => 'cplust');
47 ok 1;
48
49 my ($lib, @temps) = $b->link(objects => $object_file,
50                              module_name => 'cplust');
51 $lib =~ tr/"'//d;
52 $_ = File::Spec->rel2abs($_) for $lib_file, $lib;
53 is $lib_file, $lib;
54
55 for ($source_file, $object_file, $lib_file) {
56   tr/"'//d;
57   1 while unlink;
58 }
59
60 if ($^O eq 'VMS') {
61    1 while unlink 'CPLUST.LIS';
62    1 while unlink 'CPLUST.OPT';
63 }
64