Fix undef warnings from Text::ParseWords when running tests with -w
[dbsrgits/SQL-Translator.git] / t / 31dumper.t
CommitLineData
3c5dc866 1#!/usr/bin/perl
2# vim: set ft=perl:
8061d279 3# Test for Dumper producer
3c5dc866 4
5use strict;
04c13c01 6use File::Temp 'tempfile';
c401ac4b 7use FindBin qw/$Bin/;
8use IPC::Open3;
3c5dc866 9use SQL::Translator;
c401ac4b 10use Test::More;
3c5dc866 11use Test::SQL::Translator qw(maybe_plan);
c401ac4b 12use Symbol qw(gensym);
cb9bbc68 13use Text::ParseWords qw(shellwords);
3c5dc866 14
15BEGIN {
16 maybe_plan(
aee4b66e 17 5,
d2f0a9f6 18 'DBI',
3c5dc866 19 'SQL::Translator::Parser::SQLite',
20 'SQL::Translator::Producer::Dumper'
21 );
22}
23
04c13c01 24my $db_user = 'nomar';
25my $db_pass = 'gos0X!';
26my $dsn = 'dbi:SQLite:dbname=/tmp/foo';
3c5dc866 27my $file = "$Bin/data/sqlite/create.sql";
28my $t = SQL::Translator->new(
29 from => 'SQLite',
30 to => 'Dumper',
31 producer_args => {
04c13c01 32 skip => 'pet',
33 skiplike => '',
3c5dc866 34 db_user => $db_user,
35 db_password => $db_pass,
36 dsn => $dsn,
37 }
38);
39
40my $output = $t->translate( $file );
04c13c01 41ok( $output, 'Got dumper script' );
42
ae99f367 43like( $output, qr{DBI->connect\(\s*'$dsn',\s*'$db_user',\s*'$db_pass',},
44 'Script contains correct DSN, db user and password' );
45
46like( $output, qr/table_name\s*=>\s*'person',/, 'Found "person" table' );
47unlike( $output, qr/table_name\s*=>\s*'pet',/, 'Skipped "pet" table' );
48
04c13c01 49my ( $fh, $filename ) = tempfile( 'XXXXXXXX' );
50
51print $fh $output;
8061d279 52close $fh or die "Can't close file '$filename': $!";
04c13c01 53
ae99f367 54my $out;
7e212236 55my $pid = open3( undef, $out, undef, $^X, shellwords($ENV{HARNESS_PERL_SWITCHES}||''), '-cw', $filename );
ae99f367 56my $res = do { local $/; <$out> };
c401ac4b 57waitpid($pid, 0);
58
04c13c01 59like( $res, qr/syntax OK/, 'Generated script syntax is OK' );
60
04c13c01 61unlink $filename;