This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
t/lib/common.pl can use caller to infer the name of the pragma under test.
authorNicholas Clark <nick@ccl4.org>
Thu, 1 Jul 2010 19:41:21 +0000 (20:41 +0100)
committerNicholas Clark <nick@ccl4.org>
Thu, 1 Jul 2010 19:43:36 +0000 (20:43 +0100)
This avoids needing to use a variable in package main to pass in information.
Also, remove an unnecessary $ENV{PERL5LIB} assignment cargo-culted into most
users of t/lib/common,pl, and remove the BEGIN block as the code it contained
doesn't need to run at BEGIN time.

lib/charnames.t
lib/feature.t
lib/strict.t
lib/subs.t
lib/warnings.t
t/lib/common.pl

index f50076c..50c9837 100644 (file)
@@ -11,7 +11,6 @@ BEGIN {
     $SIG{__WARN__} = sub { push @WARN, @_ };
 }
 
-our $pragma_name = "charnames";
 our $local_tests = 58;
 
 # ---- For the alias extensions
index a60644f..0818f37 100644 (file)
@@ -1,10 +1,5 @@
 #!./perl
 
-BEGIN {
-    chdir 't' if -d 't';
-    @INC = '../lib';
-    $ENV{PERL5LIB} = '../lib';
-}
-
-our $pragma_name = "feature";
+chdir 't' if -d 't';
+@INC = '../lib';
 require "../t/lib/common.pl";
index 51e9b73..e067793 100644 (file)
@@ -1,12 +1,8 @@
 #!./perl
 
-BEGIN {
-    chdir 't' if -d 't';
-    @INC = '../lib';
-    $ENV{PERL5LIB} = '../lib';
-}
+chdir 't' if -d 't';
+@INC = '../lib';
 
-our $pragma_name = "strict";
 our $local_tests = 4;
 require "../t/lib/common.pl";
 
index 1f719c7..4ad4f8f 100644 (file)
@@ -1,10 +1,6 @@
 #!./perl
 
-BEGIN {
-    chdir 't' if -d 't';
-    @INC = '../lib';
-    $ENV{PERL5LIB} = '../lib';
-}
+chdir 't' if -d 't';
+@INC = '../lib';
 
-our $pragma_name = "subs";
 require "../t/lib/common.pl";
index d03b8c5..ee696fe 100644 (file)
@@ -1,11 +1,7 @@
 #!./perl
 
-BEGIN {
-    chdir 't' if -d 't';
-    @INC = '../lib';
-    $ENV{PERL5LIB} = '../lib';
-}
+chdir 't' if -d 't';
+@INC = '../lib';
 
-our $pragma_name = "warnings";
 our $UTF8 = (${^OPEN} || "") =~ /:utf8/;
 require "../t/lib/common.pl";
index d3bf149..e5c9af4 100644 (file)
@@ -11,7 +11,9 @@ use File::Spec::Functions;
 
 use strict;
 use warnings;
-our $pragma_name;
+my (undef, $file) = caller;
+my ($pragma_name) = $file =~ /([A-Za-z_0-9]+)\.t$/
+    or die "Can't identify pragama to test from file name '$file'";
 
 $| = 1;