File: alien_build_plugin_core_gather.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 (185 lines) | stat: -rw-r--r-- 4,162 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
use 5.008004;
use Test2::V0 -no_srand => 1;
use utf8;
use Test::Alien::Build;
use Alien::Build::Plugin::Core::Gather;
use Capture::Tiny qw( capture_merged );
use Alien::Build::Util qw( _dump _destdir_prefix );
use Path::Tiny qw( path );
use File::Temp qw( tempdir );

subtest 'destdir filter' => sub {

  my $build = alienfile q{
    use alienfile;
    use Path::Tiny qw( path );
    plugin 'Test::Mock',
      probe    => 'share',
      download => 1,
      extract  => 1;
    meta_prop->{destdir} = 1;
    meta_prop->{destdir_filter} = qr/^(bin|lib)\/.*$/;
    share {
      build sub {
        my($build) = @_;
        my $prefix = $build->install_prop->{prefix};
        $prefix =~ s{^([a-z]):}{$1}i if $^O eq 'MSWin32';
        my $destdir_prefix = path(Alien::Build::Util::_destdir_prefix($ENV{DESTDIR}, $prefix));
        $destdir_prefix->child($_)->mkpath for qw( bin lib etc );
        $destdir_prefix->child('bin/foo.exe')->touch;
        $destdir_prefix->child('lib/libfoo.a')->touch;
        $destdir_prefix->child('etc/foorc')->touch;
      };
    };
  };

  note capture_merged {
    eval {
      $build->probe;
      $build->download;
      $build->build;
    };
    warn $@ if $@;
    ();
  };

  note _dump $build->install_prop;

  my $stage = path($build->install_prop->{stage});

  ok( -f $stage->child('bin/foo.exe'), 'bin/foo.exe' );
  ok( -f $stage->child('lib/libfoo.a'), 'lib/libfoo.a' );
  ok( !-f $stage->child('etc/foorc'), 'etc/foorc' );

};

subtest 'patch' => sub {

  my $build = alienfile q{
    use alienfile;
    use Path::Tiny qw( path );
    plugin 'Test::Mock',
      probe    => 'share',
      download => 1,
      extract  => 1;
    share {
      build sub {
        my($build) = @_;
        my $prefix = path($build->install_prop->{prefix});
        print "prefix = $prefix\n";
        $prefix->mkpath;
        $prefix->child('foo.txt')->touch;
      };
    };
  };

  my $patch = path($build->install_prop->{patch} = tempdir( CLEANUP => 1 ));
  $patch->child('foo.diff')->touch;
  my $stage = path($build->install_prop->{stage});

  my $error = $@;
  note capture_merged {
    eval {
      $build->probe;
      $build->download;
      $build->build;
    };
    my $error = $@;
    warn $error if $error;
    ();
  };

  is $error, '';

  note _dump $build->install_prop;

  ok( -f $stage->child('_alien/patch/foo.diff') );
};

subtest 'pkg-config path during gather' => sub {

  my $build = alienfile_ok q{
    use alienfile;
    use Path::Tiny qw( path );
    plugin 'Test::Mock',
      probe    => 'share',
      download => 1,
      extract  => 1;
    use Env qw( @PKG_CONFIG_PATH );
    share {
      build    sub {
        my($build) = @_;
        my $prefix = path($build->install_prop->{prefix});
        $build->log("prefix = $prefix");
        $prefix->child('lib/pkgconfig')->mkpath;
        $prefix->child('lib/pkgconfig/x3.pc')->spew("Name: x3\n");
        $prefix->child('share/pkgconfig')->mkpath;
        $prefix->child('share/pkgconfig/x4.pc')->spew("Name: x4\n");
      };
      gather   sub {
        my($build) = @_;
        $build->install_prop->{my_pkg_config_path} = [@PKG_CONFIG_PATH];
      };
    };
  };

  alien_build_ok;

  is(
    $build->install_prop,
    hash {
      field my_pkg_config_path => array {
        item validator(sub {
          return -f "$_/x3.pc";
        });
        item validator(sub {
          return -f "$_/x4.pc";
        });
        end;
      };
      etc;
    },
    'has arch and arch-indy pkg-config paths',
  );


};

subtest '_alien/alien.json should be okay with unicode' => sub {

  my $build = alienfile q{
    use alienfile;
    use utf8;
    probe sub { 'system' };
    gather sub {
      my($build) = @_;
      $build->runtime_prop->{'龍'} = '火';
    };
  };

  alien_build_ok;
  is(
    $build->runtime_prop,
    hash {
      field '龍' => '火';
      etc;
    }
  );

  my $json_file = path($build->install_prop->{prefix}, '_alien', 'alien.json');
  ok -r $json_file;

  require JSON::PP;
  my $config = JSON::PP::decode_json($json_file->slurp);
  is(
    $config,
    hash {
      field '龍' => '火';
      etc;
    }
  );


};

done_testing;