Codebase list libexception-class-dbi-perl / 53fa805
Added more thorogh testing of connect() exceptions in dbi.t. Need to actually patch DBI.pm some more to make it consistent. David Wheeler 21 years ago
1 changed file(s) with 40 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
00 #!/usr/bin/perl -w
11
2 # $Id: dbi.t,v 1.1 2002/08/22 17:33:47 david Exp $
2 # $Id: dbi.t,v 1.2 2002/08/23 00:55:45 david Exp $
33
44 use strict;
5 use Test::More (tests => 8);
5 use Test::More (tests => 14);
66 BEGIN { use_ok('Exception::Class::DBI') }
77 use DBI;
8
9 {
10 # Fake out DBD::ExampleP's connect method. Take the opportunity
11 # to set the dynamic attributes.
12 use DBD::ExampleP;
13 local $^W;
14 *DBD::ExampleP::dr::connect =
15 sub { $_[0]->set_err(7, 'Dammit Jim!', 'ABCDE') };
16 }
178
189 eval {
1910 DBI->connect('dbi:Bogus', '', '',
2314 });
2415 };
2516
26 ok( my $err = $@, "Caught exception" );
17 ok( my $err = $@, "Catch exception" );
2718 SKIP: {
19 # Remove this skip when DBI->connect uses exceptions.
2820 skip 'HandleError not logic not yet used by DBI->connect', 6
2921 unless ref $@;
3022 isa_ok( $err, 'Exception::Class::DBI' );
3426 ok( ! defined $err->errstr, "Check errstr" );
3527 ok( ! defined $err->state, "Check state" );
3628 ok( ! defined $err->retval, "Check retval" );
29
30 # Try to trigger a usage exception.
31 eval {
32 DBI->connect('', '', {}, # uh-oh, referenced password.
33 { PrintError => 0,
34 RaiseError => 0,
35 HandleError => Exception::Class::DBI->handler
36 });
37 };
38 ok( $err = $@, "Catch usage exception" );
39 isa_ok( $err, 'Exception::Class::DBI' );
40 is( $err->error, 'Usage: $class->connect([$dsn [,$user [,$passwd ' .
41 '[,\%attr]]]])', "Check usage error" );
42
43 TODO: {
44 # Remove this TODO when DBI->install_driver uses exceptions.
45 local $TODO = "DBI->install_driver doesn't use HandleError Yet";
46 # Try to trigger a install driver error.
47 eval {
48 DBI->connect('dbi:dummy:foo', '', '', # dummy driver.
49 { PrintError => 0,
50 RaiseError => 0,
51 HandleError => Exception::Class::DBI->handler
52 });
53 };
54 ok( $err = $@, "Catch usage exception" );
55 isa_ok( $err, 'Exception::Class::DBI' );
56 SKIP: {
57 # Remove this SKIP when DBI->install_driver uses exceptions.
58 skip 'HandleError not logic not yet used by DBI->install_driver', 1
59 unless ref $err;
60 # Can take out "ref $err" when the TODO is completed.
61 is( $err->error, 'panic: $class->install_driver(dummy) failed',
62 "Check driver error" );
63 }
64 }
3765 }