Skip to content

Commit

Permalink
Test more expected failures
Browse files Browse the repository at this point in the history
  • Loading branch information
tsee committed Sep 6, 2012
1 parent 5ad575f commit 3fcbe25
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions Encoder/t/300_fail.t
Expand Up @@ -2,14 +2,28 @@
use strict;
use warnings;
use Sereal::Encoder;
use Test::More tests => 2;
use Test::More tests => 4;

my $ok; my $err; my $out;

# croak_on_bless test
my $e = Sereal::Encoder->new({
croak_on_bless => 1,
});
my $ok = eval{$e->encode(bless({}, "Foo")); 1};
my $err = $@ || 'Zombie error';
$ok = eval{$out = $e->encode(bless({}, "Foo")); 1};
$err = $@ || 'Zombie error';

ok(!$ok, "Object throws exception");
ok($err =~ /object/i, 'Exception refers to object');

$ok = eval {$out = $e->encode({}); 1};
ok($ok, "Non-blessed hash does not throw exception");


ok(!$ok);
ok($err =~ /object/);
# test that code refs throw exception
TODO: {
local $TODO = "Serializing CODE refs should probably fail instead of serializing to \\undef";
$ok = eval {$out = $e->encode(sub {}); 1};
ok(!$ok, "Code ref throws exception");
}

0 comments on commit 3fcbe25

Please sign in to comment.