Commit | Line | Data |
---|---|---|
5bc5f6dc RGS |
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); | |
6aaee015 RGS |
4 | BEGIN { |
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 | ||
48 | BEGIN { | |
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 | |
59 | END { | |
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 | |
65 | $ENV{PATH} = $old_path; | |
66 | ||
67 | if (defined $old_perl5lib) { | |
68 | $ENV{PERL5LIB} = $old_perl5lib; | |
69 | } else { | |
70 | delete $ENV{PERL5LIB}; | |
71 | } | |
72 | } | |
73 | } | |
74 | ||
6aaee015 RGS |
75 | use strict; |
76 | use CPANPLUS::Configure; | |
983ffab6 | 77 | use CPANPLUS::Error (); |
6aaee015 RGS |
78 | |
79 | use File::Path qw[rmtree]; | |
80 | use FileHandle; | |
81 | use 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 |
88 | my $Env = 'PERL5_CPANPLUS_TEST_VERBOSE'; |
89 | ||
6aaee015 RGS |
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'; | |
5879cbe1 | 93 | use constant TEST_CONF_MODULE_SUB => 'Foo::Bar::EU::NOXS::Sub'; |
5bc5f6dc | 94 | use constant TEST_CONF_AUTHOR => 'EUNOXS'; |
6aaee015 RGS |
95 | use constant TEST_CONF_INST_MODULE => 'Foo::Bar'; |
96 | use constant TEST_CONF_INVALID_MODULE => 'fnurk'; | |
494f1016 | 97 | use constant TEST_CONF_MIRROR_DIR => 'dummy-localmirror'; |
5bc5f6dc | 98 | use constant TEST_CONF_CPAN_DIR => 'dummy-CPAN'; |
6aaee015 RGS |
99 | |
100 | ### we might need this Some Day when we're installing into | |
101 | ### our own sandbox. see t/20.t for details | |
102 | # use constant TEST_INSTALL_DIR => do { | |
103 | # my $dir = File::Spec->rel2abs( 'dummy-perl' ); | |
104 | # | |
105 | # ### clean up paths if we are on win32 | |
106 | # ### dirs with spaces will be.. bad :( | |
107 | # $^O eq 'MSWin32' | |
108 | # ? Win32::GetShortPathName( $dir ) | |
109 | # : $dir; | |
110 | # }; | |
111 | ||
112 | # use constant TEST_INSTALL_DIR_LIB | |
113 | # => File::Spec->catdir( TEST_INSTALL_DIR, 'lib' ); | |
114 | # use constant TEST_INSTALL_DIR_BIN | |
115 | # => File::Spec->catdir( TEST_INSTALL_DIR, 'bin' ); | |
116 | # use constant TEST_INSTALL_DIR_MAN1 | |
117 | # => File::Spec->catdir( TEST_INSTALL_DIR, 'man', 'man1' ); | |
118 | # use constant TEST_INSTALL_DIR_MAN3 | |
119 | # => File::Spec->catdir( TEST_INSTALL_DIR, 'man', 'man3' ); | |
120 | # use constant TEST_INSTALL_DIR_ARCH | |
121 | # => File::Spec->catdir( TEST_INSTALL_DIR, 'arch' ); | |
122 | # | |
123 | # use constant TEST_INSTALL_EU_MM_FLAGS => | |
124 | # ' INSTALLDIRS=site' . | |
125 | # ' INSTALLSITELIB=' . TEST_INSTALL_DIR_LIB . | |
126 | # ' INSTALLSITEARCH=' . TEST_INSTALL_DIR_ARCH . # .packlist | |
127 | # ' INSTALLARCHLIB=' . TEST_INSTALL_DIR_ARCH . # perllocal.pod | |
128 | # ' INSTALLSITEBIN=' . TEST_INSTALL_DIR_BIN . | |
129 | # ' INSTALLSCRIPT=' . TEST_INSTALL_DIR_BIN . | |
130 | # ' INSTALLSITEMAN1DIR=' . TEST_INSTALL_DIR_MAN1 . | |
131 | # ' INSTALLSITEMAN3DIR=' . TEST_INSTALL_DIR_MAN3; | |
132 | ||
133 | ||
134 | sub gimme_conf { | |
d0baa00e SP |
135 | |
136 | ### don't load any other configs than the heuristic one | |
137 | ### during tests. They might hold broken/incorrect data | |
138 | ### for our test suite. Bug [perl #43629] showed this. | |
139 | my $conf = CPANPLUS::Configure->new( load_configs => 0 ); | |
5879cbe1 RGS |
140 | |
141 | ### VMS needs this in directory format for rel2abs | |
142 | my $test_dir = $^O eq 'VMS' | |
143 | ? File::Spec->catdir(TEST_CONF_CPAN_DIR) | |
144 | : TEST_CONF_CPAN_DIR; | |
145 | ||
146 | ### Convert to an absolute file specification | |
147 | my $abs_test_dir = File::Spec->rel2abs($test_dir); | |
148 | ||
149 | ### According to John M: the hosts path needs to be in UNIX format. | |
150 | ### File::Spec::Unix->rel2abs does not work at all on VMS | |
151 | $abs_test_dir = VMS::Filespec::unixify( $abs_test_dir ) if $^O eq 'VMS'; | |
152 | ||
6aaee015 | 153 | $conf->set_conf( hosts => [ { |
5879cbe1 | 154 | path => $abs_test_dir, |
6aaee015 RGS |
155 | scheme => 'file', |
156 | } ], | |
157 | ); | |
5879cbe1 | 158 | $conf->set_conf( base => File::Spec->rel2abs('dummy-cpanplus') ); |
6aaee015 RGS |
159 | $conf->set_conf( dist_type => '' ); |
160 | $conf->set_conf( signature => 0 ); | |
5bc5f6dc RGS |
161 | $conf->set_conf( verbose => 1 ) if $ENV{ $Env }; |
162 | ||
163 | ### never use a pager in the test suite | |
164 | $conf->set_program( pager => '' ); | |
6aaee015 | 165 | |
622d31ac JB |
166 | ### dmq tells us that we should run with /nologo |
167 | ### if using nmake, as it's very noise otherwise. | |
168 | { my $make = $conf->get_program('make'); | |
169 | if( $make and basename($make) =~ /^nmake/i and | |
170 | $make !~ m|/nologo| | |
171 | ) { | |
172 | $make .= ' /nologo'; | |
173 | $conf->set_program( make => $make ); | |
174 | } | |
175 | } | |
176 | ||
6aaee015 RGS |
177 | _clean_test_dir( [ |
178 | $conf->get_conf('base'), | |
494f1016 | 179 | TEST_CONF_MIRROR_DIR, |
6aaee015 RGS |
180 | # TEST_INSTALL_DIR_LIB, |
181 | # TEST_INSTALL_DIR_BIN, | |
182 | # TEST_INSTALL_DIR_MAN1, | |
183 | # TEST_INSTALL_DIR_MAN3, | |
53873a16 | 184 | ], ( $ENV{PERL_CORE} ? 0 : 1 ) ); |
6aaee015 RGS |
185 | |
186 | return $conf; | |
187 | }; | |
188 | ||
494f1016 JB |
189 | { |
190 | my $fh; | |
191 | my $file = ".".basename($0).".output"; | |
192 | sub output_handle { | |
193 | return $fh if $fh; | |
194 | ||
195 | $fh = FileHandle->new(">$file") | |
196 | or warn "Could not open output file '$file': $!"; | |
197 | ||
198 | $fh->autoflush(1); | |
199 | return $fh; | |
200 | } | |
6aaee015 | 201 | |
494f1016 | 202 | sub output_file { return $file } |
983ffab6 JB |
203 | |
204 | ||
5bc5f6dc | 205 | |
983ffab6 | 206 | ### redirect output from msg() and error() output to file |
5bc5f6dc | 207 | unless( $ENV{$Env} ) { |
983ffab6 JB |
208 | |
209 | print "# To run tests in verbose mode, set ". | |
5bc5f6dc | 210 | "\$ENV{$Env} = 1\n" unless $ENV{PERL_CORE}; |
983ffab6 | 211 | |
5bc5f6dc | 212 | 1 while unlink $file; # just in case |
983ffab6 JB |
213 | |
214 | $CPANPLUS::Error::ERROR_FH = | |
215 | $CPANPLUS::Error::ERROR_FH = output_handle(); | |
216 | ||
217 | $CPANPLUS::Error::MSG_FH = | |
218 | $CPANPLUS::Error::MSG_FH = output_handle(); | |
219 | ||
220 | } | |
6aaee015 RGS |
221 | } |
222 | ||
494f1016 JB |
223 | |
224 | ### clean these files if we're under perl core | |
225 | END { | |
226 | if ( $ENV{PERL_CORE} ) { | |
227 | close output_handle(); 1 while unlink output_file(); | |
228 | ||
229 | _clean_test_dir( [ | |
230 | gimme_conf->get_conf('base'), | |
231 | TEST_CONF_MIRROR_DIR, | |
232 | # TEST_INSTALL_DIR_LIB, | |
233 | # TEST_INSTALL_DIR_BIN, | |
234 | # TEST_INSTALL_DIR_MAN1, | |
235 | # TEST_INSTALL_DIR_MAN3, | |
53873a16 | 236 | ], 0 ); # DO NOT be verbose under perl core -- makes tests fail |
494f1016 JB |
237 | } |
238 | } | |
239 | ||
6aaee015 RGS |
240 | ### whenever we start a new script, we want to clean out our |
241 | ### old files from the test '.cpanplus' dir.. | |
242 | sub _clean_test_dir { | |
243 | my $dirs = shift || []; | |
244 | my $verbose = shift || 0; | |
245 | ||
246 | for my $dir ( @$dirs ) { | |
247 | ||
53873a16 RGS |
248 | ### no point if it doesn't exist; |
249 | next unless -d $dir; | |
250 | ||
6aaee015 RGS |
251 | my $dh; |
252 | opendir $dh, $dir or die "Could not open basedir '$dir': $!"; | |
253 | while( my $file = readdir $dh ) { | |
254 | next if $file =~ /^\./; # skip dot files | |
255 | ||
256 | my $path = File::Spec->catfile( $dir, $file ); | |
257 | ||
258 | ### directory, rmtree it | |
259 | if( -d $path ) { | |
5879cbe1 RGS |
260 | |
261 | ### John Malmberg reports yet another VMS issue: | |
262 | ### A directory name on VMS in VMS format ends with .dir | |
263 | ### when it is referenced as a file. | |
264 | ### In UNIX format traditionally PERL on VMS does not remove the | |
265 | ### '.dir', however the VMS C library conversion routines do | |
266 | ### remove the '.dir' and the VMS C library routines can not | |
267 | ### handle the '.dir' being present on UNIX format filenames. | |
268 | ### So code doing the fixup has on VMS has to be able to handle | |
269 | ### both UNIX format names and VMS format names. | |
270 | ||
271 | ### XXX See http://www.xray.mpe.mpg.de/ | |
272 | ### mailing-lists/perl5-porters/2007-10/msg00064.html | |
273 | ### for details -- the below regex could use some touchups | |
274 | ### according to John. M. | |
275 | $file =~ s/\.dir//i if $^O eq 'VMS'; | |
276 | ||
277 | my $dirpath = File::Spec->catdir( $dir, $file ); | |
278 | ||
279 | print "# Deleting directory '$dirpath'\n" if $verbose; | |
280 | eval { rmtree( $dirpath ) }; | |
281 | warn "Could not delete '$dirpath' while cleaning up '$dir'" | |
282 | if $@; | |
6aaee015 RGS |
283 | |
284 | ### regular file | |
285 | } else { | |
983ffab6 | 286 | print "# Deleting file '$path'\n" if $verbose; |
6aaee015 RGS |
287 | 1 while unlink $path; |
288 | } | |
289 | } | |
290 | ||
291 | close $dh; | |
292 | } | |
293 | ||
294 | return 1; | |
295 | } | |
296 | 1; |