From cde75d7bf891bbe6766106a74b96e201b12aaf26 Mon Sep 17 00:00:00 2001 From: Gabor Szabo Date: Wed, 9 Oct 2013 16:05:10 +0300 Subject: [PATCH 1/2] test with predictable hashes --- t/001Basic.t | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/t/001Basic.t b/t/001Basic.t index 5d3c043..b82f995 100644 --- a/t/001Basic.t +++ b/t/001Basic.t @@ -15,7 +15,12 @@ use URI::Escape; # We rely on keys() returning the keys of a hash in a reproducable order # within the process, see http://perlmonks.org/?node_id=1056280 and # https://github.com/mschilli/php-httpbuildquery-perl/pull/3 for details. -$ENV{ PERL_PERTURB_KEYS } = "DETERMINISTIC"; +#$ENV{ PERL_PERTURB_KEYS } = "DETERMINISTIC"; + +unless (defined $ENV{PERL_PERTURB_KEYS} and $ENV{PERL_PERTURB_KEYS} == 0 + and defined $ENV{PERL_HASH_SEED} and $ENV{PERL_HASH_SEED} == 1) { + plan skip_all => 'PERL_PERTURB_KEYS=0 and PERL_HASH_SEED=1 has to be in order to have predictable Hashes'; +} plan tests => 14; From 2e82d587e894acdecb6788a0562447cb7014675b Mon Sep 17 00:00:00 2001 From: Gabor Szabo Date: Wed, 16 Oct 2013 06:57:57 +0300 Subject: [PATCH 2/2] skip only the problematic test cases and only on 5.18 and newer --- t/001Basic.t | 85 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 32 deletions(-) diff --git a/t/001Basic.t b/t/001Basic.t index b82f995..8593838 100644 --- a/t/001Basic.t +++ b/t/001Basic.t @@ -17,24 +17,39 @@ use URI::Escape; # https://github.com/mschilli/php-httpbuildquery-perl/pull/3 for details. #$ENV{ PERL_PERTURB_KEYS } = "DETERMINISTIC"; -unless (defined $ENV{PERL_PERTURB_KEYS} and $ENV{PERL_PERTURB_KEYS} == 0 - and defined $ENV{PERL_HASH_SEED} and $ENV{PERL_HASH_SEED} == 1) { - plan skip_all => 'PERL_PERTURB_KEYS=0 and PERL_HASH_SEED=1 has to be in order to have predictable Hashes'; +# make test +# prove -bv t/001Basic.t +# will skip the problematic tests on perl 5.18 and newer. +# PERL_PERTURB_KEYS=0 PERL_HASH_SEED=1 make test +# PERL_PERTURB_KEYS=0 PERL_HASH_SEED=1 prove -bv t/001Basic.t +# will run the problematic tests too + +my $skip_hash = 1; +if ($] < 5.018000 or + (defined $ENV{PERL_PERTURB_KEYS} + and $ENV{PERL_PERTURB_KEYS} == 0 + and defined $ENV{PERL_HASH_SEED} + and $ENV{PERL_HASH_SEED} == 1)) { + $skip_hash = 0; } +my $reason = 'PERL_PERTURB_KEYS=0 and PERL_HASH_SEED=1 has to be in order to have predictable Hashes'; plan tests => 14; -is( http_build_query( - { foo => { - bar => "baz", - quick => { "quack" => "schmack" }, +SKIP: { + skip $reason, 1 if $skip_hash; + is( http_build_query( + { foo => { + bar => "baz", + quick => { "quack" => "schmack" }, + }, }, - }, - ), - cobble("foo[bar]=baz", "foo[quick][quack]=schmack", - ['bar', 'quick']), - "pod" -); + ), + cobble("foo[bar]=baz", "foo[quick][quack]=schmack", + ['bar', 'quick']), + "pod" + ); +} is( http_build_query( ['foo', 'bar'], "name" ), "name_0=foo&name_1=bar", @@ -61,16 +76,19 @@ is( http_build_query( { foo => { "bar" => { quick => "quack" }}} ), "nested hash" ); -is( http_build_query( { foo => "bar", "baz" => "quack" } ), - cobble("foo=bar", "baz=quack", ['foo', 'baz']), - "two elements" - ); - -is( http_build_query( { foo => "bar", "baz" => "quack", "me" => "you" } ), - cobble("foo=bar", "baz=quack", "me=you", - ['foo', 'baz', 'me']), - "three elements" - ); +SKIP: { + skip $reason, 2 if $skip_hash; + is( http_build_query( { foo => "bar", "baz" => "quack" } ), + cobble("foo=bar", "baz=quack", ['foo', 'baz']), + "two elements" + ); + + is( http_build_query( { foo => "bar", "baz" => "quack", "me" => "you" } ), + cobble("foo=bar", "baz=quack", "me=you", + ['foo', 'baz', 'me']), + "three elements" + ); +} is( http_build_query( { "foo%" => "bar" } ), "foo%25=bar", @@ -82,15 +100,18 @@ is( http_build_query( { "foo" => "ba%r" } ), "urlesc in value" ); -is( http_build_query( { a => "b", c => { d => "e" } }, "foo" ), - cobble("a=b", "c[d]=e", ['a', 'c']), - "nested struct" - ); - -is( http_build_query( { a => { 'b' => undef }, c => undef } ), - cobble("a[b]=", "c=", ['a', 'c']), - 'undefined scalars' - ); +SKIP: { + skip $reason, 2 if $skip_hash; + is( http_build_query( { a => "b", c => { d => "e" } }, "foo" ), + cobble("a=b", "c[d]=e", ['a', 'c']), + "nested struct" + ); + + is( http_build_query( { a => { 'b' => undef }, c => undef } ), + cobble("a[b]=", "c=", ['a', 'c']), + 'undefined scalars' + ); +} is( http_build_query( 'id' ), '=id',