mirror of
https://git.proxmox.com/git/qemu-server
synced 2025-10-04 12:11:09 +00:00
t/cfg2cmd: replace is_deeply with diff
(The diff() sub is copied from our pve-common's network interfaces test scripts) Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com> Acked-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
a774013569
commit
3dc780c643
@ -125,6 +125,38 @@ $qemu_server_config->mock(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
sub diff($$) {
|
||||||
|
my ($a, $b) = @_;
|
||||||
|
return if $a eq $b;
|
||||||
|
|
||||||
|
my ($ra, $wa) = POSIX::pipe();
|
||||||
|
my ($rb, $wb) = POSIX::pipe();
|
||||||
|
my $ha = IO::Handle->new_from_fd($wa, 'w');
|
||||||
|
my $hb = IO::Handle->new_from_fd($wb, 'w');
|
||||||
|
|
||||||
|
open my $diffproc, '-|', 'diff', '-up', "/dev/fd/$ra", "/dev/fd/$rb"
|
||||||
|
or die "failed to run program 'diff': $!";
|
||||||
|
POSIX::close($ra);
|
||||||
|
POSIX::close($rb);
|
||||||
|
|
||||||
|
open my $f1, '<', \$a;
|
||||||
|
open my $f2, '<', \$b;
|
||||||
|
my ($line1, $line2);
|
||||||
|
do {
|
||||||
|
$ha->print($line1) if defined($line1 = <$f1>);
|
||||||
|
$hb->print($line2) if defined($line2 = <$f2>);
|
||||||
|
} while (defined($line1 // $line2));
|
||||||
|
close $f1;
|
||||||
|
close $f2;
|
||||||
|
close $ha;
|
||||||
|
close $hb;
|
||||||
|
|
||||||
|
local $/ = undef;
|
||||||
|
my $diff = <$diffproc>;
|
||||||
|
close $diffproc;
|
||||||
|
die "files differ:\n$diff";
|
||||||
|
}
|
||||||
|
|
||||||
sub do_test($) {
|
sub do_test($) {
|
||||||
my ($config_fn) = @_;
|
my ($config_fn) = @_;
|
||||||
|
|
||||||
@ -156,7 +188,9 @@ sub do_test($) {
|
|||||||
# comment out for easier debugging
|
# comment out for easier debugging
|
||||||
#file_set_contents("$cmd_fn.tmp", $cmdline);
|
#file_set_contents("$cmd_fn.tmp", $cmdline);
|
||||||
|
|
||||||
is_deeply($cmd, $cmd_expected, "$testname")
|
my $exp = join("\n", @$cmd_expected);
|
||||||
|
my $got = join("\n", @$cmd);
|
||||||
|
diff($exp, $got);
|
||||||
} else {
|
} else {
|
||||||
file_set_contents($cmd_fn, $cmdline);
|
file_set_contents($cmd_fn, $cmdline);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user