1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#!perl -w
use strict;
use Test::More tests => 7;
use DBIx::RunSQL;
use Data::Dumper;
my $have_scalar_open = eval {
require 5.008; # for scalar open
require DBD::SQLite;
1;
};
my @received;
{
no warnings 'redefine';
sub DBIx::RunSQL::create {
@received= @_;
};
};
DBIx::RunSQL->handle_command_line(
"my-test-app",
);
my ($package,%options)= @received;
is $options{ dsn }, "dbi:SQLite:dbname=db/my-test-app.sqlite", "DSN gets appname used as default";
DBIx::RunSQL->handle_command_line(
"my-test-app",
['--dsn' => 'dbi:Magic:'],
);
($package,%options)= @received;
is $options{ dsn }, "dbi:Magic:", "DSN gets passed through";
# Test the invocation styles for SQL
DBIx::RunSQL->handle_command_line(
"my-test-app",
['--sql' => 'sql 1', "some more stuff that's ignored"],
);
($package,%options)= @received;
is ${$options{ sql }}, "sql 1", "Explicit SQL gets returned";
DBIx::RunSQL->handle_command_line(
"my-test-app",
['--', 'sql 2 on command line'],
);
($package,%options)= @received;
is ${$options{ sql }}, "sql 2 on command line", "SQL on the command line gets returned";
SKIP: {
if( ! $have_scalar_open ) {
skip "No scalar open on this version of Perl", 3;
};
{ open *STDIN, '<', \'sql from STDIN';
DBIx::RunSQL->handle_command_line(
"my-test-app",
['--'],
);
($package,%options)= @received;
};
ok !$options{ sql }, "We got no SQL string";
ok $options{ fh }, "We'll read sql from STDIN";
{ open *STDIN, '<', \'sql from STDIN 2';
DBIx::RunSQL->handle_command_line(
"my-test-app",
['--', "some SQL"],
);
($package,%options)= @received;
};
is ${$options{ sql }}, "some SQL", "We don't read from STDIN if we get other stuff";
};
|