runtests: move showdiff into runtests.pl

It's not used anywhere else.
This commit is contained in:
Dan Fandrich 2023-04-21 11:10:22 -07:00
parent 20fa5b74a5
commit a8706fd8d0
2 changed files with 48 additions and 47 deletions

View File

@ -31,16 +31,15 @@ BEGIN {
use base qw(Exporter);
our @EXPORT = qw(
getpartattr
getpart
partexists
loadtest
fulltest
striparray
compareparts
writearray
fulltest
getpart
getpartattr
loadarray
showdiff
loadtest
partexists
striparray
writearray
);
}
@ -356,44 +355,5 @@ sub loadarray {
return @array;
}
# Given two array references, this function will store them in two temporary
# files, run 'diff' on them, store the result and return the diff output!
sub showdiff {
my ($logdir, $firstref, $secondref)=@_;
my $file1="$logdir/check-generated";
my $file2="$logdir/check-expected";
open(my $temp, ">", "$file1") || die "Failure writing diff file";
for(@$firstref) {
my $l = $_;
$l =~ s/\r/[CR]/g;
$l =~ s/\n/[LF]/g;
$l =~ s/([^\x20-\x7f])/sprintf "%%%02x", ord $1/eg;
print $temp $l;
print $temp "\n";
}
close($temp) || die "Failure writing diff file";
open($temp, ">", "$file2") || die "Failure writing diff file";
for(@$secondref) {
my $l = $_;
$l =~ s/\r/[CR]/g;
$l =~ s/\n/[LF]/g;
$l =~ s/([^\x20-\x7f])/sprintf "%%%02x", ord $1/eg;
print $temp $l;
print $temp "\n";
}
close($temp) || die "Failure writing diff file";
my @out = `diff -u $file2 $file1 2>/dev/null`;
if(!$out[0]) {
@out = `diff -c $file2 $file1 2>/dev/null`;
}
return @out;
}
1;

View File

@ -297,6 +297,47 @@ sub cleardir {
return $done;
}
#######################################################################
# Given two array references, this function will store them in two temporary
# files, run 'diff' on them, store the result and return the diff output!
sub showdiff {
my ($logdir, $firstref, $secondref)=@_;
my $file1="$logdir/check-generated";
my $file2="$logdir/check-expected";
open(my $temp, ">", "$file1") || die "Failure writing diff file";
for(@$firstref) {
my $l = $_;
$l =~ s/\r/[CR]/g;
$l =~ s/\n/[LF]/g;
$l =~ s/([^\x20-\x7f])/sprintf "%%%02x", ord $1/eg;
print $temp $l;
print $temp "\n";
}
close($temp) || die "Failure writing diff file";
open($temp, ">", "$file2") || die "Failure writing diff file";
for(@$secondref) {
my $l = $_;
$l =~ s/\r/[CR]/g;
$l =~ s/\n/[LF]/g;
$l =~ s/([^\x20-\x7f])/sprintf "%%%02x", ord $1/eg;
print $temp $l;
print $temp "\n";
}
close($temp) || die "Failure writing diff file";
my @out = `diff -u $file2 $file1 2>/dev/null`;
if(!$out[0]) {
@out = `diff -c $file2 $file1 2>/dev/null`;
}
return @out;
}
#######################################################################
# compare test results with the expected output, we might filter off
# some pattern that is allowed to differ, output test results