This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
ExtUtils-CBuilder test tweak for VMS.
[perl5.git] / cpan / ExtUtils-CBuilder / t / 02-link.t
CommitLineData
6b09c160
YST
1#! perl -w
2
6b09c160 3use strict;
9015f106 4use Test::More;
506098d4 5BEGIN {
6b09c160
YST
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
YST
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
YST
18
19my $b = ExtUtils::CBuilder->new(quiet => $quiet);
6b09c160 20
9015f106
DG
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 {
506098d4 29 plan tests => 8;
9015f106
DG
30}
31
32ok $b, "created EU::CB object";
33
34$source_file = File::Spec->catfile('t', 'compilet.c');
6b09c160
YST
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
YST
42
43# Compile
9015f106
DG
44eval { $object_file = $b->compile(source => $source_file) };
45is $@, q{}, "no exception from compilation";
46ok -e $object_file, "found object file";
6b09c160
YST
47
48# Link
9015f106 49SKIP: {
506098d4 50 skip "error compiling source", 4
9015f106 51 unless -e $object_file;
6b09c160 52
9015f106
DG
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";
506098d4 57 ok -x $exe_file, "executable file appears to be executable";
d1cf867f 58
9015f106
DG
59 if ($^O eq 'os2') { # Analogue of LDLOADPATH...
60 # Actually, not needed now, since we do not link with the generated DLL
61 my $old = OS2::extLibpath(); # [builtin function]
62 $old = ";$old" if defined $old and length $old;
63 # To pass the sanity check, components must have backslashes...
64 OS2::extLibpath_set(".\\$old");
65 }
66
67 # Try the executable
68 my $ec = my_system($exe_file);
506098d4
DG
69 is( $ec, 11, "got expected exit code from executable" )
70 or diag( $ec == -1 ? "Could not run '$exe_file': $!\n"
71 : "Unexpected exit code '$ec'\n");
9015f106 72}
6b09c160
YST
73
74# Clean up
4e96f8e9
SH
75for ($source_file, $object_file, $exe_file) {
76 tr/"'//d;
77 1 while unlink;
78}
6b09c160 79
100ba297
DG
80if ($^O eq 'VMS') {
81 1 while unlink 'COMPILET.LIS';
82 1 while unlink 'COMPILET.OPT';
83}
84
6b09c160
YST
85sub my_system {
86 my $cmd = shift;
506098d4 87 my $ec;
6b09c160 88 if ($^O eq 'VMS') {
aa3f85c5
CB
89 # Preserve non-posixified status and don't bit shift the result.
90 use vmsish 'status';
506098d4 91 $ec = system("mcr $cmd");
aa3f85c5 92 return $ec;
6b09c160 93 }
506098d4
DG
94 $ec = system($cmd);
95 return $ec == -1 ? -1 : $ec >> 8;
6b09c160 96}