Debian Codegraph @

dist/Locale-Maketext/t/30_eval_dollar_at.t

raw
1 use strict;
2 use warnings;
3
4 {
5 package TEST;
6 use parent qw(Locale::Maketext);
7 }
8
9 {
10 package TEST::en;
11 use parent -norequire, qw(TEST);
12 our %Lexicon = (
13 _AUTO => 1,
14 );
15 }
16
17 package main;
18 use strict;
19 use warnings;
20 use Test::More tests => 12;
21
22 my $lh = TEST->get_handle('en');
23 $@ = "foo";
24 is($lh->maketext("This works fine"), "This works fine", "straight forward _AUTO string test");
25 is($@, "foo", q{$@ isn't altered during calls to maketext});
26
27 my $err = eval {
28 $lh->maketext('this is ] an error');
29 };
30 is($err, undef, "no return from eval");
31 like("$@", qr/Unbalanced\s'\]',\sin/ms, '$@ shows that ] was unbalanced');
32
33 # _try_use doesn't pollute $@
34 $@ = 'foo2';
35 is(Locale::Maketext::_try_use("This::module::does::not::exist"), 0, "0 return if module is missing when _try_use is called");
36 is($@, 'foo2', '$@ is unmodified by a failed _try_use');
37
38 # _try_use doesn't pollute $@ for valid call
39 $@ = '';
40 is(Locale::Maketext::_try_use("Locale::Maketext::Guts"), 1, "1 return using valid module Locale::Maketext::Guts");
41 is($@, '', '$@ is clean after failed _try_use');
42
43 # failure_handler_auto handles $@ locally.
44 {
45 $@ = '';
46 my $err = '';
47 $lh->{failure_lex}->{"foo_fail"} = sub {die("fail message");};
48 $err = eval {$lh->failure_handler_auto("foo_fail")};
49 is($err, undef, "die event calling failure_handler on bad code");
50 like($@, qr/^Error in maketexting "foo_fail":/ms, "\$@ is re-written as expected.");
51 }
52
53 $@ = 'foo';
54 is($lh->maketext('Eval error: [_1]', $@), 'Eval error: foo', "Make sure \$@ is localized when passed to maketext");
55 is($@, 'foo', "\$@ wasn't modified during call");