File: 08-handle.t

package info (click to toggle)
libtest-database-perl 1.112-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 272 kB
  • ctags: 83
  • sloc: perl: 637; makefile: 2
file content (51 lines) | stat: -rw-r--r-- 1,384 bytes parent folder | download | duplicates (2)
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
use strict;
use warnings;
use Test::More;
use Test::Database::Handle;
use List::Util qw( sum );

my @tests = (

    # args, expected result, error regex
    [ [], undef, qr/^dsn argument required/ ],
    [ [ dbd => 'Zlonk' ], undef, qr/^dsn argument required/ ],
    [   [ driver => 'Foo', dsn => 'dbi:SQLite:dbname=zlonk' ],
        {   dsn      => 'dbi:SQLite:dbname=zlonk',
            username => undef,
            password => undef ,
            dbd      => 'SQLite',
            driver   => 'Foo',
        }
    ],
    [   [   dbd  => 'SQLite',
            dsn  => 'dbi:SQLite:dbname=zlonk',
            name => 'zlonk'
        ],
        {   dsn      => 'dbi:SQLite:dbname=zlonk',
            username => undef,
            password => undef,
            dbd      => 'SQLite',
            name     => 'zlonk',
        }
    ],
);
my @attr = qw( dsn username password dbd );

plan tests => sum map { $_->[2] ? 1 : 1 + @attr } @tests;

for my $t (@tests) {
    my ( $args, $expected, $err ) = @$t;

    my $got = eval { Test::Database::Handle->new(@$args) };
    my $call = "Test::Database::Handle->new( "
        . join( ', ', map {"'$_'"} @$args ) . " )";

    if ($@) {
        like( $@, $err, "Expected error message for $call" );
    }
    else {
        isa_ok( $got, 'Test::Database::Handle' );
        is( $got->$_, $expected->{$_}, "$_ for $call" ) for @attr;
    }
}