Skip to content

Commit

Permalink
Tie-File: make some test files give better output
Browse files Browse the repository at this point in the history
For 29_downcopy.t and 29a_upcopy.t, which both just call a function
try() many times with different args, make the 'ok NNN' line and any
diagnotics display the parameters and the line number of the caller.
  • Loading branch information
iabyn committed Feb 25, 2024
1 parent de05a3d commit de42fb9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
22 changes: 15 additions & 7 deletions dist/Tie-File/t/29_downcopy.t
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,14 @@ try(42000, 0, 0); # old=0 , new=0 ; old = new

sub try {
my ($pos, $len, $newlen) = @_;

# try() is called with defined len, but then calls itself again with
# undef $len
my $line = (caller(defined $len ? 0 : 1))[2];
my $desc = sprintf "try(%5s, %5s, %5s) FLEN=%5s called from line %d",
map { defined $_ ? $_ : 'undef' }
$pos, $len, $newlen, $FLEN, $line;

open F, '>', $file or die "Couldn't open file $file: $!";
binmode F;

Expand Down Expand Up @@ -282,13 +290,13 @@ sub try {
undef $o; untie @lines; alarm(0);
if ($err) {
if ($err =~ /^Alarm clock/) {
print STDERR "# $0 Timeout after $alarm_time seconds at test $N\n";
print "not ok $N\n"; $N++;
print "not ok $N\n"; $N++;
print STDERR "# $0 Timeout after $alarm_time seconds at test $N - $desc\n";
print "not ok $N - $desc\n"; $N++;
print "not ok $N - $desc\n"; $N++;
if (defined $len) {
# Fail the tests in the recursive call as well
print "not ok $N\n"; $N++;
print "not ok $N\n"; $N++;
print "not ok $N - $desc\n"; $N++;
print "not ok $N - $desc\n"; $N++;
}
return;
} else {
Expand All @@ -311,9 +319,9 @@ sub try {
for (@ARGS) { $_ = "UNDEF" unless defined }
print "# try(@ARGS) expected file length $xlen, actual $alen!\n";
}
print $actual eq $expected ? "ok $N\n" : "not ok $N\n";
print $actual eq $expected ? "ok $N - $desc\n" : "not ok $N - $desc\n";
$N++;
print $a_retval eq $x_retval ? "ok $N\n" : "not ok $N\n";
print $a_retval eq $x_retval ? "ok $N - $desc\n" : "not ok $N - $desc\n";
$N++;

if (defined $len) {
Expand Down
12 changes: 8 additions & 4 deletions dist/Tie-File/t/29a_upcopy.t
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ try($FLEN-20000, 200, undef);

sub try {
my ($src, $dst, $len) = @_;

my $line = (caller(0))[2];
my $desc = sprintf "try(%5s, %5s, %5s) FLEN=%5s called from line %d",
map { defined $_ ? $_ : 'undef' }
$src, $dst, $len, $FLEN, $line;

open F, '>', $file or die "Couldn't open file $file: $!";
binmode F;

Expand Down Expand Up @@ -138,8 +144,8 @@ sub try {
undef $o; untie @lines; alarm(0);
if ($err) {
if ($err =~ /^Alarm clock/) {
print STDERR "# $0 Timeout after $alarm_time seconds at test $N\n";
print "not ok $N\n"; $N++;
print STDERR "# $0 Timeout after $alarm_time seconds at test $N - $desc\n";
print "not ok $N - $desc\n"; $N++;
return;
} else {
$@ = $err;
Expand All @@ -159,8 +165,6 @@ sub try {
unless ($alen == $xlen) {
print "# try(@_) expected file length $xlen, actual $alen!\n";
}
my $desc = sprintf "try(%d, %d, %s)",
$src, $dst, (defined $len ? $len : "undef");
print $actual eq $expected ? "ok $N - $desc\n" : "not ok $N - $desc\n";
$N++;
}
Expand Down

0 comments on commit de42fb9

Please sign in to comment.