File: log-with-levels.t

package info (click to toggle)
liblog-contextual-perl 0.009001-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 432 kB
  • sloc: perl: 889; makefile: 2
file content (69 lines) | stat: -rw-r--r-- 1,763 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
use strict;
use warnings;

use Log::Contextual qw{:dlog :log with_logger set_logger},
  -levels => ['custom'];
use Log::Contextual::SimpleLogger;
use Test::More;

my $logger = DumbLogger->new;

set_logger(sub { $logger });

log_custom { 'fiSMBoC' };
is($DumbLogger::var, "fiSMBoC", "custom works");

my @vars = log_custom { 'fiSMBoC: ' . $_[1] } qw{foo bar baz};
is($DumbLogger::var, "fiSMBoC: bar", "log_custom works with input");
ok(
  eq_array(\@vars, [qw{foo bar baz}]),
  "log_custom passes data through correctly"
);

my $val = logS_custom { 'fiSMBoC: ' . $_[0] } 'foo';
is($DumbLogger::var, "fiSMBoC: foo", "logS_custom works with input");
is($val, 'foo', "logS_custom passes data through correctly");

my @foo = Dlog_custom { "Look ma, data: $_" } qw{frew bar baz};

ok(
  eq_array(\@foo, [qw{frew bar baz}]),
  "Dlog_custom passes data through correctly"
);
is(
  $DumbLogger::var,
  qq(Look ma, data: "frew"\n"bar"\n"baz"\n),
  "Output for Dlog_custom is correct"
);

my $bar = DlogS_custom { "Look ma, data: $_" }[qw{frew bar baz}];
ok(eq_array($bar, [qw{frew bar baz}]),
  'DlogS_custom passes data through correctly');
like(
  $DumbLogger::var,
  qr(Look ma, data: \[),
  "Output for DlogS_custom is correct"
);

@foo = Dlog_custom { "nothing: $_" } ();
ok(eq_array(\@foo, []), "Dlog_custom passes nothing through correctly");
is($DumbLogger::var, "nothing: ()", "Output for Dlog_custom is correct");

ok(!main->can($_), "$_ not imported")
  for map +("log_$_", "logS_$_"), qw(debug trace warn info error fatal);

ok(!eval { Log::Contextual->import; 1 }, 'Blank Log::Contextual import dies');

BEGIN {

  package DumbLogger;

  our $var;
  sub new { bless {}, 'DumbLogger' }
  sub is_custom { 1 }
  sub custom { $var = $_[1] }

  1;
}

done_testing;