namespace ::Easy::Default
[p5sagit/Log-Contextual.git] / t / log-with-levels.t
CommitLineData
5fd26f45 1use strict;
2use warnings;
3
6ae293d7 4use Log::Contextual qw{:dlog :log with_logger set_logger},
5 -levels => ['custom'];
5fd26f45 6use Log::Contextual::SimpleLogger;
7use Test::More qw(no_plan);
8
9my $logger = DumbLogger->new;
10
11set_logger(sub { $logger });
12
13log_custom { 'fiSMBoC' };
6ae293d7 14is($DumbLogger::var, "fiSMBoC", "custom works");
5fd26f45 15
16my @vars = log_custom { 'fiSMBoC: ' . $_[1] } qw{foo bar baz};
6ae293d7 17is($DumbLogger::var, "fiSMBoC: bar", "log_custom works with input");
18ok(
19 eq_array(\@vars, [qw{foo bar baz}]),
20 "log_custom passes data through correctly"
21);
5fd26f45 22
23my $val = logS_custom { 'fiSMBoC: ' . $_[0] } 'foo';
6ae293d7 24is($DumbLogger::var, "fiSMBoC: foo", "logS_custom works with input");
25is($val, 'foo', "logS_custom passes data through correctly");
5fd26f45 26
27my @foo = Dlog_custom { "Look ma, data: $_" } qw{frew bar baz};
28
29ok(
30 eq_array(\@foo, [qw{frew bar baz}]),
31 "Dlog_custom passes data through correctly"
32);
33is(
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 39my $bar = DlogS_custom { "Look ma, data: $_" }[qw{frew bar baz}];
40ok(eq_array($bar, [qw{frew bar baz}]),
41 'DlogS_custom passes data through correctly');
5fd26f45 42is(
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 49ok(eq_array(\@foo, []), "Dlog_custom passes nothing through correctly");
50is($DumbLogger::var, "nothing: ()", "Output for Dlog_custom is correct");
5fd26f45 51
8112b699 52ok(!main->can($_), "$_ not imported")
6ae293d7 53 for map +("log_$_", "logS_$_"), qw(debug trace warn info error fatal);
5fd26f45 54
55ok(!eval { Log::Contextual->import; 1 }, 'Blank Log::Contextual import dies');
56
57BEGIN {
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}