File: 74-class.t

package info (click to toggle)
libdbd-csv-perl 0.6200-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 332 kB
  • sloc: perl: 2,065; makefile: 4
file content (46 lines) | stat: -rw-r--r-- 1,070 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/perl

use strict;
use warnings;
use Test::More;

BEGIN { use_ok ("DBI"); }

my $tbl = "foo_class$$";
my $fnm = "$tbl.csv";

END { unlink $fnm; }

my @fail;
foreach my $class ("", "Text::CSV_XS", "Text::CSV", "Text::CSV_SX") {
    my %opt = (f_ext => ".csv/r");
    if ($class) {
	$opt{csv_class} = $class;
	eval "require $class";	# Ignore errors, let the DBD fail
	}
    # Connect won't fail ...
    ok (my $dbh = DBI->connect ("dbi:CSV:",
	undef, undef, \%opt),			"Connect $class");
    my @warn;
    my $sth = eval {
	local $SIG{__WARN__} = sub { push @warn => @_ };
	$dbh->do ("create table $tbl (c_tbl integer)");
	};
    if ($@ || !$sth) {
	note ("$class is not supported");
	like ("@warn", qr{"new" via package "$class"});
	push @fail => $class;
	next;
	}
    $class and note (join "-" => $class, $class->VERSION);

    ok ($dbh->do ("drop table $tbl"),		"drop table");
    ok (!-f $fnm,				"is removed");

    ok ($dbh->disconnect,			"disconnect");
    undef $dbh;
    }

ok (@fail == 1 || @fail == 2, "2 or 3 out of 4 should pass");

done_testing ();