From: Peter Rabbitson Date: Sun, 1 Feb 2009 21:33:32 +0000 (+0000) Subject: Fix the dbicadmin test for good X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e1e87a42eb5756abf6aba429378c5d4085f1d67c;p=dbsrgits%2FDBIx-Class-Historic.git Fix the dbicadmin test for good --- diff --git a/t/89dbicadmin.t b/t/89dbicadmin.t index 229ade7..167a1d5 100644 --- a/t/89dbicadmin.t +++ b/t/89dbicadmin.t @@ -38,25 +38,49 @@ sub test_dbicadmin { my $schema = DBICTest->init_schema( sqlite_use_file => 1 ); # reinit a fresh db for every run 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|); - system(@cmd, qw|--op=insert --set={"name":"Matt"}|); - ok( ($employees->count()==1), 'insert count' ); + system( _prepare_system_args( qw|--op=insert --set={"name":"Matt"}| ) ); + ok( ($employees->count()==1), "$ENV{JSON_ANY_ORDER}: insert count" ); my $employee = $employees->find(1); - ok( ($employee->name() eq 'Matt'), 'insert valid' ); + ok( ($employee->name() eq 'Matt'), "$ENV{JSON_ANY_ORDER}: insert valid" ); - system(@cmd, qw|--op=update --set={"name":"Trout"}|); + system( _prepare_system_args( qw|--op=update --set={"name":"Trout"}| ) ); $employee = $employees->find(1); - ok( ($employee->name() eq 'Trout'), 'update' ); + ok( ($employee->name() eq 'Trout'), "$ENV{JSON_ANY_ORDER}: update" ); - system(@cmd, qw|--op=insert --set={"name":"Aran"}|); + system( _prepare_system_args( qw|--op=insert --set={"name":"Aran"}| ) ); - open(my $fh, "-|", @cmd, qw|--op=select --attrs={"order_by":"name"}|) or die $!; + open(my $fh, "-|", _prepare_system_args( qw|--op=select --attrs={"order_by":"name"}| ) ) or die $!; my $data = do { local $/; <$fh> }; close($fh); - ok( ($data=~/Aran.*Trout/s), 'select with attrs' ); + ok( ($data=~/Aran.*Trout/s), "$ENV{JSON_ANY_ORDER}: select with attrs" ); - system(@cmd, qw|--op=delete --where={"name":"Trout"}|); - ok( ($employees->count()==1), 'delete' ); + system( _prepare_system_args( qw|--op=delete --where={"name":"Trout"}| ) ); + ok( ($employees->count()==1), "$ENV{JSON_ANY_ORDER}: delete" ); +} + +# Why do we need this crap? Apparently MSWin32 can not pass through quotes properly +# (sometimes it will and sometimes not, depending on what compiler was used to build +# perl). So we go the extra mile to escape all the quotes. We can't also use ' instead +# of ", because JSON::XS (proudly) does not support "malformed JSON" as the author +# calls it. Bleh. +# +sub _prepare_system_args { + my $perl = $^X; + my @args = ( + qw|script/dbicadmin --quiet --schema=DBICTest::Schema --class=Employee --tlibs|, + q|--connect=["dbi:SQLite:dbname=t/var/DBIxClass.db","","",{"AutoCommit":1}]|, + qw|--force --tlibs|, + @_, + ); + + if ( $^O eq 'MSWin32' ) { + $perl = qq|"$perl"|; # execution will fail if $^X contains paths + for (@args) { + $_ =~ s/"/\\"/g; + } + } + + return ($perl, @args); }