8 $ENV{PERL5LIB} = join ($Config{path_sep}, @INC);
14 plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for('admin_script')
15 unless DBIx::Class::Optional::Dependencies->req_ok_for('admin_script');
18 my @json_backends = qw/XS JSON DWIW/;
19 my $tests_per_run = 5;
21 plan tests => ($tests_per_run * @json_backends) + 1;
23 for my $js (@json_backends) {
25 eval {JSON::Any->import ($js) };
27 skip ("Json backend $js is not available, skip testing", $tests_per_run) if $@;
29 $ENV{JSON_ANY_ORDER} = $js;
30 eval { test_dbicadmin () };
36 # test the script is setting @INC properly
37 test_exec (qw| -It/lib/testinclude --schema=DBICTestAdminInc --op=deploy --connect=[] |);
38 cmp_ok ( $? >> 8, '==', 70, 'Correct exit code from deploying a custom INC schema' );
41 my $schema = DBICTest->init_schema( sqlite_use_file => 1 ); # reinit a fresh db for every run
43 my $employees = $schema->resultset('Employee');
45 test_exec( default_args(), qw|--op=insert --set={"name":"Matt"}| );
46 ok( ($employees->count()==1), "$ENV{JSON_ANY_ORDER}: insert count" );
48 my $employee = $employees->find(1);
49 ok( ($employee->name() eq 'Matt'), "$ENV{JSON_ANY_ORDER}: insert valid" );
51 test_exec( default_args(), qw|--op=update --set={"name":"Trout"}| );
52 $employee = $employees->find(1);
53 ok( ($employee->name() eq 'Trout'), "$ENV{JSON_ANY_ORDER}: update" );
55 test_exec( default_args(), qw|--op=insert --set={"name":"Aran"}| );
58 skip ("MSWin32 doesn't support -| either", 1) if $^O eq 'MSWin32';
60 open(my $fh, "-|", ( 'script/dbicadmin', default_args(), qw|--op=select --attrs={"order_by":"name"}| ) ) or die $!;
61 my $data = do { local $/; <$fh> };
63 if (!ok( ($data=~/Aran.*Trout/s), "$ENV{JSON_ANY_ORDER}: select with attrs" )) {
64 diag ("data from select is $data")
68 test_exec( default_args(), qw|--op=delete --where={"name":"Trout"}| );
69 ok( ($employees->count()==1), "$ENV{JSON_ANY_ORDER}: delete" );
74 qw|--quiet --schema=DBICTest::Schema --class=Employee|,
75 q|--connect=["dbi:SQLite:dbname=t/var/DBIxClass.db","","",{"AutoCommit":1}]|,
80 # Why do we need this crap? Apparently MSWin32 can not pass through quotes properly
81 # (sometimes it will and sometimes not, depending on what compiler was used to build
82 # perl). So we go the extra mile to escape all the quotes. We can't also use ' instead
83 # of ", because JSON::XS (proudly) does not support "malformed JSON" as the author
89 my @args = ('script/dbicadmin', @_);
91 if ( $^O eq 'MSWin32' ) {
92 $perl = qq|"$perl"|; # execution will fail if $^X contains paths
98 system ($perl, @args);