format-subunit: Improve formatting, simplify code.
[Samba/eduardoll.git] / selftest / Subunit / Diff.pm
blobde251b37b3e9ad163f278ffcec90286583d80c00
1 #!/usr/bin/perl
2 # Diff two subunit streams
3 # Copyright (C) Jelmer Vernooij <jelmer@samba.org>
4 # Published under the GNU GPL, v3 or later
6 package Subunit::Diff;
8 use strict;
10 use Subunit qw(parse_results);
12 sub control_msg() { }
13 sub report_time($$) { }
15 sub output_msg($$)
17 my ($self, $msg) = @_;
19 # No output for now, perhaps later diff this as well ?
22 sub start_test($$)
24 my ($self, $testname) = @_;
27 sub end_test($$$$$)
29 my ($self, $testname, $result, $unexpected, $reason) = @_;
31 $self->{$testname} = $result;
34 sub skip_testsuite($;$) { }
35 sub start_testsuite($;$) { }
36 sub end_testsuite($$;$) { }
37 sub testsuite_count($$) { }
39 sub new {
40 my ($class) = @_;
42 my $self = {
44 bless($self, $class);
47 sub from_file($)
49 my ($path) = @_;
50 my $statistics = {
51 TESTS_UNEXPECTED_OK => 0,
52 TESTS_EXPECTED_OK => 0,
53 TESTS_UNEXPECTED_FAIL => 0,
54 TESTS_EXPECTED_FAIL => 0,
55 TESTS_ERROR => 0,
56 TESTS_SKIP => 0,
59 my $ret = new Subunit::Diff();
60 open(IN, $path) or return;
61 parse_results($ret, $statistics, *IN);
62 close(IN);
63 return $ret;
66 sub diff($$)
68 my ($old, $new) = @_;
69 my $ret = {};
71 foreach my $testname (keys %$old) {
72 if ($new->{$testname} ne $old->{$testname}) {
73 $ret->{$testname} = [$old->{$testname}, $new->{$testname}];
77 return $ret;