Upgrade to ExtUtils-CBuilder-0.15 (with a small edit to
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / CBuilder / t / 02-link.t
CommitLineData
6b09c160 1#! perl -w
2
3BEGIN {
4 if ($ENV{PERL_CORE}) {
5 chdir 't' if -d 't';
6 chdir '../lib/ExtUtils/CBuilder'
7 or die "Can't chdir to lib/ExtUtils/CBuilder: $!";
8 @INC = qw(../..);
9 }
10}
11
12use strict;
13use Test;
14BEGIN {
15 if ($^O eq 'MSWin32') {
16 print "1..0 # Skipped: link_executable() is not implemented yet on Win32\n";
17 exit;
18 }
19 if ($^O eq 'VMS') {
20 # So we can get the return value of system()
21 require vmsish;
22 import vmsish;
23 }
24 plan tests => 5;
25}
26
27use ExtUtils::CBuilder;
28use File::Spec;
29
30# TEST doesn't like extraneous output
31my $quiet = $ENV{PERL_CORE} && !$ENV{HARNESS_ACTIVE};
32
33my $b = ExtUtils::CBuilder->new(quiet => $quiet);
34ok $b;
35
36my $source_file = File::Spec->catfile('t', 'compilet.c');
37{
38 local *FH;
39 open FH, "> $source_file" or die "Can't create $source_file: $!";
40 print FH "int main(void) { return 11; }\n";
41 close FH;
42}
43ok -e $source_file;
44
45# Compile
46my $object_file;
47ok $object_file = $b->compile(source => $source_file);
48
49# Link
50my ($exe_file, @temps);
51($exe_file, @temps) = $b->link_executable(objects => $object_file);
52ok $exe_file;
53
d1cf867f 54if ($^O eq 'os2') { # Analogue of LDLOADPATH...
55 # Actually, not needed now, since we do not link with the generated DLL
56 my $old = OS2::extLibpath(); # [builtin function]
57 $old = ";$old" if defined $old and length $old;
58 # To pass the sanity check, components must have backslashes...
59 OS2::extLibpath_set(".\\$old");
60}
61
6b09c160 62# Try the executable
63ok my_system($exe_file), 11;
64
65# Clean up
4e96f8e9 66for ($source_file, $object_file, $exe_file) {
67 tr/"'//d;
68 1 while unlink;
69}
6b09c160 70
71sub my_system {
72 my $cmd = shift;
73 if ($^O eq 'VMS') {
74 return system("mcr $cmd");
75 }
76 return system($cmd) >> 8;
77}