Commit | Line | Data |
6b09c160 |
1 | #! perl -w |
2 | |
6b09c160 |
3 | use strict; |
9015f106 |
4 | use Test::More; |
6b09c160 |
5 | BEGIN { |
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 |
12 | use ExtUtils::CBuilder; |
13 | use File::Spec; |
14 | |
15 | # TEST doesn't like extraneous output |
16 | my $quiet = $ENV{PERL_CORE} && !$ENV{HARNESS_ACTIVE}; |
9015f106 |
17 | my ($source_file, $object_file, $exe_file); |
6b09c160 |
18 | |
19 | my $b = ExtUtils::CBuilder->new(quiet => $quiet); |
6b09c160 |
20 | |
9015f106 |
21 | # test plan |
22 | if ($^O eq 'MSWin32') { |
23 | plan skip_all => "link_executable() is not implemented yet on Win32"; |
24 | } |
25 | elsif ( ! $b->have_compiler ) { |
26 | plan skip_all => "no compiler available for testing"; |
27 | } |
28 | else { |
29 | plan tests => 7; |
30 | } |
31 | |
32 | ok $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 |
41 | ok -e $source_file, "generated '$source_file'"; |
6b09c160 |
42 | |
43 | # Compile |
9015f106 |
44 | eval { $object_file = $b->compile(source => $source_file) }; |
45 | is $@, q{}, "no exception from compilation"; |
46 | ok -e $object_file, "found object file"; |
6b09c160 |
47 | |
48 | # Link |
9015f106 |
49 | SKIP: { |
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 |
74 | for ($source_file, $object_file, $exe_file) { |
75 | tr/"'//d; |
76 | 1 while unlink; |
77 | } |
6b09c160 |
78 | |
100ba297 |
79 | if ($^O eq 'VMS') { |
80 | 1 while unlink 'COMPILET.LIS'; |
81 | 1 while unlink 'COMPILET.OPT'; |
82 | } |
83 | |
6b09c160 |
84 | sub my_system { |
85 | my $cmd = shift; |
86 | if ($^O eq 'VMS') { |
87 | return system("mcr $cmd"); |
88 | } |
89 | return system($cmd) >> 8; |
90 | } |