Author: jkeenan
Date: Sat Jul 26 19:27:14 2008
New Revision: 29783
Modified:
branches/parallel/config/gen/platform.pm
branches/parallel/t/steps/gen_platform-01.t
Log:
[configure] Make all functions into methods of the step class. This done
mainly to make content of coda universally available, so it is moved into
_init(). Refactor code from inside runstep() to _handle_begin_c() to increase
testability of previously uncovered branch. Add appropriate tests. Add
inline comments in test file.
Modified: branches/parallel/config/gen/platform.pm
==============================================================================
--- branches/parallel/config/gen/platform.pm (original)
+++ branches/parallel/config/gen/platform.pm Sat Jul 26 19:27:14 2008
@@ -27,6 +27,14 @@
$data{description} = q{Moving platform files into place};
$data{result} = q{};
$data{platform_interface} = q{config/gen/platform/platform_interface.h};
+ $data{coda} = <<'CODA';
+/*
+ * Local variables:
+ * c-file-style: "parrot"
+ * End:
+ * vim: expandtab shiftwidth=4:
+ */
+CODA
return \%data;
}
@@ -34,25 +42,17 @@
my ( $self, $conf ) = @_;
my $verbose = $conf->options->get('verbose');
- my $platform = _get_platform( $conf, $verbose );
- my $generated = _get_generated($conf, $verbose);
+ my $platform = $self->_get_platform( $conf, $verbose );
+ my $generated = $self->_get_generated($conf, $verbose);
- my $coda = <<'CODA';
-/*
- * Local variables:
- * c-file-style: "parrot"
- * End:
- * vim: expandtab shiftwidth=4:
- */
-CODA
# headers are merged into platform.h
- _set_headers($conf, $verbose, $platform, $generated, $coda);
+ $self->_set_headers($conf, $verbose, $platform, $generated);
# implementation files are merged into platform.c
- _set_implementations($conf, $verbose, $platform, $generated, $coda);
+ $self->_set_implementations($conf, $verbose, $platform, $generated);
- _handle_asm($conf, $platform);
+ $self->_handle_asm($conf, $platform);
# interface is the same for all platforms
copy_if_diff( $self->{platform_interface},
@@ -62,6 +62,7 @@
}
sub _get_platform {
+ my $self = shift;
my ($conf, $verbose) = @_;
my $platform = lc ( $conf->data->get_p5('OSNAME') );
@@ -81,6 +82,7 @@
}
sub _get_generated {
+ my $self = shift;
my ($conf, $verbose) = @_;
my $generated = $conf->data->get('TEMP_generated');
$generated = '' unless defined $generated;
@@ -89,7 +91,8 @@
}
sub _set_headers {
- my ($conf, $verbose, $platform, $generated, $coda) = @_;
+ my $self = shift;
+ my ($conf, $verbose, $platform, $generated) = @_;
my @headers = qw/
io.h
math.h
@@ -141,7 +144,7 @@
my $in_h = <$IN_H>;
# remove the (in this case) superfluous coda
- $in_h =~ s{\Q$coda\E\n*\z}{}xgs;
+ $in_h =~ s{\Q$self->{coda}\E\n*\z}{}xgs;
print {$PLATFORM_H} <<"END_HERE";
/*
@@ -185,7 +188,7 @@
print $PLATFORM_H <<"END_HERE";
#endif /* PARROT_PLATFORM_H_GUARD */
-$coda
+$self->{coda}
END_HERE
close $PLATFORM_H;
@@ -193,7 +196,8 @@
}
sub _set_implementations {
- my ($conf, $verbose, $platform, $generated, $coda) = @_;
+ my $self = shift;
+ my ($conf, $verbose, $platform, $generated) = @_;
my @impls = qw/
time.c
env.c
@@ -227,25 +231,7 @@
END_HERE
# We need to put things from begin.c before the parrot.h include.
- if ( -e "config/gen/platform/$platform/begin.c" ) {
- local $/ = undef;
- open my $IN_C, "<", "config/gen/platform/$platform/begin.c" or die
"Can't open begin.c: $!";
-
- # slurp in the C file
- my $in_c = <$IN_C>;
-
- # remove the (in this case) superfluous coda
- $in_c =~ s{\Q$coda\E\n*\z}{}xgs;
-
- print {$PLATFORM_C} <<"END_HERE";
-/*
-** begin.c
-*/
-#line 1 "config/gen/platform/$platform/begin.c"
-END_HERE
- print {$PLATFORM_C} $in_c, "\n\n";
- close $IN_C;
- }
+ $self->_handle_begin_c($platform, $PLATFORM_C);
# Copy the rest.
print {$PLATFORM_C} <<'END_HERE';
@@ -268,7 +254,7 @@
my $in_c = <$IN_C>;
# remove the (in this case) superfluous coda
- $in_c =~ s{\Q$coda\E\n*\z}{}xgs;
+ $in_c =~ s{\Q$self->{coda}\E\n*\z}{}xgs;
print {$PLATFORM_C} <<"END_HERE";
/*
@@ -302,14 +288,39 @@
# append the C code coda to the generated file
print {$PLATFORM_C} <<"END_HERE";
-$coda
+$self->{coda}
END_HERE
close $PLATFORM_C;
return 1;
}
+sub _handle_begin_c {
+ my $self = shift;
+ my ($platform, $PLATFORM_C) = @_;
+ if ( -e "config/gen/platform/$platform/begin.c" ) {
+ local $/ = undef;
+ open my $IN_C, "<", "config/gen/platform/$platform/begin.c" or die
"Can't open begin.c: $!";
+
+ # slurp in the C file
+ my $in_c = <$IN_C>;
+
+ # remove the (in this case) superfluous coda
+ $in_c =~ s{\Q$self->{coda}\E\n*\z}{}xgs;
+
+ print {$PLATFORM_C} <<"END_HERE";
+/*
+** begin.c
+*/
+#line 1 "config/gen/platform/$platform/begin.c"
+END_HERE
+ print {$PLATFORM_C} $in_c, "\n\n";
+ close $IN_C;
+ }
+}
+
sub _handle_asm {
+ my $self = shift;
my ($conf, $platform) = @_;
if ( $conf->data->get('platform_asm') ) {
my $asm_file = "config/gen/platform/$platform/asm.s";
Modified: branches/parallel/t/steps/gen_platform-01.t
==============================================================================
--- branches/parallel/t/steps/gen_platform-01.t (original)
+++ branches/parallel/t/steps/gen_platform-01.t Sat Jul 26 19:27:14 2008
@@ -5,7 +5,7 @@
use strict;
use warnings;
-use Test::More qw(no_plan); # tests => 16;
+use Test::More tests => 20;
use Carp;
use Cwd;
use File::Copy;
@@ -44,21 +44,23 @@
$conf->data->set_p5( archname => 'foo-bar' );
my $verbose = 0;
+########## _gen_platform() ##########
+
$conf->options->set( miniparrot => 1 );
-is( gen::platform::_get_platform( $conf, $verbose ), q{ansi},
+is( $step->_get_platform( $conf, $verbose ), q{ansi},
"Got expected platform for miniparrot");
$conf->options->set( miniparrot => undef );
$conf->data->set_p5( OSNAME => 'msys' );
-is( gen::platform::_get_platform( $conf, $verbose ), q{win32},
+is( $step->_get_platform( $conf, $verbose ), q{win32},
"Got expected platform for msys");
$conf->data->set_p5( OSNAME => 'mingw' );
-is( gen::platform::_get_platform( $conf, $verbose ), q{win32},
+is( $step->_get_platform( $conf, $verbose ), q{win32},
"Got expected platform for mingw");
$conf->data->set_p5( OSNAME => 'MSWin32' );
-is( gen::platform::_get_platform( $conf, $verbose ), q{win32},
+is( $step->_get_platform( $conf, $verbose ), q{win32},
"Got expected platform for MSWin32");
# re-set to original values
@@ -66,7 +68,7 @@
$conf->data->set_p5( archname => $archname_orig );
$conf->data->set_p5( archname => 'ia64-bar' );
-is( gen::platform::_get_platform( $conf, $verbose ), q{ia64},
+is( $step->_get_platform( $conf, $verbose ), q{ia64},
"Got expected platform for ia64");
$conf->data->set_p5( archname => 'foo-bar' );
@@ -76,7 +78,7 @@
my ($stdout, $stderr, $rv);
my $expected = q{generic};
capture(
- sub { $rv = gen::platform::_get_platform( $conf, $verbose ) },
+ sub { $rv = $step->_get_platform( $conf, $verbose ) },
\$stdout,
\$stderr,
);
@@ -88,6 +90,8 @@
$conf->data->set_p5( archname => $archname_orig );
$conf->data->set_p5( OSNAME => $platform_orig );
+########## _gen_generated() ##########
+
my $TEMP_generated_orig = $conf->data->get('TEMP_generated');
{
$verbose = 1;
@@ -95,7 +99,7 @@
my $expected = q{foo};
$conf->data->set( TEMP_generated => $expected );
capture(
- sub { $rv = gen::platform::_get_generated( $conf, $verbose ) },
+ sub { $rv = $step->_get_generated( $conf, $verbose ) },
\$stdout,
\$stderr,
);
@@ -104,12 +108,14 @@
}
$conf->data->set( TEMP_generated => undef );
$verbose = 0;
-is( gen::platform::_get_generated( $conf, $verbose ), q{},
+is( $step->_get_generated( $conf, $verbose ), q{},
"Got expected generated");
# re-set to original values
$conf->data->set( TEMP_generated => $TEMP_generated_orig );
+########## _handle_asm() ##########
+
my $platform_asm_orig = $conf->data->get('platform_asm');
my $cwd = cwd();
{
@@ -122,12 +128,14 @@
open my $FH, '>', $asmfile or croak "Unable to open handle for writing";
print $FH "Hello asm\n";
close $FH or croak "Unable to close handle after writing";
- gen::platform::_handle_asm($conf, $platform);
+ $step->_handle_asm($conf, $platform);
my $text = _slurp( $asmfile );
like($text, qr/Hello asm/s, "File unchanged, as expected");
chdir $cwd or croak "Unable to change back to starting directory";
}
+# re-set to original values
+$conf->data->set( platform_asm => $platform_asm_orig );
{
my $tdir = tempdir( CLEANUP => 1 );
@@ -150,17 +158,43 @@
print $FH2 "Goodbye world\n";
close $FH2 or croak "Unable to close handle after writing";
- gen::platform::_handle_asm($conf, $platform);
+ $step->_handle_asm($conf, $platform);
my $text = _slurp( $asmfile );
like($text, qr/Goodbye world/s, "File changed, as expected");
chdir $cwd or croak "Unable to change back to starting directory";
}
-
# re-set to original values
$conf->data->set( platform_asm => $platform_asm_orig );
+########## _handle_begin_c() ##########
+{
+ my $tdir = tempdir( CLEANUP => 1 );
+ chdir $tdir or croak "Unable to change to temporary directory";
+ my $platform = 'darwin';
+
+ my $path = File::Spec->catdir( 'config', 'gen', 'platform', $platform );
+ mkpath( $path, 0, 755 ) or croak "Unable to make testing directory";
+ copy qq{$cwd/config/gen/platform/$platform/begin.c},
+ qq{$path/begin.c}
+ or croak "Unable to copy file for testing";
+
+ mkpath( 'src', 0, 755 ) or croak "Unable to make testing directory";
+ my $plat_c = q{src/platform.c};
+ open my $PLATFORM_C, '>', $plat_c
+ or croak "Unable to open handle for writing";
+ $step->_handle_begin_c($platform, $PLATFORM_C);
+ close $PLATFORM_C or croak "Unable to close handle after writing";
+
+ my $text = _slurp( $plat_c );
+ like($text, qr/#undef environ.*#undef bool/s,
+ "Got expected text in header file");
+ unlike($text, qr/Local variables/s, "Coda stripped, as desired");
+
+ chdir $cwd or croak "Unable to change back to starting directory";
+}
+
pass("Completed all tests in $0");
################### DOCUMENTATION ###################