8 $ENV{PERL5LIB} = join ($Config{path_sep}, @INC);
13 eval "require DBIx::Class::Admin";
14 plan skip_all => "Deps not installed: $@" if $@;
16 eval "require Getopt::Long::Descriptive";
17 plan skip_all => 'Install Getopt::Long::Descriptive to run this test' if ($@);
19 eval 'require JSON::Any';
20 plan skip_all => 'Install JSON::Any to run this test' if ($@);
22 eval 'require Text::CSV_XS';
24 eval 'require Text::CSV_PP';
25 plan skip_all => 'Install Text::CSV_XS or Text::CSV_PP to run this test' if ($@);
28 my @json_backends = qw/XS JSON DWIW/;
29 my $tests_per_run = 5;
31 plan tests => $tests_per_run * @json_backends;
33 for my $js (@json_backends) {
35 eval {JSON::Any->import ($js) };
37 skip ("Json backend $js is not available, skip testing", $tests_per_run) if $@;
39 $ENV{JSON_ANY_ORDER} = $js;
40 eval { test_dbicadmin () };
46 # $ENV{PERL5LIB} = join ':', @INC;
48 my $schema = DBICTest->init_schema( sqlite_use_file => 1 ); # reinit a fresh db for every run
50 my $employees = $schema->resultset('Employee');
52 system( _prepare_system_args( qw|--op=insert --set={"name":"Matt"}| ) );
53 ok( ($employees->count()==1), "$ENV{JSON_ANY_ORDER}: insert count" );
55 my $employee = $employees->find(1);
56 ok( ($employee->name() eq 'Matt'), "$ENV{JSON_ANY_ORDER}: insert valid" );
58 system( _prepare_system_args( qw|--op=update --set={"name":"Trout"}| ) );
59 $employee = $employees->find(1);
60 ok( ($employee->name() eq 'Trout'), "$ENV{JSON_ANY_ORDER}: update" );
62 system( _prepare_system_args( qw|--op=insert --set={"name":"Aran"}| ) );
65 skip ("MSWin32 doesn't support -| either", 1) if $^O eq 'MSWin32';
67 open(my $fh, "-|", _prepare_system_args( qw|--op=select --attrs={"order_by":"name"}| ) ) or die $!;
68 my $data = do { local $/; <$fh> };
70 if (!ok( ($data=~/Aran.*Trout/s), "$ENV{JSON_ANY_ORDER}: select with attrs" )) {
71 diag ("data from select is $data")
75 system( _prepare_system_args( qw|--op=delete --where={"name":"Trout"}| ) );
76 ok( ($employees->count()==1), "$ENV{JSON_ANY_ORDER}: delete" );
79 # Why do we need this crap? Apparently MSWin32 can not pass through quotes properly
80 # (sometimes it will and sometimes not, depending on what compiler was used to build
81 # perl). So we go the extra mile to escape all the quotes. We can't also use ' instead
82 # of ", because JSON::XS (proudly) does not support "malformed JSON" as the author
85 sub _prepare_system_args {
89 qw|script/dbicadmin --quiet --schema=DBICTest::Schema --class=Employee|,
90 q|--connect=["dbi:SQLite:dbname=t/var/DBIxClass.db","","",{"AutoCommit":1}]|,
95 if ( $^O eq 'MSWin32' ) {
96 $perl = qq|"$perl"|; # execution will fail if $^X contains paths
102 return ($perl, @args);