summaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-07-23 11:46:07 -0400
committerJesse Luehrs <doy@tozt.net>2013-07-23 11:46:07 -0400
commit310ba62c846379ad914942e36b9111084a364899 (patch)
treeba10e262aa8df6ab3601298e6e0c50dd63b0ac36 /t
parent61549ba2da59230f7eb8b53745ea25729f7b1eb9 (diff)
downloadparse-keyword-310ba62c846379ad914942e36b9111084a364899.tar.gz
parse-keyword-310ba62c846379ad914942e36b9111084a364899.zip
actually, throw an exception on parse errors
Diffstat (limited to 't')
-rw-r--r--t/error.t36
1 files changed, 31 insertions, 5 deletions
diff --git a/t/error.t b/t/error.t
index 08a478a..4e5b70d 100644
--- a/t/error.t
+++ b/t/error.t
@@ -7,10 +7,13 @@ my $got_code;
BEGIN {
package My::Parser;
use Exporter 'import';
- our @EXPORT = 'foo';
- use Parse::Keyword { foo => \&parse_foo };
+ our @EXPORT = ('foo', 'bar');
+ use Parse::Keyword {
+ foo => \&parse_foo,
+ bar => \&parse_bar,
+ };
- sub foo {}
+ sub foo { 1 }
sub parse_foo {
lex_read_space;
my $code = parse_block;
@@ -18,16 +21,39 @@ BEGIN {
return sub {};
}
+ sub bar { 1 }
+ sub parse_bar {
+ lex_read_space;
+ my $code = eval { parse_block };
+ $got_code = $code ? 1 : 0;
+ return sub {};
+ }
+
$INC{'My/Parser.pm'} = __FILE__;
}
use My::Parser;
-eval "foo";
+ok(!eval "foo");
+ok($@);
+ok(!$got_code);
+ok(eval "foo { }");
+ok(!$@);
+ok($got_code);
+ok(!eval 'foo { $baz }');
+like($@, qr/^Global symbol "\$baz" requires explicit package name/);
+
+# even in an eval, unrecoverable errors still throw, because the parser state
+# is now too confused to continue - the error will be thrown after normal
+# parsing continues
+ok(!eval "bar");
ok($@);
ok(!$got_code);
-eval "foo { }";
+ok(eval "bar { }");
ok(!$@);
ok($got_code);
+# but recoverable errors no longer throw
+ok(eval 'bar { $baz }');
+is($@, '');
done_testing;