12 plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for('admin_script')
13 unless DBIx::Class::Optional::Dependencies->req_ok_for('admin_script');
17 $ENV{PERL5LIB} = join ($Config{path_sep}, @INC);
19 my @json_backends = qw/XS JSON DWIW/;
21 # test the script is setting @INC properly
22 test_exec (qw|-It/lib/testinclude --schema=DBICTestAdminInc --connect=[] --insert|);
23 cmp_ok ( $? >> 8, '==', 70, 'Correct exit code from connecting a custom INC schema' );
25 # test that config works properly
28 test_exec(qw|-It/lib/testinclude --schema=DBICTestConfig --create --connect=["klaatu","barada","nikto"]|);
29 cmp_ok( $? >> 8, '==', 71, 'Correct schema loaded via config' ) || exit;
32 # test that config-file works properly
33 test_exec(qw|-It/lib/testinclude --schema=DBICTestConfig --config=t/lib/admincfgtest.json --config-stanza=Model::Gort --deploy|);
34 cmp_ok ($? >> 8, '==', 71, 'Correct schema loaded via testconfig');
36 for my $js (@json_backends) {
38 eval {JSON::Any->import ($js) };
40 skip ("JSON backend $js is not available, skip testing", 1) if $@;
42 $ENV{JSON_ANY_ORDER} = $js;
43 eval { test_dbicadmin () };
51 my $schema = DBICTest->init_schema( sqlite_use_file => 1 ); # reinit a fresh db for every run
53 my $employees = $schema->resultset('Employee');
55 test_exec( default_args(), qw|--op=insert --set={"name":"Matt"}| );
56 ok( ($employees->count()==1), "$ENV{JSON_ANY_ORDER}: insert count" );
58 my $employee = $employees->find(1);
59 ok( ($employee->name() eq 'Matt'), "$ENV{JSON_ANY_ORDER}: insert valid" );
61 test_exec( default_args(), qw|--op=update --set={"name":"Trout"}| );
62 $employee = $employees->find(1);
63 ok( ($employee->name() eq 'Trout'), "$ENV{JSON_ANY_ORDER}: update" );
65 test_exec( default_args(), qw|--op=insert --set={"name":"Aran"}| );
68 skip ("MSWin32 doesn't support -| either", 1) if $^O eq 'MSWin32';
70 my ($perl) = $^X =~ /(.*)/;
72 open(my $fh, "-|", ( $perl, 'script/dbicadmin', default_args(), qw|--op=select --attrs={"order_by":"name"}| ) ) or die $!;
73 my $data = do { local $/; <$fh> };
75 if (!ok( ($data=~/Aran.*Trout/s), "$ENV{JSON_ANY_ORDER}: select with attrs" )) {
76 diag ("data from select is $data")
80 test_exec( default_args(), qw|--op=delete --where={"name":"Trout"}| );
81 ok( ($employees->count()==1), "$ENV{JSON_ANY_ORDER}: delete" );
85 my $dbname = DBICTest->_sqlite_dbfilename;
87 qw|--quiet --schema=DBICTest::Schema --class=Employee|,
88 qq|--connect=["dbi:SQLite:dbname=$dbname","","",{"AutoCommit":1}]|,
89 qw|--force -I testincludenoniterference|,
93 # Why do we need this crap? Apparently MSWin32 can not pass through quotes properly
94 # (sometimes it will and sometimes not, depending on what compiler was used to build
95 # perl). So we go the extra mile to escape all the quotes. We can't also use ' instead
96 # of ", because JSON::XS (proudly) does not support "malformed JSON" as the author
100 my ($perl) = $^X =~ /(.*)/;
102 my @args = ('script/dbicadmin', @_);
104 if ( $^O eq 'MSWin32' ) {
105 $perl = qq|"$perl"|; # execution will fail if $^X contains paths
111 system ($perl, @args);