~ubuntu-branches/ubuntu/wily/libsereal-encoder-perl/wily

« back to all changes in this revision

Viewing changes to t/010_desperate.t

  • Committer: Package Import Robot
  • Author(s): Alexandre Mestiashvili
  • Date: 2013-02-20 08:29:14 UTC
  • Revision ID: package-import@ubuntu.com-20130220082914-dljb6eixvtj2m1v2
Tags: upstream-0.31
ImportĀ upstreamĀ versionĀ 0.31

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!perl
 
2
use strict;
 
3
use warnings;
 
4
# most be loaded before Sereal::TestSet
 
5
use Sereal::Encoder qw(encode_sereal);
 
6
use Sereal::Encoder::Constants qw(:all);
 
7
use File::Spec;
 
8
 
 
9
use lib File::Spec->catdir(qw(t lib));
 
10
BEGIN {
 
11
  lib->import('lib')
 
12
    if !-d 't';
 
13
}
 
14
 
 
15
use Sereal::TestSet qw(:all);
 
16
 
 
17
use Data::Dumper; # must be loaded AFTER the test set (bug in perl)
 
18
 
 
19
# These tests are extraordinarily basic, badly-done and really just
 
20
# for basic sanity testing during development.
 
21
 
 
22
use Test::More;
 
23
 
 
24
run_tests("plain");
 
25
run_tests("no_shared_hk", {no_shared_hashkeys => 1});
 
26
done_testing();
 
27
 
 
28
sub run_tests {
 
29
  my ($extra_name, $opt_hash) = @_;
 
30
  foreach my $bt (@BasicTests) {
 
31
    my (undef, $exp, $name) = @$bt;
 
32
 
 
33
    $exp = $exp->($opt_hash) if ref($exp) eq 'CODE';
 
34
    $name="unnamed" if not defined $name;
 
35
    #next unless $name=~/PAD/;
 
36
 
 
37
    $exp = "$Header$exp";
 
38
    my $enc = Sereal::Encoder->new($opt_hash ? $opt_hash : ());
 
39
    my $out;
 
40
    eval{
 
41
        $out= $enc->encode($bt->[0]); # must use bt here or we get a copy
 
42
        1;
 
43
    } or die "Failed to encode: \n$@\n". Data::Dumper::Dumper($bt->[0]);
 
44
    ok(defined $out, "($extra_name) defined: $name");
 
45
    #is(length($out), length($exp));
 
46
    is(Data::Dumper::qquote($out), Data::Dumper::qquote($exp), "($extra_name) correct: $name")
 
47
      or do {
 
48
        if ($ENV{DEBUG_SEREAL}) {
 
49
          print STDERR "\nEXPECTED:\n";
 
50
          hobodecode($exp);
 
51
          print STDERR "\nGOT:\n";
 
52
          hobodecode($out);
 
53
          print STDERR "\n";
 
54
        }
 
55
      };
 
56
  }
 
57
}
 
58