File: strawberry.t

package info (click to toggle)
libpkgconfig-perl 0.26026-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,912 kB
  • sloc: ansic: 6,120; perl: 1,922; makefile: 4; sh: 3
file content (133 lines) | stat: -rw-r--r-- 3,015 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
use strict;
use warnings;
use Test::More;
BEGIN { delete $ENV{PKG_CONFIG_PATH} }
use PkgConfig;
use Config;
use FindBin ();
use File::Spec;

plan skip_all => "Test only for MSWin32" unless $^O eq 'MSWin32';
plan skip_all => "Test only for strawberry MSWin32" unless $Config{myuname} =~ /strawberry-perl/;
plan tests => 3;

# this assumes that zlib comes with Strawberry,
# which seems a fairly safe assumption.
my $pkg = PkgConfig->find('zlib');
is $pkg->errmsg, undef, 'found zlib';
diag $pkg->errmsg if $pkg->errmsg;

my $dir = File::Spec->catdir($FindBin::Bin, qw( data strawberry c lib pkgconfig ));
$dir =~ s{\\}{/}g;

my @pcfiles = do {
  @PkgConfig::DEFAULT_SEARCH_PATH = ($dir);
  my $lib = "$dir/../../lib";
  my $inc = "$dir/../../include";
  @PkgConfig::DEFAULT_EXCLUDE_LFLAGS = ("-L$lib");
  @PkgConfig::DEFAULT_EXCLUDE_CFLAGS = ("-I$inc");

  note "dir  = $dir";
  note "lib  = $lib";
  note "inc  = $inc";

  my $dh;
  opendir $dh, $dir;
  my @list = map { s/\.pc$//; $_ } grep !/^\./, grep /\.pc$/, readdir $dh;
  closedir $dh;
  @list;
};

my @good_includes;
my @good_libs;

subtest 'pcfiles excluded' => sub {
  plan tests => int @pcfiles;
  foreach my $pcfile (@pcfiles)
  {
    subtest $pcfile => sub {
      plan tests => 4;
      my $pkg = PkgConfig->find($pcfile);
      isa_ok $pkg, 'PkgConfig';
      is $pkg->errmsg, undef, 'no error';

      my $ok1 = 1;

      foreach my $cflag ($pkg->get_cflags)
      {
        if($cflag =~ /^-I(.*)$/)
        {
          my $dir = $1;
          if(-r File::Spec->catfile($dir, 'bad.h'))
          {
            $ok1 = 0;
            diag "header directory $dir should not been included";
          }
          else
          {
            push @good_includes, [ $pcfile, $dir ];
          }
        }
      }

      ok $ok1, "headers excluded correctly";

      my $ok2 = 1;

      foreach my $ldflag ($pkg->get_ldflags)
      {
        if($ldflag =~ /^-L(.*)$/)
        {
          my $dir = $1;
          if(-r File::Spec->catfile($dir, 'libbad.a'))
          {
            $ok2 = 0;
            diag "lib directory $dir should not have been included";
          }
          else
          {
            push @good_libs, [ $pcfile, $dir ];
          }
        }
      }

      ok $ok2, "lib excluded correctly";
    };
  }
};

note "inc";
note sprintf("  %20s %s", $_->[0], $_->[1]) for @good_includes;
note "lib";
note sprintf("  %20s %s", $_->[0], $_->[1]) for @good_libs;

subtest 'pcfiles included' => sub {
  my @pcfiles = qw(
    freetype2 libexslt libpng libpng16 libxml-2.0 libxslt plplotd-c++ plplotd
  );
  plan tests => int @pcfiles;

  foreach my $pcfile (@pcfiles)
  {
    subtest $pcfile => sub {

      my $pkg = PkgConfig->find($pcfile);

      my $ok1 = 0;

      foreach my $flag ($pkg->get_cflags)
      {
        if($flag =~ m{^-I(.*)$})
        {
          my $dir = $1;
          $ok1 = -d $dir;
          note $dir;
        }
      }
      $dir ||= '';
      ok $ok1, "good directory included, found '$dir'";

    };
  }

};