In perl.git, the branch jkeenan/refactor-podcheck has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/e5a804972a8f82d8c4e0a28693f179795b99c50c?hp=d836a3d5a60d72e84cd919ccb125a2fd97cfc3ca>

- Log -----------------------------------------------------------------
commit e5a804972a8f82d8c4e0a28693f179795b99c50c
Author: James E Keenan <[email protected]>
Date:   Sat Aug 16 09:30:35 2014 -0400

    Fiddle with starting directory.
    
    t/porting/podcheck.t, invoked without either '--add_link' or '--regen', is
    documented to be callable either from the top-level directory:
    
      ./perl -Ilib t/porting/podcheck.t
    
    ... or from t/ via the harness (as in 'make test'):
    
      cd t;./perl harness porting/podcheck.t;cd -
    
    I've begun to refactor code in podcheck.t into subroutines and to move those
    subroutines into t/lib/PodcheckUtils.pm.  But those subroutines, as well as
    code still left in podcheck.t, depend on functions require-ed in from
    regen/regen_lib.pl.  This poses the problem of locating regen/regen_lib.pl:
    Is it in ./ or in ../?  Depends on whether we have chdir-ed to t/ or not.
    
    For the time being, invoking podcheck.t via the harness after having 
chdir-ed
    to t/ is broken.  But the other invocation methods seem to be working.  So
    let's continue along the path of encapsulating podcheck.t code into
    subroutines and moving them into the module.  We'll come back to the harness
    problem later.
-----------------------------------------------------------------------

Summary of changes:
 t/lib/PodcheckUtils.pm | 98 ++++++++++++++++++++++++--------------------------
 t/porting/podcheck.t   | 40 +++++++++++++--------
 2 files changed, 71 insertions(+), 67 deletions(-)

diff --git a/t/lib/PodcheckUtils.pm b/t/lib/PodcheckUtils.pm
index 891ca01..54c61c7 100644
--- a/t/lib/PodcheckUtils.pm
+++ b/t/lib/PodcheckUtils.pm
@@ -1,4 +1,7 @@
 package PodcheckUtils;
+BEGIN {
+    require './regen/regen_lib.pl';
+}
 use base qw( Exporter );
 our @EXPORT_OK = qw(
     regen_sort_valid
@@ -8,73 +11,64 @@ our @EXPORT_OK = qw(
     regen_cleanup
     my_safer_print
     canonicalize
+    test_count_discrepancy
+    plan
+    ok
+    skip
+    note
 );
 use File::Spec;
-#*skip = *Test::More::skip;
-#*note = *Test::More::note;
-#*ok = *Test::More::ok;
-#BEGIN { require '../regen/regen_lib.pl'; }
-BEGIN {
-    chdir 't';
-    unshift @INC, ("../t/lib", "../lib");
-    require '../regen/regen_lib.pl';
-}
-
-{   # Closure to contain a simple subset of test.pl.  This is to get rid of the
-    # unnecessary 'failed at' messages that would otherwise be output pointing
-    # to a particular line in this file.
 
-    my $current_test = 0;
-    my $planned;
+our $current_test = 0;
+our $planned;
+sub plan {
+    my %plan = @_;
+    $planned = $plan{tests} + 1;    # +1 for final test that files haven't
+                                    # been removed
+    print "1..$planned\n";
+    return;
+}
 
-    sub plan {
-        my %plan = @_;
-        $planned = $plan{tests} + 1;    # +1 for final test that files haven't
-                                        # been removed
-        print "1..$planned\n";
-        return;
-    }
+sub ok {
+    my $success = shift;
+    my $message = shift;
 
-    sub ok {
-        my $success = shift;
-        my $message = shift;
+    chomp $message;
 
-        chomp $message;
+    $current_test++;
+    print "not " unless $success;
+    print "ok $current_test - $message\n";
+    return $success;
+}
 
+sub skip {
+    my $why = shift;
+    my $n    = @_ ? shift : 1;
+    for (1..$n) {
         $current_test++;
-        print "not " unless $success;
-        print "ok $current_test - $message\n";
-        return $success;
-    }
-
-    sub skip {
-        my $why = shift;
-        my $n    = @_ ? shift : 1;
-        for (1..$n) {
-            $current_test++;
-            print "ok $current_test # skip $why\n";
-        }
-        no warnings 'exiting';
-        last SKIP;
+        print "ok $current_test # skip $why\n";
     }
+    no warnings 'exiting';
+    last SKIP;
+}
 
-    sub note {
-        my $message = shift;
+sub note {
+    my $message = shift;
 
-        chomp $message;
+    chomp $message;
 
-        print $message =~ s/^/# /mgr;
-        print "\n";
-        return;
-    }
+    print $message =~ s/^/# /mgr;
+    print "\n";
+    return;
+}
 
-    END {
-        if ($planned && $planned != $current_test) {
-            print STDERR
-            "# Looks like you planned $planned tests but ran $current_test.\n";
-        }
+sub test_count_discrepancy {
+    if ($planned && $planned != $current_test) {
+        print STDERR
+        "# Looks like you planned $planned tests but ran $current_test.\n";
     }
 }
+
 { # Closure
     my $first_time = 1;
 
diff --git a/t/porting/podcheck.t b/t/porting/podcheck.t
index c350fe1..3d916b4 100644
--- a/t/porting/podcheck.t
+++ b/t/porting/podcheck.t
@@ -1,21 +1,8 @@
 #!/usr/bin/perl -w
 
 BEGIN {
-    chdir 't';
-    unshift @INC, "../t/lib", "../lib";
+    unshift @INC, "t/lib";
 }
-
-use strict;
-use warnings;
-use feature 'unicode_strings';
-
-use Carp;
-use Config;
-use Digest;
-use File::Find;
-use File::Spec;
-use Scalar::Util;
-use Text::Tabs;
 use PodcheckUtils qw(
     regen_sort_valid
     analyze_one_file
@@ -24,16 +11,38 @@ use PodcheckUtils qw(
     regen_cleanup
     my_safer_print
     canonicalize
+    test_count_discrepancy
+    plan
+    ok
+    skip
+    note
 );
-
+BEGIN {
+    chdir 't';
+    unshift @INC, "../t/lib", "../lib";
+}
 BEGIN {
     if ( $Config{usecrosscompile} ) {
         print "1..0 # Not all files are available during cross-compilation\n";
         exit 0;
     }
     require '../regen/regen_lib.pl';
+#    require './regen/regen_lib.pl';
 }
 
+
+use strict;
+use warnings;
+use feature 'unicode_strings';
+
+use Carp;
+use Config;
+use Digest;
+use File::Find;
+use File::Spec;
+use Scalar::Util;
+use Text::Tabs;
+
 sub DEBUG { 0 };
 
 =pod
@@ -1827,3 +1836,4 @@ final_notification(
 
 regen_cleanup($regen, $original_dir, $copy_fh);
 
+END { test_count_discrepancy(); }

--
Perl5 Master Repository

Reply via email to