Tests for C4::Output::JSONStream made the invalid assumption
that the hash keys of the modules internal structure
will always be returned in the same sequence.
A hash is an unordered structure. as of perl 5.18
this has beem reinforced by random seeding of the
hashing function. See the info in perldelta and
the doc for JSON.
This patch changes the tests to be sequence-neutral
where the previous test was testing that a new element
was added and an existing one was untouched these have
been separated into individual tests.
Some typos in the messages have been corrected
Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Test Plan
1/ Run t/Output_JSONStream.t , 8 tests should pass (or perhaps fail,
but inconsistently under perl 5.18 or greater)
2/ Apply patch
3/ Run t/Output_JSONStream.t 10 tests should pass now
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
use strict;
use warnings;
use strict;
use warnings;
-use Test::More tests => 8;
+use Test::More tests => 10;
BEGIN {
use_ok('C4::Output::JSONStream');
BEGIN {
use_ok('C4::Output::JSONStream');
$json->param( issues => [ 'yes!', 'please', 'no' ] );
is($json->output,'{"issues":["yes!","please","no"]}',"Making sure JSON output has added what we told it to.");
$json->param( stuff => ['realia'] );
$json->param( issues => [ 'yes!', 'please', 'no' ] );
is($json->output,'{"issues":["yes!","please","no"]}',"Making sure JSON output has added what we told it to.");
$json->param( stuff => ['realia'] );
-is($json->output,'{"issues":["yes!","please","no"],"stuff":["realia"]}',"Making sure JSON output has added more params correctly.");
+like($json->output,'/"stuff":\["realia"\]/',"Making sure JSON output has added more params correctly.");
+like($json->output,'/"issues":\["yes!","please","no"\]/',"Making sure existing elements remain in JSON output");
$json->param( stuff => ['fun','love'] );
$json->param( stuff => ['fun','love'] );
-is($json->output,'{"issues":["yes!","please","no"],"stuff":["fun","love"]}',"Making sure JSON output can obverwrite params.");
+like($json->output,'/"stuff":\["fun","love"\]/',"Making sure JSON output can overwrite params.");
+like($json->output,'/"issues":\["yes!","please","no"\]/',"Making non overwitten elements remain in JSON output");
eval{$json->param( die )};
ok($@,'Dies');
eval{$json->param( die => ['yes','sure','now'])};
eval{$json->param( die )};
ok($@,'Dies');
eval{$json->param( die => ['yes','sure','now'])};
+ok(!$@,'Does not die.');
eval{$json->param( die => ['yes','sure','now'], die2 =>)};
ok($@,'Dies.');
eval{$json->param( die => ['yes','sure','now'], die2 =>)};
ok($@,'Dies.');