Adjust code spacing, tweak comments, do only (de)serialize tests with database, give tests names.

This commit is contained in:
Daniel Nichter
2011-12-28 15:47:50 -07:00
parent 88e82d665d
commit 4197b09f53
2 changed files with 55 additions and 51 deletions

View File

@@ -9,7 +9,7 @@ BEGIN {
use strict;
use warnings FATAL => 'all';
use English qw(-no_match_vars);
use Test::More tests => 63;
use Test::More tests => 47;
use Quoter;
use PerconaTest;
@@ -99,6 +99,10 @@ is( $q->join_quote('`db`', '`tbl`'), '`db`.`tbl`', 'join_merge(`db`, `tbl`)' );
is( $q->join_quote(undef, '`tbl`'), '`tbl`', 'join_merge(undef, `tbl`)' );
is( $q->join_quote('`db`', '`foo`.`tbl`'), '`foo`.`tbl`', 'join_merge(`db`, `foo`.`tbl`)' );
# ###########################################################################
# (de)serialize_list
# ###########################################################################
my @serialize_tests = (
[ 'a', 'b', ],
[ 'a,', 'b', ],
@@ -118,22 +122,17 @@ my @serialize_tests = (
[ '', '', '', ],
);
for my $test ( @serialize_tests ) {
my $ser = Quoter::serialize_list( @$test );
is_deeply(
[Quoter::deserialize_list($ser)],
$test,
"serialize then deserialize works"
);
}
use DSNParser;
use Sandbox;
my $dp = new DSNParser(opts=>$dsn_opts);
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
my $dp = new DSNParser(opts=>$dsn_opts);
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
my $dbh = $sb->get_dbh_for('master');
SKIP: {
skip 'Cannot connect to sandbox master', 1 unless $dbh;
skip 'Cannot connect to sandbox master', scalar @serialize_tests unless $dbh;
# Prevent "Wide character in print at Test/Builder.pm" warnings.
binmode Test::More->builder->$_(), ':encoding(UTF-8)'
for qw(output failure_output);
$dbh->do('CREATE DATABASE IF NOT EXISTS serialize_test');
$dbh->do('DROP TABLE IF EXISTS serialize_test.serialize');
@@ -147,7 +146,7 @@ SKIP: {
);
for my $test_index ( 0..$#serialize_tests ) {
my $ser = Quoter::serialize_list( @{$serialize_tests[$test_index]} );
my $ser = $q->serialize_list( @{$serialize_tests[$test_index]} );
# Bit of a hack, but we want to test both of Perl's internal encodings
# for correctness.
@@ -156,10 +155,13 @@ SKIP: {
$sth->execute($test_index, $ser);
$selsth->execute($test_index);
my $flat_string = "@{$serialize_tests[$test_index]}";
$flat_string =~ s/\n/\\n/g;
is_deeply(
[Quoter::deserialize_list($selsth->fetchrow_array())],
[ $q->deserialize_list($selsth->fetchrow_array()) ],
$serialize_tests[$test_index],
"serialize then deserialize through the DB works"
"Serialize $flat_string"
);
}
@@ -171,4 +173,7 @@ SKIP: {
$dbh->disconnect();
};
# ###########################################################################
# Done.
# ###########################################################################
exit;