# Test for Dumper producer
use strict;
-use Config;
-use FindBin qw/$Bin/;
-use Test::More;
use File::Temp 'tempfile';
+use FindBin qw/$Bin/;
+use IPC::Open3;
use SQL::Translator;
+use Test::More;
use Test::SQL::Translator qw(maybe_plan);
+use Symbol qw(gensym);
+use Text::ParseWords qw(shellwords);
BEGIN {
maybe_plan(
- 5,
+ 5,
+ 'DBI',
'SQL::Translator::Parser::SQLite',
'SQL::Translator::Producer::Dumper'
);
);
my $output = $t->translate( $file );
-
ok( $output, 'Got dumper script' );
+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' );
+
my ( $fh, $filename ) = tempfile( 'XXXXXXXX' );
print $fh $output;
close $fh or die "Can't close file '$filename': $!";
-my $perl = $Config{'perlpath'};
-my $cmd = "$perl -cw $filename";
-my $res = `$cmd 2>&1`;
-like( $res, qr/syntax OK/, 'Generated script syntax is OK' );
+my $out;
+my $pid = open3( undef, $out, undef, $^X, shellwords($ENV{HARNESS_PERL_SWITCHES}||''), '-cw', $filename );
+my $res = do { local $/; <$out> };
+waitpid($pid, 0);
-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' );
+like( $res, qr/syntax OK/, 'Generated script syntax is OK' );
unlink $filename;