1 package # Hide from PAUSE
5 use warnings FATAL => 'all';
14 use File::Temp qw( tempfile tempdir );
15 use Fcntl qw( :flock );
17 my $parent = $ENV{WORK_DIR} || File::Spec->tmpdir;
18 our $dir = tempdir( CLEANUP => 1, DIR => $parent );
21 my ($fh, $filename) = tempfile( 'tmpXXXX', DIR => $dir, UNLINK => 1 );
23 # This is because tempfile() returns a flock'ed $fh on MacOSX.
26 return ($fh, $filename);
31 my ($fh, $filename) = new_fh();
33 my (@names, @reset_funcs, @extra_args);
35 unless ( $ENV{NO_TEST_FILE} ) {
37 push @reset_funcs, undef;
43 if ( $ENV{TEST_SQLITE} ) {
44 (undef, my $filename) = new_fh();
45 push @names, 'SQLite';
46 push @reset_funcs, sub {
48 my $dbh = DBI->connect(
49 "dbi:SQLite:dbname=$filename", '', '',
52 my $filename = 'etc/sqlite_tables.sql';
53 open my $fh, '<', $filename
54 or die "Cannot open '$filename' for reading: $!\n";
58 foreach my $line ( split ';', $sql ) {
59 $dbh->do( "$line" ) if $line =~ /\S/;
64 dsn => "dbi:SQLite:dbname=$filename",
71 if ( $ENV{TEST_MYSQL_DSN} ) {
73 push @reset_funcs, sub {
75 my $dbh = DBI->connect(
77 $ENV{TEST_MYSQL_USER},
78 $ENV{TEST_MYSQL_PASS},
81 my $filename = 'etc/mysql_tables.sql';
82 open my $fh, '<', $filename
83 or die "Cannot open '$filename' for reading: $!\n";
87 foreach my $line ( split ';', $sql ) {
88 $dbh->do( "$line" ) if $line =~ /\S/;
93 dsn => $ENV{TEST_MYSQL_DSN},
94 user => $ENV{TEST_MYSQL_USER},
95 password => $ENV{TEST_MYSQL_PASS},
101 return unless @extra_args;
102 my @these_args = @{ shift @extra_args };
103 if ( my $reset = shift @reset_funcs ) {
106 Test::More::diag( "Testing '@{[shift @names]}'\n" ) if $ENV{TEST_VERBOSE};
108 DBM::Deep->new( @these_args, @args, @_ )