Commit | Line | Data |
9b4bd854 |
1 | ### XXX copied from cpanplus's t/inc/conf.pl |
2 | BEGIN { |
3 | use FindBin; |
4 | use File::Spec; |
5 | |
6 | ### paths to our own 'lib' and 'inc' dirs |
7 | ### include them, relative from t/ |
8 | my @paths = map { "$FindBin::Bin/$_" } qw[../lib inc]; |
9 | |
10 | ### absolute'ify the paths in @INC; |
11 | my @rel2abs = map { File::Spec->rel2abs( $_ ) } |
12 | grep { not File::Spec->file_name_is_absolute( $_ ) } @INC; |
13 | |
14 | ### use require to make devel::cover happy |
15 | require lib; |
16 | for ( @paths, @rel2abs ) { |
17 | my $l = 'lib'; |
18 | $l->import( $_ ) |
19 | } |
20 | |
21 | use Config; |
22 | |
23 | ### and add them to the environment, so shellouts get them |
24 | $ENV{'PERL5LIB'} = join ':', |
25 | grep { defined } $ENV{'PERL5LIB'}, @paths, @rel2abs; |
26 | |
27 | ### add our own path to the front of $ENV{PATH}, so that cpanp-run-perl |
28 | ### and friends get picked up |
29 | $ENV{'PATH'} = join $Config{'path_sep'}, |
30 | grep { defined } "$FindBin::Bin/../../../bin", $ENV{'PATH'}; |
31 | |
32 | ### Fix up the path to perl, as we're about to chdir |
33 | ### but only under perlcore, or if the path contains delimiters, |
34 | ### meaning it's relative, but not looked up in your $PATH |
35 | $^X = File::Spec->rel2abs( $^X ) |
36 | if $ENV{PERL_CORE} or ( $^X =~ m|[/\\]| ); |
37 | |
38 | ### chdir to our own test dir, so we know all files are relative |
39 | ### to this point, no matter whether run from perlcore tests or |
40 | ### regular CPAN installs |
41 | chdir "$FindBin::Bin" if -d "$FindBin::Bin" |
42 | } |
43 | |
44 | BEGIN { |
45 | use IPC::Cmd; |
46 | |
47 | ### Win32 has issues with redirecting FD's properly in IPC::Run: |
48 | ### Can't redirect fd #4 on Win32 at IPC/Run.pm line 2801 |
49 | $IPC::Cmd::USE_IPC_RUN = 0 if $^O eq 'MSWin32'; |
50 | $IPC::Cmd::USE_IPC_RUN = 0 if $^O eq 'MSWin32'; |
51 | } |
52 | |
53 | use strict; |
54 | use CPANPLUS::Configure; |
55 | |
56 | use File::Path qw[rmtree]; |
57 | use FileHandle; |
58 | use File::Basename qw[basename]; |
59 | |
60 | { ### Force the ignoring of .po files for L::M::S |
61 | $INC{'Locale::Maketext::Lexicon.pm'} = __FILE__; |
62 | $Locale::Maketext::Lexicon::VERSION = 0; |
63 | } |
64 | |
078adea4 |
65 | ### clean up files for PERLCORE mostly -- make clean isn't invoked |
66 | ### there... otoh, we should clean up after ourselves anyway. |
67 | END { |
68 | ### chdir to our own test dir, so we know all files are relative |
69 | ### to this point, no matter whether run from perlcore tests or |
70 | ### regular CPAN installs |
71 | chdir "$FindBin::Bin" if -d "$FindBin::Bin"; |
72 | |
73 | ### XXX hardcoded |
74 | _clean_test_dir( [qw|dummy-perl dummy-cpanplus| ] ); |
75 | } |
76 | |
77 | ### whenever we start a new script, we want to clean out our |
78 | ### old files from the test '.cpanplus' dir.. |
79 | sub _clean_test_dir { |
80 | my $dirs = shift || []; |
81 | my $verbose = shift || 0; |
82 | |
83 | for my $dir ( @$dirs ) { |
84 | |
85 | ### if it's not there, don't bother |
86 | next unless -d $dir; |
87 | |
88 | my $dh; |
89 | opendir $dh, $dir or die "Could not open basedir '$dir': $!"; |
90 | while( my $file = readdir $dh ) { |
91 | next if $file =~ /^\./; # skip dot files |
92 | |
93 | my $path = File::Spec->catfile( $dir, $file ); |
94 | |
95 | ### directory, rmtree it |
96 | if( -d $path ) { |
97 | print "Deleting directory '$path'\n" if $verbose; |
98 | eval { rmtree( $path ) }; |
99 | warn "Could not delete '$path' while cleaning up '$dir'" if $@; |
100 | |
101 | ### regular file |
102 | } else { |
103 | print "Deleting file '$path'\n" if $verbose; |
104 | 1 while unlink $path; |
105 | } |
106 | } |
107 | |
108 | close $dh; |
109 | } |
110 | |
111 | return 1; |
112 | } |
113 | |
9b4bd854 |
114 | 1; |
115 | |
116 | __END__ |
117 | |
118 | # prereq has to be in our package file && core! |
119 | use constant TEST_CONF_PREREQ => 'Cwd'; |
120 | use constant TEST_CONF_MODULE => 'Foo::Bar::EU::NOXS'; |
121 | use constant TEST_CONF_INST_MODULE => 'Foo::Bar'; |
122 | use constant TEST_CONF_INVALID_MODULE => 'fnurk'; |
123 | use constant TEST_CONF_MIRROR_DIR => 'dummy-localmirror'; |
124 | |
125 | ### we might need this Some Day when we're installing into |
126 | ### our own sandbox. see t/20.t for details |
127 | # use constant TEST_INSTALL_DIR => do { |
128 | # my $dir = File::Spec->rel2abs( 'dummy-perl' ); |
129 | # |
130 | # ### clean up paths if we are on win32 |
131 | # ### dirs with spaces will be.. bad :( |
132 | # $^O eq 'MSWin32' |
133 | # ? Win32::GetShortPathName( $dir ) |
134 | # : $dir; |
135 | # }; |
136 | |
137 | # use constant TEST_INSTALL_DIR_LIB |
138 | # => File::Spec->catdir( TEST_INSTALL_DIR, 'lib' ); |
139 | # use constant TEST_INSTALL_DIR_BIN |
140 | # => File::Spec->catdir( TEST_INSTALL_DIR, 'bin' ); |
141 | # use constant TEST_INSTALL_DIR_MAN1 |
142 | # => File::Spec->catdir( TEST_INSTALL_DIR, 'man', 'man1' ); |
143 | # use constant TEST_INSTALL_DIR_MAN3 |
144 | # => File::Spec->catdir( TEST_INSTALL_DIR, 'man', 'man3' ); |
145 | # use constant TEST_INSTALL_DIR_ARCH |
146 | # => File::Spec->catdir( TEST_INSTALL_DIR, 'arch' ); |
147 | # |
148 | # use constant TEST_INSTALL_EU_MM_FLAGS => |
149 | # ' INSTALLDIRS=site' . |
150 | # ' INSTALLSITELIB=' . TEST_INSTALL_DIR_LIB . |
151 | # ' INSTALLSITEARCH=' . TEST_INSTALL_DIR_ARCH . # .packlist |
152 | # ' INSTALLARCHLIB=' . TEST_INSTALL_DIR_ARCH . # perllocal.pod |
153 | # ' INSTALLSITEBIN=' . TEST_INSTALL_DIR_BIN . |
154 | # ' INSTALLSCRIPT=' . TEST_INSTALL_DIR_BIN . |
155 | # ' INSTALLSITEMAN1DIR=' . TEST_INSTALL_DIR_MAN1 . |
156 | # ' INSTALLSITEMAN3DIR=' . TEST_INSTALL_DIR_MAN3; |
157 | |
158 | |
159 | sub gimme_conf { |
160 | my $conf = CPANPLUS::Configure->new(); |
161 | $conf->set_conf( hosts => [ { |
162 | path => 'dummy-CPAN', |
163 | scheme => 'file', |
164 | } ], |
165 | ); |
166 | $conf->set_conf( base => 'dummy-cpanplus' ); |
167 | $conf->set_conf( dist_type => '' ); |
168 | $conf->set_conf( signature => 0 ); |
169 | |
170 | _clean_test_dir( [ |
171 | $conf->get_conf('base'), |
172 | TEST_CONF_MIRROR_DIR, |
173 | # TEST_INSTALL_DIR_LIB, |
174 | # TEST_INSTALL_DIR_BIN, |
175 | # TEST_INSTALL_DIR_MAN1, |
176 | # TEST_INSTALL_DIR_MAN3, |
177 | ], 1 ); |
178 | |
179 | return $conf; |
180 | }; |
181 | |
182 | { |
183 | my $fh; |
184 | my $file = ".".basename($0).".output"; |
185 | sub output_handle { |
186 | return $fh if $fh; |
187 | |
188 | $fh = FileHandle->new(">$file") |
189 | or warn "Could not open output file '$file': $!"; |
190 | |
191 | $fh->autoflush(1); |
192 | return $fh; |
193 | } |
194 | |
195 | sub output_file { return $file } |
196 | } |
197 | |
198 | |
199 | ### clean these files if we're under perl core |
200 | END { |
201 | if ( $ENV{PERL_CORE} ) { |
202 | close output_handle(); 1 while unlink output_file(); |
203 | |
204 | _clean_test_dir( [ |
205 | gimme_conf->get_conf('base'), |
206 | TEST_CONF_MIRROR_DIR, |
207 | # TEST_INSTALL_DIR_LIB, |
208 | # TEST_INSTALL_DIR_BIN, |
209 | # TEST_INSTALL_DIR_MAN1, |
210 | # TEST_INSTALL_DIR_MAN3, |
211 | ], 1 ); |
212 | } |
213 | } |
214 | |
215 | |
216 | |
217 | ### whenever we start a new script, we want to clean out our |
218 | ### old files from the test '.cpanplus' dir.. |
219 | sub _clean_test_dir { |
220 | my $dirs = shift || []; |
221 | my $verbose = shift || 0; |
222 | |
223 | for my $dir ( @$dirs ) { |
224 | |
225 | my $dh; |
226 | opendir $dh, $dir or die "Could not open basedir '$dir': $!"; |
227 | while( my $file = readdir $dh ) { |
228 | next if $file =~ /^\./; # skip dot files |
229 | |
230 | my $path = File::Spec->catfile( $dir, $file ); |
231 | |
232 | ### directory, rmtree it |
233 | if( -d $path ) { |
234 | print "Deleting directory '$path'\n" if $verbose; |
235 | eval { rmtree( $path ) }; |
236 | warn "Could not delete '$path' while cleaning up '$dir'" if $@; |
237 | |
238 | ### regular file |
239 | } else { |
240 | print "Deleting file '$path'\n" if $verbose; |
241 | 1 while unlink $path; |
242 | } |
243 | } |
244 | |
245 | close $dh; |
246 | } |
247 | |
248 | return 1; |
249 | } |
250 | 1; |