#
#
$Level = 1;
my $test = 1;
my $planned;
$TODO = 0;
$NO_ENDING = 0;
sub plan {
my $n;
if (@_ == 1) {
$n = shift;
} else {
my %plan = @_;
}
print STDOUT "1..$n\n";
$planned = $n;
}
END {
print STDERR "# Looks like you planned $planned tests but ran $ran.\n";
}
}
# Use this instead of "print STDERR" when outputing failure diagnostic
# messages
sub _diag {
return unless @_;
my @mess = map { /^#/ ? "$_\n" : "# $_\n" }
map { split /\n/ } @_;
}
sub skip_all {
if (@_) {
print STDOUT "1..0 # Skipped: @_\n";
} else {
print STDOUT "1..0\n";
}
exit(0);
}
sub _ok {
# 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;
} else {
}
print STDOUT "$out\n";
unless ($pass) {
_diag "# Failed $where\n";
}
# Ensure that the message is properly escaped.
$test++;
return $pass;
}
sub _where {
return "at $caller[1] line $caller[2]";
}
# DON'T use this for matches. Use like() instead.
sub ok ($@) {
}
sub _q {
my $x = shift;
return 'undef' unless defined $x;
my $q = $x;
$q =~ s/\\/\\\\/;
$q =~ s/'/\\'/;
return "'$q'";
}
sub _qq {
my $x = shift;
};
# keys are the codes \n etc map to, values are 2 char strings such as \n
my %backslash_escape;
foreach my $x (split //, 'nrtfa\\\'"') {
}
# A way to display scalars containing control characters and Unicode.
# Trying to avoid setting $_, or relying on local $_ to work.
sub display {
my @result;
foreach my $x (@_) {
if (defined $x and not ref $x) {
my $y = '';
foreach my $c (unpack("U*", $x)) {
if ($c > 255) {
$y .= sprintf "\\x{%x}", $c;
} elsif ($backslash_escape{$c}) {
$y .= $backslash_escape{$c};
} else {
my $z = chr $c; # Maybe we can get away with a literal...
$z = sprintf "\\%03o", $c if $z =~ /[[:^print:]]/;
$y .= $z;
}
}
$x = $y;
}
return $x unless wantarray;
push @result, $x;
}
return @result;
}
sub is ($$@) {
my $pass;
# undef only matches undef
}
else {
}
unless ($pass) {
}
}
sub isnt ($$@) {
my $pass;
# undef only matches undef
}
else {
}
unless( $pass ) {
"# but it is.\n");
}
}
sub cmp_ok ($$$@) {
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 acutally numerically
# different. Display the numbers if $type isn't a string operator,
# and the numbers are stringwise the same.
# This will also show numbers for some uneeded cases, but will
# definately be helpful for things such as == and <= that fail
}
}
}
# 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 $pass;
# This is a fail, but doesn't need extra diagnostics
# 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 ==
} elsif ($expected == 0) {
# If expected is 0, treat range as absolute
} else {
}
unless ($pass) {
}
}
}
# Note: this isn't quite as fancy as Test::More::like().
sub like ($$@) {
my $pass;
if (ref $expected eq 'Regexp') {
unless ($pass) {
unshift(@mess, "# got '$got'\n",
"# expected /$expected/\n");
}
} else {
unless ($pass) {
unshift(@mess, "# got '$got'\n",
"# expected /$expected/\n");
}
}
}
sub pass {
}
sub fail {
}
sub curr_test {
$test = shift if @_;
return $test;
}
sub next_test {
$test++;
}
# 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;
for (1..$n) {
print STDOUT "ok $test # skip: $why\n";
$test++;
}
local $^W = 0;
last SKIP;
}
sub eq_array {
return 0 unless $#$ra == $#$rb;
for my $i (0..$#$ra) {
}
return 1;
}
sub eq_hash {
my $fail;
# Force a hash recompute if this perl's internals can cache the hash key.
$fail = 1;
}
} else {
", 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->{$_});
$fail = 1;
}
!$fail;
}
sub require_ok ($) {
my ($require) = @_;
eval <<REQUIRE_OK;
require $require;
}
sub use_ok ($) {
my ($use) = @_;
eval <<USE_OK;
use $use;
}
# runperl - Runs a separate perl interpreter.
# Arguments :
# switches => [ command-line switches ]
# prog => one-liner (avoid quotes)
# progs => [ multi-liner (avoid quotes) ]
# progfile => perl script
# stdin => string to feed the stdin
# stderr => redirect stderr to stdout
# args => [ command-line arguments to the perl program ]
# verbose => print the command line
my $is_mswin = $^O eq 'MSWin32';
my $is_netware = $^O eq 'NetWare';
my $is_macos = $^O eq 'MacOS';
my $is_vms = $^O eq 'VMS';
sub _quote_args {
foreach (@$args) {
# In VMS protect with doublequotes because otherwise
# DCL will lowercase -- unless already doublequoted.
$$runperl .= ' ' . $_;
}
}
my %args = @_;
my $runperl = $^X =~ m/\s/ ? qq{"$^X"} : $^X;
if ($is_macos) {
$runperl .= ' -I::lib';
# Use UNIX style error messages instead of MPW style.
}
else {
}
}
local $Level = 2;
}
}
$runperl .= qq ( -e "$prog" );
}
else {
$runperl .= qq ( -e '$prog' );
}
}
$runperl .= qq( "$args{progfile}");
}
# so we don't try to put literal newlines and crs onto the
# command line.
$runperl = qq{$^X -e "print qq(} .
}
elsif ($is_macos) {
# MacOS can only do two processes under MPW at once;
# the test itself is one; we can't do two more, so
# write to temp file
my $stdindisplay = $stdin;
$stdindisplay =~ s/\n/\n\#/g;
print STDERR "# $stdindisplay\n";
}
`$stdin`;
}
else {
$runperl = qq{$^X -e 'print qq(} .
}
}
}
my $runperldisplay = $runperl;
$runperldisplay =~ s/\n/\n\#/g;
print STDERR "# $runperldisplay\n";
}
return $runperl;
}
sub runperl {
my $runperl = &_create_runperl;
return $result;
}
sub DIE {
print STDERR "# @_\n";
exit 1;
}
# A somewhat safer version of the sometimes wrong $^X.
my $Perl;
sub which_perl {
unless (defined $Perl) {
$Perl = $^X;
# VMS should have 'perl' aliased properly
return $Perl if $^O eq 'VMS';
my $exe;
eval "require Config; Config->import";
if ($@) {
warn "test.pl had problems loading Config: $@";
$exe = '';
} else {
}
# This doesn't absolutize the path: beware of future chdirs().
# We could do File::Spec->abs2rel() but that does getcwd()s,
# which is a bit heavyweight to do here.
my $perl = "perl$exe";
eval "require File::Spec";
if ($@) {
warn "test.pl had problems loading File::Spec: $@";
$Perl = "./$perl";
} else {
}
}
# Build up the name of the executable file from the name of
# the command.
}
warn "which_perl: cannot find $Perl from $^X" unless -f $Perl;
# For subcommands to use.
}
return $Perl;
}
sub unlink_all {
foreach my $file (@_) {
1 while unlink $file;
}
}
my $tmpfile = "misctmp000";
1 while -f ++$tmpfile;
END { unlink_all $tmpfile }
#
# _fresh_perl
#
# The $resolve must be a subref that tests the first argument
# for success, or returns the definition of success (e.g. the
# expected scalar) if given no arguments.
#
sub _fresh_perl {
$runperl_args ||= {};
# VMS adjustments
if( $^O eq 'VMS' ) {
# VMS file locking
$prog =~ s{if \(-e _ and -f _ and -r _\)}
{if (-e _ and -f _)}
}
close TEST or die "Cannot close $tmpfile: $!";
my $status = $?;
# Clean up the results into something a bit more predictable.
$results =~ s/\n+$//;
# bison says 'parse error' instead of 'syntax error',
# various yaccs may or may not capitalize 'syntax'.
if ($^O eq 'VMS') {
# some tests will trigger VMS messages that won't be expected
# pipes double these sometimes
$results =~ s/\n\n/\n/g;
}
unless ($pass) {
_diag "# PROG: \n$prog\n";
_diag "# GOT:\n$results\n";
_diag "# STATUS: $status\n";
}
# Use the first line of the program as a name if none was given
unless( $name ) {
}
}
#
# fresh_perl_is
#
# Combination of run_perl() and is().
#
sub fresh_perl_is {
local $Level = 2;
$runperl_args, $name);
}
#
# fresh_perl_like
#
# Combination of run_perl() and like().
#
sub fresh_perl_like {
local $Level = 2;
sub { @_ ?
$expected },
$runperl_args, $name);
}
1;