Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Bug for recursive validation failure with pure Perl code

  • Loading branch information...
commit f7829e2f60ffb6141b909fd5c1d05e78f7ef5831 1 parent 96e3c90
@autarch authored
Showing with 51 additions and 0 deletions.
  1. +51 −0 t/34-recursive-validation.t
View
51 t/34-recursive-validation.t
@@ -0,0 +1,51 @@
+use strict;
+use warnings;
+
+use Test::Fatal;
+use Test::More;
+
+{
+ package Foo;
+
+ use Params::Validate qw( validate SCALAR );
+
+ Params::Validate::validation_options( allow_extra => 1 );
+
+ sub test_foo {
+ my %p = validate( @_, { arg1 => { type => SCALAR } } );
+ print "test foo\n";
+ }
+}
+
+{
+ package Bar;
+
+ use Params::Validate qw( validate SCALAR );
+ Params::Validate::validation_options( allow_extra => 0 );
+
+ sub test_bar {
+
+ # catch die signal
+ local $SIG{__DIE__} = sub {
+
+ # we died from within Params::Validate (because of wrong_Arg) we call
+ # Foo::test_foo with OK args, but it'll die, because
+ # Params::ValidatePP::options is still set to the options of the Bar
+ # package, and so it won't retreive the one from Foo.
+ Foo::test_foo( arg1 => 1, extra_arg => 2 );
+ };
+
+ # this will die because the arg received is 'wrong_arg'
+ my %p = validate( @_, { arg1 => { type => SCALAR } } );
+ }
+}
+
+# This bug only manifested with the pure Perl code because of its use of local
+# to remember the per-package options.
+unlike(
+ exception { Bar::test_bar( bad_arg => 2 ) },
+ qr/was passed in the call to Foo::test_foo/,
+ 'no exception from Foo::test_foo when when calling validate() from within a __DIE__ handler'
+);
+
+done_testing();
Please sign in to comment.
Something went wrong with that request. Please try again.