Author: jkeenan
Date: Tue Jul 22 19:03:35 2008
New Revision: 29689

Modified:
   branches/parallel/config/gen/languages.pm
   branches/parallel/config/gen/makefiles.pm
   branches/parallel/config/gen/parrot_include.pm
   branches/parallel/t/steps/gen_call_list-01.t
   branches/parallel/t/steps/gen_languages-01.t
   branches/parallel/t/steps/gen_makefiles-01.t
   branches/parallel/t/steps/gen_parrot_include-01.t

Log:
Refactor configuration step classes to move hard-coded lists of required files
and similar data to the step object's data structure.  Write basic tests of
step classes, e.g., can we locate the prerequisite files and directories.


Modified: branches/parallel/config/gen/languages.pm
==============================================================================
--- branches/parallel/config/gen/languages.pm   (original)
+++ branches/parallel/config/gen/languages.pm   Tue Jul 22 19:03:35 2008
@@ -33,20 +33,10 @@
 
 sub _init {
     my $self = shift;
-
-    return
-        { description => q{Configuring languages},
-          result      => q{},
-        };
-}
-
-sub runstep {
-    my ( $self, $conf ) = @_;
-
-    $conf->genfile('config/gen/makefiles/languages.in' => 'languages/Makefile' 
);
-
-    my $languages = $conf->options->get('languages');
-    $languages = qq{
+    my %data;
+    $data{description} = q{Configuring languages};
+    $data{result} = q{};
+    $data{default_languages} = qq{
         APL abc
         befunge bf
         cardinal chitchat cola c99
@@ -64,7 +54,18 @@
         unlambda urm
         WMLScript
         Zcode
-    } unless defined $languages;
+    };
+    $data{languages_source} = q{config/gen/makefiles/languages.in};
+    return \%data;
+}
+
+sub runstep {
+    my ( $self, $conf ) = @_;
+
+    $conf->genfile( $self->{languages_source} => 'languages/Makefile' );
+
+    my $languages = $conf->options->get('languages');
+    $languages = $self->{default_languages} unless defined $languages;
 
     foreach my $language ( split ' ', $languages ) {        # split ' ' splits 
on all whitespace
         my $langdir = "languages/$language";

Modified: branches/parallel/config/gen/makefiles.pm
==============================================================================
--- branches/parallel/config/gen/makefiles.pm   (original)
+++ branches/parallel/config/gen/makefiles.pm   Tue Jul 22 19:03:35 2008
@@ -26,51 +26,51 @@
     my %data;
     $data{description} = q{Generating makefiles and other build files};
     $data{result}      = q{};
+    $data{makefiles}   = {
+        'Makefile' => { SOURCE => 'config/gen/makefiles/root.in' },
+    
+        'ext/Makefile' => {
+            SOURCE            => 'config/gen/makefiles/ext.in',
+            commentType       => '#',
+            replace_slashes   => 1,
+            conditioned_lines => 1,
+        },
+        'ext/Parrot-Embed/Makefile.PL' => {
+            SOURCE            => 'config/gen/makefiles/parrot_embed.in',
+            replace_slashes   => 0,
+            conditioned_lines => 1,
+        },
+    
+        'compilers/nqp/Makefile'     => { SOURCE => 
'config/gen/makefiles/nqp.in' },
+        'compilers/pct/Makefile'     => { SOURCE => 
'config/gen/makefiles/pct.in' },
+        'compilers/pge/Makefile'     => { SOURCE => 
'config/gen/makefiles/pge.in' },
+        'compilers/tge/Makefile'     => { SOURCE => 
'config/gen/makefiles/tge.in' },
+        'compilers/bcg/Makefile'     => { SOURCE => 
'config/gen/makefiles/bcg.in' },
+        'compilers/json/Makefile'    => { SOURCE => 
'config/gen/makefiles/json.in' },
+        'compilers/pirc/Makefile'    => { SOURCE => 
'config/gen/makefiles/pirc.in' },
+        'src/dynpmc/Makefile'        => { SOURCE => 
'config/gen/makefiles/dynpmc.in' },
+        'src/dynoplibs/Makefile'     => { SOURCE => 
'config/gen/makefiles/dynoplibs.in' },
+        'editor/Makefile'            => { SOURCE => 
'config/gen/makefiles/editor.in' },
+    
+        'tools/build/dynpmc.pl' => {
+            SOURCE            => 'config/gen/makefiles/dynpmc_pl.in',
+            comment_type      => '#',
+            replace_slashes   => 0,
+            conditioned_lines => 1,
+        },
+        'tools/build/dynoplibs.pl' => {
+            SOURCE            => 'config/gen/makefiles/dynoplibs_pl.in',
+            comment_type      => '#',
+            replace_slashes   => 0,
+            conditioned_lines => 1,
+        },
+        'parrot.pc'     => { SOURCE => 'config/gen/makefiles/parrot_pc.in' },
+        'docs/Makefile' => { SOURCE => 'config/gen/makefiles/docs.in' },
+    };
+    $data{CFLAGS_source} = 'config/gen/makefiles/CFLAGS.in';
     return \%data;
 }
 
-my %makefiles = (
-    'Makefile' => { SOURCE => 'config/gen/makefiles/root.in' },
-
-    'ext/Makefile' => {
-        SOURCE            => 'config/gen/makefiles/ext.in',
-        commentType       => '#',
-        replace_slashes   => 1,
-        conditioned_lines => 1,
-    },
-    'ext/Parrot-Embed/Makefile.PL' => {
-        SOURCE            => 'config/gen/makefiles/parrot_embed.in',
-        replace_slashes   => 0,
-        conditioned_lines => 1,
-    },
-
-    'compilers/nqp/Makefile'     => { SOURCE => 'config/gen/makefiles/nqp.in' 
},
-    'compilers/pct/Makefile'     => { SOURCE => 'config/gen/makefiles/pct.in' 
},
-    'compilers/pge/Makefile'     => { SOURCE => 'config/gen/makefiles/pge.in' 
},
-    'compilers/tge/Makefile'     => { SOURCE => 'config/gen/makefiles/tge.in' 
},
-    'compilers/bcg/Makefile'     => { SOURCE => 'config/gen/makefiles/bcg.in' 
},
-    'compilers/json/Makefile'    => { SOURCE => 'config/gen/makefiles/json.in' 
},
-    'compilers/pirc/Makefile'    => { SOURCE => 'config/gen/makefiles/pirc.in' 
},
-    'src/dynpmc/Makefile'        => { SOURCE => 
'config/gen/makefiles/dynpmc.in' },
-    'src/dynoplibs/Makefile'     => { SOURCE => 
'config/gen/makefiles/dynoplibs.in' },
-    'editor/Makefile'            => { SOURCE => 
'config/gen/makefiles/editor.in' },
-
-    'tools/build/dynpmc.pl' => {
-        SOURCE            => 'config/gen/makefiles/dynpmc_pl.in',
-        comment_type      => '#',
-        replace_slashes   => 0,
-        conditioned_lines => 1,
-    },
-    'tools/build/dynoplibs.pl' => {
-        SOURCE            => 'config/gen/makefiles/dynoplibs_pl.in',
-        comment_type      => '#',
-        replace_slashes   => 0,
-        conditioned_lines => 1,
-    },
-    'parrot.pc'     => { SOURCE => 'config/gen/makefiles/parrot_pc.in' },
-    'docs/Makefile' => { SOURCE => 'config/gen/makefiles/docs.in' },
-);
-
 sub runstep {
     my ( $self, $conf ) = @_;
 
@@ -84,7 +84,7 @@
 sub cflags {
     my ( $self, $conf ) = @_;
 
-    $conf->genfile('config/gen/makefiles/CFLAGS.in' => 'CFLAGS',
+    $conf->genfile( $self->{CFLAGS_source} => 'CFLAGS',
         comment_type                     => '#'
     );
 
@@ -113,10 +113,10 @@
     my @targets =
         defined $targets
         ? split ' ', $targets
-        : keys %makefiles;
+        : keys %{ $self->{makefiles} };
 
     foreach my $target (@targets) {
-        my $args   = $makefiles{$target};
+        my $args   = $self->{makefiles}->{$target};
         my $source = delete $args->{SOURCE};
 
         if ( $target ne 'docs/Makefile' ) {
@@ -132,7 +132,8 @@
                 my @ops = sort grep { !/^\./ && /\.ops$/ } readdir OPS;
                 closedir OPS;
 
-                my $pod = join " ", map { my $t = $_; $t =~ s/\.ops$/.pod/; 
"ops/$t" } @ops;
+                my $pod = join " " =>
+                    map { my $t = $_; $t =~ s/\.ops$/.pod/; "ops/$t" } @ops;
 
                 $conf->data->set( pod => $pod );
 

Modified: branches/parallel/config/gen/parrot_include.pm
==============================================================================
--- branches/parallel/config/gen/parrot_include.pm      (original)
+++ branches/parallel/config/gen/parrot_include.pm      Tue Jul 22 19:03:35 2008
@@ -26,9 +26,8 @@
     my %data;
     $data{description} = q{Generating runtime/parrot/include};
     $data{result} = q{};
-    $data{files} = [ qw(
+    $data{source_files} = [ qw(
         include/parrot/cclass.h
-        include/parrot/core_pmcs.h
         include/parrot/datatypes.h
         include/parrot/enums.h
         include/parrot/events.h
@@ -42,11 +41,14 @@
         include/parrot/stat.h
         include/parrot/string.h
         include/parrot/pmc.h
-        include/parrot/vtable.h
         include/parrot/warnings.h
         src/pmc/timer.pmc
         src/utils.c
     ) ];
+    $data{generated_files} = [ qw(
+        include/parrot/vtable.h
+        include/parrot/core_pmcs.h
+    ) ];
     $data{destdir} = 'runtime/parrot/include';
     return \%data;
 }
@@ -177,29 +179,6 @@
     return @d;
 }
 
-#my @files = qw(
-#    include/parrot/cclass.h
-#    include/parrot/core_pmcs.h
-#    include/parrot/datatypes.h
-#    include/parrot/enums.h
-#    include/parrot/events.h
-#    include/parrot/scheduler.h
-#    include/parrot/exceptions.h
-#    include/parrot/interpreter.h
-#    include/parrot/io.h
-#    include/parrot/longopt.h
-#    include/parrot/mmd.h
-#    include/parrot/resources.h
-#    include/parrot/stat.h
-#    include/parrot/string.h
-#    include/parrot/pmc.h
-#    include/parrot/vtable.h
-#    include/parrot/warnings.h
-#    src/pmc/timer.pmc
-#    src/utils.c
-#);
-#my $destdir = 'runtime/parrot/include';
-
 sub runstep {
     my ( $self, $conf ) = @_;
 
@@ -207,8 +186,7 @@
     system( $^X, "tools/build/vtable_h.pl" );
 
     my @generated;
-#    for my $file (@files) {
-    for my $file ( @{ $self->{files} } ) {
+    for my $file ( @{ $self->{source_files} }, @{ $self->{generated_files} } ) 
{
         open my $fh, '<', $file or die "Can't open $file: $!\n";
         my @directives = parse_file $file, $fh;
         close $fh;

Modified: branches/parallel/t/steps/gen_call_list-01.t
==============================================================================
--- branches/parallel/t/steps/gen_call_list-01.t        (original)
+++ branches/parallel/t/steps/gen_call_list-01.t        Tue Jul 22 19:03:35 2008
@@ -5,7 +5,7 @@
 
 use strict;
 use warnings;
-use Test::More qw(no_plan); # tests =>  2;
+use Test::More tests =>  6;
 use Carp;
 use lib qw( lib );
 use_ok('config::gen::call_list');

Modified: branches/parallel/t/steps/gen_languages-01.t
==============================================================================
--- branches/parallel/t/steps/gen_languages-01.t        (original)
+++ branches/parallel/t/steps/gen_languages-01.t        Tue Jul 22 19:03:35 2008
@@ -5,15 +5,32 @@
 
 use strict;
 use warnings;
-use Test::More tests =>  2;
+use Test::More tests =>  7;
 use Carp;
 use lib qw( lib );
 use_ok('config::gen::languages');
-
-=for hints_for_testing Consider testing the content of the files which
-the POD claims the module creates.
-
-=cut
+use Parrot::Configure;
+use Parrot::Configure::Options qw( process_options );
+use Parrot::Configure::Test qw(
+    test_step_thru_runstep
+    test_step_constructor_and_description
+);
+
+my $args = process_options(
+    {
+        argv => [ ],
+        mode => q{configure},
+    }
+);
+
+my $conf = Parrot::Configure->new;
+my $pkg = q{gen::languages};
+$conf->add_steps($pkg);
+$conf->options->set( %{$args} );
+my $step = test_step_constructor_and_description($conf);
+ok($step->{default_languages}, "default languages string is present");
+ok(-f $step->{languages_source},
+    "source file for languages/Makefile located");
 
 pass("Completed all tests in $0");
 

Modified: branches/parallel/t/steps/gen_makefiles-01.t
==============================================================================
--- branches/parallel/t/steps/gen_makefiles-01.t        (original)
+++ branches/parallel/t/steps/gen_makefiles-01.t        Tue Jul 22 19:03:35 2008
@@ -5,16 +5,36 @@
 
 use strict;
 use warnings;
-use Test::More tests =>  2;
+use Test::More tests =>  7;
 use Carp;
 use lib qw( lib );
 use_ok('config::gen::makefiles');
-
-=for hints_for_testing Consider testing the content of the files which
-the POD claims the module creates.  Consider resolving questions raised
-in inline comments such as "Why is this here?"
-
-=cut
+use Parrot::Configure;
+use Parrot::Configure::Options qw( process_options );
+use Parrot::Configure::Test qw(
+    test_step_thru_runstep
+    test_step_constructor_and_description
+);
+
+my $args = process_options(
+    {
+        argv => [ ],
+        mode => q{configure},
+    }
+);
+
+my $conf = Parrot::Configure->new;
+my $pkg = q{gen::makefiles};
+$conf->add_steps($pkg);
+$conf->options->set( %{$args} );
+my $step = test_step_constructor_and_description($conf);
+my $missing_SOURCE = 0;
+my %makefiles = %{ $step->{makefiles} };
+foreach my $k ( keys %makefiles ) {
+    $missing_SOURCE++ unless (-f $makefiles{$k}{SOURCE});
+}
+is($missing_SOURCE, 0, "No Makefile source file missing");
+ok(-f $step->{CFLAGS_source}, "CFLAGS source file located");
 
 pass("Completed all tests in $0");
 

Modified: branches/parallel/t/steps/gen_parrot_include-01.t
==============================================================================
--- branches/parallel/t/steps/gen_parrot_include-01.t   (original)
+++ branches/parallel/t/steps/gen_parrot_include-01.t   Tue Jul 22 19:03:35 2008
@@ -7,7 +7,6 @@
 use warnings;
 use Test::More tests =>  7;
 use Carp;
-use Data::Dumper;
 use lib qw( lib );
 use_ok('config::gen::parrot_include');
 use Parrot::Configure;
@@ -29,15 +28,11 @@
 $conf->add_steps($pkg);
 $conf->options->set( %{$args} );
 my $step = test_step_constructor_and_description($conf);
-TODO: {
-    local $TODO = '2 files in list are generated; need to fix';
-    my %missing_files = ();
-    foreach my $f ( @{ $step->{files} } ) {
-        $missing_files{$f}++ unless (-f $f);
-    }
-    is(keys %missing_files, 0, "No needed source files are missing");
-    print STDERR Dumper \%missing_files;
+my %missing_files = ();
+foreach my $f ( @{ $step->{source_files} } ) {
+    $missing_files{$f}++ unless (-f $f);
 }
+is(keys %missing_files, 0, "No needed source files are missing");
 ok(-d $step->{destdir}, "Directory needed has been located");
 
 pass("Completed all tests in $0");

Reply via email to