1 |
wakaba |
1.1 |
#!/usr/bin/perl |
2 |
wakaba |
1.3 |
use strict; |
3 |
wakaba |
1.1 |
use Message::Util::Error; |
4 |
|
|
use Test::Simple tests => 4; |
5 |
|
|
sub OK ($$) { |
6 |
|
|
my ($result, $expect) = @_; |
7 |
|
|
if ($result eq $expect) { |
8 |
|
|
ok 1; |
9 |
|
|
} else { |
10 |
|
|
ok 0, qq("$result" : "$expect" expected); |
11 |
|
|
} |
12 |
|
|
} |
13 |
|
|
|
14 |
|
|
try { |
15 |
wakaba |
1.2 |
throw Message::Util::Error -type => 'SOMETHING_UNKNOWN'; |
16 |
wakaba |
1.1 |
} catch Message::Util::Error with { |
17 |
|
|
my $err = shift; |
18 |
wakaba |
1.3 |
warn $err->stringify if $^W; |
19 |
wakaba |
1.1 |
OK $err->text, qq("SOMETHING_UNKNOWN": Unknown error); |
20 |
|
|
} except { |
21 |
|
|
OK 1, 0; |
22 |
|
|
} otherwise { |
23 |
|
|
OK 1, 0; |
24 |
|
|
} finally { |
25 |
|
|
OK 1, 1; |
26 |
|
|
}; |
27 |
|
|
OK 1, 1; |
28 |
|
|
|
29 |
|
|
try { |
30 |
wakaba |
1.2 |
throw test_error -type => 'ERR1', param1 => 'VAL1', param2 => 'VAL2'; |
31 |
wakaba |
1.1 |
} catch test_error with { |
32 |
|
|
my $err = shift; |
33 |
|
|
OK $err->text, qq(Param1 "VAL1"; Param2 "VAL2"); |
34 |
|
|
}; |
35 |
|
|
|
36 |
|
|
package test_error; |
37 |
|
|
BEGIN { |
38 |
|
|
our @ISA = 'Message::Util::Error'; |
39 |
|
|
} |
40 |
wakaba |
1.2 |
sub ___error_def () {+{ |
41 |
wakaba |
1.1 |
ERR1 => { |
42 |
|
|
description => q(Param1 "%t(name=>param1);"; Param2 "%t(name=>param2);"), |
43 |
|
|
}, |
44 |
|
|
}} |
45 |
|
|
|
46 |
|
|
|