~percona-toolkit-dev/percona-toolkit/fix-log-parser-writer-bug-963225

« back to all changes in this revision

Viewing changes to t/lib/TableParser.pl

  • Committer: Daniel Nichter
  • Date: 2011-06-24 17:22:06 UTC
  • Revision ID: daniel@percona.com-20110624172206-c7q4s4ad6r260zz6
Add lib/, t/lib/, and sandbox/.  All modules are updated and passing on MySQL 5.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
# ##########################################################################
 
4
# This is a magic test file that is designed to be run manually.
 
5
# ##########################################################################
 
6
 
 
7
# This program is copyright (c) 2007 Baron Schwartz.
 
8
# Feedback and improvements are welcome.
 
9
#
 
10
# THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
 
11
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 
12
# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
13
#
 
14
# This program is free software; you can redistribute it and/or modify it under
 
15
# the terms of the GNU General Public License as published by the Free Software
 
16
# Foundation, version 2; OR the Perl Artistic License.  On UNIX and similar
 
17
# systems, you can issue `man perlgpl' or `man perlartistic' to read these
 
18
# licenses.
 
19
#
 
20
# You should have received a copy of the GNU General Public License along with
 
21
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 
22
# Place, Suite 330, Boston, MA  02111-1307  USA.
 
23
use strict;
 
24
use warnings FATAL => 'all';
 
25
 
 
26
use Test::More qw(no_plan);
 
27
use English qw(-no_match_vars);
 
28
use DBI;
 
29
 
 
30
require "../TableParser.pm";
 
31
require "../MySQLFind.pm";
 
32
require "../MySQLDump.pm";
 
33
require "../Quoter.pm";
 
34
 
 
35
my $p = new TableParser();
 
36
my $q = new Quoter();
 
37
my $d = new MySQLDump();
 
38
my $t;
 
39
 
 
40
# This part of the test inspects every table in the local MySQL server, if a
 
41
# connection can be made.  It checks that parsing produces the same columns
 
42
# and types and nullability etc as reported by SHOW COLUMNS.
 
43
 
 
44
my $dbh;
 
45
eval {
 
46
   $dbh = DBI->connect(
 
47
   "DBI:mysql:;mysql_read_default_group=mysql", undef, undef,
 
48
   { PrintError => 0, RaiseError => 1 })
 
49
};
 
50
if ( $EVAL_ERROR ) {
 
51
   diag "Cannot connect";
 
52
   exit(0);
 
53
}
 
54
 
 
55
my $f = new MySQLFind(
 
56
   dbh    => $dbh,
 
57
   quoter => $q,
 
58
   engines => {
 
59
      views => 0,
 
60
   },
 
61
);
 
62
 
 
63
foreach my $database ( $f->find_databases() ) {
 
64
   foreach my $table ( $f->find_tables(database => $database) ) {
 
65
      my $ddl  = $d->get_create_table($dbh, $q, $database, $table);
 
66
      my $str  = $p->parse($ddl);
 
67
      my $cols = $d->get_columns($dbh, $q, $database, $table);
 
68
 
 
69
      is_deeply(
 
70
         $str->{cols},
 
71
         [ map { $_->{field} } @$cols ],
 
72
         "Columns for $database.$table",
 
73
      );
 
74
 
 
75
      is_deeply(
 
76
         $str->{type_for},
 
77
         { map {
 
78
            my $t = $_->{type};
 
79
            $t =~ s/\W.*$//;
 
80
            $_->{field} => $t;
 
81
         } @$cols },
 
82
         "Column types for $database.$table",
 
83
      );
 
84
 
 
85
      is_deeply(
 
86
         $str->{null_cols},
 
87
         [ map { $_->{field} } grep { $_->{null} eq 'YES' } @$cols ],
 
88
         "Nullability for $database.$table",
 
89
      );
 
90
 
 
91
   }
 
92
}