This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add skip_all_without_config() to test.pl, and use it in 6 tests.
authorNicholas Clark <nick@ccl4.org>
Mon, 7 Mar 2011 19:25:13 +0000 (19:25 +0000)
committerNicholas Clark <nick@ccl4.org>
Mon, 7 Mar 2011 19:25:13 +0000 (19:25 +0000)
This abstracts out the common idiom of loading Config, checking if a particular
key is true, and if not implementing a "skip all" with an appropriate reason.

t/op/getpid.t
t/op/getppid.t
t/op/threads-dirh.t
t/op/threads.t
t/run/cloexec.t
t/run/runenv.t
t/test.pl

index b51b064..ac066d5 100644 (file)
@@ -12,14 +12,7 @@ use strict;
 use Config;
 
 BEGIN {
-    if (!$Config{useithreads}) {
-       print "1..0 # Skip: no ithreads\n";
-       exit;
-    }
-    if (!$Config{d_getppid}) {
-       print "1..0 # Skip: no getppid\n";
-       exit;
-    }
+    skip_all_without_config($_) foreach qw(useithreads d_getppid);
     if ($ENV{PERL_CORE_MINITEST}) {
         print "1..0 # Skip: no dynamic loading on miniperl, no threads\n";
         exit 0;
index f4ebc7e..23428f0 100644 (file)
@@ -13,16 +13,10 @@ BEGIN {
 }
 
 use strict;
-use Config;
 
 BEGIN {
-    for my $syscall (qw(pipe fork waitpid getppid)) {
-       if (!$Config{"d_$syscall"}) {
-           print "1..0 # Skip: no $syscall\n";
-           exit;
-       }
-    }
     require './test.pl';
+    skip_all_without_config($_) foreach qw(d_pipe d_fork d_waitpid d_getppid);
     plan (8);
 }
 
index 900a62a..b481992 100644 (file)
@@ -9,10 +9,7 @@ BEGIN {
      $| = 1;
 
      require Config;
-     if (!$Config::Config{useithreads}) {
-        print "1..0 # Skip: no ithreads\n";
-        exit 0;
-     }
+     skip_all_without_config('useithreads');
      skip_all_if_miniperl("no dynamic loading on miniperl, no threads");
 
      plan(6);
index 94dad6e..24e84e4 100644 (file)
@@ -6,11 +6,7 @@ BEGIN {
      require './test.pl';
      $| = 1;
 
-     require Config;
-     if (!$Config::Config{useithreads}) {
-        print "1..0 # Skip: no ithreads\n";
-        exit 0;
-     }
+     skip_all_without_config('useithreads');
      skip_all_if_miniperl("no dynamic loading on miniperl, no threads");
 
      plan(24);
index 314d5fa..486df1e 100644 (file)
 BEGIN {
     chdir 't' if -d 't';
     @INC = '../lib';
-    require Config;
-    if (!$Config::Config{'d_fcntl'}) {
-        print("1..0 # Skip: fcntl() is not available\n");
-        exit(0);
-    }
     require './test.pl';
+    skip_all_without_config('d_fcntl');
 }
 
 use strict;
index b3e47a6..cea2590 100644 (file)
@@ -8,11 +8,8 @@ BEGIN {
     chdir 't' if -d 't';
     @INC = '../lib';
     require Config; import Config;
-    unless ($Config{'d_fork'}) {
-        print "1..0 # Skip: no fork\n";
-           exit 0;
-    }
-    require './test.pl'
+    require './test.pl';
+    skip_all_without_config('d_fork');
 }
 
 plan tests => 84;
index a09c831..fa151ec 100644 (file)
--- a/t/test.pl
+++ b/t/test.pl
@@ -136,6 +136,21 @@ sub skip_all_without_perlio {
     skip_all('no PerlIO') unless PerlIO::Layer->find('perlio');
 }
 
+sub skip_all_without_config {
+    my ($key, $reason) = @_;
+    unless (eval 'require Config; 1') {
+       warn "test.pl had problems loading Config: $@";
+       return;
+    }
+    return if $Config::Config{$key};
+    unless (defined $reason) {
+       $key =~ s/^use//;
+       $key =~ s/^d_//;
+       $reason = "no $key";
+    }
+    skip_all($reason);
+}
+
 sub _ok {
     my ($pass, $where, $name, @mess) = @_;
     # Do not try to microoptimize by factoring out the "not ".