Exception-Base
view release on metacpan or search on metacpan
t/tlib/Exception/BaseTest.pm view on Meta::CPAN
$self->assert_equals('', $obj->to_string);
$obj->{verbosity} = 1;
$self->assert_equals("Stringify\n", $obj->to_string);
$obj->{verbosity} = 2;
$self->assert_matches(qr/Stringify at .* line \d+.\n/s, $obj->to_string);
$obj->{verbosity} = 3;
$self->assert_matches(qr/Exception::Base: Stringify at .* line \d+\n/s, $obj->to_string);
$obj->{message} = ['%s', 'Stringify'];
$self->assert_matches(qr/Exception::Base: Stringify at .* line \d+\n/s, $obj->to_string);
$obj->{message} = "Ends with EOL\n";
$obj->{value} = 123;
$obj->{verbosity} = 0;
$self->assert_equals('', $obj->to_string);
$obj->{verbosity} = 1;
$self->assert_equals("Ends with EOL\n", $obj->to_string);
$obj->{verbosity} = 2;
$self->assert_equals("Ends with EOL\n", $obj->to_string);
$obj->{verbosity} = 3;
$self->assert_matches(qr/Exception::Base: Ends with EOL\n at .* line \d+\n/s, $obj->to_string);
$obj->{message} = "Stringify";
$obj->{verbosity} = 2;
$obj->{ignore_packages} = [ ];
$obj->{ignore_class} = [ ];
$obj->{ignore_level} = 0;
$obj->{max_arg_len} = 64;
$obj->{max_arg_nums} = 8;
$obj->{max_eval_len} = 0;
$obj->{caller_stack} = [ [ 'main', '-e', 1, 'Exception::Base::throw', 1, undef, undef, undef, 'Exception::Base' ] ];
$obj->{file} = '-e';
$obj->{line} = 1;
$self->assert_equals("Stringify at -e line 1.\n", $obj->to_string);
$obj->{caller_stack} = [
['Package1', 'Package1.pm', 1, 'Package1::func1', 0, undef, undef, undef ],
['Package1', 'Package1.pm', 1, 'Package1::func1', 0, undef, undef, undef ],
['Package2', 'Package2.pm', 2, 'Package2::func2', 1, 1, undef, undef, 1, [], {}, sub {1; }, $self, $obj ],
['Package3', 'Package3.pm', 3, '(eval)', 0, undef, 1, undef ],
['Package4', 'Package4.pm', 4, 'Package4::func4', 0, undef, 'Require', 1 ],
['Package5', 'Package5.pm', 5, 'Package5::func5', 1, undef, undef, undef, "\x{00}", "'\"\\\`\x{0d}\x{c3}", "\x{09}\x{263a}", undef, 123, -123.56, 1, 2, 3 ],
['Package6', '-e', 6, 'Package6::func6', 0, undef, undef, undef ],
['Package7', undef, undef, 'Package7::func7', 0, undef, undef, undef ],
];
$obj->{propagated_stack} = [
['Exception::BaseTest::Propagate1', 'Propagate1.pm', 11],
['Exception::BaseTest::Propagate2', 'Propagate2.pm', 22],
];
$self->assert_equals("Stringify at Package1.pm line 1.\n", $obj->to_string(2));
my $s1 = << 'END';
Exception::Base: Stringify at Package1.pm line 1
\t$_ = Package1::func1 called in package Package1 at Package1.pm line 1
\t$_ = Package1::func1 called in package Package1 at Package1.pm line 1
\t@_ = Package2::func2(1, "ARRAY(0x1234567)", "HASH(0x1234567)", "CODE(0x1234567)", "Exception::BaseTest=HASH(0x1234567)", "Exception::Base=HASH(0x1234567)") called in package Package2 at Package2.pm line 2
\t$_ = eval '1' called in package Package3 at Package3.pm line 3
\t$_ = require Require called in package Package4 at Package4.pm line 4
\t$_ = Package5::func5("\x{00}", "'\"\\\`\x{0d}\x{c3}", "\x{09}\x{263a}", undef, 123, -123.56, 1, ...) called in package Package5 at Package5.pm line 5
\t$_ = Package6::func6 called in package Package6 at -e line 6
\t$_ = Package7::func7 called in package Package7 at unknown line 0
\t...propagated in package Exception::BaseTest::Propagate1 at Propagate1.pm line 11.
\t...propagated in package Exception::BaseTest::Propagate2 at Propagate2.pm line 22.
END
$s1 =~ s/\\t/\t/g;
$obj->{verbosity} = 4;
my $s2 = $obj->to_string;
$s2 =~ s/(ARRAY|HASH|CODE)\(0x\w+\)/$1(0x1234567)/g;
$self->assert_equals($s1, $s2);
$obj->{verbosity} = 2;
$self->assert_equals("Stringify at Package1.pm line 1.\n", $obj->to_string);
$obj->{caller_stack} = [
['Exception::BaseTest::Package1', 'Package1.pm', 1, 'Exception::BaseTest::Package1::func1', 0, undef, undef, undef ],
['Exception::BaseTest::Package1', 'Package1.pm', 1, 'Exception::BaseTest::Package1::func1', 6, 1, undef, undef, 1, 2, 3, 4, 5, 6 ],
['Exception::BaseTest::Package2', 'Package2.pm', 2, 'Exception::BaseTest::Package2::func2', 2, 1, undef, undef, "123456789", "123456789" ],
['Exception::BaseTest::Package3', 'Package3.pm', 3, '(eval)', 0, undef, "123456789", undef ],
];
$obj->{max_arg_nums} = 2;
$obj->{max_arg_len} = 5;
$obj->{max_eval_len} = 5;
my $s4 = << 'END';
Exception::Base: Stringify at Package1.pm line 1
\t$_ = Exception::BaseTest::Package1::func1 called in package Exception::BaseTest::Package1 at Package1.pm line 1
\t@_ = Exception::BaseTest::Package1::func1(1, ...) called in package Exception::BaseTest::Package1 at Package1.pm line 1
\t@_ = Exception::BaseTest::Package2::func2(12..., 12...) called in package Exception::BaseTest::Package2 at Package2.pm line 2
\t$_ = eval '12...' called in package Exception::BaseTest::Package3 at Package3.pm line 3
\t...propagated in package Exception::BaseTest::Propagate1 at Propagate1.pm line 11.
\t...propagated in package Exception::BaseTest::Propagate2 at Propagate2.pm line 22.
END
$s4 =~ s/\\t/\t/g;
$obj->{verbosity} = 4;
my $s5 = $obj->to_string;
$self->assert_equals($s4, $s5);
$obj->{ignore_level} = 1;
my $s6 = << 'END';
Exception::Base: Stringify at Package1.pm line 1
\t@_ = Exception::BaseTest::Package2::func2(12..., 12...) called in package Exception::BaseTest::Package2 at Package2.pm line 2
\t$_ = eval '12...' called in package Exception::BaseTest::Package3 at Package3.pm line 3
\t...propagated in package Exception::BaseTest::Propagate1 at Propagate1.pm line 11.
\t...propagated in package Exception::BaseTest::Propagate2 at Propagate2.pm line 22.
END
$s6 =~ s/\\t/\t/g;
$obj->{verbosity} = 3;
my $s7 = $obj->to_string;
$self->assert_equals($s6, $s7);
$obj->{verbosity} = 2;
$self->assert_equals("Stringify at Package1.pm line 1.\n", $obj->to_string);
( run in 0.668 second using v1.01-cache-2.11-cpan-39bf76dae61 )