Function returning data from bug-tracker


Look at the code that generates the bug reports you'll see that testing the 4th return value - which is quite complex already - is hard. We cannot test against a fixed hash as some of the values are totally dynamic (e.g. a timestamp).

examples/test-more/lib/MyBugs.pm
package MyBugs;
use strict;
use warnings FATAL => 'all';

our $VERSION = '0.01';

use base 'Exporter';
our @EXPORT = qw(fetch_data_from_bug_tracking_system);

=head2 fetch_data_from_bug_tracking_system

fake the behavior of a bug tracking system by returning various constructs

=cut
sub fetch_data_from_bug_tracking_system {
    my @sets = (
        {   bugs     => 3,
            errors   => 6,
            failures => 8,
            warnings => 1,
        },
        {   bugs     => 3,
            errors   => 9,
            failures => 8,
            warnings => 1,
        },
        {   bogs     => 3,
            erors    => 9,
            failures => 8,
            warnings => 1,
        },
        {   bugs     => 'many',
            errors   => 6,
            failures => 8,
            warnings => 1,
        },
        {
            bugs => [
                {
                    ts   => time,
                    name => "System bug",
                    severity => 3,
                },
                {
                    ts    => time - int rand(100),
                    name  => "Incorrect severity bug",
                    severity => "extreme",
                },
                {
                    ts    => time - int rand(200),
                    name  => "Missing severity bug",
                },
            ],
        },
    );
    my $h = $sets[shift];
    return %$h;
}


1;