develooper Front page | perl.perl5.porters | Postings from December 2004

[PATCH] Cleanup ext/B tests for -w and to run separately

Thread Next
From:
Stephen McCamant
Date:
December 28, 2004 13:49
Subject:
[PATCH] Cleanup ext/B tests for -w and to run separately
Message ID:
16849.54495.424654.896889@apocalypse.OCF.Berkeley.EDU
The appended patch changes the preambles of the compiler tests in
ext/B/t so that you can run them by saying "make test" in ext/B as if
it were a standalone module. (B was once a standalone module, but IIRC
the tests came after it was integrated into the core). I modeled the
changes after the tests for Storable. I was driven to do this because
I've been hacking on B on an old laptop where a full "make test" takes
more than ten minutes.

The patch also includes some small changes to make the tests and the
B::Terse wrapper "-w"-clean. 

 -- Stephen

Index: ext/B/B/Terse.pm
===================================================================
--- ext/B/B/Terse.pm	(revision 18175)
+++ ext/B/B/Terse.pm	(working copy)
@@ -51,14 +51,14 @@
 }
 
 sub B::NULL::terse {
-    my ($sv, $level) = @_;
+    my ($sv, $level) = (@_, 0);
     my $s = indent($level) . sprintf "%s (0x%lx)", class($sv), $$sv;
     print "$s\n" unless defined wantarray;
     $s;
 }
 
 sub B::SPECIAL::terse {
-    my ($sv, $level) = @_;
+    my ($sv, $level) = (@_, 0);
     my $s = indent($level)
 	. sprintf( "%s #%d %s", class($sv), $$sv, $specialsv_name[$$sv]);
     print "$s\n" unless defined wantarray;
Index: ext/B/t/b.t
===================================================================
--- ext/B/t/b.t	(revision 18175)
+++ ext/B/t/b.t	(working copy)
@@ -1,12 +1,16 @@
 #!./perl
 
 BEGIN {
-    chdir 't' if -d 't';
-    if ($^O eq 'MacOS') {
-	@INC = qw(: ::lib ::macos:lib);
+    if ($ENV{PERL_CORE}){
+	chdir('t') if -d 't';
+	if ($^O eq 'MacOS') {
+	    @INC = qw(: ::lib ::macos:lib);
+	} else {
+	    @INC = '.';
+	    push @INC, '../lib';
+	}
     } else {
-	@INC = '.';
-	push @INC, '../lib';
+	unshift @INC, 't';
     }
     require Config;
     if (($Config::Config{'extensions'} !~ /\bB\b/) ){
Index: ext/B/t/optree_specials.t
===================================================================
--- ext/B/t/optree_specials.t	(revision 18175)
+++ ext/B/t/optree_specials.t	(working copy)
@@ -1,8 +1,13 @@
 #!./perl
 
 BEGIN {
-    chdir 't';
-    @INC = ('../lib', '../ext/B/t');
+    if ($ENV{PERL_CORE}){
+	chdir('t') if -d 't';
+	@INC = ('.', '../lib', '../ext/B/t');
+    } else {
+	unshift @INC, 't';
+	push @INC, "../../t";
+    }
     require Config;
     if (($Config::Config{'extensions'} !~ /\bB\b/) ){
         print "1..0 # Skip -- Perl configured without B module\n";
@@ -13,7 +18,7 @@
 	    "1..0 # Skip: Data::Dumper was not built, needed by OptreeCheck\n";
 	exit 0;
     }
-    require './test.pl';
+    require 'test.pl';
 }
 
 # import checkOptree(), and %gOpts (containing test state)
Index: ext/B/t/f_map.t
===================================================================
--- ext/B/t/f_map.t	(revision 18175)
+++ ext/B/t/f_map.t	(working copy)
@@ -1,8 +1,13 @@
 #!perl
 
 BEGIN {
-    chdir q(t);
-    @INC = qw(../lib ../ext/B/t);
+    if ($ENV{PERL_CORE}){
+	chdir('t') if -d 't';
+	@INC = ('.', '../lib', '../ext/B/t');
+    } else {
+	unshift @INC, 't';
+	push @INC, "../../t";
+    }
     require Config;
     if (($Config::Config{'extensions'} !~ /\bB\b/) ){
         print "1..0 # Skip -- Perl configured without B module\n";
@@ -21,7 +26,7 @@
         print "1..0 # Skip -- TODO - provide golden result regexps for 5.8\n";
         exit 0;
     }
-   require q(./test.pl);
+    require q(test.pl);
 }
 use OptreeCheck;
 plan tests => 9;
Index: ext/B/t/optree_samples.t
===================================================================
--- ext/B/t/optree_samples.t	(revision 18175)
+++ ext/B/t/optree_samples.t	(working copy)
@@ -1,8 +1,13 @@
 #!perl
 
 BEGIN {
-    chdir 't';
-    @INC = ('../lib', '../ext/B/t');
+    if ($ENV{PERL_CORE}){
+	chdir('t') if -d 't';
+	@INC = ('.', '../lib', '../ext/B/t');
+    } else {
+	unshift @INC, 't';
+	push @INC, "../../t";
+    }
     require Config;
     if (($Config::Config{'extensions'} !~ /\bB\b/) ){
         print "1..0 # Skip -- Perl configured without B module\n";
@@ -17,7 +22,7 @@
         print "1..0 # Skip -- TODO - provide golden result regexps for 5.8\n";
         exit 0;
     }
-    require './test.pl';
+    require 'test.pl';
 }
 use OptreeCheck;
 use Config;
Index: ext/B/t/stash.t
===================================================================
--- ext/B/t/stash.t	(revision 18175)
+++ ext/B/t/stash.t	(working copy)
@@ -1,11 +1,16 @@
 #!./perl
 
 BEGIN {
-    chdir 't' if -d 't';
-    if ($^O eq 'MacOS') {
-	@INC = qw(: ::lib ::macos:lib);
+    if ($ENV{PERL_CORE}){
+	chdir('t') if -d 't';
+	if ($^O eq 'MacOS') {
+	    @INC = qw(: ::lib ::macos:lib);
+	} else {
+	    @INC = '.';
+	    push @INC, '../lib';
+	}
     } else {
-	@INC = '../lib';
+	unshift @INC, 't';
     }
     require Config;
     if (($Config::Config{'extensions'} !~ /\bB\b/) ){
Index: ext/B/t/terse.t
===================================================================
--- ext/B/t/terse.t	(revision 18175)
+++ ext/B/t/terse.t	(working copy)
@@ -1,8 +1,12 @@
 #!./perl
 
 BEGIN {
-	chdir 't' if -d 't';
-	@INC = '../lib';
+        if ($ENV{PERL_CORE}){
+	        chdir('t') if -d 't';
+	        @INC = ('.', '../lib');
+        } else {
+	        unshift @INC, 't';
+        }
 	require Config;
 	if (($Config::Config{'extensions'} !~ /\bB\b/) ){
 		print "1..0 # Skip -- Perl configured without B module\n";
@@ -50,8 +54,8 @@
 		my $op = $1;
 		next unless exists $ops{$op};
 		like( $_, $ops{$op}, "$op " );
+		s/$ops{$op}//;
 		delete $ops{$op};
-		s/$ops{$op}//;
 		redo if $_;
 	}
 }
@@ -76,7 +80,7 @@
 	$a = 1.234;
 
 	# this is awful, but it gives a PMOP
-	my $boo = split('', $foo);
+	our @ary = split('', $foo);
 
 	# PVOP, LOOP
 	LOOP: for (1 .. 10) {
Index: ext/B/t/deparse.t
===================================================================
--- ext/B/t/deparse.t	(revision 18175)
+++ ext/B/t/deparse.t	(working copy)
@@ -1,12 +1,16 @@
 #!./perl
 
 BEGIN {
-    chdir 't' if -d 't';
-    if ($^O eq 'MacOS') {
-	@INC = qw(: ::lib ::macos:lib);
+    if ($ENV{PERL_CORE}){
+	chdir('t') if -d 't';
+	if ($^O eq 'MacOS') {
+	    @INC = qw(: ::lib ::macos:lib);
+	} else {
+	    @INC = '.';
+	    push @INC, '../lib';
+	}
     } else {
-	@INC = '.';
-	push @INC, '../lib';
+	unshift @INC, 't';
     }
     require Config;
     if (($Config::Config{'extensions'} !~ /\bB\b/) ){
Index: ext/B/t/concise.t
===================================================================
--- ext/B/t/concise.t	(revision 18175)
+++ ext/B/t/concise.t	(working copy)
@@ -1,14 +1,19 @@
 #!./perl
 
 BEGIN {
-    chdir 't';
-    @INC = '../lib';
+    if ($ENV{PERL_CORE}){
+	chdir('t') if -d 't';
+	@INC = ('.', '../lib');
+    } else {
+	unshift @INC, 't';
+	push @INC, "../../t";
+    }
     require Config;
     if (($Config::Config{'extensions'} !~ /\bB\b/) ){
         print "1..0 # Skip -- Perl configured without B module\n";
         exit 0;
     }
-    require './test.pl';
+    require 'test.pl';
 }
 
 plan tests => 142;
@@ -119,6 +124,7 @@
 
 #### for content with doc'd options
 
+our($a, $b);
 my $func = sub{ $a = $b+42 };	# canonical example asub
 
 SKIP: {
@@ -246,7 +252,7 @@
     }
 
     my %save = %combos;
-    my %combos;	# outputs for $mode=any($order) and any($style)
+    %combos = ();	# outputs for $mode=any($order) and any($style)
 
     # add more samples with switching modes & sticky styles
     for $style (@styles) {
@@ -292,7 +298,7 @@
 
 
     #now do double crosschecks: commutativity across stick / nostick
-    my %combos = (%combos, %save);
+    %combos = (%combos, %save);
 
     # test commutativity of flags, ie that AB == BA
     for $mode (@modes) {
Index: ext/B/t/debug.t
===================================================================
--- ext/B/t/debug.t	(revision 18175)
+++ ext/B/t/debug.t	(working copy)
@@ -1,12 +1,16 @@
 #!./perl
 
 BEGIN {
-    chdir 't' if -d 't';
-    if ($^O eq 'MacOS') {
-	@INC = qw(: ::lib ::macos:lib);
+    if ($ENV{PERL_CORE}){
+	chdir('t') if -d 't';
+	if ($^O eq 'MacOS') {
+	    @INC = qw(: ::lib ::macos:lib);
+	} else {
+	    @INC = '.';
+	    push @INC, '../lib';
+	}
     } else {
-	@INC = '.';
-	push @INC, '../lib';
+	unshift @INC, 't';
     }
     require Config;
     if (($Config::Config{'extensions'} !~ /\bB\b/) ){
Index: ext/B/t/showlex.t
===================================================================
--- ext/B/t/showlex.t	(revision 18175)
+++ ext/B/t/showlex.t	(working copy)
@@ -1,18 +1,24 @@
 #!./perl
 
 BEGIN {
-    chdir 't' if -d 't';
-    if ($^O eq 'MacOS') {
-	@INC = qw(: ::lib ::macos:lib);
+    if ($ENV{PERL_CORE}){
+	chdir('t') if -d 't';
+	if ($^O eq 'MacOS') {
+	    @INC = qw(: ::lib ::macos:lib);
+	} else {
+	    @INC = '.';
+	    push @INC, '../lib';
+	}
     } else {
-	@INC = '../lib';
+	unshift @INC, 't';
+	push @INC, "../../t";
     }
     require Config;
     if (($Config::Config{'extensions'} !~ /\bB\b/) ){
         print "1..0 # Skip -- Perl configured without B module\n";
         exit 0;
     }
-    require './test.pl';
+    require 'test.pl';
 }
 
 $| = 1;
Index: ext/B/t/optree_varinit.t
===================================================================
--- ext/B/t/optree_varinit.t	(revision 18175)
+++ ext/B/t/optree_varinit.t	(working copy)
@@ -1,8 +1,13 @@
 #!perl
 
 BEGIN {
-    chdir 't';
-    @INC = ('../lib', '../ext/B/t');
+    if ($ENV{PERL_CORE}){
+	chdir('t') if -d 't';
+	@INC = ('.', '../lib', '../ext/B/t');
+    } else {
+	unshift @INC, 't';
+	push @INC, "../../t";
+    }
     require Config;
     if (($Config::Config{'extensions'} !~ /\bB\b/) ){
         print "1..0 # Skip -- Perl configured without B module\n";
@@ -13,7 +18,7 @@
 	    "1..0 # Skip: Data::Dumper was not built, needed by OptreeCheck\n";
 	exit 0;
     }
-    require './test.pl';
+    require 'test.pl';
 }
 use OptreeCheck;
 use Config;
Index: ext/B/t/optree_check.t
===================================================================
--- ext/B/t/optree_check.t	(revision 18175)
+++ ext/B/t/optree_check.t	(working copy)
@@ -1,8 +1,13 @@
 #!perl
 
 BEGIN {
-    chdir 't';
-    @INC = ('../lib', '../ext/B/t');
+    if ($ENV{PERL_CORE}){
+	chdir('t') if -d 't';
+	@INC = ('.', '../lib', '../ext/B/t');
+    } else {
+	unshift @INC, 't';
+	push @INC, "../../t";
+    }
     require Config;
     if (($Config::Config{'extensions'} !~ /\bB\b/) ){
         print "1..0 # Skip -- Perl configured without B module\n";
@@ -13,7 +18,7 @@
 	    "1..0 # Skip: Data::Dumper was not built, needed by OptreeCheck\n";
 	exit 0;
     }
-    require './test.pl';
+    require 'test.pl';
 }
 
 use OptreeCheck;
Index: ext/B/t/f_sort.t
===================================================================
--- ext/B/t/f_sort.t	(revision 18175)
+++ ext/B/t/f_sort.t	(working copy)
@@ -1,8 +1,13 @@
 #!perl
 
 BEGIN {
-    chdir q(t);
-    @INC = qw(../lib ../ext/B/t);
+    if ($ENV{PERL_CORE}){
+	chdir('t') if -d 't';
+	@INC = ('.', '../lib', '../ext/B/t');
+    } else {
+	unshift @INC, 't';
+	push @INC, "../../t";
+    }
     require Config;
     if (($Config::Config{'extensions'} !~ /\bB\b/) ){
         print "1..0 # Skip -- Perl configured without B module\n";
@@ -21,7 +26,7 @@
         print "1..0 # Skip -- TODO - provide golden result regexps for 5.8\n";
         exit 0;
     }
-    require q(./test.pl);
+    require q(test.pl);
 }
 use OptreeCheck;
 plan tests => 20;
Index: ext/B/t/bblock.t
===================================================================
--- ext/B/t/bblock.t	(revision 18175)
+++ ext/B/t/bblock.t	(working copy)
@@ -1,8 +1,12 @@
 #!./perl -Tw
 
 BEGIN {
-    chdir 't';
-    @INC = '../lib';
+    if ($ENV{PERL_CORE}){
+	chdir('t') if -d 't';
+	@INC = ('.', '../lib');
+    } else {
+	unshift @INC, 't';
+    }
     require Config;
     if (($Config::Config{'extensions'} !~ /\bB\b/) ){
         print "1..0 # Skip -- Perl configured without B module\n";
Index: ext/B/t/o.t
===================================================================
--- ext/B/t/o.t	(revision 18175)
+++ ext/B/t/o.t	(working copy)
@@ -1,8 +1,13 @@
 #!./perl -w
 
 BEGIN {
-	chdir 't' if -d 't';
-	@INC = ('../lib', 'lib', '.');
+        if ($ENV{PERL_CORE}){
+	        chdir('t') if -d 't';
+	        @INC = ('.', 'lib', '../lib');
+        } else {
+	        unshift @INC, 't';
+	        push @INC, "../../t";
+        }
 	require Config;
 	if (($Config::Config{'extensions'} !~ /\bB\b/) ){
 		print "1..0 # Skip -- Perl configured without B module\n";
Index: ext/B/t/bytecode.t
===================================================================
--- ext/B/t/bytecode.t	(revision 18175)
+++ ext/B/t/bytecode.t	(working copy)
@@ -7,8 +7,13 @@
        print "1..0 # skip - Bytecode/ByteLoader doesn't work on VMS\n";
        exit 0;
     }
-    chdir 't' if -d 't';
-    @INC = qw(../lib);
+    if ($ENV{PERL_CORE}){
+	chdir('t') if -d 't';
+	@INC = ('.', '../lib');
+    } else {
+	unshift @INC, 't';
+	push @INC, "../../t";
+    }
     use Config;
     if (($Config{'extensions'} !~ /\bB\b/) ){
         print "1..0 # Skip -- Perl configured without B module\n";
@@ -18,7 +23,7 @@
 	print "1..0 # skip - no COW for now\n";
 	exit 0;
     }
-    require './test.pl'; # for run_perl()
+    require 'test.pl'; # for run_perl()
 }
 use strict;
 
@@ -114,6 +119,9 @@
 my $i = 1;
 my $foo = sub {$i = shift if @_};
 &$foo(3);
+print 'ok';
+>>>>
+ok
 ############################################################
 $x="Cannot use"; print index $x, "Can"
 >>>>
@@ -127,7 +135,10 @@
 >>>>
 4
 ############################################################
-open our $T,"a"
+open our $T,"a";
+print 'ok';
+>>>>
+ok
 ############################################################
 print <DATA>
 __DATA__
Index: ext/B/t/optree_concise.t
===================================================================
--- ext/B/t/optree_concise.t	(revision 18175)
+++ ext/B/t/optree_concise.t	(working copy)
@@ -1,8 +1,13 @@
 #!perl
 
 BEGIN {
-    chdir 't';
-    @INC = ('../lib', '../ext/B/t');
+    if ($ENV{PERL_CORE}){
+	chdir('t') if -d 't';
+	@INC = ('.', '../lib', '../ext/B/t');
+    } else {
+	unshift @INC, 't';
+	push @INC, "../../t";
+    }
     require Config;
     if (($Config::Config{'extensions'} !~ /\bB\b/) ){
         print "1..0 # Skip -- Perl configured without B module\n";
@@ -13,7 +18,7 @@
 	    "1..0 # Skip: Data::Dumper was not built, needed by OptreeCheck\n";
 	exit 0;
     }
-    require './test.pl';
+    require 'test.pl';
 }
 
 # import checkOptree(), and %gOpts (containing test state)
Index: ext/B/t/xref.t
===================================================================
--- ext/B/t/xref.t	(revision 18175)
+++ ext/B/t/xref.t	(working copy)
@@ -1,8 +1,12 @@
 #!./perl
 
 BEGIN {
-    chdir 't' if -d 't';
-    @INC = qw(../lib);
+    if ($ENV{PERL_CORE}){
+	chdir('t') if -d 't';
+	@INC = ('.', '../lib');
+    } else {
+	unshift @INC, 't';
+    }
     require Config;
     if (($Config::Config{'extensions'} !~ /\bB\b/) ){
         print "1..0 # Skip -- Perl configured without B module\n";
Index: ext/B/t/optree_sort.t
===================================================================
--- ext/B/t/optree_sort.t	(revision 18175)
+++ ext/B/t/optree_sort.t	(working copy)
@@ -1,8 +1,13 @@
 #!perl
 
 BEGIN {
-    chdir 't';
-    @INC = ('../lib', '../ext/B/t');
+    if ($ENV{PERL_CORE}){
+	chdir('t') if -d 't';
+	@INC = ('.', '../lib', '../ext/B/t');
+    } else {
+	unshift @INC, 't';
+	push @INC, "../../t";
+    }
     require Config;
     if (($Config::Config{'extensions'} !~ /\bB\b/) ){
         print "1..0 # Skip -- Perl configured without B module\n";
@@ -13,7 +18,7 @@
 	    "1..0 # Skip: Data::Dumper was not built, needed by OptreeCheck\n";
 	exit 0;
     }
-    require './test.pl';
+    require 'test.pl';
 }
 use OptreeCheck;
 use Config;
Index: ext/B/t/lint.t
===================================================================
--- ext/B/t/lint.t	(revision 18175)
+++ ext/B/t/lint.t	(working copy)
@@ -1,14 +1,19 @@
 #!./perl -w
 
 BEGIN {
-    chdir 't' if -d 't';
-    @INC = qw(../lib);
+    if ($ENV{PERL_CORE}){
+	chdir('t') if -d 't';
+	@INC = ('.', '../lib');
+    } else {
+	unshift @INC, 't';
+	push @INC, "../../t";
+    }
     require Config;
     if (($Config::Config{'extensions'} !~ /\bB\b/) ){
         print "1..0 # Skip -- Perl configured without B module\n";
         exit 0;
     }
-    require './test.pl';
+    require 'test.pl';
 }
 
 plan tests => 15; # adjust also number of skipped tests !
Index: ext/B/t/asmdata.t
===================================================================
--- ext/B/t/asmdata.t	(revision 18175)
+++ ext/B/t/asmdata.t	(working copy)
@@ -1,8 +1,12 @@
 #!./perl -Tw
 
 BEGIN {
-    chdir 't';
-    @INC = '../lib';
+    if ($ENV{PERL_CORE}){
+	chdir('t') if -d 't';
+	@INC = ('.', '../lib');
+    } else {
+	unshift @INC, 't';
+    }
     require Config;
     if (($Config::Config{'extensions'} !~ /\bB\b/) ){
         print "1..0 # Skip -- Perl configured without B module\n";

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About