Author: dagolden
Date: Sat Jun 27 13:56:35 2009
New Revision: 12934
Added:
ExtUtils-CBuilder/trunk/t/00-have-compiler.t (contents, props changed)
Modified:
ExtUtils-CBuilder/trunk/lib/ExtUtils/CBuilder/Base.pm
ExtUtils-CBuilder/trunk/t/01-basic.t
ExtUtils-CBuilder/trunk/t/02-link.t
Log:
added have_compiler testing/skips; switched to Test::More
Modified: ExtUtils-CBuilder/trunk/lib/ExtUtils/CBuilder/Base.pm
==============================================================================
--- ExtUtils-CBuilder/trunk/lib/ExtUtils/CBuilder/Base.pm (original)
+++ ExtUtils-CBuilder/trunk/lib/ExtUtils/CBuilder/Base.pm Sat Jun 27 13:56:35 2009
@@ -116,7 +116,7 @@
sub have_compiler {
my ($self) = @_;
return $self->{have_compiler} if defined $self->{have_compiler};
-
+
my $tmpfile = File::Spec->catfile(File::Spec->tmpdir, 'compilet.c');
{
my $FH = IO::File->new("> $tmpfile") or die "Can't create $tmpfile: $!";
@@ -125,16 +125,17 @@
my ($obj_file, @lib_files);
eval {
+ local $^W = 0;
$obj_file = $self->compile(source => $tmpfile);
@lib_files = $self->link(objects => $obj_file, module_name => 'compilet');
};
- warn $@ if $@;
- my $result = $self->{have_compiler} = $@ ? 0 : 1;
-
+ my $result = $@ ? 0 : 1;
+
foreach (grep defined, $tmpfile, $obj_file, @lib_files) {
1 while unlink;
}
- return $result;
+
+ return $self->{have_compiler} = $result;
}
sub lib_file {
Added: ExtUtils-CBuilder/trunk/t/00-have-compiler.t
==============================================================================
--- (empty file)
+++ ExtUtils-CBuilder/trunk/t/00-have-compiler.t Sat Jun 27 13:56:35 2009
@@ -0,0 +1,41 @@
+#! perl -w
+
+BEGIN {
+ if ($ENV{PERL_CORE}) {
+ chdir 't' if -d 't';
+ chdir '../lib/ExtUtils/CBuilder'
+ or die "Can't chdir to lib/ExtUtils/CBuilder: $!";
+ @INC = qw(../..);
+ }
+}
+
+use strict;
+use Test::More;
+use File::Spec;
+BEGIN {
+ if ($^O eq 'VMS') {
+ # So we can get the return value of system()
+ require vmsish;
+ import vmsish;
+ }
+}
+
+plan tests => 4;
+
+require_ok "ExtUtils::CBuilder";
+
+my $b = eval { ExtUtils::CBuilder->new(quiet => 1) };
+ok( $b, "got CBuilder object" ) or diag $@;
+
+# test missing compiler
+$b->{config}{cc} = 'djaadjfkadjkfajdf';
+$b->{config}{ld} = 'djaadjfkadjkfajdf';
+is( $b->have_compiler, 0, "have_compiler: fake missing cc" );
+
+# test found compiler
+$b->{have_compiler} = undef;
+$b->{config}{cc} = "$^X -e1 --";
+$b->{config}{ld} = "$^X -e1 --";
+is( $b->have_compiler, 1, "have_compiler: fake present cc" );
+
+
Modified: ExtUtils-CBuilder/trunk/t/01-basic.t
==============================================================================
--- ExtUtils-CBuilder/trunk/t/01-basic.t (original)
+++ ExtUtils-CBuilder/trunk/t/01-basic.t Sat Jun 27 13:56:35 2009
@@ -10,42 +10,56 @@
}
use strict;
-use Test;
-BEGIN { plan tests => 11 }
-
+use Test::More;
+BEGIN {
+ if ($^O eq 'VMS') {
+ # So we can get the return value of system()
+ require vmsish;
+ import vmsish;
+ }
+}
use ExtUtils::CBuilder;
use File::Spec;
-ok 1;
# TEST doesn't like extraneous output
my $quiet = $ENV{PERL_CORE} && !$ENV{HARNESS_ACTIVE};
+my ($source_file, $object_file, $lib_file);
my $b = ExtUtils::CBuilder->new(quiet => $quiet);
-ok $b;
-ok $b->have_compiler;
+# test plan
+if ( ! $b->have_compiler ) {
+ plan skip_all => "no compiler available for testing";
+}
+else {
+ plan tests => 10;
+}
+
+ok $b, "created EU::CB object";
-my $source_file = File::Spec->catfile('t', 'compilet.c');
+ok $b->have_compiler, "have_compiler";
+
+$source_file = File::Spec->catfile('t', 'compilet.c');
{
local *FH;
open FH, "> $source_file" or die "Can't create $source_file: $!";
print FH "int boot_compilet(void) { return 1; }\n";
close FH;
}
-ok -e $source_file;
+ok -e $source_file, "source file '$source_file' created";
-my $object_file = $b->object_file($source_file);
+$object_file = $b->object_file($source_file);
ok 1;
-ok $object_file, $b->compile(source => $source_file);
+is $object_file, $b->compile(source => $source_file);
-my $lib_file = $b->lib_file($object_file);
+$lib_file = $b->lib_file($object_file);
ok 1;
my ($lib, @temps) = $b->link(objects => $object_file,
module_name => 'compilet');
$lib =~ tr/"'//d;
-ok $lib_file, $lib;
+is $lib_file, $lib;
for ($source_file, $object_file, $lib_file) {
tr/"'//d;
@@ -54,15 +68,9 @@
my @words = $b->split_like_shell(' foo bar');
-skip(
- $^O =~ m/MSWin/ ? "Skip under MSWindows" : 0, # whether to skip
- @words, 2
- );
-skip(
- $^O =~ m/MSWin/ ? "Skip under MSWindows" : 0, # whether to skip
- $words[0], 'foo'
-);
-skip(
- $^O =~ m/MSWin/ ? "Skip under MSWindows" : 0, # whether to skip
- $words[1], 'bar'
-);
+SKIP: {
+ skip "MSWindows", 3 if $^O =~ m/MSWin/;
+ is( @words, 2 );
+ is( $words[0], 'foo' );
+ is( $words[1], 'bar' );
+}
Modified: ExtUtils-CBuilder/trunk/t/02-link.t
==============================================================================
--- ExtUtils-CBuilder/trunk/t/02-link.t (original)
+++ ExtUtils-CBuilder/trunk/t/02-link.t Sat Jun 27 13:56:35 2009
@@ -10,60 +10,74 @@
}
use strict;
-use Test;
+use Test::More;
BEGIN {
- if ($^O eq 'MSWin32') {
- print "1..0 # Skipped: link_executable() is not implemented yet on Win32\n";
- exit;
- }
if ($^O eq 'VMS') {
# So we can get the return value of system()
require vmsish;
import vmsish;
}
- plan tests => 5;
}
-
use ExtUtils::CBuilder;
use File::Spec;
# TEST doesn't like extraneous output
my $quiet = $ENV{PERL_CORE} && !$ENV{HARNESS_ACTIVE};
+my ($source_file, $object_file, $exe_file);
my $b = ExtUtils::CBuilder->new(quiet => $quiet);
-ok $b;
-my $source_file = File::Spec->catfile('t', 'compilet.c');
+# test plan
+if ($^O eq 'MSWin32') {
+ plan skip_all => "link_executable() is not implemented yet on Win32";
+}
+elsif ( ! $b->have_compiler ) {
+ plan skip_all => "no compiler available for testing";
+}
+else {
+ plan tests => 7;
+}
+
+ok $b, "created EU::CB object";
+
+$source_file = File::Spec->catfile('t', 'compilet.c');
{
local *FH;
open FH, "> $source_file" or die "Can't create $source_file: $!";
print FH "int main(void) { return 11; }\n";
close FH;
}
-ok -e $source_file;
+ok -e $source_file, "generated '$source_file'";
# Compile
-my $object_file;
-ok $object_file = $b->compile(source => $source_file);
+eval { $object_file = $b->compile(source => $source_file) };
+is $@, q{}, "no exception from compilation";
+ok -e $object_file, "found object file";
# Link
-my ($exe_file, @temps);
-($exe_file, @temps) = $b->link_executable(objects => $object_file);
-ok -e $exe_file;
-
-if ($^O eq 'os2') { # Analogue of LDLOADPATH...
- # Actually, not needed now, since we do not link with the generated DLL
- my $old = OS2::extLibpath(); # [builtin function]
- $old = ";$old" if defined $old and length $old;
- # To pass the sanity check, components must have backslashes...
- OS2::extLibpath_set(".\\$old");
-}
-
-# Try the executable
-my $ec = my_system($exe_file);
-ok $ec, 11
- or print( $? == -1 ? "# Could not run '$exe_file'\n"
- : "# Unexpected exit code '$ec'\n");
+SKIP: {
+ skip "error compiling source", 3
+ unless -e $object_file;
+
+ my @temps;
+ eval { ($exe_file, @temps) = $b->link_executable(objects => $object_file) };
+ is $@, q{}, "no exception from linking";
+ ok -e $exe_file, "found executable file";
+
+ if ($^O eq 'os2') { # Analogue of LDLOADPATH...
+ # Actually, not needed now, since we do not link with the generated DLL
+ my $old = OS2::extLibpath(); # [builtin function]
+ $old = ";$old" if defined $old and length $old;
+ # To pass the sanity check, components must have backslashes...
+ OS2::extLibpath_set(".\\$old");
+ }
+
+ # Try the executable
+ my $ec = my_system($exe_file);
+ is $ec, 11, "got expected exit code from executable"
+ or print( $? == -1 ? "# Could not run '$exe_file'\n"
+ : "# Unexpected exit code '$ec'\n");
+}
# Clean up
for ($source_file, $object_file, $exe_file) {
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.