3 # Test for Dumper producer
7 use File::Temp 'tempfile';
13 use Test::SQL::Translator qw(maybe_plan);
14 use Symbol qw(gensym);
20 'SQL::Translator::Parser::SQLite',
21 'SQL::Translator::Producer::Dumper'
25 my $db_user = 'nomar';
26 my $db_pass = 'gos0X!';
27 my $dsn = 'dbi:SQLite:dbname=/tmp/foo';
28 my $file = "$Bin/data/sqlite/create.sql";
29 my $t = SQL::Translator->new(
36 db_password => $db_pass,
41 my $output = $t->translate( $file );
43 ok( $output, 'Got dumper script' );
45 my ( $fh, $filename ) = tempfile( 'XXXXXXXX' );
48 close $fh or die "Can't close file '$filename': $!";
50 my $perl = $Config{'perlpath'};
51 open( NULL, ">", File::Spec->devnull );
52 my $pid = open3( gensym, \*NULL, \*PH, "$perl -cw $filename" );
54 while( <PH> ) { $res .= $_; }
57 like( $res, qr/syntax OK/, 'Generated script syntax is OK' );
59 like( $output, qr{DBI->connect\(\s*'$dsn',\s*'$db_user',\s*'$db_pass',},
60 'Script contains correct DSN, db user and password' );
62 like( $output, qr/table_name\s*=>\s*'person',/, 'Found "person" table' );
63 unlike( $output, qr/table_name\s*=>\s*'pet',/, 'Skipped "pet" table' );