7 # So we can get the return value of system()
12 use ExtUtils::CBuilder;
15 # TEST doesn't like extraneous output
16 my $quiet = $ENV{PERL_CORE} && !$ENV{HARNESS_ACTIVE};
17 my ($source_file, $object_file, $exe_file);
19 my $b = ExtUtils::CBuilder->new(quiet => $quiet);
22 if ($^O eq 'MSWin32') {
23 plan skip_all => "link_executable() is not implemented yet on Win32";
25 elsif ( ! $b->have_compiler ) {
26 plan skip_all => "no compiler available for testing";
32 ok $b, "created EU::CB object";
34 $source_file = File::Spec->catfile('t', 'compilet.c');
37 open FH, "> $source_file" or die "Can't create $source_file: $!";
38 print FH "int main(void) { return 11; }\n";
41 ok -e $source_file, "generated '$source_file'";
44 eval { $object_file = $b->compile(source => $source_file) };
45 is $@, q{}, "no exception from compilation";
46 ok -e $object_file, "found object file";
50 skip "error compiling source", 4
51 unless -e $object_file;
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";
57 ok -x $exe_file, "executable file appears to be executable";
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");
68 my $ec = my_system($exe_file);
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");
75 for ($source_file, $object_file, $exe_file) {
81 1 while unlink 'COMPILET.LIS';
82 1 while unlink 'COMPILET.OPT';
89 # Preserve non-posixified status and don't bit shift the result.
91 $ec = system("mcr $cmd");
95 return $ec == -1 ? -1 : $ec >> 8;