From: Peter Rabbitson Date: Tue, 27 Jan 2009 09:14:29 +0000 (+0000) Subject: Test all available JSON:: implementations in 89dbicadmin.t X-Git-Tag: v0.08240~171 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d1b1377b14286dc357e395f2bd0f43976bd3815a;p=dbsrgits%2FDBIx-Class.git Test all available JSON:: implementations in 89dbicadmin.t --- diff --git a/t/89dbicadmin.t b/t/89dbicadmin.t index 095204d..c435294 100644 --- a/t/89dbicadmin.t +++ b/t/89dbicadmin.t @@ -6,7 +6,6 @@ use Test::More; use lib qw(t/lib); use DBICTest; -my $schema = DBICTest->init_schema( sqlite_use_file => 1 ); eval 'require JSON::Any'; plan skip_all => 'Install JSON::Any to run this test' if ($@); @@ -17,33 +16,47 @@ if ($@) { plan skip_all => 'Install Text::CSV_XS or Text::CSV_PP to run this test' if ($@); } -plan tests => 5; +my @json_backends = qw/XS JSON DWIW Syck/; +my $tests_per_run = 5; -# the script supports double quotes round the arguments and single-quote within -# to make sure it runs on windows as well, but only if JSON::Any picks the right module +plan tests => $tests_per_run * @json_backends; +use JSON::Any; +for my $js (@json_backends) { + eval {JSON::Any->import ($js) }; + SKIP: { + skip ("Json module $js is not available, skip testing", $tests_per_run) if $@; -my $employees = $schema->resultset('Employee'); -my @cmd = ($^X, qw|script/dbicadmin --quiet --schema=DBICTest::Schema --class=Employee --tlibs|, q|--connect=["dbi:SQLite:dbname=t/var/DBIxClass.db","","",{"AutoCommit":1}]|, qw|--force --tlibs|); + $ENV{JSON_ANY_ORDER} = $js; + eval { test_dbicadmin () }; + diag $@ if $@; + } +} + +sub test_dbicadmin { + my $schema = DBICTest->init_schema( sqlite_use_file => 1 ); # reinit a fresh db for every run -system(@cmd, qw|--op=insert --set={"name":"Matt"}|); -ok( ($employees->count()==1), 'insert count' ); + my $employees = $schema->resultset('Employee'); + my @cmd = ($^X, qw|script/dbicadmin --quiet --schema=DBICTest::Schema --class=Employee --tlibs|, q|--connect=["dbi:SQLite:dbname=t/var/DBIxClass.db","","",{"AutoCommit":1}]|, qw|--force --tlibs|); -my $employee = $employees->find(1); -ok( ($employee->name() eq 'Matt'), 'insert valid' ); + system(@cmd, qw|--op=insert --set={"name":"Matt"}|); + ok( ($employees->count()==1), 'insert count' ); -system(@cmd, qw|--op=update --set={"name":"Trout"}|); -$employee = $employees->find(1); -ok( ($employee->name() eq 'Trout'), 'update' ); + my $employee = $employees->find(1); + ok( ($employee->name() eq 'Matt'), 'insert valid' ); -system(@cmd, qw|--op=insert --set={"name":"Aran"}|); + system(@cmd, qw|--op=update --set={"name":"Trout"}|); + $employee = $employees->find(1); + ok( ($employee->name() eq 'Trout'), 'update' ); -open(my $fh, "-|", @cmd, qw|--op=select --attrs={"order_by":"name"}|) or die $!; -my $data = do { local $/; <$fh> }; -close($fh); -ok( ($data=~/Aran.*Trout/s), 'select with attrs' ); + system(@cmd, qw|--op=insert --set={"name":"Aran"}|); -system(@cmd, qw|--op=delete --where={"name":"Trout"}|); -ok( ($employees->count()==1), 'delete' ); + open(my $fh, "-|", @cmd, qw|--op=select --attrs={"order_by":"name"}|) or die $!; + my $data = do { local $/; <$fh> }; + close($fh); + ok( ($data=~/Aran.*Trout/s), 'select with attrs' ); + system(@cmd, qw|--op=delete --where={"name":"Trout"}|); + ok( ($employees->count()==1), 'delete' ); +}