in reply to CPAN test suites with SQL

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","","");

Replies are listed 'Best First'.
Re^2: CPAN test suites with SQL
by swl (Prior) on Apr 15, 2024 at 02:38 UTC

    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.
Re^2: CPAN test suites with SQL
by LanX (Saint) on Apr 14, 2024 at 10:52 UTC
    > 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
        I use Test::PostgreSQL for that all the time, in my applications. I usually don't for my CPAN modules, though SQL::Translator's tests conditionally check for it and SKIP otherwise.