Merge branch 'vincent/rvalue_stmt_given' into blead
[p5sagit/p5-mst-13.2.git] / cpan / Module-Build / t / properties / share_dir.t
CommitLineData
613f422f 1#!/usr/bin/perl -w
2
3use strict;
4use lib 't/lib';
5use MBTest;
6use File::Spec::Functions qw/catdir catfile/;
7
8#--------------------------------------------------------------------------#
9# Begin testing
10#--------------------------------------------------------------------------#
11
12plan tests => 21;
13
14blib_load('Module::Build');
15
16#--------------------------------------------------------------------------#
17# Create test distribution
18#--------------------------------------------------------------------------#
19
20my $tmp = MBTest->tmpdir;
21
22use DistGen;
23my $dist = DistGen->new( dir => $tmp, name => 'Simple::Share' );
24$dist->regen;
25$dist->chdir_in;
26
27#--------------------------------------------------------------------------#
28# Test setting 'share_dir'
29#--------------------------------------------------------------------------#
30
31my $mb = $dist->new_from_context;
32
33# Test without a 'share' dir
34ok( $mb, "Created Module::Build object" );
35is( $mb->share_dir, undef,
53fc1c7e 36 "default share_dir undef if no 'share' dir exists"
613f422f 37);
38ok( ! exists $mb->{properties}{requires}{'File::ShareDir'},
39 "File::ShareDir not added to 'requires'"
40);
41
42# Add 'share' dir and an 'other' dir and content
43$dist->add_file('share/foo.txt',<< '---');
44This is foo.txt
45---
46$dist->add_file('other/share/bar.txt',<< '---');
47This is bar.txt
48---
49$dist->regen;
50ok( -e catfile(qw/share foo.txt/), "Created 'share' directory" );
51ok( -e catfile(qw/other share bar.txt/), "Created 'other/share' directory" );
52
53# Check default when share_dir is not given
54stdout_stderr_of( sub { $mb = $dist->new_from_context });
53fc1c7e 55is( $mb->share_dir, undef,
56 "Default share_dir is undef even if 'share' exists"
613f422f 57);
53fc1c7e 58ok( ! exists $mb->{properties}{requires}{'File::ShareDir'},
59 "File::ShareDir not added to 'requires'"
613f422f 60);
61
53fc1c7e 62
613f422f 63# share_dir set to scalar
64$dist->change_build_pl(
65 {
66 module_name => $dist->name,
67 license => 'perl',
68 share_dir => 'share',
69 }
70);
71$dist->regen;
72stdout_stderr_of( sub { $mb = $dist->new_from_context });
73is_deeply( $mb->share_dir, { dist => [ 'share' ] },
74 "Scalar share_dir set as dist-type share"
75);
76
77# share_dir set to arrayref
78$dist->change_build_pl(
79 {
80 module_name => $dist->name,
81 license => 'perl',
82 share_dir => [ 'share' ],
83 }
84);
85$dist->regen;
86stdout_stderr_of( sub { $mb = $dist->new_from_context });
87is_deeply( $mb->share_dir, { dist => [ 'share' ] },
88 "Arrayref share_dir set as dist-type share"
89);
90
91# share_dir set to hashref w scalar
92$dist->change_build_pl(
93 {
94 module_name => $dist->name,
95 license => 'perl',
96 share_dir => { dist => 'share' },
97 }
98);
99$dist->regen;
100stdout_stderr_of( sub { $mb = $dist->new_from_context });
101is_deeply( $mb->share_dir, { dist => [ 'share' ] },
102 "Hashref share_dir w/ scalar dist set as dist-type share"
103);
104
105# share_dir set to hashref w array
106$dist->change_build_pl(
107 {
108 module_name => $dist->name,
109 license => 'perl',
110 share_dir => { dist => [ 'share' ] },
111 }
112);
113$dist->regen;
114stdout_stderr_of( sub { $mb = $dist->new_from_context });
115is_deeply( $mb->share_dir, { dist => [ 'share' ] },
116 "Hashref share_dir w/ arrayref dist set as dist-type share"
117);
118
119# Generate a module sharedir (scalar)
120$dist->change_build_pl(
121 {
122 module_name => $dist->name,
123 license => 'perl',
124 share_dir => {
125 dist => 'share',
126 module => { $dist->name => 'other/share' },
127 },
128 }
129);
130$dist->regen;
131stdout_stderr_of( sub { $mb = $dist->new_from_context });
132is_deeply( $mb->share_dir,
133 { dist => [ 'share' ],
134 module => { $dist->name => ['other/share'] },
135 },
136 "Hashref share_dir w/ both dist and module shares (scalar-form)"
137);
138
139# Generate a module sharedir (array)
140$dist->change_build_pl(
141 {
142 module_name => $dist->name,
143 license => 'perl',
144 share_dir => {
145 dist => [ 'share' ],
146 module => { $dist->name => ['other/share'] },
147 },
148 }
149);
150$dist->regen;
151stdout_stderr_of( sub { $mb = $dist->new_from_context });
152is_deeply( $mb->share_dir,
153 { dist => [ 'share' ],
154 module => { $dist->name => ['other/share'] },
155 },
156 "Hashref share_dir w/ both dist and module shares (array-form)"
157);
158
159#--------------------------------------------------------------------------#
160# test constructing to/from mapping
161#--------------------------------------------------------------------------#
162
163is_deeply( $mb->_find_share_dir_files,
164 {
53fc1c7e 165 "share/foo.txt" => "dist/Simple-Share/foo.txt",
166 "other/share/bar.txt" => "module/Simple-Share/bar.txt",
613f422f 167 },
168 "share_dir filemap for copying to lib complete"
169);
170
171#--------------------------------------------------------------------------#
172# test moving files to blib
173#--------------------------------------------------------------------------#
174
175$mb->dispatch('build');
176
177ok( -d 'blib', "Build ran and blib exists" );
178ok( -d 'blib/lib/auto/share', "blib/lib/auto/share exists" );
179
180my $share_list = Module::Build->rscan_dir('blib/lib/auto/share', sub {-f});
181
3ec89e6d 182SKIP:
183{
184
185skip 'filename case not necessarily preserved', 1 if $^O eq 'VMS';
186
613f422f 187is_deeply(
188 [ sort @$share_list ], [
189 'blib/lib/auto/share/dist/Simple-Share/foo.txt',
190 'blib/lib/auto/share/module/Simple-Share/bar.txt',
191 ],
192 "share_dir files copied to blib"
193);
194
3ec89e6d 195}
196
613f422f 197#--------------------------------------------------------------------------#
198# test installing
199#--------------------------------------------------------------------------#
200
201my $temp_install = 'temp_install';
202mkdir $temp_install;
203ok( -d $temp_install, "temp install dir created" );
204
205$mb->install_base($temp_install);
206stdout_of( sub { $mb->dispatch('install') } );
207
208$share_list = Module::Build->rscan_dir(
209 "$temp_install/lib/perl5/auto/share", sub {-f}
210);
211
3ec89e6d 212SKIP:
213{
214
215skip 'filename case not necessarily preserved', 1 if $^O eq 'VMS';
216
613f422f 217is_deeply(
218 [ sort @$share_list ], [
219 "$temp_install/lib/perl5/auto/share/dist/Simple-Share/foo.txt",
220 "$temp_install/lib/perl5/auto/share/module/Simple-Share/bar.txt",
221 ],
222 "share_dir files correctly installed"
223);
224
3ec89e6d 225}
226
613f422f 227#--------------------------------------------------------------------------#
228# test with File::ShareDir
229#--------------------------------------------------------------------------#
230
231SKIP: {
232 eval { require File::ShareDir; File::ShareDir->VERSION(1.00) };
233 skip "needs File::ShareDir 1.00", 2 if $@;
234
235 unshift @INC, File::Spec->catdir($temp_install, qw/lib perl5/);
236 require Simple::Share;
237
238 eval {File::ShareDir::dist_file('Simple-Share','foo.txt') };
239 is( $@, q{}, "Found shared dist file" );
240
241 eval {File::ShareDir::module_file('Simple::Share','bar.txt') };
242 is( $@, q{}, "Found shared module file" );
243}