File: alien_base_pkgconfig.t

package info (click to toggle)
libalien-build-perl 2.84-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,116 kB
  • sloc: perl: 10,350; ansic: 134; sh: 66; makefile: 2
file content (125 lines) | stat: -rw-r--r-- 3,506 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
use 5.008004;
use Test2::V0 -no_srand => 1;
use Alien::Base::PkgConfig;
use Capture::Tiny qw( capture_merged );

subtest 'basic' => sub {

  my $file = 'corpus/ab_pkgconfig/test.pc';
  ok( -e $file, "Test file found" );

  my $pc = Alien::Base::PkgConfig->new($file);
  isa_ok( $pc, 'Alien::Base::PkgConfig' );

  # read tests
  my $pcfiledir = delete $pc->{vars}{pcfiledir};
  ok( -d $pcfiledir, 'pcfiledir is a directory' );
  ok( -e "$pcfiledir/test.pc", 'pcfiledir contains test.pc' );

  is(
    $pc->{vars},
    {
      'INTERNAL_VARIABLE' => '-lotherlib',
      'prefix' => '/home/test/path',
    },
    "read vars"
  );

  is(
    $pc->{keywords},
    {
      'Version' => '1.01',
      'Libs' => '-L/home/test/path/lib -lsomelib ${INTERNAL_VARIABLE} -lm -lm',
      'Cflags' => '-Dfoo=bar -I/home/test/path/deeper/include',
      'Requires' => 'lib1 >= 1.0.0 lib2 >= 1.2.3',
      'Description' => 'My TEST Library',
      'Name' => 'TEST',
    },
    "read keywords"
  );

  is( $pc->{package}, 'test', "understands package name from file path" );

  # vars getter/setter
  is( $pc->var('prefix'), '/home/test/path', "var getter" );
  is( $pc->var(deeper => '/home/test/path/deeper'), '/home/test/path/deeper', "var setter" );

  # abstract vars
  $pc->make_abstract('prefix');

  is( $pc->{vars}{deeper}, '${prefix}/deeper', "abstract vars in terms of each other" );
  is( (split qr/\s+/, $pc->{keywords}{Libs})[0], '-L${prefix}/lib', "abstract simple" );

  $pc->make_abstract('deeper');
  is( $pc->{keywords}{Cflags}, '-Dfoo=bar -I${deeper}/include', "abstract abstract 'nested'" );

  # interpolate vars into keywords
  is( $pc->keyword('Version'), '1.01', "Simple keyword getter" );
  is( (split qr/\s+/, $pc->keyword('Libs'))[0], '-L/home/test/path/lib', "single interpolation keyword" );
  is( $pc->keyword('Cflags'), '-Dfoo=bar -I/home/test/path/deeper/include', "multiple interpolation keyword" );

  # interpolate with overrides
  is(
    $pc->keyword( 'Cflags', {prefix => '/some/other/path'}),
    '-Dfoo=bar -I/some/other/path/deeper/include',
    "multiple interpolation keyword with override"
  );

};

subtest 'version' => sub {

  skip_all 'Test requires Alien::Base::ModuleBuild'
    unless eval { require Alien::Base::ModuleBuild; Alien::Base::ModuleBuild->VERSION('1.00') };

  my $pkg_config = Alien::Base::PkgConfig->pkg_config_command;

  my(undef,$ret) = capture_merged { system( "$pkg_config --version" ); $? };
  if ( $ret ) {
    skip_all "Cannot use pkg-config: $ret";
  }

  my @installed = map { /^(\S+)/ ? $1 : () } `$pkg_config --list-all`;
  skip_all "pkg-config returned no packages" unless @installed;
  my $lib = $installed[0];

  my ($builder_ok, $builder_bad) = map {
    require Alien::Base::ModuleBuild;
    my($out, $builder) = capture_merged {
      Alien::Base::ModuleBuild->new(
        module_name => 'My::Test',
        dist_version => 0.01,
        alien_name => $_,
        share_dir => 't',
      );
    };
    note $out if $out ne '';
    $builder;
  }
  ($lib, 'siughspidghsp');

  subtest 'good' => sub {

    my($out, $value) = capture_merged {
      $builder_ok->alien_check_installed_version,
    };
    note $out if $out ne '';

    is( $value, T(), 'found installed library' );
    note "lib is $lib";

  };

  subtest 'bad' => sub {
    my($out, $value) = capture_merged {
      $builder_bad->alien_check_installed_version,
    };
    note $out if $out ne '';

    is( $value, F(), "returns false if not found");

  };
};

done_testing;