From 749851eda39056fde2452dc1de1ed089221c5695 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 22 Jul 2013 21:58:17 -0400 Subject: add test for injecting scopes --- t/scope-inject.t | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 t/scope-inject.t diff --git a/t/scope-inject.t b/t/scope-inject.t new file mode 100644 index 0000000..625896f --- /dev/null +++ b/t/scope-inject.t @@ -0,0 +1,48 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; + +BEGIN { + if (!eval { require B::Hooks::EndOfScope }) { + plan skip_all => "B::Hooks::EndOfScope is required for this test"; + } +} + +BEGIN { + package My::Parser; + use Exporter 'import'; + our @EXPORT = 'foo'; + use Parse::Keyword { foo => \&parse_foo }; + + sub foo { $_[0]->() } + sub parse_foo { + lex_read_space; + die "syntax error" unless lex_peek eq '{'; + lex_read; + lex_stuff( + '{' + . 'my $foo = 42;' + . '{' + . 'BEGIN { B::Hooks::EndOfScope::on_scope_end {' + . 'Parse::Keyword::lex_stuff(q[}])' + . '} }' + ); + my $body = parse_block; + return sub { $body }; + } + + $INC{'My/Parser.pm'} = __FILE__; +} + +use My::Parser; + +is(foo { $foo }, 42); +{ + my $warnings; + local $SIG{__WARN__} = sub { $warnings .= $_[0] }; + is(foo { my $foo = 12; $foo }, 12); + is($warnings, undef); +} + +done_testing; -- cgit v1.2.3-54-g00ecf