Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

CPAN test suites with SQL

by LanX (Saint)
on Apr 14, 2024 at 10:22 UTC ( [id://11158861]=perlquestion: print w/replies, xml ) Need Help??

LanX has asked for the wisdom of the Perl Monks concerning the following question:


I'm developing a DBIx distribution and need to check plenty of SQL in the tests.

My approach is to use SQLite as primary engine, since it comes with the DBD::SQLite module installed and that's not much of a prerequisite (it's even comes bundled with Strawberry Perl!)

My issue is where to put the temporary SQLite file...

  • in the distribution's /t directory?
  • in the FS's /tmp ? What about other OSes?
  • or should I restrict the SQL-testing to the authors system

Those SQLite files don't become big, but I'm not sure about writing stuff into the dist directory. On a side note:

I want to be able to switch to other DB-Servers while testing. (But now really author's side unless explicitly wanted by the user)

What's the best approach to make this configurable?

  • A prove option
  • an ENV setting
  • a prompt while testing? (DBI can test for available DBD:: drivers)

Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re: CPAN test suites with SQL
by Corion (Patriarch) on Apr 14, 2024 at 10:35 UTC

    Why not keep the SQLite files in :memory: ?

    my $dbh = DBI->connect("dbi:SQLite:dbname=:memory:","","");

    Alternatively, have the filenames be created by File::Temp and clean up afterwards:

    use File::Temp 'tempfile'; my ($fh, $tempname) = tempfile(); close $fh; END { unlink $tempname }; my $dbh = DBI->connect("dbi:SQLite:dbname=$tempname","","");

      I've found Test::TempDir::Tiny to be pretty useful for this. It requires less code (it wraps File::Temp), it handles the cleanup, and also leaves the files on disk if the tests fail.

        Oh, nice one. I'll probably start using this.
      > Why not keep the SQLite files in :memory: ?

      Cool, didn't know that one!

      Should have asked earlier! :)

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      see Wikisyntax for the Monastery

        As for testing against other databases: You can, in some cases, just spin up a temporary instance. If i remember correctly, DBD::Pg does (or "did"?) this during testing for PostgreSQL by using a temporary directory. And i'm pretty sure you can start a mysqld instance the same way.

        PerlMonks XP is useless? Not anymore: XPD - Do more with your PerlMonks XP

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11158861]
Front-paged by davies
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-05-27 16:25 GMT
Find Nodes?
    Voting Booth?

    No recent polls found