9 # Make sure none of our tests load the users ~/.modulebuildrc file
10 $ENV{MODULEBUILDRC} = 'NONE';
12 # In case the test wants to use Test::More or our other bundled
13 # modules, make sure they can be loaded. They'll still do "use
14 # Test::More" in the test script.
15 my $t_lib = File::Spec->catdir('t', 'bundled');
17 unless ($ENV{PERL_CORE}) {
18 push @INC, $t_lib; # Let user's installed version override
20 # We change directories, so expand @INC to absolute paths
22 @INC = (map(File::Spec->rel2abs($_), @INC), ".");
24 # we are in 't', go up a level so we don't create t/t/_tmp
25 chdir '..' or die "Couldn't chdir to ..";
27 push @INC, File::Spec->catdir(qw/lib Module Build/, $t_lib);
29 # make sure children get @INC pointing to uninstalled files
31 $ENV{PERL5LIB} = File::Spec->catdir(Cwd::cwd(), 'lib');
40 # We pass everything through to Test::More
41 use vars qw($VERSION @ISA @EXPORT %EXPORT_TAGS $TODO);
43 @ISA = qw(Test::More); # Test::More isa Exporter
44 @EXPORT = @Test::More::EXPORT;
45 %EXPORT_TAGS = %Test::More::EXPORT_TAGS;
47 # We have a few extra exports, but Test::More has a special import()
48 # that won't take extra additions.
49 my @extra_exports = qw(
58 push @EXPORT, @extra_exports;
59 __PACKAGE__->export(scalar caller, @extra_exports);
60 # XXX ^-- that should really happen in import()
61 ########################################################################
63 { # Setup a temp directory if it doesn't exist
65 my $tmp = File::Spec->catdir( $cwd, 't', '_tmp.' . $$);
66 mkdir $tmp, 0777 unless -d $tmp;
71 File::Path::rmtree($tmp) or warn "cannot clean dir '$tmp'";
75 ########################################################################
77 { # backwards compatible temp filename recipe adapted from perlfaq
79 my $tmp_base_name = sprintf("%d-%d", $$, time());
81 sprintf("%s-%04d", $tmp_base_name, ++$tmp_count)
84 ########################################################################
87 my ($handle, $subr) = @_;
88 my $outfile = temp_file_name();
91 open SAVEOUT, ">&" . fileno($handle)
92 or die "Can't save output handle: $!";
93 open $handle, "> $outfile" or die "Can't create $outfile: $!";
96 open $handle, ">&SAVEOUT" or die "Can't restore output: $!";
98 my $ret = slurp($outfile);
99 1 while unlink $outfile;
103 sub stdout_of { save_handle(\*STDOUT, @_) }
104 sub stderr_of { save_handle(\*STDERR, @_) }
105 sub stdout_stderr_of {
107 my ($stdout, $stderr);
108 $stdout = stdout_of ( sub {
109 $stderr = stderr_of( $subr )
111 return ($stdout, $stderr);
115 my $fh = IO::File->new($_[0]) or die "Can't open $_[0]: $!";
120 # Some extensions we should know about if we're looking for executables
123 if ($^O eq 'MSWin32') {
124 return split($Config{path_sep}, $ENV{PATHEXT} || '.com;.exe;.bat');
127 return qw(.exe .com .pl .cmd .bat .sh .ksh);
135 my @path = split $Config{path_sep}, $ENV{PATH};
136 my @exe_ext = exe_exts();
138 my $fullpath = File::Spec->catfile($_, $thing);
139 foreach my $ext ( '', @exe_ext ) {
140 return "$fullpath$ext" if -e "$fullpath$ext";
146 # returns ($have_c_compiler, $C_support_feature);
148 return (1,1) if $ENV{PERL_CORE};
150 local $SIG{__WARN__} = sub {};
152 my $mb = Module::Build->current;
156 stderr_of( sub {$have_c_compiler = $mb->have_c_compiler} );
158 return ($have_c_compiler, $mb->feature('C_support'));
163 return eval "use $module; 1";
167 # vim:ts=2:sw=2:et:sta