Move ExtUtils::CBuilder from ext/ to cpan/
[p5sagit/p5-mst-13.2.git] / cpan / ExtUtils-CBuilder / t / 02-link.t
CommitLineData
6b09c160 1#! perl -w
2
6b09c160 3use strict;
9015f106 4use Test::More;
6b09c160 5BEGIN {
6b09c160 6 if ($^O eq 'VMS') {
7 # So we can get the return value of system()
8 require vmsish;
9 import vmsish;
10 }
6b09c160 11}
6b09c160 12use ExtUtils::CBuilder;
13use File::Spec;
14
15# TEST doesn't like extraneous output
16my $quiet = $ENV{PERL_CORE} && !$ENV{HARNESS_ACTIVE};
9015f106 17my ($source_file, $object_file, $exe_file);
6b09c160 18
19my $b = ExtUtils::CBuilder->new(quiet => $quiet);
6b09c160 20
9015f106 21# test plan
22if ($^O eq 'MSWin32') {
23 plan skip_all => "link_executable() is not implemented yet on Win32";
24}
25elsif ( ! $b->have_compiler ) {
26 plan skip_all => "no compiler available for testing";
27}
28else {
29 plan tests => 7;
30}
31
32ok $b, "created EU::CB object";
33
34$source_file = File::Spec->catfile('t', 'compilet.c');
6b09c160 35{
36 local *FH;
37 open FH, "> $source_file" or die "Can't create $source_file: $!";
38 print FH "int main(void) { return 11; }\n";
39 close FH;
40}
9015f106 41ok -e $source_file, "generated '$source_file'";
6b09c160 42
43# Compile
9015f106 44eval { $object_file = $b->compile(source => $source_file) };
45is $@, q{}, "no exception from compilation";
46ok -e $object_file, "found object file";
6b09c160 47
48# Link
9015f106 49SKIP: {
50 skip "error compiling source", 3
51 unless -e $object_file;
6b09c160 52
9015f106 53 my @temps;
54 eval { ($exe_file, @temps) = $b->link_executable(objects => $object_file) };
55 is $@, q{}, "no exception from linking";
56 ok -e $exe_file, "found executable file";
d1cf867f 57
9015f106 58 if ($^O eq 'os2') { # Analogue of LDLOADPATH...
59 # Actually, not needed now, since we do not link with the generated DLL
60 my $old = OS2::extLibpath(); # [builtin function]
61 $old = ";$old" if defined $old and length $old;
62 # To pass the sanity check, components must have backslashes...
63 OS2::extLibpath_set(".\\$old");
64 }
65
66 # Try the executable
67 my $ec = my_system($exe_file);
68 is $ec, 11, "got expected exit code from executable"
69 or print( $? == -1 ? "# Could not run '$exe_file'\n"
70 : "# Unexpected exit code '$ec'\n");
71}
6b09c160 72
73# Clean up
4e96f8e9 74for ($source_file, $object_file, $exe_file) {
75 tr/"'//d;
76 1 while unlink;
77}
6b09c160 78
100ba297 79if ($^O eq 'VMS') {
80 1 while unlink 'COMPILET.LIS';
81 1 while unlink 'COMPILET.OPT';
82}
83
6b09c160 84sub my_system {
85 my $cmd = shift;
86 if ($^O eq 'VMS') {
87 return system("mcr $cmd");
88 }
89 return system($cmd) >> 8;
90}