2ea101696e020e994b76cf7c7a4dcf21e5c7ca49
[dbsrgits/DBIx-Class.git] / t / 91debug.t
1 use strict;
2 use warnings; 
3
4 use Test::More;
5 use lib qw(t/lib);
6 use DBICTest;
7
8 my $schema = DBICTest->init_schema();
9
10 plan tests => 5;
11
12 ok ( $schema->storage->debug(1), 'debug' );
13 ok ( defined(
14        $schema->storage->debugfh(
15          IO::File->new('t/var/sql.log', 'w')
16        )
17      ),
18      'debugfh'
19    );
20
21 my $rs = $schema->resultset('CD')->search({});
22 $rs->count();
23
24 my $log = new IO::File('t/var/sql.log', 'r') or die($!);
25 my $line = <$log>;
26 $log->close();
27 ok($line =~ /^SELECT COUNT/, 'Log success');
28
29 $schema->storage->debugfh(undef);
30 $ENV{'DBIC_TRACE'} = '=t/var/foo.log';
31 $rs = $schema->resultset('CD')->search({});
32 $rs->count();
33 $log = new IO::File('t/var/foo.log', 'r') or die($!);
34 $line = <$log>;
35 $log->close();
36 ok($line =~ /^SELECT COUNT/, 'Log success');
37
38 $schema->storage->debugobj->debugfh(undef);
39 delete($ENV{'DBIC_TRACE'});
40 open(STDERRCOPY, '>&STDERR');
41 stat(STDERRCOPY); # nop to get warnings quiet
42 close(STDERR);
43 eval {
44     $rs = $schema->resultset('CD')->search({});
45     $rs->count();
46 };
47 ok($@, 'Died on closed FH');
48 open(STDERR, '>&STDERRCOPY');
49
50 1;