File: 11-finds-shared-lib.t

package info (click to toggle)
libmodule-scandeps-perl 0.98-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 576 kB
  • ctags: 231
  • sloc: perl: 3,910; makefile: 10; ansic: 1
file content (55 lines) | stat: -rw-r--r-- 1,338 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
#!/usr/bin/perl

use strict;
use warnings;

use lib 't';
use vars qw/%INC/;
use File::Temp;
use Test::More;
use Cwd;
use Data::Dumper;
use Config qw/%Config/;

BEGIN {
  plan('skip_all', 'Cwd is builtin on OS/2') if $^O eq 'os2';
  plan('skip_all', 'Cwd does not have a C part') if Cwd->VERSION<2.08; #2.08 has, 2.04 does not
  plan(tests => 3);
}

# Tests that scan_deps finds the shared library associated
# with an XS module (example: Cwd) both when scanned as a
# dependency and directly as the specified user code/file.

BEGIN { use_ok( 'Module::ScanDeps' ); }

my $cwd_file = $INC{"Cwd.pm"};
my $code = "use Cwd;\n";
my $dl_ext = $Config{dlext};

my ($fh, $filename) = File::Temp::tempfile( UNLINK => 1, SUFFIX => '.pl' );
print $fh $code, "\n" or die $!;
close $fh;

my $rv = scan_deps(files => [$filename]);
#print Dumper $rv;

ok(
    (grep { /\bCwd\.$dl_ext$/ } keys %$rv),
    "Found shared library when module is scanned as dependency."
);

$rv = scan_deps(files => [$cwd_file]);
#print Dumper $rv;

if (not -f $cwd_file) {
    fail("Could not determine the location of the Cwd.pm file. Can't run all tests.");
}
else {
    ok(
        (grep { /\bCwd\.$dl_ext$/ } keys %$rv),
        "Found shared library when module is scanned as user code / script."
    );
}

__END__