Created
November 7, 2010 06:36
-
-
Save xaicron/665984 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use inc::Module::Install; | |
use Module::Install::TestTarget; | |
name 'MyApp'; | |
all_from 'lib/MyApp.pm'; | |
requires 'DBI'; | |
requires 'JSON'; | |
test_requires 'Test::More'; | |
test_requires 'Test::mysqld'; | |
tests 't/*.t t/*/*.t t/*/*/*.t'; | |
author_tests 'xt'; | |
default_test_target( | |
includes => ['t/lib'], | |
run_on_prepare => ['t/script/setup_mysqld.pl'], | |
); | |
auto_include(); | |
WriteAll; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Test::MyApp::mysqld; | |
use strict; | |
use warnings; | |
use Test::mysqld; | |
use JSON; | |
use DBI; | |
our $SKIP_DROP_DB_MAP = { | |
information_schema => 1, | |
mysql => 1, | |
test => 1, | |
}; | |
sub setup { | |
my ($class, %config) = @_; | |
my $mysqld; | |
if (my $json = $ENV{TEST_MYSQLD}) { | |
my $obj = decode_json $json; | |
$mysqld = bless $obj, 'Test::mysqld'; | |
} | |
else { | |
$mysqld = Test::mysqld->new(my_cnf => { | |
'skip-networking' => '', | |
%config, | |
}) or die $Test::mysqld::errstr; | |
} | |
return $mysqld; | |
} | |
sub cleanup { | |
my ($class, $mysqld) = @_; | |
my $dbh = DBI->connect($mysqld->dsn, '', '', { | |
AutoCommit => 1, | |
RaiseError => 1, | |
}); | |
my $rs = $dbh->selectall_hashref('SHOW DATABASES', 'Database'); | |
for my $dbname (keys %$rs) { | |
next if $SKIP_DROP_DB_MAP->{$dbname}; | |
$dbh->do("DROP DATABASE $dbname"); | |
} | |
} | |
1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Test::MyApp::mysqld; | |
use JSON; | |
$SIG{INT} = sub { CORE::exit 1 }; | |
$mysqld = Test::MyApp::mysqld->setup; | |
$ENV{TEST_MYSQLD} = encode_json +{ %$mysqld }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment