From: Ken Youens-Clark Date: Thu, 11 Mar 2004 19:14:19 +0000 (+0000) Subject: Added tests for Dumper producer. X-Git-Tag: v0.06~136 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=04c13c01d1a2f27d3229a818e3a662f7446f4552;p=dbsrgits%2FSQL-Translator.git Added tests for Dumper producer. --- diff --git a/t/31dumper.t b/t/31dumper.t index ac2df91..add05a6 100644 --- a/t/31dumper.t +++ b/t/31dumper.t @@ -1,28 +1,32 @@ #!/usr/bin/perl # vim: set ft=perl: -# use strict; +use Config; use FindBin qw/$Bin/; use Test::More; +use File::Temp 'tempfile'; use SQL::Translator; use Test::SQL::Translator qw(maybe_plan); BEGIN { maybe_plan( - 1, + 5, 'SQL::Translator::Parser::SQLite', 'SQL::Translator::Producer::Dumper' ); } +my $db_user = 'nomar'; +my $db_pass = 'gos0X!'; +my $dsn = 'dbi:SQLite:dbname=/tmp/foo'; my $file = "$Bin/data/sqlite/create.sql"; my $t = SQL::Translator->new( from => 'SQLite', to => 'Dumper', producer_args => { - skip => $skip, - skiplike => $skiplike, + skip => 'pet', + skiplike => '', db_user => $db_user, db_password => $db_pass, dsn => $dsn, @@ -30,3 +34,22 @@ my $t = SQL::Translator->new( ); my $output = $t->translate( $file ); + +ok( $output, 'Got dumper script' ); + +my ( $fh, $filename ) = tempfile( 'XXXXXXXX' ); + +print $fh $output; + +my $perl = $Config{'perlpath'}; +my $cmd = "$perl -cw $filename"; +my $res = `$cmd 2>&1`; +like( $res, qr/syntax OK/, 'Generated script syntax is OK' ); + +like( $output, qr{DBI->connect\(\s*'$dsn',\s*'$db_user',\s*'$db_pass',}, + 'Script contains correct DSN, db user and password' ); + +like( $output, qr/table_name\s*=>\s*'person',/, 'Found "person" table' ); +unlike( $output, qr/table_name\s*=>\s*'pet',/, 'Skipped "pet" table' ); + +unlink $filename;