This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
add step to update RT version numbers in release_managers_guide
[perl5.git] / cpan / CPANPLUS / t / inc / conf.pl
CommitLineData
5bc5f6dc
RGS
1### On VMS, the ENV is not reset after the program terminates.
2### So reset it here explicitly
3my ($old_env_path, $old_env_perl5lib);
6aaee015
RGS
4BEGIN {
5 use FindBin;
6 use File::Spec;
7
8 ### paths to our own 'lib' and 'inc' dirs
9 ### include them, relative from t/
10 my @paths = map { "$FindBin::Bin/$_" } qw[../lib inc];
11
12 ### absolute'ify the paths in @INC;
13 my @rel2abs = map { File::Spec->rel2abs( $_ ) }
14 grep { not File::Spec->file_name_is_absolute( $_ ) } @INC;
15
16 ### use require to make devel::cover happy
17 require lib;
18 for ( @paths, @rel2abs ) {
19 my $l = 'lib';
20 $l->import( $_ )
21 }
22
23 use Config;
24
25 ### and add them to the environment, so shellouts get them
5bc5f6dc 26 $old_env_perl5lib = $ENV{'PERL5LIB'};
768b421c 27 $ENV{'PERL5LIB'} = join $Config{'path_sep'},
6aaee015
RGS
28 grep { defined } $ENV{'PERL5LIB'}, @paths, @rel2abs;
29
30 ### add our own path to the front of $ENV{PATH}, so that cpanp-run-perl
31 ### and friends get picked up
5bc5f6dc
RGS
32 $old_env_path = $ENV{PATH};
33 $ENV{'PATH'} = join $Config{'path_sep'},
6aaee015
RGS
34 grep { defined } "$FindBin::Bin/../bin", $ENV{'PATH'};
35
36 ### Fix up the path to perl, as we're about to chdir
37 ### but only under perlcore, or if the path contains delimiters,
38 ### meaning it's relative, but not looked up in your $PATH
39 $^X = File::Spec->rel2abs( $^X )
40 if $ENV{PERL_CORE} or ( $^X =~ m|[/\\]| );
41
42 ### chdir to our own test dir, so we know all files are relative
43 ### to this point, no matter whether run from perlcore tests or
44 ### regular CPAN installs
45 chdir "$FindBin::Bin" if -d "$FindBin::Bin"
46}
47
48BEGIN {
49 use IPC::Cmd;
50
51 ### Win32 has issues with redirecting FD's properly in IPC::Run:
52 ### Can't redirect fd #4 on Win32 at IPC/Run.pm line 2801
53 $IPC::Cmd::USE_IPC_RUN = 0 if $^O eq 'MSWin32';
54 $IPC::Cmd::USE_IPC_RUN = 0 if $^O eq 'MSWin32';
55}
56
5bc5f6dc
RGS
57### Use a $^O comparison, as depending on module at this time
58### may cause weird errors/warnings
59END {
60 if ($^O eq 'VMS') {
61 ### VMS environment variables modified by this test need to be put back
62 ### path is "magic" on VMS, we can not tell if it really existed before
63 ### this was run, because VMS will magically pretend that a PATH
64 ### environment variable exists set to the current working directory
75046b50 65 $ENV{PATH} = $old_env_path;
5bc5f6dc 66
75046b50
JM
67 if (defined $old_env_perl5lib) {
68 $ENV{PERL5LIB} = $old_env_perl5lib;
5bc5f6dc
RGS
69 } else {
70 delete $ENV{PERL5LIB};
71 }
72 }
73}
74
6aaee015
RGS
75use strict;
76use CPANPLUS::Configure;
983ffab6 77use CPANPLUS::Error ();
6aaee015
RGS
78
79use File::Path qw[rmtree];
80use FileHandle;
81use File::Basename qw[basename];
82
83{ ### Force the ignoring of .po files for L::M::S
84 $INC{'Locale::Maketext::Lexicon.pm'} = __FILE__;
85 $Locale::Maketext::Lexicon::VERSION = 0;
86}
87
5bc5f6dc
RGS
88my $Env = 'PERL5_CPANPLUS_TEST_VERBOSE';
89
6aaee015
RGS
90# prereq has to be in our package file && core!
91use constant TEST_CONF_PREREQ => 'Cwd';
92use constant TEST_CONF_MODULE => 'Foo::Bar::EU::NOXS';
5879cbe1 93use constant TEST_CONF_MODULE_SUB => 'Foo::Bar::EU::NOXS::Sub';
5bc5f6dc 94use constant TEST_CONF_AUTHOR => 'EUNOXS';
6aaee015
RGS
95use constant TEST_CONF_INST_MODULE => 'Foo::Bar';
96use constant TEST_CONF_INVALID_MODULE => 'fnurk';
494f1016 97use constant TEST_CONF_MIRROR_DIR => 'dummy-localmirror';
5bc5f6dc 98use constant TEST_CONF_CPAN_DIR => 'dummy-CPAN';
4443dd53
JB
99use constant TEST_CONF_CPANPLUS_DIR => 'dummy-cpanplus';
100use constant TEST_CONF_INSTALL_DIR => File::Spec->rel2abs(
101 File::Spec->catdir(
102 TEST_CONF_CPANPLUS_DIR,
103 'install'
104 )
20afcebf 105 );
6aaee015 106
4443dd53 107sub dummy_cpan_dir {
5879cbe1
RGS
108 ### VMS needs this in directory format for rel2abs
109 my $test_dir = $^O eq 'VMS'
110 ? File::Spec->catdir(TEST_CONF_CPAN_DIR)
111 : TEST_CONF_CPAN_DIR;
112
113 ### Convert to an absolute file specification
114 my $abs_test_dir = File::Spec->rel2abs($test_dir);
115
116 ### According to John M: the hosts path needs to be in UNIX format.
117 ### File::Spec::Unix->rel2abs does not work at all on VMS
118 $abs_test_dir = VMS::Filespec::unixify( $abs_test_dir ) if $^O eq 'VMS';
4443dd53
JB
119
120 return $abs_test_dir;
121}
122
123sub gimme_conf {
124
125 ### don't load any other configs than the heuristic one
126 ### during tests. They might hold broken/incorrect data
127 ### for our test suite. Bug [perl #43629] showed this.
128 my $conf = CPANPLUS::Configure->new( load_configs => 0 );
129
130 my $dummy_cpan = dummy_cpan_dir();
5879cbe1 131
6aaee015 132 $conf->set_conf( hosts => [ {
4443dd53 133 path => $dummy_cpan,
6aaee015
RGS
134 scheme => 'file',
135 } ],
136 );
4443dd53 137 $conf->set_conf( base => File::Spec->rel2abs(TEST_CONF_CPANPLUS_DIR));
6aaee015
RGS
138 $conf->set_conf( dist_type => '' );
139 $conf->set_conf( signature => 0 );
5bc5f6dc
RGS
140 $conf->set_conf( verbose => 1 ) if $ENV{ $Env };
141
142 ### never use a pager in the test suite
143 $conf->set_program( pager => '' );
6aaee015 144
622d31ac 145 ### dmq tells us that we should run with /nologo
74ae8479 146 ### if using nmake, as it's very noisy otherwise.
622d31ac 147 { my $make = $conf->get_program('make');
74ae8479
JB
148 if( $make and basename($make) =~ /^nmake/i ) {
149 $conf->set_conf( makeflags => '/nologo' );
622d31ac
JB
150 }
151 }
4443dd53 152
8c576062
JB
153 ### CPANPLUS::Config checks 3 specific scenarios first
154 ### when looking for cpanp-run-perl: parallel to cpanp,
155 ### parallel to CPANPLUS.pm, or installed into a custom
156 ### prefix like /tmp/foo. Only *THEN* does it check the
157 ### the path.
158 ### If the perl core is extracted to a directory that has
159 ### cpanp-run-perl installed the same amount of 'uplevels'
160 ### as the /tmp/foo prefix, we'll pull in the wrong script
161 ### by accident.
162 ### Since we set the path to cpanp-run-perl explicitily
163 ### at the top of this script, it's best to update the config
164 ### ourselves with a path lookup, rather than rely on its
165 ### heuristics. Thanks to David Wheeler, Josh Jore and Vincent
166 ### Pit for helping to track this down.
167 if( $ENV{PERL_CORE} ) {
168 $conf->set_program( "perlwrapper" => IPC::Cmd::can_run('cpanp-run-perl') );
169 }
170
4443dd53
JB
171 $conf->set_conf( source_engine => $ENV{CPANPLUS_SOURCE_ENGINE} )
172 if $ENV{CPANPLUS_SOURCE_ENGINE};
622d31ac 173
6aaee015
RGS
174 _clean_test_dir( [
175 $conf->get_conf('base'),
494f1016 176 TEST_CONF_MIRROR_DIR,
6aaee015
RGS
177# TEST_INSTALL_DIR_LIB,
178# TEST_INSTALL_DIR_BIN,
179# TEST_INSTALL_DIR_MAN1,
180# TEST_INSTALL_DIR_MAN3,
53873a16 181 ], ( $ENV{PERL_CORE} ? 0 : 1 ) );
6aaee015
RGS
182
183 return $conf;
184};
185
494f1016
JB
186{
187 my $fh;
188 my $file = ".".basename($0).".output";
189 sub output_handle {
190 return $fh if $fh;
191
192 $fh = FileHandle->new(">$file")
193 or warn "Could not open output file '$file': $!";
194
195 $fh->autoflush(1);
196 return $fh;
197 }
6aaee015 198
494f1016 199 sub output_file { return $file }
983ffab6
JB
200
201
5bc5f6dc 202
983ffab6 203 ### redirect output from msg() and error() output to file
5bc5f6dc 204 unless( $ENV{$Env} ) {
983ffab6
JB
205
206 print "# To run tests in verbose mode, set ".
5bc5f6dc 207 "\$ENV{$Env} = 1\n" unless $ENV{PERL_CORE};
983ffab6 208
5bc5f6dc 209 1 while unlink $file; # just in case
983ffab6
JB
210
211 $CPANPLUS::Error::ERROR_FH =
212 $CPANPLUS::Error::ERROR_FH = output_handle();
213
214 $CPANPLUS::Error::MSG_FH =
215 $CPANPLUS::Error::MSG_FH = output_handle();
216
217 }
6aaee015
RGS
218}
219
494f1016
JB
220
221### clean these files if we're under perl core
222END {
223 if ( $ENV{PERL_CORE} ) {
224 close output_handle(); 1 while unlink output_file();
225
226 _clean_test_dir( [
227 gimme_conf->get_conf('base'),
228 TEST_CONF_MIRROR_DIR,
229 # TEST_INSTALL_DIR_LIB,
230 # TEST_INSTALL_DIR_BIN,
231 # TEST_INSTALL_DIR_MAN1,
232 # TEST_INSTALL_DIR_MAN3,
53873a16 233 ], 0 ); # DO NOT be verbose under perl core -- makes tests fail
494f1016
JB
234 }
235}
236
6aaee015
RGS
237### whenever we start a new script, we want to clean out our
238### old files from the test '.cpanplus' dir..
239sub _clean_test_dir {
240 my $dirs = shift || [];
241 my $verbose = shift || 0;
242
243 for my $dir ( @$dirs ) {
244
53873a16
RGS
245 ### no point if it doesn't exist;
246 next unless -d $dir;
247
6aaee015
RGS
248 my $dh;
249 opendir $dh, $dir or die "Could not open basedir '$dir': $!";
250 while( my $file = readdir $dh ) {
251 next if $file =~ /^\./; # skip dot files
252
253 my $path = File::Spec->catfile( $dir, $file );
254
255 ### directory, rmtree it
256 if( -d $path ) {
5879cbe1
RGS
257
258 ### John Malmberg reports yet another VMS issue:
259 ### A directory name on VMS in VMS format ends with .dir
260 ### when it is referenced as a file.
261 ### In UNIX format traditionally PERL on VMS does not remove the
262 ### '.dir', however the VMS C library conversion routines do
263 ### remove the '.dir' and the VMS C library routines can not
264 ### handle the '.dir' being present on UNIX format filenames.
265 ### So code doing the fixup has on VMS has to be able to handle
266 ### both UNIX format names and VMS format names.
267
268 ### XXX See http://www.xray.mpe.mpg.de/
269 ### mailing-lists/perl5-porters/2007-10/msg00064.html
270 ### for details -- the below regex could use some touchups
271 ### according to John. M.
75046b50 272 $file =~ s/\.dir$//i if $^O eq 'VMS';
5879cbe1
RGS
273
274 my $dirpath = File::Spec->catdir( $dir, $file );
275
276 print "# Deleting directory '$dirpath'\n" if $verbose;
277 eval { rmtree( $dirpath ) };
278 warn "Could not delete '$dirpath' while cleaning up '$dir'"
279 if $@;
6aaee015
RGS
280
281 ### regular file
282 } else {
983ffab6 283 print "# Deleting file '$path'\n" if $verbose;
6aaee015
RGS
284 1 while unlink $path;
285 }
286 }
287
288 close $dh;
289 }
290
291 return 1;
292}
2931;