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