File: 55throw.t

package info (click to toggle)
liblog-report-perl 1.40-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 568 kB
  • sloc: perl: 2,905; makefile: 8
file content (45 lines) | stat: -rw-r--r-- 895 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/env perl
# Test throw()

use warnings;
use strict;

use Test::More tests => 9;

use Log::Report undef, syntax => 'SHORT';

eval
{  use POSIX ':locale_h', 'setlocale';  # avoid user's environment
   setlocale(LC_ALL, 'POSIX');
};

# start a new logger
my $text = '';
open my($fh), '>', \$text;

dispatcher close => 'default';
dispatcher FILE => 'out', to => $fh, accept => 'ALL', format => sub {shift};

cmp_ok(length $text, '==', 0, 'file logger');

try { error "test" };
ok($@, 'caugth rethrown error');

my $e1 = $@->wasFatal;
isa_ok($e1, 'Log::Report::Exception');
is($e1->reason, 'ERROR');

my $m1 = $e1->message;
isa_ok($m1, 'Log::Report::Message');

is("$m1", 'test');

# Now, rethrow the exception
try { $e1->throw(reason => 'ALERT') };
ok(!$@, 'caught rethrown, non fatal');

my @e2 = $@->exceptions;
cmp_ok(scalar @e2, '==', 1);
my $e2 = $e2[0];

is("$e2", "alert: test\n");