selftest/subunit: Add diff command that can diff two subunit streams.
[ira/wip.git] / selftest / Subunit / Diff.pm
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
5
6 package Subunit::Diff;
7
8 use strict;
9
10 use Subunit qw(parse_results);
11
12 sub control_msg() { }
13 sub report_time($$) { }
14
15 sub output_msg($$)
16 {
17         my ($self, $msg) = @_;
18
19         # No output for now, perhaps later diff this as well ?
20 }
21
22 sub start_test($$)
23 {
24         my ($self, $testname) = @_;
25 }
26
27 sub end_test($$$$$)
28 {
29         my ($self, $testname, $result, $unexpected, $reason) = @_;
30
31         $self->{$testname} = $result;
32 }
33
34 sub skip_testsuite($;$) { } 
35 sub start_testsuite($;$) { }
36 sub end_testsuite($$;$) { }
37 sub testsuite_count($$) { }
38
39 sub new {
40         my ($class) = @_;
41
42         my $self = { 
43         };
44         bless($self, $class);
45 }
46
47 sub diff($$)
48 {
49         my ($fh1, $fh2) = @_;
50         my $ret = {};
51         my $statistics = {
52                 TESTS_UNEXPECTED_OK => 0,
53                 TESTS_EXPECTED_OK => 0,
54                 TESTS_UNEXPECTED_FAIL => 0,
55                 TESTS_EXPECTED_FAIL => 0,
56                 TESTS_ERROR => 0,
57                 TESTS_SKIP => 0,
58         };
59         my $old = new Subunit::Diff();
60         parse_results($old, $statistics, $fh1);
61         my $new = new Subunit::Diff();
62         parse_results($new, $statistics, $fh2);
63
64         foreach my $testname (keys %$old) {
65                 if ($new->{$testname} ne $old->{$testname}) {
66                         $ret->{$testname} = [$old->{$testname}, $new->{$testname}];
67                 }
68         }
69
70         return $ret;
71 }
72
73 1;