Commit | Line | Data |
5fd26f45 |
1 | use strict; |
2 | use warnings; |
3 | |
6ae293d7 |
4 | use Log::Contextual qw{:dlog :log with_logger set_logger}, |
5 | -levels => ['custom']; |
5fd26f45 |
6 | use Log::Contextual::SimpleLogger; |
7 | use Test::More qw(no_plan); |
8 | |
9 | my $logger = DumbLogger->new; |
10 | |
11 | set_logger(sub { $logger }); |
12 | |
13 | log_custom { 'fiSMBoC' }; |
6ae293d7 |
14 | is($DumbLogger::var, "fiSMBoC", "custom works"); |
5fd26f45 |
15 | |
16 | my @vars = log_custom { 'fiSMBoC: ' . $_[1] } qw{foo bar baz}; |
6ae293d7 |
17 | is($DumbLogger::var, "fiSMBoC: bar", "log_custom works with input"); |
18 | ok( |
19 | eq_array(\@vars, [qw{foo bar baz}]), |
20 | "log_custom passes data through correctly" |
21 | ); |
5fd26f45 |
22 | |
23 | my $val = logS_custom { 'fiSMBoC: ' . $_[0] } 'foo'; |
6ae293d7 |
24 | is($DumbLogger::var, "fiSMBoC: foo", "logS_custom works with input"); |
25 | is($val, 'foo', "logS_custom passes data through correctly"); |
5fd26f45 |
26 | |
27 | my @foo = Dlog_custom { "Look ma, data: $_" } qw{frew bar baz}; |
28 | |
29 | ok( |
30 | eq_array(\@foo, [qw{frew bar baz}]), |
31 | "Dlog_custom passes data through correctly" |
32 | ); |
33 | is( |
6ae293d7 |
34 | $DumbLogger::var, |
35 | qq(Look ma, data: "frew"\n"bar"\n"baz"\n), |
5fd26f45 |
36 | "Output for Dlog_custom is correct" |
37 | ); |
38 | |
6ae293d7 |
39 | my $bar = DlogS_custom { "Look ma, data: $_" }[qw{frew bar baz}]; |
40 | ok(eq_array($bar, [qw{frew bar baz}]), |
41 | 'DlogS_custom passes data through correctly'); |
5fd26f45 |
42 | is( |
6ae293d7 |
43 | $DumbLogger::var, |
44 | qq(Look ma, data: [\n "frew",\n "bar",\n "baz"\n]\n), |
5fd26f45 |
45 | "Output for DlogS_custom is correct" |
46 | ); |
47 | |
48 | @foo = Dlog_custom { "nothing: $_" } (); |
6ae293d7 |
49 | ok(eq_array(\@foo, []), "Dlog_custom passes nothing through correctly"); |
50 | is($DumbLogger::var, "nothing: ()", "Output for Dlog_custom is correct"); |
5fd26f45 |
51 | |
8112b699 |
52 | ok(!main->can($_), "$_ not imported") |
6ae293d7 |
53 | for map +("log_$_", "logS_$_"), qw(debug trace warn info error fatal); |
5fd26f45 |
54 | |
55 | ok(!eval { Log::Contextual->import; 1 }, 'Blank Log::Contextual import dies'); |
56 | |
57 | BEGIN { |
6ae293d7 |
58 | |
5fd26f45 |
59 | package DumbLogger; |
60 | |
61 | our $var; |
62 | sub new { bless {}, 'DumbLogger' } |
63 | sub is_custom { 1 } |
64 | sub custom { $var = $_[1] } |
65 | |
66 | 1; |
67 | } |