From 3dc780c6430c7a64b0e3254eb3b16819ea6dff0b Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Mon, 10 Dec 2018 18:00:02 +0100 Subject: [PATCH] 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 Acked-by: Thomas Lamprecht --- test/run_config2command_tests.pl | 36 +++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/test/run_config2command_tests.pl b/test/run_config2command_tests.pl index 3fe48553..0e37c172 100755 --- a/test/run_config2command_tests.pl +++ b/test/run_config2command_tests.pl @@ -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($) { my ($config_fn) = @_; @@ -156,7 +188,9 @@ sub do_test($) { # comment out for easier debugging #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 { file_set_contents($cmd_fn, $cmdline); } -- 2.39.5