Skip to content

Instantly share code, notes, and snippets.

@riywo
Created December 27, 2011 18:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save riywo/1524740 to your computer and use it in GitHub Desktop.
Save riywo/1524740 to your computer and use it in GitHub Desktop.
Amon2でTest::mysqld
die unless defined $ENV{TEST_DSN};
+{ 'DBI' => [
$ENV{TEST_DSN},
'',
'',
+{
} ],
};
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