Add skip_all_without_extension() to test.pl, for the common skip idiom.
authorNicholas Clark <nick@ccl4.org>
Sun, 6 Mar 2011 21:58:19 +0000 (21:58 +0000)
committerNicholas Clark <nick@ccl4.org>
Sun, 6 Mar 2011 22:48:16 +0000 (22:48 +0000)
Use it in t/io/layers.t to skip if Encode is not built.

t/io/layers.t
t/test.pl

index 01e1864..cb7cbef 100644 (file)
@@ -9,9 +9,7 @@ BEGIN {
     skip_all('not perlio') unless (find PerlIO::Layer 'perlio');
     # FIXME - more of these could be tested without Encode or full perl
     skip_all_if_miniperl("no dynamic loading on miniperl, no Encode");
-    require Config; Config->import;
-    skip_all('Encode was not built')
-       unless ($Config::Config{extensions} =~ /\bEncode\b/);
+    skip_all_without_extension('Encode');
 
     # Makes testing easier.
     $ENV{PERLIO} = 'stdio' if exists $ENV{PERLIO} && $ENV{PERLIO} eq '';
@@ -23,6 +21,7 @@ BEGIN {
     $PERLIO = exists $ENV{PERLIO} ? $ENV{PERLIO} : "(undef)";
 }
 
+use Config;
 
 my $DOSISH    = $^O =~ /^(?:MSWin32|os2|dos|NetWare)$/ ? 1 : 0;
    $DOSISH    = 1 if !$DOSISH and $^O =~ /^uwin/;
index 5eed21d..9958356 100644 (file)
--- a/t/test.pl
+++ b/t/test.pl
@@ -122,6 +122,16 @@ sub skip_all_if_miniperl {
     skip_all(@_) if is_miniperl();
 }
 
+sub skip_all_without_extension {
+    my $extension = shift;
+    unless (eval 'require Config; 1') {
+       warn "test.pl had problems loading Config: $@";
+       return;
+    }
+    return if ($Config::Config{extensions} =~ /\b$extension\b/);
+    skip_all("$extension was not built");
+}
+
 sub _ok {
     my ($pass, $where, $name, @mess) = @_;
     # Do not try to microoptimize by factoring out the "not ".