Author: jkeenan
Date: Mon Jul 21 18:22:08 2008
New Revision: 29660

Added:
   trunk/t/configure/061-revision_from_cache.t
      - copied unchanged from r29659, 
/branches/revisionpm/t/configure/061-revision_from_cache.t
Modified:
   trunk/MANIFEST
   trunk/lib/Parrot/Configure/Options/Test.pm
   trunk/lib/Parrot/Revision.pm
   trunk/t/configure/017-revision_from_cache.t

Log:
Merge revisionpm branch into trunk.  Cf.:
http://rt.perl.org/rt3/Ticket/Display.html?id=56948.  Refactor
Parrot::Revision and add tests, including one new test file.


Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST      (original)
+++ trunk/MANIFEST      Mon Jul 21 18:22:08 2008
@@ -1,7 +1,7 @@
 # ex: set ro:
 # $Id$
 #
-# generated by tools/dev/mk_manifest_and_skip.pl Sun Jul 20 10:24:04 2008 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Tue Jul 22 00:54:15 2008 UT
 #
 # See tools/dev/install_files.pl for documentation on the
 # format of this file.
@@ -3340,6 +3340,7 @@
 t/configure/058-fatal_step.t                                []
 t/configure/059-silent.t                                    []
 t/configure/060-silent.t                                    []
+t/configure/061-revision_from_cache.t                       []
 t/configure/testlib/Make_VERSION_File.pm                    []
 t/configure/testlib/Tie/Filehandle/Preempt/Stdin.pm         []
 t/configure/testlib/init/alpha.pm                           []

Modified: trunk/lib/Parrot/Configure/Options/Test.pm
==============================================================================
--- trunk/lib/Parrot/Configure/Options/Test.pm  (original)
+++ trunk/lib/Parrot/Configure/Options/Test.pm  Mon Jul 21 18:22:08 2008
@@ -85,6 +85,7 @@
     my $self = shift;
     my @preconfiguration_tests = @_;
     if ( $self->get_run('run_configure_tests') ) {
+        my $start = time();
         print "As you requested, we'll start with some tests of the 
configuration tools.\n\n";
 
         runtests(@preconfiguration_tests) or die
@@ -95,6 +96,10 @@
 Parrot's configuration tools will work as intended.
 
 TEST
+        my $end =time();
+        print scalar(@preconfiguration_tests),
+            " t/configure and t/step tests took ",
+            ($end - $start), " seconds.\n";
     }
     return 1;
 }

Modified: trunk/lib/Parrot/Revision.pm
==============================================================================
--- trunk/lib/Parrot/Revision.pm        (original)
+++ trunk/lib/Parrot/Revision.pm        Mon Jul 21 18:22:08 2008
@@ -30,36 +30,51 @@
 sub update {
     my $prev = _get_revision();
     my $revision = _analyze_sandbox();
-    if (defined ($prev) && ($revision ne $prev)) {
-        $revision = 'unknown' unless defined $revision;
-        eval {
-            open my $FH, ">", $cache;
-            print $FH "$revision\n";
-            close $FH;
-            $current = $revision;
-        };
+    $current = _handle_update( {
+        prev        => $prev,
+        revision    => $revision,
+        cache       => $cache,
+        current     => $current,
+    } );
+}
+
+sub _handle_update {
+    my $args = shift;
+    if (! defined $args->{revision}) {
+        $args->{revision} = 'unknown';
+        _print_to_cache($args->{cache}, $args->{revision});
+        return $args->{revision};
+    }
+    else {
+        if (defined ($args->{prev}) && ($args->{revision} ne $args->{prev})) {
+            _print_to_cache($args->{cache}, $args->{revision});
+            return $args->{revision};
+        }
+        else {
+            return $args->{current};
+        }
     }
 }
 
+sub _print_to_cache {
+    my ($cache, $revision) = @_;
+    open my $FH, ">", $cache
+        or die "Unable to open handle to $cache for writing: $!";
+    print $FH "$revision\n";
+    close $FH or die "Unable to close handle to $cache after writing: $!";
+}
+
 sub _get_revision {
     my $revision;
     if (-f $cache) {
-        eval {
-            open my $FH, "<", $cache;
-            chomp($revision = <$FH>);
-            close $FH;
-        };
-        return $revision unless $@;
+        open my $FH, "<", $cache
+            or die "Unable to open $cache for reading: $!";
+        chomp($revision = <$FH>);
+        close $FH or die "Unable to close $cache after reading: $!";
     }
-
-    $revision = _analyze_sandbox();
-
-    if (! -f $cache) {
-        eval {
-            open my $FH, ">", $cache;
-            print $FH "$revision\n";
-            close $FH;
-        };
+    else {
+        $revision = _analyze_sandbox();
+        _print_to_cache($cache, $revision);
     }
     return $revision;
 }

Modified: trunk/t/configure/017-revision_from_cache.t
==============================================================================
--- trunk/t/configure/017-revision_from_cache.t (original)
+++ trunk/t/configure/017-revision_from_cache.t Mon Jul 21 18:22:08 2008
@@ -20,6 +20,23 @@
 my $cwd = cwd();
 {
     my $rev = 16000;
+    my ($cache, $libdir) = setup_cache($rev, $cwd);
+    require Parrot::Revision;
+    no warnings 'once';
+    is($Parrot::Revision::current, $rev,
+        "Got expected revision number from cache");
+    use warnings;
+    unlink qq{$libdir/Parrot/Revision.pm}
+        or croak "Unable to delete file after testing";
+    ok( chdir $cwd, "Able to change back to starting directory");
+}
+
+pass("Completed all tests in $0");
+
+##### SUBROUTINES #####
+
+sub setup_cache {
+    my ($rev, $cwd) = @_;
     my $tdir = tempdir( CLEANUP => 1 );
     ok( chdir $tdir, "Changed to temporary directory for testing" );
     my $libdir = qq{$tdir/lib};
@@ -34,18 +51,9 @@
         or croak "Unable to open $cache for writing";
     print $FH qq{$rev\n};
     close $FH or croak "Unable to close $cache after writing";
-    require Parrot::Revision;
-    no warnings 'once';
-    is($Parrot::Revision::current, $rev,
-        "Got expected revision number from cache");
-    use warnings;
-    unlink qq{$libdir/Parrot/Revision.pm}
-        or croak "Unable to delete file after testing";
-    ok( chdir $cwd, "Able to change back to starting directory");
+    return ($cache, $libdir);
 }
 
-pass("Completed all tests in $0");
-
 ################### DOCUMENTATION ###################
 
 =head1 NAME

Reply via email to