12 plan skip_all => 'Test needs ' .
13 DBIx::Class::Optional::Dependencies->req_missing_for('test_admin_script')
14 unless DBIx::Class::Optional::Dependencies->req_ok_for('test_admin_script');
18 $ENV{PERL5LIB} = join ($Config{path_sep}, @INC);
20 my @json_backends = qw/XS JSON DWIW/;
22 # test the script is setting @INC properly
23 test_exec (qw|-It/lib/testinclude --schema=DBICTestAdminInc --connect=[] --insert|);
24 cmp_ok ( $? >> 8, '==', 70, 'Correct exit code from connecting a custom INC schema' );
26 # test that config works properly
29 test_exec(qw|-It/lib/testinclude --schema=DBICTestConfig --create --connect=["klaatu","barada","nikto"]|);
30 cmp_ok( $? >> 8, '==', 71, 'Correct schema loaded via config' ) || exit;
33 # test that config-file works properly
34 test_exec(qw|-It/lib/testinclude --schema=DBICTestConfig --config=t/lib/admincfgtest.json --config-stanza=Model::Gort --deploy|);
35 cmp_ok ($? >> 8, '==', 71, 'Correct schema loaded via testconfig');
38 local $TODO = 'these tests need to be fixed for Win32' if $^O eq 'MSWin32';
40 for my $js (@json_backends) {
42 eval {JSON::Any->import ($js) };
44 skip ("JSON backend $js is not available, skip testing", 1) if $@;
46 $ENV{JSON_ANY_ORDER} = $js;
47 eval { test_dbicadmin () };
56 my $schema = DBICTest->init_schema( sqlite_use_file => 1 ); # reinit a fresh db for every run
58 my $employees = $schema->resultset('Employee');
60 test_exec( default_args(), qw|--op=insert --set={"name":"Matt"}| );
61 ok( ($employees->count()==1), "$ENV{JSON_ANY_ORDER}: insert count" );
63 my $employee = $employees->find(1);
64 ok( ($employee->name() eq 'Matt'), "$ENV{JSON_ANY_ORDER}: insert valid" );
66 test_exec( default_args(), qw|--op=update --set={"name":"Trout"}| );
67 $employee = $employees->find(1);
68 ok( ($employee->name() eq 'Trout'), "$ENV{JSON_ANY_ORDER}: update" );
70 test_exec( default_args(), qw|--op=insert --set={"name":"Aran"}| );
73 skip ("MSWin32 doesn't support -| either", 1) if $^O eq 'MSWin32';
75 my ($perl) = $^X =~ /(.*)/;
77 open(my $fh, "-|", ( $perl, '-MDBICTest::RunMode', 'script/dbicadmin', default_args(), qw|--op=select --attrs={"order_by":"name"}| ) ) or die $!;
78 my $data = do { local $/; <$fh> };
80 if (!ok( ($data=~/Aran.*Trout/s), "$ENV{JSON_ANY_ORDER}: select with attrs" )) {
81 diag ("data from select is $data")
85 test_exec( default_args(), qw|--op=delete --where={"name":"Trout"}| );
86 ok( ($employees->count()==1), "$ENV{JSON_ANY_ORDER}: delete" );
90 my $dbname = DBICTest->_sqlite_dbfilename;
92 qw|--quiet --schema=DBICTest::Schema --class=Employee|,
93 qq|--connect=["dbi:SQLite:dbname=$dbname","","",{"AutoCommit":1}]|,
94 qw|--force -I testincludenoniterference|,
99 my ($perl) = $^X =~ /(.*)/;
101 my @args = ($perl, '-MDBICTest::RunMode', 'script/dbicadmin', @_);
103 if ($^O eq 'MSWin32') {
104 require Win32::ShellQuote; # included in test optdeps
105 @args = Win32::ShellQuote::quote_system_list(@args);