8 # Make sure none of our tests load the users ~/.modulebuildrc file
9 $ENV{MODULEBUILDRC} = 'NONE';
11 # In case the test wants to use Test::More or our other bundled
12 # modules, make sure they can be loaded. They'll still do "use
13 # Test::More" in the test script.
14 my $t_lib = File::Spec->catdir('t', 'bundled');
16 if (!$ENV{PERL_CORE}) {
17 push @INC, $t_lib; # Let user's installed version override
19 # We change directories, so expand @INC to absolute paths
21 @INC = (map(File::Spec->rel2abs($_), @INC), ".");
23 # we are in 't', go up a level so we don't create t/t/_tmp
24 chdir '..' or die "Couldn't chdir to ..";
26 push @INC, File::Spec->catdir(qw/lib Module Build/, $t_lib);
28 # make sure children get @INC pointing to uninstalled files
30 $ENV{PERL5LIB} = File::Spec->catdir(Cwd::cwd(), 'lib');
38 # We pass everything through to Test::More
39 use vars qw($VERSION @ISA @EXPORT %EXPORT_TAGS $TODO);
41 @ISA = qw(Test::More); # Test::More isa Exporter
42 @EXPORT = @Test::More::EXPORT;
43 %EXPORT_TAGS = %Test::More::EXPORT_TAGS;
45 # We have a few extra exports, but Test::More has a special import()
46 # that won't take extra additions.
47 my @extra_exports = qw(stdout_of stderr_of slurp find_in_path check_compiler have_module);
48 push @EXPORT, @extra_exports;
49 __PACKAGE__->export(scalar caller, @extra_exports);
53 my ($handle, $subr) = @_;
54 my $outfile = 'save_out';
57 open SAVEOUT, ">&" . fileno($handle) or die "Can't save output handle: $!";
58 open $handle, "> $outfile" or die "Can't create $outfile: $!";
61 open $handle, ">&SAVEOUT" or die "Can't restore output: $!";
63 my $ret = slurp($outfile);
64 1 while unlink $outfile;
68 sub stdout_of { save_handle(\*STDOUT, @_) }
69 sub stderr_of { save_handle(\*STDERR, @_) }
72 my $fh = IO::File->new($_[0]) or die "Can't open $_[0]: $!";
78 # Some extensions we should know about if we're looking for executables
80 if ($^O eq 'MSWin32') {
81 return split($Config{path_sep}, $ENV{PATHEXT} || '.com;.exe;.bat');
84 return qw(.exe .com .pl .cmd .bat .sh .ksh);
92 my @path = split $Config{path_sep}, $ENV{PATH};
93 my @exe_ext = exe_exts();
95 my $fullpath = File::Spec->catfile($_, $thing);
96 foreach my $ext ( '', @exe_ext ) {
97 return "$fullpath$ext" if -e "$fullpath$ext";
103 # returns ($have_c_compiler, $C_support_feature);
105 return (1,1) if $ENV{PERL_CORE};
107 local $SIG{__WARN__} = sub {};
109 my $mb = Module::Build->current;
113 stderr_of( sub {$have_c_compiler = $mb->have_c_compiler} );
115 return ($have_c_compiler, $mb->feature('C_support'));
120 return eval "use $module; 1";