| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
use Test::More; |
| 6 |
|
| 7 |
BEGIN { use_ok ("DBI"); } |
| 8 |
|
| 9 |
my $tbl = "foo_class$$"; |
| 10 |
my $fnm = "$tbl.csv"; |
| 11 |
|
| 12 |
END { unlink $fnm; } |
| 13 |
|
| 14 |
my @fail; |
| 15 |
foreach my $class ("", "Text::CSV_XS", "Text::CSV", "Text::CSV_SX") { |
| 16 |
my %opt = (f_ext => ".csv/r"); |
| 17 |
if ($class) { |
| 18 |
$opt{csv_class} = $class; |
| 19 |
eval "require $class"; # Ignore errors, let the DBD fail |
| 20 |
} |
| 21 |
# Connect won't fail ... |
| 22 |
ok (my $dbh = DBI->connect ("dbi:CSV:", |
| 23 |
undef, undef, \%opt), "Connect $class"); |
| 24 |
my @warn; |
| 25 |
my $sth = eval { |
| 26 |
local $SIG{__WARN__} = sub { push @warn => @_ }; |
| 27 |
$dbh->do ("create table $tbl (c_tbl integer)"); |
| 28 |
}; |
| 29 |
if ($@ || !$sth) { |
| 30 |
note ("$class is not supported"); |
| 31 |
like ("@warn", qr{"new" via package "$class"}); |
| 32 |
push @fail => $class; |
| 33 |
next; |
| 34 |
} |
| 35 |
$class and note (join "-" => $class, $class->VERSION); |
| 36 |
|
| 37 |
ok ($dbh->do ("drop table $tbl"), "drop table"); |
| 38 |
ok (!-f $fnm, "is removed"); |
| 39 |
|
| 40 |
ok ($dbh->disconnect, "disconnect"); |
| 41 |
undef $dbh; |
| 42 |
} |
| 43 |
|
| 44 |
ok (@fail == 1 || @fail == 2, "2 or 3 out of 4 should pass"); |
| 45 |
|
| 46 |
done_testing (); |