10 eval 'require JSON::Any';
11 plan skip_all => 'Install JSON::Any to run this test' if ($@);
13 eval 'require Text::CSV_XS';
15 eval 'require Text::CSV_PP';
16 plan skip_all => 'Install Text::CSV_XS or Text::CSV_PP to run this test' if ($@);
19 my @json_backends = qw/XS JSON DWIW Syck/;
20 my $tests_per_run = 5;
22 plan tests => $tests_per_run * @json_backends;
25 for my $js (@json_backends) {
27 eval {JSON::Any->import ($js) };
29 skip ("Json backend $js is not available, skip testing", $tests_per_run) if $@;
31 $ENV{JSON_ANY_ORDER} = $js;
32 eval { test_dbicadmin () };
38 my $schema = DBICTest->init_schema( sqlite_use_file => 1 ); # reinit a fresh db for every run
40 my $employees = $schema->resultset('Employee');
42 system( _prepare_system_args( qw|--op=insert --set={"name":"Matt"}| ) );
43 ok( ($employees->count()==1), "$ENV{JSON_ANY_ORDER}: insert count" );
45 my $employee = $employees->find(1);
46 ok( ($employee->name() eq 'Matt'), "$ENV{JSON_ANY_ORDER}: insert valid" );
48 system( _prepare_system_args( qw|--op=update --set={"name":"Trout"}| ) );
49 $employee = $employees->find(1);
50 ok( ($employee->name() eq 'Trout'), "$ENV{JSON_ANY_ORDER}: update" );
52 system( _prepare_system_args( qw|--op=insert --set={"name":"Aran"}| ) );
55 skip ("MSWin32 doesn't support -| either", 1) if $^O eq 'MSWin32';
57 open(my $fh, "-|", _prepare_system_args( qw|--op=select --attrs={"order_by":"name"}| ) ) or die $!;
58 my $data = do { local $/; <$fh> };
60 ok( ($data=~/Aran.*Trout/s), "$ENV{JSON_ANY_ORDER}: select with attrs" );
63 system( _prepare_system_args( qw|--op=delete --where={"name":"Trout"}| ) );
64 ok( ($employees->count()==1), "$ENV{JSON_ANY_ORDER}: delete" );
67 # Why do we need this crap? Apparently MSWin32 can not pass through quotes properly
68 # (sometimes it will and sometimes not, depending on what compiler was used to build
69 # perl). So we go the extra mile to escape all the quotes. We can't also use ' instead
70 # of ", because JSON::XS (proudly) does not support "malformed JSON" as the author
73 sub _prepare_system_args {
76 qw|script/dbicadmin --quiet --schema=DBICTest::Schema --class=Employee --tlibs|,
77 q|--connect=["dbi:SQLite:dbname=t/var/DBIxClass.db","","",{"AutoCommit":1}]|,
82 if ( $^O eq 'MSWin32' ) {
83 $perl = qq|"$perl"|; # execution will fail if $^X contains paths
89 return ($perl, @args);