This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Change ExtUtils::CBuilder upstream to blead
[perl5.git] / dist / ExtUtils-CBuilder / t / 01-basic.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_compiler ) {
23   plan skip_all => "no compiler available for testing";
24 }
25 else {
26   plan tests => 12;
27 }
28
29 ok $b, "created EU::CB object";
30
31 ok $b->have_compiler, "have_compiler";
32
33 $source_file = File::Spec->catfile('t', 'compilet.c');
34 {
35   local *FH;
36   open FH, "> $source_file" or die "Can't create $source_file: $!";
37   print FH "int boot_compilet(void) { return 1; }\n";
38   close FH;
39 }
40 ok -e $source_file, "source file '$source_file' created";
41
42 $object_file = $b->object_file($source_file);
43 ok 1;
44
45 is $object_file, $b->compile(source => $source_file);
46
47 $lib_file = $b->lib_file($object_file);
48 ok 1;
49
50 my ($lib, @temps) = $b->link(objects => $object_file,
51                              module_name => 'compilet');
52 $lib =~ tr/"'//d;
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 'COMPILET.LIS';
62    1 while unlink 'COMPILET.OPT';
63 }
64
65 my @words = $b->split_like_shell(' foo bar');
66
67 SKIP: {
68   skip "MSWindows", 3 if $^O =~ m/MSWin/;
69   is( @words, 2 );
70   is( $words[0], 'foo' );
71   is( $words[1], 'bar' );
72 }
73
74 # include_dirs should be settable as string or list
75 {
76   package Sub;
77   use vars '@ISA';
78   @ISA = ('ExtUtils::CBuilder');
79   my $saw = 0;
80   sub do_system {
81     if ($^O eq "MSWin32") {
82         # ExtUtils::CBuilder::MSVC::write_compiler_script() puts the
83         # include_dirs into a response file and not the commandline
84         for (@_) {
85             next unless /^\@"(.*)"$/;
86             open(my $fh, "<", $1) or next;
87             local $/;
88             $saw = 1 if <$fh> =~ /another dir/;
89             last;
90         }
91     }
92     $saw = 1 if grep {$_ =~ /another dir/} @_;
93     return 1;
94   }
95
96   package main;
97   my $s = Sub->new();
98   $s->compile(source => 'foo',
99               include_dirs => 'another dir');
100   ok $saw;
101
102   $saw = 0;
103   $s->compile(source => 'foo',
104               include_dirs => ['a dir', 'another dir']);
105   ok $saw;
106 }