Permalink
Browse files

Tests for Encoder re-entrancy

  • Loading branch information...
1 parent fea8452 commit 51e68cd9e3df9e8c56fa9c4bdec07a88b4237402 @tsee tsee committed Oct 25, 2012
Showing with 16 additions and 0 deletions.
  1. +16 −0 Perl/Encoder/t/400_evil.t
View
@@ -121,6 +121,22 @@ ok($ok, "deserializing tied scalar did not die")
ok(defined $data, "deserializing tied scalar yields defined output");
is_deeply($data, \$testscalar, "deserializing tied scalar yields expected output");
+
+# Now test re-entrancy. DO NOT DO THIS AT HOME!
+SCOPE: {
+ my $enc = Sereal::Encoder->new;
+ my $die_run = 0;
+ eval {
+ local $SIG{__DIE__} = sub {
+ $die_run++;
+ ok(defined($enc->encode("foo")), "encode does not segfault");
+ $die_run++;
+ };
+ $enc->encode(["foo", sub{}]);
+ };
+ ok($die_run == 2, "__DIE__ called, encode 2 did not die");
+}
+
pass("Alive at end");
done_testing();

0 comments on commit 51e68cd

Please sign in to comment.