From 3893f08340dfce31c76e98d279f0d63b392635ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 30 May 2013 08:17:44 +0000 Subject: [PATCH] Add tests to show that the things we advertise as rw aren't actually rw 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. --- t/99regression.t | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 t/99regression.t diff --git a/t/99regression.t b/t/99regression.t new file mode 100644 index 0000000..59e3876 --- /dev/null +++ b/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"; + }; +}