1 ### On VMS, the ENV is not reset after the program terminates.
2 ### So reset it here explicitly
3 my ($old_env_path, $old_env_perl5lib);
8 ### paths to our own 'lib' and 'inc' dirs
9 ### include them, relative from t/
10 my @paths = map { "$FindBin::Bin/$_" } qw[../lib inc];
12 ### absolute'ify the paths in @INC;
13 my @rel2abs = map { File::Spec->rel2abs( $_ ) }
14 grep { not File::Spec->file_name_is_absolute( $_ ) } @INC;
16 ### use require to make devel::cover happy
18 for ( @paths, @rel2abs ) {
25 ### and add them to the environment, so shellouts get them
26 $old_env_perl5lib = $ENV{'PERL5LIB'};
27 $ENV{'PERL5LIB'} = join $Config{'path_sep'},
28 grep { defined } $ENV{'PERL5LIB'}, @paths, @rel2abs;
30 ### add our own path to the front of $ENV{PATH}, so that cpanp-run-perl
31 ### and friends get picked up
32 $old_env_path = $ENV{PATH};
33 $ENV{'PATH'} = join $Config{'path_sep'},
34 grep { defined } "$FindBin::Bin/../bin", $ENV{'PATH'};
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|[/\\]| );
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"
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';
57 ### Use a $^O comparison, as depending on module at this time
58 ### may cause weird errors/warnings
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
65 $ENV{PATH} = $old_env_path;
67 if (defined $old_env_perl5lib) {
68 $ENV{PERL5LIB} = $old_env_perl5lib;
70 delete $ENV{PERL5LIB};
76 use CPANPLUS::Configure;
77 use CPANPLUS::Error ();
79 use File::Path qw[rmtree];
81 use File::Basename qw[basename];
83 { ### Force the ignoring of .po files for L::M::S
84 $INC{'Locale::Maketext::Lexicon.pm'} = __FILE__;
85 $Locale::Maketext::Lexicon::VERSION = 0;
88 my $Env = 'PERL5_CPANPLUS_TEST_VERBOSE';
90 # prereq has to be in our package file && core!
91 use constant TEST_CONF_PREREQ => 'Cwd';
92 use constant TEST_CONF_MODULE => 'Foo::Bar::EU::NOXS';
93 use constant TEST_CONF_MODULE_SUB => 'Foo::Bar::EU::NOXS::Sub';
94 use constant TEST_CONF_AUTHOR => 'EUNOXS';
95 use constant TEST_CONF_INST_MODULE => 'Foo::Bar';
96 use constant TEST_CONF_INVALID_MODULE => 'fnurk';
97 use constant TEST_CONF_MIRROR_DIR => 'dummy-localmirror';
98 use constant TEST_CONF_CPAN_DIR => 'dummy-CPAN';
99 use constant TEST_CONF_CPANPLUS_DIR => 'dummy-cpanplus';
100 use constant TEST_CONF_INSTALL_DIR => File::Spec->rel2abs(
102 TEST_CONF_CPANPLUS_DIR,
107 ### we might need this Some Day when we're installing into
108 ### our own sandbox. see t/20.t for details
109 # use constant TEST_INSTALL_DIR => do {
110 # my $dir = File::Spec->rel2abs( 'dummy-perl' );
112 # ### clean up paths if we are on win32
113 # ### dirs with spaces will be.. bad :(
115 # ? Win32::GetShortPathName( $dir )
119 # use constant TEST_INSTALL_DIR_LIB
120 # => File::Spec->catdir( TEST_INSTALL_DIR, 'lib' );
121 # use constant TEST_INSTALL_DIR_BIN
122 # => File::Spec->catdir( TEST_INSTALL_DIR, 'bin' );
123 # use constant TEST_INSTALL_DIR_MAN1
124 # => File::Spec->catdir( TEST_INSTALL_DIR, 'man', 'man1' );
125 # use constant TEST_INSTALL_DIR_MAN3
126 # => File::Spec->catdir( TEST_INSTALL_DIR, 'man', 'man3' );
127 # use constant TEST_INSTALL_DIR_ARCH
128 # => File::Spec->catdir( TEST_INSTALL_DIR, 'arch' );
130 # use constant TEST_INSTALL_EU_MM_FLAGS =>
131 # ' INSTALLDIRS=site' .
132 # ' INSTALLSITELIB=' . TEST_INSTALL_DIR_LIB .
133 # ' INSTALLSITEARCH=' . TEST_INSTALL_DIR_ARCH . # .packlist
134 # ' INSTALLARCHLIB=' . TEST_INSTALL_DIR_ARCH . # perllocal.pod
135 # ' INSTALLSITEBIN=' . TEST_INSTALL_DIR_BIN .
136 # ' INSTALLSCRIPT=' . TEST_INSTALL_DIR_BIN .
137 # ' INSTALLSITEMAN1DIR=' . TEST_INSTALL_DIR_MAN1 .
138 # ' INSTALLSITEMAN3DIR=' . TEST_INSTALL_DIR_MAN3;
142 ### VMS needs this in directory format for rel2abs
143 my $test_dir = $^O eq 'VMS'
144 ? File::Spec->catdir(TEST_CONF_CPAN_DIR)
145 : TEST_CONF_CPAN_DIR;
147 ### Convert to an absolute file specification
148 my $abs_test_dir = File::Spec->rel2abs($test_dir);
150 ### According to John M: the hosts path needs to be in UNIX format.
151 ### File::Spec::Unix->rel2abs does not work at all on VMS
152 $abs_test_dir = VMS::Filespec::unixify( $abs_test_dir ) if $^O eq 'VMS';
154 return $abs_test_dir;
159 ### don't load any other configs than the heuristic one
160 ### during tests. They might hold broken/incorrect data
161 ### for our test suite. Bug [perl #43629] showed this.
162 my $conf = CPANPLUS::Configure->new( load_configs => 0 );
164 my $dummy_cpan = dummy_cpan_dir();
166 $conf->set_conf( hosts => [ {
171 $conf->set_conf( base => File::Spec->rel2abs(TEST_CONF_CPANPLUS_DIR));
172 $conf->set_conf( dist_type => '' );
173 $conf->set_conf( signature => 0 );
174 $conf->set_conf( verbose => 1 ) if $ENV{ $Env };
176 ### never use a pager in the test suite
177 $conf->set_program( pager => '' );
179 ### dmq tells us that we should run with /nologo
180 ### if using nmake, as it's very noisy otherwise.
181 { my $make = $conf->get_program('make');
182 if( $make and basename($make) =~ /^nmake/i ) {
183 $conf->set_conf( makeflags => '/nologo' );
187 $conf->set_conf( source_engine => $ENV{CPANPLUS_SOURCE_ENGINE} )
188 if $ENV{CPANPLUS_SOURCE_ENGINE};
191 $conf->get_conf('base'),
192 TEST_CONF_MIRROR_DIR,
193 # TEST_INSTALL_DIR_LIB,
194 # TEST_INSTALL_DIR_BIN,
195 # TEST_INSTALL_DIR_MAN1,
196 # TEST_INSTALL_DIR_MAN3,
197 ], ( $ENV{PERL_CORE} ? 0 : 1 ) );
204 my $file = ".".basename($0).".output";
208 $fh = FileHandle->new(">$file")
209 or warn "Could not open output file '$file': $!";
215 sub output_file { return $file }
219 ### redirect output from msg() and error() output to file
220 unless( $ENV{$Env} ) {
222 print "# To run tests in verbose mode, set ".
223 "\$ENV{$Env} = 1\n" unless $ENV{PERL_CORE};
225 1 while unlink $file; # just in case
227 $CPANPLUS::Error::ERROR_FH =
228 $CPANPLUS::Error::ERROR_FH = output_handle();
230 $CPANPLUS::Error::MSG_FH =
231 $CPANPLUS::Error::MSG_FH = output_handle();
237 ### clean these files if we're under perl core
239 if ( $ENV{PERL_CORE} ) {
240 close output_handle(); 1 while unlink output_file();
243 gimme_conf->get_conf('base'),
244 TEST_CONF_MIRROR_DIR,
245 # TEST_INSTALL_DIR_LIB,
246 # TEST_INSTALL_DIR_BIN,
247 # TEST_INSTALL_DIR_MAN1,
248 # TEST_INSTALL_DIR_MAN3,
249 ], 0 ); # DO NOT be verbose under perl core -- makes tests fail
253 ### whenever we start a new script, we want to clean out our
254 ### old files from the test '.cpanplus' dir..
255 sub _clean_test_dir {
256 my $dirs = shift || [];
257 my $verbose = shift || 0;
259 for my $dir ( @$dirs ) {
261 ### no point if it doesn't exist;
265 opendir $dh, $dir or die "Could not open basedir '$dir': $!";
266 while( my $file = readdir $dh ) {
267 next if $file =~ /^\./; # skip dot files
269 my $path = File::Spec->catfile( $dir, $file );
271 ### directory, rmtree it
274 ### John Malmberg reports yet another VMS issue:
275 ### A directory name on VMS in VMS format ends with .dir
276 ### when it is referenced as a file.
277 ### In UNIX format traditionally PERL on VMS does not remove the
278 ### '.dir', however the VMS C library conversion routines do
279 ### remove the '.dir' and the VMS C library routines can not
280 ### handle the '.dir' being present on UNIX format filenames.
281 ### So code doing the fixup has on VMS has to be able to handle
282 ### both UNIX format names and VMS format names.
284 ### XXX See http://www.xray.mpe.mpg.de/
285 ### mailing-lists/perl5-porters/2007-10/msg00064.html
286 ### for details -- the below regex could use some touchups
287 ### according to John. M.
288 $file =~ s/\.dir$//i if $^O eq 'VMS';
290 my $dirpath = File::Spec->catdir( $dir, $file );
292 print "# Deleting directory '$dirpath'\n" if $verbose;
293 eval { rmtree( $dirpath ) };
294 warn "Could not delete '$dirpath' while cleaning up '$dir'"
299 print "# Deleting file '$path'\n" if $verbose;
300 1 while unlink $path;