File: reporter.t

package info (click to toggle)
libbadger-perl 0.16-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,400 kB
  • sloc: perl: 11,004; makefile: 9
file content (90 lines) | stat: -rw-r--r-- 2,084 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#============================================================= -*-perl-*-
#
# t/log/reporter.t
#
# Test the Badger::Reporter module, a new base class for Badger::Log,
# Badger::Test::Manager, and maybe a few other things.
#
# Copyright (C) 2005-2008 Andy Wardley.  All Rights Reserved.
#
# This is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
#
#========================================================================

use strict;
use warnings;
use lib qw( ./lib ../lib ../../lib );
use Badger::Test
    skip  => 'Still in development',
    tests => 40,
    debug => 'Badger::Reporter',
    args  => \@ARGV;

use Badger::Reporter;
use constant REPORTER => 'Badger::Reporter';

pass( 'Loaded ' . REPORTER );

my $reporter = REPORTER->new(
    events => [
        { name    => 'foo',
          colour  => 'green',
          message => 'FOO: %s',
          summary => '%s foo events',
          verbose => 0,
        },
        'bar'
    ],
);

$reporter->foo('the foo happened');
$reporter->foo('the foo happened again');

$reporter->bar('the bar happened');
$reporter->bar('the bar happened again');

print $reporter->summary;


#-----------------------------------------------------------------------
# subclass
#-----------------------------------------------------------------------

package My::Reporter;

use base 'Badger::Reporter';

our $EVENTS = [
    { 
        name    => 'wiz',
        colour  => 'green',
        message => 'WIZ: %s',
        summary => '%s wizzy wiz events',
        verbose => 1,
    },
    { 
        name    => 'waz',
        colour  => 'red',
        message => 'WAZ: %s',
        summary => '%s wazzy waz events',
        verbose => 1,
    },
];

our $MESSAGES = {
    missing => 'You forget to bring the %s',
};

package main;

print "\n\n";

my $reporter = My::Reporter->new( verbose => 1 );

$reporter->wiz('number one');
$reporter->waz('number two');
$reporter->wiz('buckle');
$reporter->waz('my shoe');
$reporter->wiz_msg( missing => 'wizzyment' );
$reporter->waz_msg( missing => 'wazzyment' );