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
0 | 0 | #!/usr/bin/perl -w |
1 | 1 | |
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 $ | |
3 | 3 | |
4 | 4 | use strict; |
5 | use Test::More (tests => 8); | |
5 | use Test::More (tests => 14); | |
6 | 6 | BEGIN { use_ok('Exception::Class::DBI') } |
7 | 7 | 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 | } | |
17 | 8 | |
18 | 9 | eval { |
19 | 10 | DBI->connect('dbi:Bogus', '', '', |
23 | 14 | }); |
24 | 15 | }; |
25 | 16 | |
26 | ok( my $err = $@, "Caught exception" ); | |
17 | ok( my $err = $@, "Catch exception" ); | |
27 | 18 | SKIP: { |
19 | # Remove this skip when DBI->connect uses exceptions. | |
28 | 20 | skip 'HandleError not logic not yet used by DBI->connect', 6 |
29 | 21 | unless ref $@; |
30 | 22 | isa_ok( $err, 'Exception::Class::DBI' ); |
34 | 26 | ok( ! defined $err->errstr, "Check errstr" ); |
35 | 27 | ok( ! defined $err->state, "Check state" ); |
36 | 28 | 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 | } | |
37 | 65 | } |