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