disable Module::Build bundle_inc.t
[p5sagit/p5-mst-13.2.git] / cpan / Module-Build / t / bundle_inc.t
1 # sample.t -- a sample test file for Module::Build
2
3 use strict;
4 use lib 't/lib';
5 use MBTest; # or 'no_plan'
6 use DistGen;
7 use Config;
8 use IO::File;
9 use File::Spec;
10 use ExtUtils::Packlist;
11 use File::Path;
12
13 # Ensure any Module::Build modules are loaded from correct directory
14 blib_load('Module::Build');
15 blib_load('Module::Build::ConfigData');
16
17 if ( $ENV{PERL_CORE} ) {
18   plan skip_all => 'bundle_inc tests will never succeed in PERL_CORE';
19 }
20 elsif ( Module::Build::ConfigData->feature('inc_bundling_support') ) {
21   plan tests => 18;
22 } else {
23   plan skip_all => 'inc_bundling_support feature is not enabled';
24 }
25
26 # need to do a temp install of M::B being tested to ensure a packlist
27 # is available for bundling
28
29 my $current_mb = Module::Build->resume();
30 my $temp_install = MBTest->tmpdir();
31 my $arch = $Config{archname};
32 my $lib_path = File::Spec->catdir($temp_install,qw/lib perl5/);
33 my $arch_path = File::Spec->catdir( $lib_path, $arch );
34 mkpath ( $arch_path );
35 ok( -d $arch_path, "created temporary M::B pseudo-install directory");
36
37 unshift @INC, $lib_path, $arch_path;
38 local $ENV{PERL5LIB} = join( $Config{path_sep},
39   $lib_path, $arch_path, ($ENV{PERL5LIB} ? $ENV{PERL5LIB} : () )
40 );
41
42 stdout_of( sub { $current_mb->dispatch('install', install_base => $temp_install) } );
43
44 # create dist object in a temp directory
45 # enter the directory and generate the skeleton files
46 my $dist = DistGen->new( inc => 1 )->chdir_in->regen;
47
48 # get a Module::Build object and test with it
49 my $mb = $dist->new_from_context(); # quiet by default
50 isa_ok( $mb, "Module::Build" );
51 is( $mb->dist_name, "Simple", "dist_name is 'Simple'" );
52 is_deeply( $mb->bundle_inc, [ 'Module::Build' ],
53   "Module::Build is flagged for bundling"
54 );
55
56 # see what gets bundled
57 stdout_stderr_of( sub { $mb->dispatch('distdir') } );
58
59 my $dist_inc = File::Spec->catdir($mb->dist_dir, 'inc');
60 ok( -e File::Spec->catfile( $dist_inc, 'latest.pm' ),
61   "./inc/latest.pm created"
62 );
63
64 ok( -d File::Spec->catdir( $dist_inc, 'inc_Module-Build' ),
65   "dist_dir/inc/inc_Module_Build created"
66 );
67
68 my $mb_file =
69   File::Spec->catfile( $dist_inc, qw/inc_Module-Build Module Build.pm/ );
70
71 ok( -e $mb_file,
72   "dist_dir/inc/inc_Module_Build/Module/Build.pm created"
73 );
74
75 ok( -e File::Spec->catfile( $dist_inc, qw/inc_Module-Build Module Build Base.pm/ ),
76   "dist_dir/inc/inc_Module_Build/Module/Build/Base.pm created"
77 );
78
79 # Force bundled M::B to a higher version so it gets loaded
80 # This has failed on Win32 for no known reason, so we'll skip if
81 # we can't edit the file.
82
83 eval {
84   my $fh;
85   $fh = IO::File->new($mb_file, "<") or die "Could not read $mb_file: $!";
86   my $mb_code = do { local $/; <$fh> };
87   $mb_code =~ s{\$VERSION\s+=\s+\S+}{\$VERSION = 9999;};
88   $fh->close;
89   $fh = IO::File->new($mb_file, ">") or die "Could not write $mb_file: $!";
90   print {$fh} $mb_code;
91   $fh->close;
92 };
93
94 my $err = $@;
95 diag $@ if $@;
96 SKIP: {
97   skip "Couldn't adjust \$VERSION in bundled M::B for testing", 10
98     if $err;
99
100   # test the bundling in dist_dir
101   chdir $mb->dist_dir;
102
103   stdout_of( sub { Module::Build->run_perl_script('Build.PL',[],[]) } );
104
105   my $meta = IO::File->new('MYMETA.yml');
106   ok( $meta, "found MYMETA.yml" );
107   ok( scalar( grep { /generated_by:.*9999/ } <$meta> ),
108     "dist_dir Build.PL loaded bundled Module::Build"
109   );
110
111   #--------------------------------------------------------------------------#
112   # test identification of dependencies
113   #--------------------------------------------------------------------------#
114
115   $dist->chdir_in;
116
117   $dist->add_file( 'mylib/Foo.pm', << 'HERE' );
118 package Foo;
119 our $VERSION = 1;
120 1;
121 HERE
122
123   $dist->add_file( 'mylib/Bar.pm', << 'HERE' );
124 package Bar;
125 use Foo;
126 our $VERSION = 42;
127 1;
128 HERE
129
130   $dist->change_file( 'Build.PL', << "HERE" );
131 use inc::latest 'Module::Build';
132 use inc::latest 'Foo';
133
134 Module::Build->new(
135   module_name => '$dist->{name}',
136   license => 'perl',
137 )->create_build_script;
138 HERE
139
140   $dist->regen( clean => 1 );
141
142   make_packlist($_,'mylib') for qw/Foo Bar/;
143
144   # get a Module::Build object and test with it
145   my $abs_mylib = File::Spec->rel2abs('mylib');
146
147
148   unshift @INC, $abs_mylib;
149   $mb = $dist->new_from_context(); # quiet by default
150   isa_ok( $mb, "Module::Build" );
151   is_deeply( [sort @{$mb->bundle_inc}], [ 'Foo', 'Module::Build' ],
152     "Module::Build and Foo are flagged for bundling"
153   );
154
155   my $output = stdout_stderr_of( sub { $mb->dispatch('distdir') } );
156
157   ok( -e File::Spec->catfile( $dist_inc, 'latest.pm' ),
158     "./inc/latest.pm created"
159   );
160
161   ok( -d File::Spec->catdir( $dist_inc, 'inc_Foo' ),
162     "dist_dir/inc/inc_Foo created"
163   );
164
165   $dist->change_file( 'Build.PL', << "HERE" );
166 use inc::latest 'Module::Build';
167 use inc::latest 'Bar';
168
169 Module::Build->new(
170   module_name => '$dist->{name}',
171   license => 'perl',
172 )->create_build_script;
173 HERE
174
175   $dist->regen( clean => 1 );
176   make_packlist($_,'mylib') for qw/Foo Bar/;
177
178   $mb = $dist->new_from_context(); # quiet by default
179   isa_ok( $mb, "Module::Build" );
180   is_deeply( [sort @{$mb->bundle_inc}], [ 'Bar', 'Module::Build' ],
181     "Module::Build and Bar are flagged for bundling"
182   );
183
184   $output = stdout_stderr_of( sub { $mb->dispatch('distdir') } );
185
186   ok( -e File::Spec->catfile( $dist_inc, 'latest.pm' ),
187     "./inc/latest.pm created"
188   );
189
190   ok( -d File::Spec->catdir( $dist_inc, 'inc_Bar' ),
191     "dist_dir/inc/inc_Bar created"
192   );
193 }
194
195
196 sub make_packlist {
197   my ($mod, $lib) = @_;
198   my $arch = $Config{archname};
199   (my $mod_path = $mod) =~ s{::}{/}g;
200   my $mod_file = File::Spec->catfile( $lib, "$mod_path\.pm" );
201   my $abs = File::Spec->rel2abs($mod_file);
202   my $packlist_path = File::Spec->catdir($lib, $arch, 'auto', $mod_path);
203   mkpath $packlist_path;
204   my $packlist = ExtUtils::Packlist->new;
205   $packlist->{$abs}++;
206   $packlist->write( File::Spec->catfile( $packlist_path, '.packlist' ));
207 }
208
209 # vim:ts=2:sw=2:et:sta:sts=2