File: 12missing.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 (47 lines) | stat: -rw-r--r-- 1,076 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/env perl
# Try reporting of misisng parameter.

use warnings;
use strict;
use lib 'lib', '../lib';

use Test::More;

use Log::Report;   # no domains, no translator
use Scalar::Util qw/refaddr/;

dispatcher close => 'default';

my $a = __x"testA {a}", a => undef;
isa_ok($a, 'Log::Report::Message');

is $a->toString, "testA undef";

### warn on normal message
my $linenr  = __LINE__ + 1;
my $b       = __x"testB {b}";

my $bs      = try { $b->toString };
(my $warning) = $@->exceptions;
isa_ok $warning, 'Log::Report::Exception';

is $bs, "testB undef";
is $warning->reason, 'WARNING';
is $warning->message,
   "Missing key 'b' in format 'testB {b}', file $0 line $linenr";

### warn on exception
$linenr     = __LINE__ + 1;
try { error __x"testC {c}" };
my $error   = $@->wasFatal;

my $cs      = try { $error->toString };
($warning)  = $@->exceptions;
isa_ok $warning, 'Log::Report::Exception';

is $cs, "error: testC undef\n";
is $warning->reason, 'WARNING';
is $warning->message,
   "Missing key 'c' in format 'testC {c}', file $0 line $linenr";

done_testing;