12 # Setup the code to clean out %ENV
14 # Environment variables which might effect our testing
15 my @delete_env_keys = qw(
28 # Remember the ENV values because on VMS %ENV is global
29 # to the user, not the process.
33 for my $key (@delete_env_keys) {
34 if( exists $ENV{$key} ) {
35 $restore_env_keys{$key} = delete $ENV{$key};
44 while( my($key, $val) = each %restore_env_keys ) {
54 # In case the test wants to use our other bundled
55 # modules, make sure they can be loaded.
56 my $t_lib = File::Spec->catdir('t', 'bundled');
57 push @INC, $t_lib; # Let user's installed version override
59 if ($ENV{PERL_CORE}) {
60 # We change directories, so expand @INC and $^X to absolute paths
62 @INC = (map(File::Spec->rel2abs($_), @INC), ".");
63 $^X = File::Spec->rel2abs($^X);
72 # We pass everything through to Test::More
73 use vars qw($VERSION @ISA @EXPORT %EXPORT_TAGS $TODO);
75 @ISA = qw(Test::More); # Test::More isa Exporter
76 @EXPORT = @Test::More::EXPORT;
77 %EXPORT_TAGS = %Test::More::EXPORT_TAGS;
79 # We have a few extra exports, but Test::More has a special import()
80 # that won't take extra additions.
81 my @extra_exports = qw(
92 push @EXPORT, @extra_exports;
93 __PACKAGE__->export(scalar caller, @extra_exports);
94 # XXX ^-- that should really happen in import()
97 ########################################################################
99 # always return to the current directory
101 my $cwd = File::Spec->rel2abs(Cwd::cwd);
103 sub original_cwd { return $cwd }
106 # Go back to where you came from!
107 chdir $cwd or die "Couldn't chdir to $cwd";
110 ########################################################################
112 { # backwards compatible temp filename recipe adapted from perlfaq
114 my $tmp_base_name = sprintf("MB-%d-%d", $$, time());
116 sprintf("%s-%04d", $tmp_base_name, ++$tmp_count)
119 ########################################################################
121 # Setup a temp directory
123 my ($self, @args) = @_;
124 my $dir = $ENV{PERL_CORE} ? MBTest->original_cwd : File::Spec->tmpdir;
125 return File::Temp::tempdir('MB-XXXXXXXX', CLEANUP => 1, DIR => $dir, @args);
129 $ENV{HOME} = tmpdir; # don't want .modulebuildrc or other things interfering
133 my ($handle, $subr) = @_;
134 my $outfile = File::Spec->catfile(File::Spec->tmpdir, temp_file_name());
137 open SAVEOUT, ">&" . fileno($handle)
138 or die "Can't save output handle: $!";
139 open $handle, "> $outfile" or die "Can't create $outfile: $!";
142 open $handle, ">&SAVEOUT" or die "Can't restore output: $!";
144 my $ret = slurp($outfile);
145 1 while unlink $outfile;
149 sub stdout_of { save_handle(\*STDOUT, @_) }
150 sub stderr_of { save_handle(\*STDERR, @_) }
151 sub stdout_stderr_of {
153 my ($stdout, $stderr);
154 $stdout = stdout_of ( sub {
155 $stderr = stderr_of( $subr )
157 return wantarray ? ($stdout, $stderr) : $stdout . $stderr;
161 my $fh = IO::File->new($_[0]) or die "Can't open $_[0]: $!";
166 # Some extensions we should know about if we're looking for executables
169 if ($^O eq 'MSWin32') {
170 return split($Config{path_sep}, $ENV{PATHEXT} || '.com;.exe;.bat');
173 return qw(.exe .com .pl .cmd .bat .sh .ksh);
181 my @exe_ext = exe_exts();
182 if ( File::Spec->file_name_is_absolute( $thing ) ) {
183 foreach my $ext ( '', @exe_ext ) {
184 return "$thing$ext" if -e "$thing$ext";
188 my @path = split $Config{path_sep}, $ENV{PATH};
190 my $fullpath = File::Spec->catfile($_, $thing);
191 foreach my $ext ( '', @exe_ext ) {
192 return "$fullpath$ext" if -e "$fullpath$ext";
200 return (1,1) if $ENV{PERL_CORE};
202 local $SIG{__WARN__} = sub {};
204 blib_load('Module::Build');
205 my $mb = Module::Build->current;
209 stderr_of( sub {$have_c_compiler = $mb->have_c_compiler} );
211 # check noexec tmpdir
213 if ( $have_c_compiler ) {
214 my $dir = MBTest->tmpdir;
215 my $c_file = File::Spec->catfile($dir,'test.c');
216 open my $fh, ">", $c_file;
217 print {$fh} "int main() { return 0; }\n";
219 my $exe = $mb->cbuilder->link_executable(
220 objects => $mb->cbuilder->compile( source => $c_file )
222 $tmp_exec = 0 == system( $exe );
224 return ($have_c_compiler, $tmp_exec);
229 return eval "require $module; 1";
233 # Load the given module and ensure it came from blib/, not the larger system
235 have_module($mod) or die "Error loading $mod\: $@\n";
237 (my $path = $mod) =~ s{::}{/}g;
239 my ($pkg, $file, $line) = caller;
240 unless($ENV{PERL_CORE}) {
241 unless($INC{$path} =~ m/\bblib\b/) {
242 (my $load_from = $INC{$path}) =~ s{$path$}{};
243 die "$mod loaded from '$load_from'\nIt should have been loaded from blib. \@INC contains:\n ",
244 join("\n ", @INC) . "\nFatal error occured in blib_load() at $file, line $line.\n";
250 my ($sub, $timeout) = @_;
256 local $SIG{ALRM} = sub { $saw_alarm++; die "alarm\n"; }; # NB: \n required
262 die unless $@ eq "alarm\n"; # propagate unexpected errors
269 stdout_stderr_of( sub {
270 $timed_out = timed_out( sub {
271 ExtUtils::Installed->new(extra_libs => [@INC])
280 # vim:ts=2:sw=2:et:sta