diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2012-09-24 10:15:50 +0000 |
---|---|---|
committer | Lorry <lorry@roadtrain.codethink.co.uk> | 2012-09-26 13:46:46 +0000 |
commit | 485b97be9f2f2abf5a40923b5fd85f75714a8c02 (patch) | |
tree | ca05cb0ecf3828d909a898c3e5805804a0aff5f8 /t/49_trace_and_profile.t | |
download | perl-dbd-sqlite-tarball-485b97be9f2f2abf5a40923b5fd85f75714a8c02.tar.gz |
Imported from /srv/lorry/lorry-area/perl-dbd-sqlite-tarball/DBD-SQLite-1.38_01.tar.gz.HEADDBD-SQLite-1.38_01masterbaserock/morph
Diffstat (limited to 't/49_trace_and_profile.t')
-rw-r--r-- | t/49_trace_and_profile.t | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/t/49_trace_and_profile.t b/t/49_trace_and_profile.t new file mode 100644 index 0000000..b56826a --- /dev/null +++ b/t/49_trace_and_profile.t @@ -0,0 +1,61 @@ +#!/usr/bin/perl + +use strict; +BEGIN { + $| = 1; + $^W = 1; +} + +use t::lib::Test qw/connect_ok @CALL_FUNCS/; +use Test::More; +use Test::NoWarnings; + +plan tests => 12 * @CALL_FUNCS + 1; + +my $flag = 0; +for my $call_func (@CALL_FUNCS) { + my $dbh = connect_ok(); + + # sqlite_trace should always be called as sqlite_trace, + # i.e. $dbh->func(..., "sqlite_trace") and $dbh->sqlite_trace(...) + my $func_name = $flag++ ? "trace" : "sqlite_trace"; + + # trace + my @trace; + $dbh->$call_func(sub { push @trace, [@_] }, $func_name); + $dbh->do('create table foo (id integer)'); + is $trace[0][0] => "create table foo (id integer)"; + + $dbh->do('insert into foo values (?)', undef, 1); + is $trace[1][0] => "insert into foo values ('1')"; + + $dbh->$call_func(undef, $func_name); + + $dbh->do('insert into foo values (?)', undef, 2); + is @trace => 2; + + $dbh->$call_func(sub { push @trace, [@_] }, $func_name); + $dbh->do('insert into foo values (?)', undef, 3); + is $trace[2][0] => "insert into foo values ('3')"; + + # profile + my @profile; + $dbh->$call_func(sub { push @profile, [@_] }, "profile"); + $dbh->do('create table bar (id integer)'); + is $profile[0][0] => "create table bar (id integer)"; + like $profile[0][1] => qr/^[0-9]+$/; + + $dbh->do('insert into bar values (?)', undef, 1); + is $profile[1][0] => "insert into bar values (?)"; + like $profile[1][1] => qr/^[0-9]+$/; + + $dbh->$call_func(undef, "profile"); + + $dbh->do('insert into bar values (?)', undef, 2); + is @profile => 2; + + $dbh->$call_func(sub { push @profile, [@_] }, "profile"); + $dbh->do('insert into bar values (?)', undef, 3); + is $profile[2][0] => "insert into bar values (?)"; + like $profile[2][1] => qr/^[0-9]+$/; +} |