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