Skip to content

Commit

Permalink
Add tests to show that the things we advertise as rw aren't actually rw
Browse files Browse the repository at this point in the history
Since 1.09 when we've had the magical pluggable formats we've been
failing horribly on cases where we did the right thing before,
i.e. when we change the input/output format at runtime.

I did a limited patch to solve the latter in the last commit, but we
still do completely the wrong thing with input formats. If you change
$flex->detect_*(Bool) it's just silently ignored.

Arguably we should just not support any rw operations at all. It makes
the implementation much more painful, but we shouldn't advertise that
it works and then completely fail on it.

So add failing tests to show that changing it at runtime completely
fails, we can then decide how to proceed with this. I.e. whether to
fix this up or to remove support for dynamically changing the output
format.
  • Loading branch information
avar committed May 30, 2013
1 parent 28fde2f commit 3893f08
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions t/99regression.t
@@ -0,0 +1,49 @@
use strict;
use warnings;
use Test::More qw(no_plan);
use Data::FlexSerializer;
use Sereal::Encoder qw(encode_sereal);
use Sereal::Decoder qw(decode_sereal);
use Data::Dumper;

{
my $flex = Data::FlexSerializer->new(
assume_compression => 0,
detect_compression => 0,
output_format => 'storable',
detect_json => 1,
detect_storable => 1,
detect_sereal => 0,
);
is_deeply($flex->detect_formats, { storable => 1, json => 1, sereal => 0 }, "We have the expected detection formats");
is_deeply($flex->deserialize(qq[{"foo": "bar"}]), { foo => "bar" }, "We can detect JSON");
$flex->detect_json(0);
is_deeply($flex->detect_formats, { storable => 1, json => 0, sereal => 0 }, "We have the expected detection formats");
eval {
$flex->deserialize(qq[{"foo": "bar"}]);
fail "Why does this work now?";
1;
} or do {
chomp(my $error = $@ || "Zombie Error");
pass "We shouldn't be able to deserialize JSON anymore: $error";
};
$flex->detect_storable(0);
$flex->detect_sereal(1);
is_deeply($flex->detect_formats, { storable => 0, json => 0, sereal => 1 }, "We have the expected detection formats");
eval {
is_deeply($flex->deserialize(encode_sereal({foo => "bar"})), { foo => "bar" }, "We can now deserialize Sereal");
1;
} or do {
chomp(my $error = $@ || "Zombie Error");
fail "We shouldn't die on this: $error";
};
$flex->detect_sereal(0);
is_deeply($flex->detect_formats, { storable => 0, json => 0, sereal => 0 }, "We have the expected detection formats");
eval {
$flex->deserialize(qq[{"foo": "bar"}]);
fail "We should die on this as we have no formats left";
1;
} or do {
pass "We died because we had no formats left";
};
}

0 comments on commit 3893f08

Please sign in to comment.