From: Peter Rabbitson Date: Mon, 31 May 2010 16:03:07 +0000 (+0000) Subject: Simplify includedir testing X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=20c48bc466a8f3fffb84833002d5932d861c8d61;p=dbsrgits%2FDBIx-Class-Historic.git Simplify includedir testing --- diff --git a/t/admin/04include.t b/t/admin/04include.t index 8d3926e..6929193 100644 --- a/t/admin/04include.t +++ b/t/admin/04include.t @@ -12,15 +12,15 @@ BEGIN { if(use_ok 'DBIx::Class::Admin') { my $admin = DBIx::Class::Admin->new( - include_dirs => ['t/dbicadmin-test-include/lib'], - schema_class => 'Foo', - config => { Foo => {} }, - config_stanza => 'Foo' + include_dirs => ['t/lib/testinclude'], + schema_class => 'DBICTestAdminInc', + config => { DBICTestAdminInc => {} }, + config_stanza => 'DBICTestAdminInc' ); lives_ok { $admin->_build_schema } 'should survive attempt to load module located in include_dirs'; { no warnings 'once'; - ok($Foo::loaded); + ok($DBICTestAdminInc::loaded); } } diff --git a/t/admin/10script.t b/t/admin/10script.t index 633d797..20e884b 100644 --- a/t/admin/10script.t +++ b/t/admin/10script.t @@ -16,9 +16,9 @@ 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; +plan tests => ($tests_per_run * @json_backends) + 1; for my $js (@json_backends) { @@ -30,34 +30,34 @@ for my $js (@json_backends) { 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| - ); } } +# 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' ); + sub test_dbicadmin { my $schema = DBICTest->init_schema( sqlite_use_file => 1 ); # reinit a fresh db for every run 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 +65,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|, + ); +} + # 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); } diff --git a/t/dbicadmin-test-include/lib/Foo.pm b/t/dbicadmin-test-include/lib/Foo.pm deleted file mode 100644 index 1175c56..0000000 --- a/t/dbicadmin-test-include/lib/Foo.pm +++ /dev/null @@ -1,9 +0,0 @@ -package Foo; -use base 'DBIx::Class::Schema'; - -our $loaded = 1; -our $deploy = 0; -sub connect { bless {}, 'Foo' } -sub deploy {$deploy = 1} - -1; diff --git a/t/dbicadmincrap/lib/Foo.pm b/t/dbicadmincrap/lib/Foo.pm deleted file mode 100644 index 2801e9e..0000000 --- a/t/dbicadmincrap/lib/Foo.pm +++ /dev/null @@ -1,7 +0,0 @@ -package Foo; - -our $loaded = 1; - -sub connect {} - -1; diff --git a/t/lib/testinclude/DBICTestAdminInc.pm b/t/lib/testinclude/DBICTestAdminInc.pm new file mode 100644 index 0000000..111bfcd --- /dev/null +++ b/t/lib/testinclude/DBICTestAdminInc.pm @@ -0,0 +1,9 @@ +package DBICTestAdminInc; +use base 'DBIx::Class::Schema'; + +our $loaded = 1; +sub connect { bless {}, __PACKAGE__ } + +sub deploy { exit 70 } + +1;