File: 00error.t

package info (click to toggle)
libsql-statement-perl 1.414-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 804 kB
  • sloc: perl: 10,528; makefile: 14
file content (51 lines) | stat: -rw-r--r-- 1,482 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/perl -w
use strict;
use warnings;
use lib qw(t);

use Test::More;
use TestLib qw(connect prove_reqs show_reqs);

my ( $required, $recommended ) = prove_reqs();
show_reqs( $required, $recommended );
my @test_dbds = ( 'SQL::Statement', grep { /^dbd:/i } keys %{$recommended} );

foreach my $test_dbd (@test_dbds)
{
    my $dbh;
    note("Running tests for $test_dbd");

    # Test RaiseError for prepare errors
    #
    $dbh = connect(
                    $test_dbd,
                    {
                       PrintError => 0,
                       RaiseError => 0,
                    }
                  );
    eval { $dbh->prepare("Junk"); };
    ok( !$@, 'Parse "Junk" RaiseError=0 (default)' ) or diag($@);
    eval { $dbh->do("SELECT UPPER('a')"); };
    ok( !$@, 'Execute function succeeded' ) or diag($@);
    ok( !$dbh->errstr(), 'Execute function no errstr' ) or diag($dbh->errstr());
    eval { $dbh->do( "SELECT * FROM nonexistant" ); };
    ok( !$@, 'Execute RaiseError=0' ) or diag($@);

    $dbh = connect(
                    $test_dbd,
                    {
                       PrintError => 0,
                       RaiseError => 1,
                    }
                  );
    eval { $dbh->prepare("Junk"); };
    ok( $@, 'Parse "Junk" RaiseError=1' );
    {
	eval { $dbh->do( "SELECT * FROM nonexistant" ); };
	ok( $@, 'Execute RaiseError=1' );
	ok( $dbh->errstr(), 'Execute "SELECT * FROM nonexistant" has errstr' );
    }
}

done_testing();