Imported Upstream version 3.001.011
authorgregor herrmann <gregoa@debian.org>
Tue, 12 Aug 2014 19:11:11 +0000 (21:11 +0200)
committergregor herrmann <gregoa@debian.org>
Tue, 12 Aug 2014 19:11:11 +0000 (21:11 +0200)
14 files changed:
Changes
META.json
META.yml
lib/Sereal/Encoder.pm
t/010_desperate.t
t/700_roundtrip/v1/plain_canon.t
t/700_roundtrip/v1/snappy_canon.t
t/700_roundtrip/v2/plain_canon.t
t/700_roundtrip/v2/snappy_canon.t
t/700_roundtrip/v2/snappy_incr_canon.t
t/700_roundtrip/v3/plain_canon.t
t/700_roundtrip/v3/snappy_canon.t
t/700_roundtrip/v3/snappy_incr_canon.t
t/lib/Sereal/TestSet.pm

diff --git a/Changes b/Changes
index 590b16df606f8a33608ccf7986db9c36da278ac0..993c892ee445e7c085b02c00f5e9e8869c21b5f0 100644 (file)
--- a/Changes
+++ b/Changes
@@ -3,6 +3,15 @@ Revision history for Perl extension Sereal-Encoder
 * Warning: For a seamless upgrade, upgrade to version 3
 *          of the decoder before upgrading to version 3 of the
 *          encoder!
+3.001_011 Tues, Aug 12 2014
+  - Remove use of defined-or in t/lib/TestSet.pm
+
+3.001_010 Tues, Aug 12 2014
+  - Cleanup and enhance the "alternates" testing in t/010_desperate.t
+
+3.001_007 .. 3.001_009
+  - Try to fix t/010_desperate.t on threaded perls (yes that many releases. sigh)
+
 3.001_006 Sun, Aug 03 2014
   - Rework bulk tests so we test more, but report less tests.
     The test infrastructure doesn't play well with lots of tests
index f2fb3e4ceeadb154e91c9928ac1568c9d7ebb3de..d07a3045ef8fe5f1a818c10a966fd84077960e9a 100644 (file)
--- a/META.json
+++ b/META.json
@@ -55,5 +55,5 @@
          "url" : "git://github.com/Sereal/Sereal.git"
       }
    },
-   "version" : "3.001_009"
+   "version" : "3.001_011"
 }
index 677e645dae39ae35f1f7cd3f372c56b34960d4ec..2bb664c59d8200b638236652ca97677229e24ea9 100644 (file)
--- a/META.yml
+++ b/META.yml
@@ -32,4 +32,4 @@ requires:
 resources:
   bugtracker: https://github.com/Sereal/Sereal/issues
   repository: git://github.com/Sereal/Sereal.git
-version: 3.001_009
+version: 3.001_011
index f9d17ca9c12f7e3f4fa52d154b228a7e7839f36e..0e71e186ba9d6e703a9e71764d46a4605301a802 100644 (file)
@@ -5,7 +5,7 @@ use warnings;
 use Carp qw/croak/;
 use XSLoader;
 
-our $VERSION = '3.001_009'; # Don't forget to update the TestCompat set for testing against installed decoders!
+our $VERSION = '3.001_011'; # Don't forget to update the TestCompat set for testing against installed decoders!
 our $XS_VERSION = $VERSION; $VERSION= eval $VERSION;
 
 # not for public consumption, just for testing.
index 7a3eb9c6cc424744bc091f1de1f63aa473945903..ef5faafdc35ffc6f036381af2ef3663d481d9510 100644 (file)
@@ -31,31 +31,37 @@ sub run_tests {
   my ($extra_name, $opt_hash) = @_;
   setup_tests(3);
   foreach my $bt (@BasicTests) {
-    my (undef, $expect, $name, $accept_cond, @accept) = @$bt;
+    my (undef, $expect, $name, @alternate) = @$bt;
 
-    $expect = $expect->($opt_hash) if ref($expect) eq 'CODE';
     $name="unnamed" if not defined $name;
     #next unless $name=~/PAD/;
 
-    $expect = Header(). $expect;
+    for my $x ( $expect, @alternate ) {
+        $x = $x->($opt_hash) if ref($x) eq 'CODE';
+        # add the header ...
+        $x = Header() . $x;
+    }
+
     my $enc = Sereal::Encoder->new($opt_hash ? $opt_hash : ());
     my $out;
     eval{
         $out= $enc->encode($bt->[0]); # must use bt here or we get a copy
         1;
     } or die "Failed to encode: \n$@\n". Data::Dumper::Dumper($bt->[0]);
-    ok(defined $out, "($extra_name) defined: $name");
+    ok(defined $out, "($extra_name) defined: $name")
+        or next;
 
-    if ($accept_cond and $out ne $expect) {
-        foreach my $accept (@accept) {
+    my $alt= "";
+    if ($out ne $expect) {
+        foreach my $accept (@alternate) {
             if ($out eq $accept) {
-                diag("Using alternate expect for test '$name'");
                 $expect= $accept;
+                $alt= " - alternate";
                 last;
             }
         }
     }
-    is(Data::Dumper::qquote($out), Data::Dumper::qquote($expect), "($extra_name) correct: $name")
+    is(Data::Dumper::qquote($out), Data::Dumper::qquote($expect), "($extra_name) correct: $name" . $alt)
       or do {
         if ($ENV{DEBUG_SEREAL}) {
           print STDERR "\nEXPECTED:\n";
index 00cbb89e77680efda3c8a7f23f61cd101ed84ff4..e8b9f0486282815e3746531552de7f43f00495b5 100644 (file)
@@ -16,7 +16,7 @@ use Test::More;
 my $ok = have_encoder_and_decoder();
 $ok= 0 if $Sereal::Encoder::VERSION < 3.001006;
 if (not $ok) {
-    plan skip_all => 'Did not find right version of encoder';
+    plan skip_all => 'Did not find right version of encoder (want 3.001006)';
 }
 else {
     run_roundtrip_tests("plain_canon",{canonical => 1});
index acb9611091cda3a86f74fd9ad748f6abc20a82d3..605956d60943313d77e122120790eb7ca9f6a8e3 100644 (file)
@@ -16,7 +16,7 @@ use Test::More;
 my $ok = have_encoder_and_decoder();
 $ok= 0 if $Sereal::Encoder::VERSION < 3.001006;
 if (not $ok) {
-    plan skip_all => 'Did not find right version of encoder';
+    plan skip_all => 'Did not find right version of encoder (want 3.001006)';
 }
 else {
     run_roundtrip_tests('snappy_canon', { snappy => 1, canonical => 1 } );
index 00cbb89e77680efda3c8a7f23f61cd101ed84ff4..e8b9f0486282815e3746531552de7f43f00495b5 100644 (file)
@@ -16,7 +16,7 @@ use Test::More;
 my $ok = have_encoder_and_decoder();
 $ok= 0 if $Sereal::Encoder::VERSION < 3.001006;
 if (not $ok) {
-    plan skip_all => 'Did not find right version of encoder';
+    plan skip_all => 'Did not find right version of encoder (want 3.001006)';
 }
 else {
     run_roundtrip_tests("plain_canon",{canonical => 1});
index acb9611091cda3a86f74fd9ad748f6abc20a82d3..605956d60943313d77e122120790eb7ca9f6a8e3 100644 (file)
@@ -16,7 +16,7 @@ use Test::More;
 my $ok = have_encoder_and_decoder();
 $ok= 0 if $Sereal::Encoder::VERSION < 3.001006;
 if (not $ok) {
-    plan skip_all => 'Did not find right version of encoder';
+    plan skip_all => 'Did not find right version of encoder (want 3.001006)';
 }
 else {
     run_roundtrip_tests('snappy_canon', { snappy => 1, canonical => 1 } );
index 6d5f4f9ee2f9e88eac04ecf1ffbcf57516ea0f1a..1cd5327755a7256b7c7ebf3927a9756aade69219 100644 (file)
@@ -16,7 +16,7 @@ use Test::More;
 my $ok = have_encoder_and_decoder();
 $ok= 0 if $Sereal::Encoder::VERSION < 3.001006;
 if (not $ok) {
-    plan skip_all => 'Did not find right version of encoder';
+    plan skip_all => 'Did not find right version of encoder (want 3.001006)';
 }
 else {
     run_roundtrip_tests(
index 00cbb89e77680efda3c8a7f23f61cd101ed84ff4..e8b9f0486282815e3746531552de7f43f00495b5 100644 (file)
@@ -16,7 +16,7 @@ use Test::More;
 my $ok = have_encoder_and_decoder();
 $ok= 0 if $Sereal::Encoder::VERSION < 3.001006;
 if (not $ok) {
-    plan skip_all => 'Did not find right version of encoder';
+    plan skip_all => 'Did not find right version of encoder (want 3.001006)';
 }
 else {
     run_roundtrip_tests("plain_canon",{canonical => 1});
index acb9611091cda3a86f74fd9ad748f6abc20a82d3..605956d60943313d77e122120790eb7ca9f6a8e3 100644 (file)
@@ -16,7 +16,7 @@ use Test::More;
 my $ok = have_encoder_and_decoder();
 $ok= 0 if $Sereal::Encoder::VERSION < 3.001006;
 if (not $ok) {
-    plan skip_all => 'Did not find right version of encoder';
+    plan skip_all => 'Did not find right version of encoder (want 3.001006)';
 }
 else {
     run_roundtrip_tests('snappy_canon', { snappy => 1, canonical => 1 } );
index 6d5f4f9ee2f9e88eac04ecf1ffbcf57516ea0f1a..1cd5327755a7256b7c7ebf3927a9756aade69219 100644 (file)
@@ -16,7 +16,7 @@ use Test::More;
 my $ok = have_encoder_and_decoder();
 $ok= 0 if $Sereal::Encoder::VERSION < 3.001006;
 if (not $ok) {
-    plan skip_all => 'Did not find right version of encoder';
+    plan skip_all => 'Did not find right version of encoder (want 3.001006)';
 }
 else {
     run_roundtrip_tests(
index 021bc7bcb4f5c87298206b3483c896bf3f5e8293..6b1841370865d993e1f290e19ae452c9ec4947be 100644 (file)
@@ -12,7 +12,6 @@ use Test::LongString;
 use Devel::Peek;
 use Encode qw(encode_utf8 is_utf8);
 use Scalar::Util qw(reftype blessed refaddr);
-use Data::Dumper;
 use Config;
 
 # Dynamically load constants from whatever is being tested
@@ -184,6 +183,7 @@ sub offseti {
 sub debug_checks {
     my ($data_ref, $encoded_ref, $decoded_ref, $debug) = @_;
     if ($debug or defined $ENV{DEBUG_SEREAL}) {
+        require Data::Dumper;
         note("Original data was: " . Data::Dumper::Dumper($$data_ref))
             if defined $data_ref;
         note("Encoded data is: " . (defined($$encoded_ref) ? Data::Dumper::qquote($$encoded_ref) : "<undef>"))
@@ -213,7 +213,11 @@ sub setup_tests {
 
     my $unicode1= "Ba\xDF Ba\xDF"; my $unicode2= "\x{168}nix! \x{263a}"; utf8::upgrade($unicode1); utf8::upgrade($unicode2);
 
-
+    # each test is an array:
+    # index 0 is the input to the encoder
+    # index 1 is the output *without* header - or a sub which returns an expected output
+    # index 2 is the name of the test
+    # index 3 and on are alternate outputs (or subs which return alternate output(s))
     @BasicTests = (
         # warning: this hardcodes the POS/NEG headers
         [-16, chr(0b0001_0000), "encode -16"],
@@ -521,13 +525,33 @@ sub setup_tests {
             ),
             "simple unicode hash key and value"
         ],
+        # Test true/false. Due to some edge case behavior in perl these two tests
+        # produce different "expected" results depending on such things as how many
+        # times we perform the test. Therefore we allow various "alternates" to
+        # be produced. An example of the underlying weirdness is that on an unthreaded
+        # linux perl 5.14 the two tests have their expected output first, which
+        # as you will note is different for the first and second call, despite the underlying
+        # code being the same both times.
+        #
+        # So for instance the first test need not have the last two options, at least
+        # on perl 5.14, but the second test requires one of those options. Working around
+        # perl bugs sucks.
+        [
+            sub { \@_ }->(!1,!0),
+            array(chr(SRL_HDR_FALSE),chr(SRL_HDR_TRUE)),  # this is the "correct" response.
+            "true/false (prefered order)",
+            array(chr(SRL_HDR_FALSE),short_string("1")),  # this is what threaded perls will probably match
+            array(short_string(""),chr(SRL_HDR_TRUE)),    # accept this also (but we dont expect we will)
+            array(short_string(""),short_string("1")),    # accept this also (but we dont expect we will)
+        ],
         [
             sub { \@_ }->(!1,!0),
+            array(short_string(""),short_string("1")),    # this is the expected value on perl 5.14 unthreaded
+            "true/false (reversed alternates)",
+            array(short_string(""),chr(SRL_HDR_TRUE)),    # from here we just reverse the order from the first test
+            array(chr(SRL_HDR_FALSE),short_string("1")),  # ....
             array(chr(SRL_HDR_FALSE),chr(SRL_HDR_TRUE)),
-            "true/false",
-            $Config{usethreads},                            # if this is true
-            array(chr(SRL_HDR_FALSE),short_string("1")),    # the we will accept this
-        ]
+        ],
     );
 }
 
@@ -772,6 +796,7 @@ sub run_roundtrip_tests {
 
 sub _test {
     my ($msg, $v1, $v2)= @_;
+    # require Data::Dumper not needed, called in parent frame
     if ($v1 ne $v2) {
         my $q1= Data::Dumper::qquote($v1);
         my $q2= Data::Dumper::qquote($v2);
@@ -806,7 +831,7 @@ sub _cmp_str {
 
     $length_to_show= $max_diff_len if $length_to_show > $max_diff_len;
 
-
+    # require Data::Dumper not needed, called in parent frame
     my $q1= Data::Dumper::qquote(substr($v1, $diff_start, $length_to_show ));
     my $q2= Data::Dumper::qquote(substr($v2, $diff_start, $length_to_show ));
     my $context_start= $diff_start > $max_context_len ? $diff_start - $max_context_len : 0;
@@ -869,7 +894,7 @@ sub _deep_cmp {
         $cmp=  _test("seen ref", ++$seenx->{refaddr $x}, ++$seeny->{refaddr $y})
             || _test("reftype mismatch",reftype($x), reftype($y))
             || _test("class mismatch", !blessed($x), !blessed($y))
-            || _test("class different", blessed($x)//"", blessed($y)//"")
+            || _test("class different", blessed($x) || "", blessed($y) || "")
             and return $cmp;
         return "" if $x == $y
                   or $seenx->{refaddr $x} > 1;
@@ -919,6 +944,8 @@ sub deep_cmp {
 
 sub run_roundtrip_tests_internal {
     my ($ename, $opt, $encode_decode_callbacks) = @_;
+    require Data::Dumper;
+
     my $decoder = Sereal::Decoder->new($opt);
     my $encoder = Sereal::Encoder->new($opt);
     my %seen_name;