5 unshift @INC, '../blib/lib';
13 use constant SUBTESTS_PER_TESTS => 6;
15 use constant TESTS =>(
16 ["ok", "my warning", "my warning", "standard warning to find"],
17 ["not ok", "my warning", "another warning", "another warning instead of my warning"],
18 ["not ok", "warning general not", "warning general", "quite only a sub warning"],
19 ["not ok", undef, "a warning", "no warning, but expected one"],
20 ["not ok", "a warning", undef, "warning, but didn't expect one"],
21 ["ok", undef, undef, "no warning"],
22 ["ok", '$!"%&/()=', '$!"%&/()=', "warning with crazy letters"],
23 ["not ok", "warning 1|warning 2", "warning1", "more than one warning"]
26 use Test::Builder::Tester tests => TESTS() * SUBTESTS_PER_TESTS;
30 Test::Builder::Tester::color 'on';
32 use constant WARN_LINE => line_num +2;
34 warn $_ for grep $_, split m:\|:, (shift() || "");
37 use constant CARP_LINE => line_num +2;
39 carp $_ for grep $_, split m:\|:, (shift() || "");
42 use constant CARP_LEVELS => (0 .. 2);
43 sub _create_exp_warning {
44 my ($carplevel, $warning) = @_;
45 return $warning if $carplevel == 0;
46 return {carped => $warning} if $carplevel == 1;
47 return {carped => [$warning]} if $carplevel == 2;
50 test_warning_is(@$_) foreach TESTS();
53 my ($ok, $msg, $exp_warning, $testname) = @_;
54 for my $carp (CARP_LEVELS) {
55 *_found_msg = $carp ? *_found_carp_msg : *_found_warn_msg;
56 *_exp_msg = $carp ? *_exp_carp_msg : *_exp_warn_msg;
57 *_make_warn_or_carp = $carp ? *_make_carp : *_make_warn;
58 for my $t (undef, $testname) {
59 test_out "$ok 1" . ($t ? " - $t" : "");
62 test_diag _found_msg($_) for ($msg ? (split m-\|-, $msg) : $msg);
63 test_diag _exp_msg($exp_warning);
65 warning_is {_make_warn_or_carp($msg)} _create_exp_warning($carp, $exp_warning), $t;
66 test_test "$testname (with" . ($_ ? "" : "out") . " a testname)";
74 ? ( join " " => ("found warning:",
80 : "didn't found a warning";
85 ? "expected to find warning: $_[0]"
86 : "didn't expect to find a warning";
91 ? ( join " " => ("found carped warning:",
96 CARP_LINE) ) # Note the difference, that carp msg
97 : "didn't found a warning"; # aren't finished by '.'
102 ? "expected to find carped warning: $_[0]"
103 : "didn't expect to find a warning";