File: 903_reentrancy.t

package info (click to toggle)
libsereal-decoder-perl 5.004%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 2,556 kB
  • sloc: ansic: 11,615; perl: 6,938; sh: 25; makefile: 9
file content (49 lines) | stat: -rw-r--r-- 1,136 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use strict;
use warnings;
use File::Spec;
use lib File::Spec->catdir(qw(t lib));

BEGIN {
    lib->import('lib')
        if !-d 't';
}

use Sereal::TestSet qw(:all);
use Test::More tests => 2;
use Sereal::Decoder;

# Regression test for RT #93563

# Decoder is (was) not re-entrant.

my $dec;

package Foo;
sub FREEZE { my $x= Sereal::Encoder->new->encode( $_[0]->{a} ); return $x; }
sub THAW { bless( { a => $dec->decode( $_[2] ) }, $_[0] ) }

package main;

SKIP: {
    my $have_enc= have_encoder_and_decoder();
    if ( not $have_enc ) {
        skip "Need encoder for Snappy regression tests", 2;
    }
    else {
        $dec= Sereal::Decoder->new;
        my $z= [ bless( { a => 42 }, "Foo" ) ];
        push @$z, $z;
        my $a= Sereal::Encoder->new( { freeze_callbacks => 1 } )->encode($z);
        my $b;
        my $err;
        eval {
            $b= $dec->decode($a);
            1;
        } or do {
            $err= $@ || 'Zombie error';
        };
        ok( !$err, "Decoding did not barf" )
            or diag("Decoding barfed with '$err'");
        is_deeply( $b, $z, "Output from decoding is correct" );
    }
}