X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fadmin%2F10script.t;h=04d327cf6906e6046f09df99e7d304fbed88802c;hb=099f10d17d95b08b12a9c88129c65b4bab0b60e2;hp=633d7972f7988710a0ac5d8f0f0af9163e58c070;hpb=578eee18878eb863685897a0d85cb6926408c5af;p=dbsrgits%2FDBIx-Class.git diff --git a/t/admin/10script.t b/t/admin/10script.t index 633d797..04d327c 100644 --- a/t/admin/10script.t +++ b/t/admin/10script.t @@ -16,9 +16,13 @@ BEGIN { } my @json_backends = qw/XS JSON DWIW/; -my $tests_per_run = 6; +my $tests_per_run = 5; +plan tests => ($tests_per_run * @json_backends) + 1; -plan tests => $tests_per_run * @json_backends; + +# test the script is setting @INC properly +test_exec (qw| -It/lib/testinclude --schema=DBICTestAdminInc --op=deploy --connect=[] |); +cmp_ok ( $? >> 8, '==', 70, 'Correct exit code from deploying a custom INC schema' ); for my $js (@json_backends) { @@ -29,11 +33,6 @@ for my $js (@json_backends) { $ENV{JSON_ANY_ORDER} = $js; eval { test_dbicadmin () }; diag $@ if $@; - - # test the script is setting @INC properly - like(`script/dbicadmin -It/dbicadmin-test-include/lib --schema=Foo --op=deploy --connect=[] --debug`, - qr|Adding to \@INC:\nt/dbicadmin-test-include/lib| - ); } } @@ -42,22 +41,22 @@ sub test_dbicadmin { my $employees = $schema->resultset('Employee'); - system( _prepare_system_args( qw|--op=insert --set={"name":"Matt"}| ) ); + test_exec( default_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'), "$ENV{JSON_ANY_ORDER}: insert valid" ); - system( _prepare_system_args( qw|--op=update --set={"name":"Trout"}| ) ); + test_exec( default_args(), qw|--op=update --set={"name":"Trout"}| ); $employee = $employees->find(1); ok( ($employee->name() eq 'Trout'), "$ENV{JSON_ANY_ORDER}: update" ); - system( _prepare_system_args( qw|--op=insert --set={"name":"Aran"}| ) ); + test_exec( default_args(), qw|--op=insert --set={"name":"Aran"}| ); SKIP: { skip ("MSWin32 doesn't support -| either", 1) if $^O eq 'MSWin32'; - open(my $fh, "-|", _prepare_system_args( qw|--op=select --attrs={"order_by":"name"}| ) ) or die $!; + open(my $fh, "-|", ( 'script/dbicadmin', default_args(), qw|--op=select --attrs={"order_by":"name"}| ) ) or die $!; my $data = do { local $/; <$fh> }; close($fh); if (!ok( ($data=~/Aran.*Trout/s), "$ENV{JSON_ANY_ORDER}: select with attrs" )) { @@ -65,32 +64,35 @@ sub test_dbicadmin { }; } - system( _prepare_system_args( qw|--op=delete --where={"name":"Trout"}| ) ); + test_exec( default_args(), qw|--op=delete --where={"name":"Trout"}| ); ok( ($employees->count()==1), "$ENV{JSON_ANY_ORDER}: delete" ); } +sub default_args { + return ( + qw|--quiet --schema=DBICTest::Schema --class=Employee|, + q|--connect=["dbi:SQLite:dbname=t/var/DBIxClass.db","","",{"AutoCommit":1}]|, + qw|--force -I testincludenoniterference|, + ); +} + # 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|, - q|--connect=["dbi:SQLite:dbname=t/var/DBIxClass.db","","",{"AutoCommit":1}]|, - qw|--force|, - @_, - ); - - if ( $^O eq 'MSWin32' ) { - $perl = qq|"$perl"|; # execution will fail if $^X contains paths - for (@args) { - $_ =~ s/"/\\"/g; - } +sub test_exec { + my $perl = $^X; + + my @args = ('script/dbicadmin', @_); + + if ( $^O eq 'MSWin32' ) { + $perl = qq|"$perl"|; # execution will fail if $^X contains paths + for (@args) { + $_ =~ s/"/\\"/g; } + } - return ($perl, @args); + system ($perl, @args); }