Created
December 27, 2011 18:42
-
-
Save riywo/1524740 to your computer and use it in GitHub Desktop.
Amon2でTest::mysqld
This file contains 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
die unless defined $ENV{TEST_DSN}; | |
+{ 'DBI' => [ | |
$ENV{TEST_DSN}, | |
'', | |
'', | |
+{ | |
} ], | |
}; |
This file contains 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 t::Util; | |
BEGIN { | |
unless ($ENV{PLACK_ENV}) { | |
$ENV{PLACK_ENV} = 'test'; | |
} | |
if ($ENV{PLACK_ENV} eq 'deployment') { | |
die "Do not run a test script on deployment environment"; | |
} | |
} | |
use File::Spec; | |
use File::Basename; | |
use lib File::Spec->rel2abs(File::Spec->catdir(dirname(__FILE__), '..', 'extlib', 'lib', 'perl5')); | |
use lib File::Spec->rel2abs(File::Spec->catdir(dirname(__FILE__), '..', 'lib')); | |
use parent qw/Exporter/; | |
use Test::More 0.98; | |
use Test::mysqld; | |
our @EXPORT = qw(slurp); | |
{ | |
# utf8 hack. | |
binmode Test::More->builder->$_, ":utf8" for qw/output failure_output todo_output/; | |
no warnings 'redefine'; | |
my $code = \&Test::Builder::child; | |
*Test::Builder::child = sub { | |
my $builder = $code->(@_); | |
binmode $builder->output, ":utf8"; | |
binmode $builder->failure_output, ":utf8"; | |
binmode $builder->todo_output, ":utf8"; | |
return $builder; | |
}; | |
} | |
my $MYSQLD; | |
use MyApp; | |
{ | |
unless (defined $ENV{TEST_DSN}) { | |
$MYSQLD = Test::mysqld->new( | |
my_cnf => { | |
"skip-networking" => "" | |
} | |
); | |
$ENV{TEST_DSN} = $MYSQLD->dsn; | |
my $c = MyApp->new(); | |
$c->setup_schema(); | |
} | |
} | |
END { undef $MYSQLD } | |
sub slurp { | |
my $fname = shift; | |
open my $fh, '<:encoding(UTF-8)', $fname or die "$fname: $!"; | |
do { local $/; <$fh> }; | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment