This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
D:P: Convert to use modern Test functions
authorKarl Williamson <khw@cpan.org>
Fri, 1 Nov 2019 19:09:11 +0000 (13:09 -0600)
committerKarl Williamson <khw@cpan.org>
Fri, 22 Nov 2019 13:49:03 +0000 (06:49 -0700)
This commit copies much of test.pl from blead to replace the Test ones.

These versions are much friendlier to use.  Several .t files required
minor changes to work with these.  pv_tools.t was the only file using
the old obsolete skip() functionality fully.  The new version does not
do a 'last SKIP', for compatibility.

like and unlike were not ported because of the absence of qr// in perls
this is supposed to work on.

And the portions of test.pl that were copied also required a few minor
changes to work back to 5.3.7.

Not all the ported functionality is currently in used.  It may be that
changes will have to be made to it to get it to work; or will have to be
deleted.

42 files changed:
dist/Devel-PPPort/mktests.PL
dist/Devel-PPPort/parts/inc/call
dist/Devel-PPPort/parts/inc/cop
dist/Devel-PPPort/parts/inc/pv_tools
dist/Devel-PPPort/t/01_test.t
dist/Devel-PPPort/t/HvNAME.t
dist/Devel-PPPort/t/MY_CXT.t
dist/Devel-PPPort/t/SvPV.t
dist/Devel-PPPort/t/SvREFCNT.t
dist/Devel-PPPort/t/Sv_set.t
dist/Devel-PPPort/t/call.t
dist/Devel-PPPort/t/cop.t
dist/Devel-PPPort/t/exception.t
dist/Devel-PPPort/t/format.t
dist/Devel-PPPort/t/grok.t
dist/Devel-PPPort/t/gv.t
dist/Devel-PPPort/t/limits.t
dist/Devel-PPPort/t/locale.t
dist/Devel-PPPort/t/mPUSH.t
dist/Devel-PPPort/t/magic.t
dist/Devel-PPPort/t/memory.t
dist/Devel-PPPort/t/mess.t
dist/Devel-PPPort/t/misc.t
dist/Devel-PPPort/t/newCONSTSUB.t
dist/Devel-PPPort/t/newRV.t
dist/Devel-PPPort/t/newSV_type.t
dist/Devel-PPPort/t/newSVpv.t
dist/Devel-PPPort/t/podtest.t
dist/Devel-PPPort/t/ppphtest.t
dist/Devel-PPPort/t/pv_tools.t
dist/Devel-PPPort/t/pvs.t
dist/Devel-PPPort/t/shared_pv.t
dist/Devel-PPPort/t/snprintf.t
dist/Devel-PPPort/t/sprintf.t
dist/Devel-PPPort/t/strlfuncs.t
dist/Devel-PPPort/t/sv_xpvf.t
dist/Devel-PPPort/t/testutil.pl
dist/Devel-PPPort/t/threads.t
dist/Devel-PPPort/t/utf8.t
dist/Devel-PPPort/t/uv.t
dist/Devel-PPPort/t/variables.t
dist/Devel-PPPort/t/warn.t

index ae776c4..217afef 100644 (file)
@@ -92,8 +92,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
index 683887f..bdfe812 100644 (file)
@@ -338,12 +338,6 @@ load_module(flags, name, version, ...)
 
 =tests plan => 86
 
-sub eq_array
-{
-  my($a, $b) = @_;
-  join(':', @$a) eq join(':', @$b);
-}
-
 sub f
 {
   shift;
index 8af91b2..061166a 100644 (file)
@@ -167,7 +167,7 @@ caller_cx(level)
 
 #endif /* 5.6.0 */
 
-=tests plan => 28
+=tests plan => 8
 
 my $package;
 {
@@ -184,7 +184,7 @@ ok($file =~ /cop/i);
 BEGIN {
   if ("$]" < 5.006000) {
     # Skip
-    for (1..28) {
+    for (1..8) {
       ok(1, 1);
     }
     exit;
@@ -223,9 +223,6 @@ for (
 ) {
     my ($sub, $arg, @want) = @$_;
     my @got = $sub->($arg);
-    ok(@got, @want);
-    for (0..$#want) {
-        ok($got[$_], $want[$_]);
-    }
+    ok(eq_array(\@got, \@want));
 }
 
index c51d91a..31b330e 100644 (file)
@@ -262,11 +262,19 @@ ok($r[0], "foobarbaz");
 ok($r[2], $r[3]);
 ok($r[2], '<leftpv_p\retty\nright>');
 ok($r[4], $r[5]);
-skip(ord("A") != 65 ? "Skip for non-ASCII platform" : 0,
-     $r[4], $uni ? 'N\375 Batter\355' : 'N\303\275 Batter\303');
+if(ord("A") == 65) {
+    is($r[4], $uni ? 'N\375 Batter\355' : 'N\303\275 Batter\303');
+}
+else {
+    skip("Skip for non-ASCII platform");
+}
 ok($r[6], $r[7]);
-skip(ord("A") != 65 ? "Skip for non-ASCII platform" : 0,
-     $r[6], $uni ? '\301g\346tis Byrju...' : '\303\201g\303\246t...');
+if(ord("A") == 65) {
+    is($r[6], $uni ? '\301g\346tis Byrju...' : '\303\201g\303\246t...');
+}
+else {
+    skip("Skip for non-ASCII platform");
+}
 
 @r = &Devel::PPPort::pv_display();
 ok($r[0], $r[1]);
index c6fbf3a..0215f90 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
index a3dbf5f..f4dee5f 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
index 416f2a8..7a7ce39 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
index c8ac91c..28d570e 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
index 43e6211..d918e2b 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
index 3066333..d109628 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
index 957a77d..efac739 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
@@ -53,12 +52,6 @@ bootstrap Devel::PPPort;
 
 package main;
 
-sub eq_array
-{
-  my($a, $b) = @_;
-  join(':', @$a) eq join(':', @$b);
-}
-
 sub f
 {
   shift;
index bf886d8..2849a19 100644 (file)
@@ -30,14 +30,13 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
-  if (28) {
+  if (8) {
     load();
-    plan(tests => 28);
+    plan(tests => 8);
   }
 }
 
@@ -68,7 +67,7 @@ ok($file =~ /cop/i);
 BEGIN {
   if ("$]" < 5.006000) {
     # Skip
-    for (1..28) {
+    for (1..8) {
       ok(1, 1);
     }
     exit;
@@ -107,9 +106,6 @@ for (
 ) {
     my ($sub, $arg, @want) = @$_;
     my @got = $sub->($arg);
-    ok(@got, @want);
-    for (0..$#want) {
-        ok($got[$_], $want[$_]);
-    }
+    ok(eq_array(\@got, \@want));
 }
 
index e430a53..6d99402 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
index c6f64d9..2014ed5 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
index bb71bd3..ac5fd34 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
index b522c69..97d4ec2 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
index 9b39ab5..d2dfc7f 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
index a743fd4..67929c4 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
index d9f2bce..75b6605 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
index 17d254b..c2cb4d3 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
index 4be34a3..cf9a038 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
index de42e4e..42e5f31 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
index 0149cc5..e187e1d 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
index 474c999..763df33 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
index 40d05f8..3a873ae 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
index 5082552..01544a9 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
index 6781823..8e7c14d 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
index ded8f9c..7aea495 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
index bbf14b6..17f71f5 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
index d166fac..613e646 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
@@ -66,11 +65,19 @@ ok($r[0], "foobarbaz");
 ok($r[2], $r[3]);
 ok($r[2], '<leftpv_p\retty\nright>');
 ok($r[4], $r[5]);
-skip(ord("A") != 65 ? "Skip for non-ASCII platform" : 0,
-     $r[4], $uni ? 'N\375 Batter\355' : 'N\303\275 Batter\303');
+if(ord("A") == 65) {
+    is($r[4], $uni ? 'N\375 Batter\355' : 'N\303\275 Batter\303');
+}
+else {
+    skip("Skip for non-ASCII platform");
+}
 ok($r[6], $r[7]);
-skip(ord("A") != 65 ? "Skip for non-ASCII platform" : 0,
-     $r[6], $uni ? '\301g\346tis Byrju...' : '\303\201g\303\246t...');
+if(ord("A") == 65) {
+    is($r[6], $uni ? '\301g\346tis Byrju...' : '\303\201g\303\246t...');
+}
+else {
+    skip("Skip for non-ASCII platform");
+}
 
 @r = &Devel::PPPort::pv_display();
 ok($r[0], $r[1]);
index fa748d0..7238262 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
index 2f1c1be..a17f228 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
index 2f6f953..12ac152 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
index ab80af6..cba5ce7 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
index 8b0edc5..1882399 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
index d96ef48..7e4814c 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
index 4fc7d66..0bc0508 100644 (file)
-{
-  my $__ntest;
-  my $__total;
-
-  sub plan {
-    @_ == 2 or die "usage: plan(tests => count)";
-    my $what = shift;
-    $what eq 'tests' or die "cannot plan anything but tests";
-    $__total = shift;
-    defined $__total && $__total > 0 or die "need a positive number of tests";
-    print "1..$__total\n";
-  }
+#
+# t/test.pl - most of Test::More functionality without the fuss
 
-  sub skip {
-    my $reason = shift;
-    ++$__ntest;
-    print "ok $__ntest # skip: $reason\n"
-  }
 
-  sub ok ($;$$) {
-    local($\,$,);
-    my $ok = 0;
-    my $result = shift;
-    if (@_ == 0) {
-      $ok = $result;
+# NOTE:
+#
+# Do not rely on features found only in more modern Perls here, as some CPAN
+# distributions copy this file and must operate on older Perls. Similarly, keep
+# things, simple as this may be run under fairly broken circumstances. For
+# example, increment ($x++) has a certain amount of cleverness for things like
+#
+#   $x = 'zz';
+#   $x++; # $x eq 'aaa';
+#
+# This stands more chance of breaking than just a simple
+#
+#   $x = $x + 1
+#
+# In this file, we use the latter "Baby Perl" approach, and increment
+# will be worked over by t/op/inc.t
+
+$| = 1;
+$Level = 1;
+my $test = 1;
+my $planned;
+my $noplan;
+
+# This defines ASCII/UTF-8 vs EBCDIC/UTF-EBCDIC
+$::IS_ASCII  = ord 'A' ==  65;
+$::IS_EBCDIC = ord 'A' == 193;
+
+$TODO = 0;
+$NO_ENDING = 0;
+$Tests_Are_Passing = 1;
+
+# Use this instead of print to avoid interference while testing globals.
+sub _print {
+    local($\, $", $,) = (undef, ' ', '') if "$]" >= 5.004;
+    print STDOUT @_;
+}
+
+sub _print_stderr {
+    local($\, $", $,) = (undef, ' ', '') if "$]" >= 5.004;
+    print STDERR @_;
+}
+
+sub plan {
+    my $n;
+    if (@_ == 1) {
+       $n = shift;
+       if ($n eq 'no_plan') {
+         undef $n;
+         $noplan = 1;
+       }
     } else {
-      $expected = shift;
-      if (!defined $expected) {
-        $ok = !defined $result;
-      } elsif (!defined $result) {
-        $ok = 0;
-      } elsif (ref($expected) eq 'Regexp') {
-        die "using regular expression objects is not backwards compatible";
-      } else {
-        $ok = $result eq $expected;
-      }
+       my %plan = @_;
+       $plan{skip_all} and skip_all($plan{skip_all});
+       $n = $plan{tests};
+    }
+    _print "1..$n\n" unless $noplan;
+    $planned = $n;
+}
+
+
+# Set the plan at the end.  See Test::More::done_testing.
+sub done_testing {
+    my $n = $test - 1;
+    $n = shift if @_;
+
+    _print "1..$n\n";
+    $planned = $n;
+}
+
+
+END {
+    my $ran = $test - 1;
+    if (!$NO_ENDING) {
+       if (defined $planned && $planned != $ran) {
+           _print_stderr
+               "# Looks like you planned $planned tests but ran $ran.\n";
+       } elsif ($noplan) {
+           _print "1..$ran\n";
+       }
+    }
+}
+
+sub _diag {
+    return unless @_;
+    my @mess = _comment(@_);
+    $TODO ? _print(@mess) : _print_stderr(@mess);
+}
+
+# Use this instead of "print STDERR" when outputting failure diagnostic
+# messages
+sub diag {
+    _diag(@_);
+}
+
+# Use this instead of "print" when outputting informational messages
+sub note {
+    return unless @_;
+    _print( _comment(@_) );
+}
+
+sub _comment {
+    return map { /^#/ ? "$_\n" : "# $_\n" }
+           map { split /\n/ } @_;
+}
+
+sub _have_dynamic_extension {
+    my $extension = shift;
+    unless (eval {require Config; 1}) {
+       warn "test.pl had problems loading Config: $@";
+       return 1;
+    }
+    $extension =~ s!::!/!g;
+    return 1 if ($Config::Config{extensions} =~ /\b$extension\b/);
+}
+
+sub skip_all {
+    if (@_) {
+        _print "1..0 # Skip @_\n";
+    } else {
+       _print "1..0\n";
+    }
+    exit(0);
+}
+
+sub BAIL_OUT {
+    my ($reason) = @_;
+    _print("Bail out!  $reason\n");
+    exit 255;
+}
+
+sub _ok {
+    my ($pass, $where, $name, @mess) = @_;
+    # Do not try to microoptimize by factoring out the "not ".
+    # VMS will avenge.
+    my $out;
+    if ($name) {
+        # escape out '#' or it will interfere with '# skip' and such
+        $name =~ s/#/\\#/g;
+       $out = $pass ? "ok $test - $name" : "not ok $test - $name";
+    } else {
+       $out = $pass ? "ok $test" : "not ok $test";
+    }
+
+    if ($TODO) {
+       $out = $out . " # TODO $TODO";
+    } else {
+       $Tests_Are_Passing = 0 unless $pass;
+    }
+
+    _print "$out\n";
+
+    if ($pass) {
+       note @mess; # Ensure that the message is properly escaped.
+    }
+    else {
+       my $msg = "# Failed test $test - ";
+       $msg.= "$name " if $name;
+       $msg .= "$where\n";
+       _diag $msg;
+       _diag @mess;
+    }
+
+    $test = $test + 1; # don't use ++
+
+    return $pass;
+}
+
+sub _where {
+    my @caller = caller($Level);
+    return "at $caller[1] line $caller[2]";
+}
+
+sub ok ($@) {
+    if (@_ > 1) {   # ok() really was modern 'is', though limited
+        local $Level = $Level + 1;
+        return is(@_);
     }
-    ++$__ntest;
-    if ($ok) {
-      print "ok $__ntest\n"
+    my ($pass, $name, @mess) = @_;
+    _ok($pass, _where(), $name, @mess);
+}
+
+sub _q {
+    my $x = shift;
+    return 'undef' unless defined $x;
+    my $q = $x;
+    $q =~ s/\\/\\\\/g;
+    $q =~ s/'/\\'/g;
+    return "'$q'";
+}
+
+sub _qq {
+    my $x = shift;
+    return defined $x ? '"' . display ($x) . '"' : 'undef';
+};
+
+# Support pre-5.10 Perls, for the benefit of CPAN dists that copy this file.
+# Note that chr(90) exists in both ASCII ("Z") and EBCDIC ("!").
+my $chars_template = defined(eval { pack "W*", 90 }) ? "W*" : "U*";
+eval 'sub re::is_regexp { ref($_[0]) eq "Regexp" }'
+    if !defined &re::is_regexp;
+
+# keys are the codes \n etc map to, values are 2 char strings such as \n
+my %backslash_escape;
+my $x;
+foreach $x (split //, 'nrtfa\\\'"') {
+    $backslash_escape{ord eval "\"\\$x\""} = "\\$x";
+}
+# A way to display scalars containing control characters and Unicode.
+# Trying to avoid setting $_, or relying on local $_ to work.
+sub display {
+    my @result;
+    my $x;
+    foreach $x (@_) {
+        if (defined $x and not ref $x) {
+            my $y = '';
+            my $c;
+            foreach $c (unpack($chars_template, $x)) {
+                if ($c > 255) {
+                    $y = $y . sprintf "\\x{%x}", $c;
+                } elsif ($backslash_escape{$c}) {
+                    $y = $y . $backslash_escape{$c};
+                } else {
+                    my $z = chr $c; # Maybe we can get away with a literal...
+                    my $is_printable = ($::IS_ASCII)
+                        ? $c  >= ord(" ") && $c <= ord("~")
+                        : $z !~ /[^[:^print:][:^ascii:]]/;
+                            # /[::]/ was introduced before non-ASCII support
+                            # The pattern above is equivalent (by de Morgan's
+                            # laws) to:
+                            #     $z !~ /(?[ [:print:] & [:ascii:] ])/
+                            # or, $z is not an ascii printable character
+
+                    unless ($is_printable) {
+                        # Use octal for characters with small ordinals that
+                        # are traditionally expressed as octal: the controls
+                        # below space, which on EBCDIC are almost all the
+                        # controls, but on ASCII don't include DEL nor the C1
+                        # controls.
+                        if ($c < ord " ") {
+                            $z = sprintf "\\%03o", $c;
+                        } else {
+                            $z = sprintf "\\x{%x}", $c;
+                        }
+                    }
+                    $y = $y . $z;
+                }
+            }
+            $x = $y;
+        }
+        return $x unless wantarray;
+        push @result, $x;
+    }
+    return @result;
+}
+
+sub is ($$@) {
+    my ($got, $expected, $name, @mess) = @_;
+
+    my $pass;
+    if( !defined $got || !defined $expected ) {
+        # undef only matches undef
+        $pass = !defined $got && !defined $expected;
+    }
+    else {
+        $pass = $got eq $expected;
+    }
+
+    unless ($pass) {
+       unshift(@mess, "#      got "._qq($got)."\n",
+                      "# expected "._qq($expected)."\n");
+    }
+    _ok($pass, _where(), $name, @mess);
+}
+
+sub isnt ($$@) {
+    my ($got, $isnt, $name, @mess) = @_;
+
+    my $pass;
+    if( !defined $got || !defined $isnt ) {
+        # undef only matches undef
+        $pass = defined $got || defined $isnt;
     }
     else {
-      print "not ok $__ntest\n"
+        $pass = $got ne $isnt;
+    }
+
+    unless( $pass ) {
+        unshift(@mess, "# it should not be "._qq($got)."\n",
+                       "# but it is.\n");
     }
+    _ok($pass, _where(), $name, @mess);
+}
+
+sub cmp_ok ($$$@) {
+    my($got, $type, $expected, $name, @mess) = @_;
+
+    my $pass;
+    {
+        local $^W = 0;
+        local($@,$!);   # don't interfere with $@
+                        # eval() sometimes resets $!
+        $pass = eval "\$got $type \$expected";
+    }
+    unless ($pass) {
+        # It seems Irix long doubles can have 2147483648 and 2147483648
+        # that stringify to the same thing but are actually numerically
+        # different. Display the numbers if $type isn't a string operator,
+        # and the numbers are stringwise the same.
+        # (all string operators have alphabetic names, so tr/a-z// is true)
+        # This will also show numbers for some unneeded cases, but will
+        # definitely be helpful for things such as == and <= that fail
+        if ($got eq $expected and $type !~ tr/a-z//) {
+            unshift @mess, "# $got - $expected = " . ($got - $expected) . "\n";
+        }
+        unshift(@mess, "#      got "._qq($got)."\n",
+                       "# expected $type "._qq($expected)."\n");
+    }
+    _ok($pass, _where(), $name, @mess);
+}
+
+# Check that $got is within $range of $expected
+# if $range is 0, then check it's exact
+# else if $expected is 0, then $range is an absolute value
+# otherwise $range is a fractional error.
+# Here $range must be numeric, >= 0
+# Non numeric ranges might be a useful future extension. (eg %)
+sub within ($$$@) {
+    my ($got, $expected, $range, $name, @mess) = @_;
+    my $pass;
+    if (!defined $got or !defined $expected or !defined $range) {
+        # This is a fail, but doesn't need extra diagnostics
+    } elsif ($got !~ tr/0-9// or $expected !~ tr/0-9// or $range !~ tr/0-9//) {
+        # This is a fail
+        unshift @mess, "# got, expected and range must be numeric\n";
+    } elsif ($range < 0) {
+        # This is also a fail
+        unshift @mess, "# range must not be negative\n";
+    } elsif ($range == 0) {
+        # Within 0 is ==
+        $pass = $got == $expected;
+    } elsif ($expected == 0) {
+        # If expected is 0, treat range as absolute
+        $pass = ($got <= $range) && ($got >= - $range);
+    } else {
+        my $diff = $got - $expected;
+        $pass = abs ($diff / $expected) < $range;
+    }
+    unless ($pass) {
+        if ($got eq $expected) {
+            unshift @mess, "# $got - $expected = " . ($got - $expected) . "\n";
+        }
+       unshift@mess, "#      got "._qq($got)."\n",
+                     "# expected "._qq($expected)." (within "._qq($range).")\n";
+    }
+    _ok($pass, _where(), $name, @mess);
+}
+
+sub pass {
+    _ok(1, '', @_);
+}
+
+sub fail {
+    _ok(0, _where(), @_);
+}
+
+sub curr_test {
+    $test = shift if @_;
+    return $test;
+}
+
+sub next_test {
+  my $retval = $test;
+  $test = $test + 1; # don't use ++
+  $retval;
+}
+
+# Note: can't pass multipart messages since we try to
+# be compatible with Test::More::skip().
+sub skip {
+    my $why = shift;
+    my $n   = @_ ? shift : 1;
+    my $bad_swap;
+    my $both_zero;
+    $n = 1 if $n == 0;  # XXX Temporary
+    {
+      local $^W = 0;
+      $bad_swap = $why > 0 && $n == 0;
+      $both_zero = $why == 0 && $n == 0;
+    }
+    if ($bad_swap || $both_zero || @_) {
+      my $arg = "'$why', '$n'";
+      if (@_) {
+        $arg .= join(", ", '', map { qq['$_'] } @_);
+      }
+      die qq[$0: expected skip(why, count), got skip($arg)\n];
+    }
+    for (1..$n) {
+        _print "ok $test # skip $why\n";
+        $test = $test + 1;
+    }
+    local $^W = 0;
+    #last SKIP;
+}
+
+sub eq_array {
+    my ($ra, $rb) = @_;
+    return 0 unless $#$ra == $#$rb;
+    my $i;
+    for $i (0..$#$ra) {
+       next     if !defined $ra->[$i] && !defined $rb->[$i];
+       return 0 if !defined $ra->[$i];
+       return 0 if !defined $rb->[$i];
+       return 0 unless $ra->[$i] eq $rb->[$i];
+    }
+    return 1;
+}
+
+sub eq_hash {
+  my ($orig, $suspect) = @_;
+  my $fail;
+  while (my ($key, $value) = each %$suspect) {
+    # Force a hash recompute if this perl's internals can cache the hash key.
+    $key = "" . $key;
+    if (exists $orig->{$key}) {
+      if (
+        defined $orig->{$key} != defined $value
+        || (defined $value && $orig->{$key} ne $value)
+      ) {
+        _print "# key ", _qq($key), " was ", _qq($orig->{$key}),
+                     " now ", _qq($value), "\n";
+        $fail = 1;
+      }
+    } else {
+      _print "# key ", _qq($key), " is ", _qq($value),
+                   ", not in original.\n";
+      $fail = 1;
+    }
+  }
+  foreach (keys %$orig) {
+    # Force a hash recompute if this perl's internals can cache the hash key.
+    $_ = "" . $_;
+    next if (exists $suspect->{$_});
+    _print "# key ", _qq($_), " was ", _qq($orig->{$_}), " now missing.\n";
+    $fail = 1;
   }
+  !$fail;
 }
 
 1;
index 074ea34..67a3b44 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
index fc494ac..a74ad21 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
index 0003403..39e44be 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
index d2e7349..842b75c 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }
 
index 3d21251..0707e76 100644 (file)
@@ -30,8 +30,7 @@ BEGIN {
   die qq[Cannot find "$FindBin::Bin/../parts/inc"] unless -d "$FindBin::Bin/../parts/inc";
 
   sub load {
-    eval "use Test";
-    require 'testutil.pl' if $@;
+    require 'testutil.pl';
     require 'inctools';
   }