11 eval "require DBIx::Class::Admin";
12 plan skip_all => "Deps not installed: $@" if $@;
14 eval "require Getopt::Long::Descriptive";
15 plan skip_all => 'Install Getopt::Long::Descriptive to run this test' if ($@);
17 eval 'require JSON::Any';
18 plan skip_all => 'Install JSON::Any to run this test' if ($@);
20 eval 'require Text::CSV_XS';
22 eval 'require Text::CSV_PP';
23 plan skip_all => 'Install Text::CSV_XS or Text::CSV_PP to run this test' if ($@);
26 my @json_backends = qw/XS JSON DWIW/;
27 my $tests_per_run = 5;
29 plan tests => $tests_per_run * @json_backends;
31 for my $js (@json_backends) {
33 eval {JSON::Any->import ($js) };
35 skip ("Json backend $js is not available, skip testing", $tests_per_run) if $@;
37 $ENV{JSON_ANY_ORDER} = $js;
38 eval { test_dbicadmin () };
44 my $schema = DBICTest->init_schema( sqlite_use_file => 1 ); # reinit a fresh db for every run
46 my $employees = $schema->resultset('Employee');
48 system( _prepare_system_args( qw|--op=insert --set={"name":"Matt"}| ) );
49 ok( ($employees->count()==1), "$ENV{JSON_ANY_ORDER}: insert count" );
51 my $employee = $employees->find(1);
52 ok( ($employee->name() eq 'Matt'), "$ENV{JSON_ANY_ORDER}: insert valid" );
54 system( _prepare_system_args( qw|--op=update --set={"name":"Trout"}| ) );
55 $employee = $employees->find(1);
56 ok( ($employee->name() eq 'Trout'), "$ENV{JSON_ANY_ORDER}: update" );
58 system( _prepare_system_args( qw|--op=insert --set={"name":"Aran"}| ) );
61 skip ("MSWin32 doesn't support -| either", 1) if $^O eq 'MSWin32';
63 open(my $fh, "-|", _prepare_system_args( qw|--op=select --attrs={"order_by":"name"}| ) ) or die $!;
64 my $data = do { local $/; <$fh> };
66 if (!ok( ($data=~/Aran.*Trout/s), "$ENV{JSON_ANY_ORDER}: select with attrs" )) {
67 diag ("data from select is $data")
71 system( _prepare_system_args( qw|--op=delete --where={"name":"Trout"}| ) );
72 ok( ($employees->count()==1), "$ENV{JSON_ANY_ORDER}: delete" );
75 # Why do we need this crap? Apparently MSWin32 can not pass through quotes properly
76 # (sometimes it will and sometimes not, depending on what compiler was used to build
77 # perl). So we go the extra mile to escape all the quotes. We can't also use ' instead
78 # of ", because JSON::XS (proudly) does not support "malformed JSON" as the author
81 sub _prepare_system_args {
84 qw|script/dbicadmin --quiet --schema=DBICTest::Schema --class=Employee --tlibs|,
85 q|--connect=["dbi:SQLite:dbname=t/var/DBIxClass.db","","",{"AutoCommit":1}]|,
90 if ( $^O eq 'MSWin32' ) {
91 $perl = qq|"$perl"|; # execution will fail if $^X contains paths
97 return ($perl, @args);