File: 02-link.t

package info (click to toggle)
libextutils-cbuilder-perl 0.11-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 124 kB
  • ctags: 69
  • sloc: perl: 862; makefile: 44
file content (57 lines) | stat: -rw-r--r-- 1,072 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#! perl -w

use strict;
use Test;
BEGIN { 
  if ($^O eq 'MSWin32') {
    print "1..0 # Skipped: link_executable() is not implemented yet on Win32\n";
    exit;
  }
  if ($^O eq 'VMS') {
    # So we can get the return value of system()
    require vmsish;
    import vmsish;
  }
  plan tests => 5;
}

use ExtUtils::CBuilder;
use File::Spec;

my $b = ExtUtils::CBuilder->new;
ok $b;

my $source_file = File::Spec->catfile('t', 'compilet.c');
{
  local *FH;
  open FH, "> $source_file" or die "Can't create $source_file: $!";
  print FH "int main(void) { return 11; }\n";
  close FH;
}
ok -e $source_file;

# Compile
my $object_file;
ok $object_file = $b->compile(source => $source_file);

# Link
my ($exe_file, @temps);
($exe_file, @temps) = $b->link_executable(objects => $object_file);
ok $exe_file;

# Try the executable
ok my_system($exe_file), 11;

# Clean up
for ($source_file, $exe_file, $object_file, @temps) {
  tr/"'//d;
  1 while unlink;
}

sub my_system {
  my $cmd = shift;
  if ($^O eq 'VMS') {
    return system("mcr $cmd");
  }
  return system($cmd) >> 8;
}