Author: jkeenan
Date: Sat Jul 26 18:41:25 2008
New Revision: 29781
Modified:
branches/parallel/config/gen/platform.pm
branches/parallel/t/steps/gen_platform-01.t
Log:
Refactor some code from inside runstep() into _handle_asm() and add appropriate
tests.
Modified: branches/parallel/config/gen/platform.pm
==============================================================================
--- branches/parallel/config/gen/platform.pm (original)
+++ branches/parallel/config/gen/platform.pm Sat Jul 26 18:41:25 2008
@@ -52,12 +52,7 @@
# implementation files are merged into platform.c
_set_implementations($conf, $verbose, $platform, $generated, $coda);
- if ( $conf->data->get('platform_asm') ) {
- my $asm_file = "config/gen/platform/$platform/asm.s";
- if ( -e $asm_file ) {
- copy_if_diff( $asm_file, "src/platform_asm.s" );
- }
- }
+ _handle_asm($conf, $platform);
# interface is the same for all platforms
copy_if_diff( $self->{platform_interface},
@@ -167,22 +162,22 @@
# finally append generated
@headers = grep { /\.h$/ } split( m/,/, $generated );
- for (@headers) {
- if ( -e $_ ) {
+ for my $h (@headers) {
+ if ( -e $h ) {
local $/ = undef;
- print("\t$_\n") if $verbose;
- open my $IN_H, "<", "$_" or die "Can't open $_: $!";
+ print("\t$h\n") if $verbose;
+ open my $IN_H, "<", $h or die "Can't open $h: $!";
print {$PLATFORM_H} <<"END_HERE";
/*
-** $_
+** $h
*/
-#line 1 "$_"
+#line 1 "$h"
END_HERE
print {$PLATFORM_H} <$IN_H>, "\n\n";
close $IN_H;
}
else {
- warn("Header file '$_' listed in TEMP_generated but not found\n");
+ warn("Header file '$h' listed in TEMP_generated but not found\n");
}
}
@@ -258,16 +253,16 @@
END_HERE
- for (@impls) {
- my $impl_file = "config/gen/platform/generic/$_";
- if ( -e "config/gen/platform/$platform/$_" ) {
- $impl_file = "config/gen/platform/$platform/$_";
+ for my $im (@impls) {
+ my $impl_file = "config/gen/platform/generic/$im";
+ if ( -e "config/gen/platform/$platform/$im" ) {
+ $impl_file = "config/gen/platform/$platform/$im";
}
if ( -e $impl_file ) {
local $/ = undef;
print("\t$impl_file\n") if $verbose;
- open my $IN_C, "<", "$impl_file" or die "Can't open $impl_file:
$!";
+ open my $IN_C, "<", $impl_file or die "Can't open $impl_file: $!";
# slurp in the C file
my $in_c = <$IN_C>;
@@ -288,16 +283,16 @@
# append generated c files
@impls = grep { /\.c$/ } split( m/,/, $generated );
- for (@impls) {
- if ( -e $_ ) {
+ for my $im (@impls) {
+ if ( -e $im ) {
local $/ = undef;
- print("\t$_\n") if $verbose;
- open my $IN_C, "<", "$_" or die "Can't open $_: $!";
+ print("\t$im\n") if $verbose;
+ open my $IN_C, "<", $im or die "Can't open $im: $!";
print {$PLATFORM_C} <<"END_HERE";
/*
-** $_:
+** $im:
*/
-#line 1 "$_"
+#line 1 "$im"
END_HERE
print {$PLATFORM_C} <$IN_C>, "\n\n";
close $IN_C;
@@ -314,6 +309,16 @@
return 1;
}
+sub _handle_asm {
+ my ($conf, $platform) = @_;
+ if ( $conf->data->get('platform_asm') ) {
+ my $asm_file = "config/gen/platform/$platform/asm.s";
+ if ( -e $asm_file ) {
+ copy_if_diff( $asm_file, "src/platform_asm.s" );
+ }
+ }
+}
+
1;
# Local Variables:
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 18:41:25 2008
@@ -5,8 +5,13 @@
use strict;
use warnings;
-use Test::More tests => 16;
+use Test::More qw(no_plan); # tests => 16;
use Carp;
+use Cwd;
+use File::Copy;
+use File::Path qw( mkpath );
+use File::Temp qw( tempdir );
+use File::Spec;
use lib qw( lib );
use_ok('config::gen::platform');
use Parrot::Configure;
@@ -15,6 +20,7 @@
test_step_thru_runstep
test_step_constructor_and_description
);
+use Parrot::Configure::Utils qw( _slurp );
use IO::CaptureOutput qw( capture );
my $args = process_options(
@@ -104,6 +110,57 @@
# re-set to original values
$conf->data->set( TEMP_generated => $TEMP_generated_orig );
+my $platform_asm_orig = $conf->data->get('platform_asm');
+my $cwd = cwd();
+{
+ my $tdir = tempdir( CLEANUP => 1 );
+ chdir $tdir or croak "Unable to change to temporary directory";
+ $conf->data->set( platform_asm => 1 );
+ my $platform = 'aix';
+ mkpath( 'src', 0, 755 ) or croak "Unable to make testing directory";
+ my $asmfile = File::Spec->catfile( 'src', 'platform_asm.s' );
+ 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);
+ 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";
+}
+
+{
+ my $tdir = tempdir( CLEANUP => 1 );
+ chdir $tdir or croak "Unable to change to temporary directory";
+ $conf->data->set( platform_asm => 1 );
+ my $platform = 'aix';
+
+ mkpath( 'src', 0, 755 ) or croak "Unable to make testing directory";
+
+ my $asmfile = File::Spec->catfile( 'src', 'platform_asm.s' );
+ 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";
+
+ my $path = File::Spec->catdir( 'config', 'gen', 'platform', $platform );
+ mkpath( $path, 0, 755 ) or croak "Unable to make testing directory";
+
+ my $configfile = File::Spec->catfile( $path, 'asm.s' );
+ open my $FH2, '>', $configfile or croak "Unable to open handle for
writing";
+ print $FH2 "Goodbye world\n";
+ close $FH2 or croak "Unable to close handle after writing";
+
+ gen::platform::_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 );
+
pass("Completed all tests in $0");
################### DOCUMENTATION ###################