Commit | Line | Data |
613f422f |
1 | #!/usr/bin/perl -w |
2 | |
3 | use strict; |
4 | use lib 't/lib'; |
5 | use MBTest; |
6 | use File::Spec::Functions qw/catdir catfile/; |
7 | |
8 | #--------------------------------------------------------------------------# |
9 | # Begin testing |
10 | #--------------------------------------------------------------------------# |
11 | |
12 | plan tests => 21; |
13 | |
14 | blib_load('Module::Build'); |
15 | |
16 | #--------------------------------------------------------------------------# |
17 | # Create test distribution |
18 | #--------------------------------------------------------------------------# |
19 | |
20 | my $tmp = MBTest->tmpdir; |
21 | |
22 | use DistGen; |
23 | my $dist = DistGen->new( dir => $tmp, name => 'Simple::Share' ); |
24 | $dist->regen; |
25 | $dist->chdir_in; |
26 | |
27 | #--------------------------------------------------------------------------# |
28 | # Test setting 'share_dir' |
29 | #--------------------------------------------------------------------------# |
30 | |
31 | my $mb = $dist->new_from_context; |
32 | |
33 | # Test without a 'share' dir |
34 | ok( $mb, "Created Module::Build object" ); |
35 | is( $mb->share_dir, undef, |
53fc1c7e |
36 | "default share_dir undef if no 'share' dir exists" |
613f422f |
37 | ); |
38 | ok( ! 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',<< '---'); |
44 | This is foo.txt |
45 | --- |
46 | $dist->add_file('other/share/bar.txt',<< '---'); |
47 | This is bar.txt |
48 | --- |
49 | $dist->regen; |
50 | ok( -e catfile(qw/share foo.txt/), "Created 'share' directory" ); |
51 | ok( -e catfile(qw/other share bar.txt/), "Created 'other/share' directory" ); |
52 | |
53 | # Check default when share_dir is not given |
54 | stdout_stderr_of( sub { $mb = $dist->new_from_context }); |
53fc1c7e |
55 | is( $mb->share_dir, undef, |
56 | "Default share_dir is undef even if 'share' exists" |
613f422f |
57 | ); |
53fc1c7e |
58 | ok( ! 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; |
72 | stdout_stderr_of( sub { $mb = $dist->new_from_context }); |
73 | is_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; |
86 | stdout_stderr_of( sub { $mb = $dist->new_from_context }); |
87 | is_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; |
100 | stdout_stderr_of( sub { $mb = $dist->new_from_context }); |
101 | is_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; |
114 | stdout_stderr_of( sub { $mb = $dist->new_from_context }); |
115 | is_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; |
131 | stdout_stderr_of( sub { $mb = $dist->new_from_context }); |
132 | is_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; |
151 | stdout_stderr_of( sub { $mb = $dist->new_from_context }); |
152 | is_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 | |
163 | is_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 | |
177 | ok( -d 'blib', "Build ran and blib exists" ); |
178 | ok( -d 'blib/lib/auto/share', "blib/lib/auto/share exists" ); |
179 | |
180 | my $share_list = Module::Build->rscan_dir('blib/lib/auto/share', sub {-f}); |
181 | |
182 | is_deeply( |
183 | [ sort @$share_list ], [ |
184 | 'blib/lib/auto/share/dist/Simple-Share/foo.txt', |
185 | 'blib/lib/auto/share/module/Simple-Share/bar.txt', |
186 | ], |
187 | "share_dir files copied to blib" |
188 | ); |
189 | |
190 | #--------------------------------------------------------------------------# |
191 | # test installing |
192 | #--------------------------------------------------------------------------# |
193 | |
194 | my $temp_install = 'temp_install'; |
195 | mkdir $temp_install; |
196 | ok( -d $temp_install, "temp install dir created" ); |
197 | |
198 | $mb->install_base($temp_install); |
199 | stdout_of( sub { $mb->dispatch('install') } ); |
200 | |
201 | $share_list = Module::Build->rscan_dir( |
202 | "$temp_install/lib/perl5/auto/share", sub {-f} |
203 | ); |
204 | |
205 | is_deeply( |
206 | [ sort @$share_list ], [ |
207 | "$temp_install/lib/perl5/auto/share/dist/Simple-Share/foo.txt", |
208 | "$temp_install/lib/perl5/auto/share/module/Simple-Share/bar.txt", |
209 | ], |
210 | "share_dir files correctly installed" |
211 | ); |
212 | |
213 | #--------------------------------------------------------------------------# |
214 | # test with File::ShareDir |
215 | #--------------------------------------------------------------------------# |
216 | |
217 | SKIP: { |
218 | eval { require File::ShareDir; File::ShareDir->VERSION(1.00) }; |
219 | skip "needs File::ShareDir 1.00", 2 if $@; |
220 | |
221 | unshift @INC, File::Spec->catdir($temp_install, qw/lib perl5/); |
222 | require Simple::Share; |
223 | |
224 | eval {File::ShareDir::dist_file('Simple-Share','foo.txt') }; |
225 | is( $@, q{}, "Found shared dist file" ); |
226 | |
227 | eval {File::ShareDir::module_file('Simple::Share','bar.txt') }; |
228 | is( $@, q{}, "Found shared module file" ); |
229 | } |