Devel-PPPort

 view release on metacpan or  search on metacpan

t/testutil.pl  view on Meta::CPAN

#
# t/test.pl - most of Test::More functionality without the fuss


# 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;

# Fatalize warnings, so that we don't introduce new warnings.  But on early
# perls the burden of avoiding warnings becomes too large, and someone still
# trying to use such outmoded versions should be willing to accept warnings in
# our test suite.
$SIG{__WARN__} = sub { die "Fatalized: $_[0]" } if $] ge "5.6.0";

# This defines ASCII/UTF-8 vs EBCDIC/UTF-EBCDIC
$::IS_ASCII  = ord 'A' ==  65;

$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 {
	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 {



( run in 2.240 seconds using v1.01-cache-2.11-cpan-b301d465b3d )