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