| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
# Test whether data_sources () returns something useful |
| 4 |
|
| 5 |
use strict; |
| 6 |
use warnings; |
| 7 |
use Test::More; |
| 8 |
|
| 9 |
# Include lib.pl |
| 10 |
BEGIN { use_ok ("DBI") } |
| 11 |
do "./t/lib.pl"; |
| 12 |
|
| 13 |
ok (1, "Driver is CSV\n"); |
| 14 |
|
| 15 |
ok (my $dbh = Connect (), "Connect"); |
| 16 |
|
| 17 |
$dbh or BAIL_OUT "Cannot connect"; |
| 18 |
|
| 19 |
ok ($dbh->ping, "ping"); |
| 20 |
|
| 21 |
# This returns at least ".", "lib", and "t" |
| 22 |
ok (my @dsn = DBI->data_sources ("CSV"), "data_sources"); |
| 23 |
ok (@dsn >= 2, "more than one"); |
| 24 |
ok ($dbh->disconnect, "disconnect"); |
| 25 |
|
| 26 |
# Try different DSN's |
| 27 |
foreach my $d (qw( . examples lib t )) { |
| 28 |
ok (my $dns = Connect ("dbi:CSV:f_dir=$d"), "use $d as f_dir"); |
| 29 |
ok ($dbh->disconnect, "disconnect"); |
| 30 |
} |
| 31 |
|
| 32 |
if ($DBD::File::VERSION ge "0.45") { |
| 33 |
my @err; |
| 34 |
is (eval { |
| 35 |
local $SIG{__WARN__} = sub { push @err => @_ }; |
| 36 |
local $SIG{__DIE__} = sub { push @err => @_ }; |
| 37 |
Connect ("dbi:CSV:f_dir=d/non/exist/here"); |
| 38 |
}, undef, "f_dir = nonexting dir"); |
| 39 |
like ("@err", qr{d/non/exist/here}, "Error caught"); |
| 40 |
} |
| 41 |
|
| 42 |
done_testing (); |