use File::Spec::Functions qw(catfile updir tmpdir);
use FindBin qw($Bin);
use Test::More;
+use IPC::Open3;
use Test::SQL::Translator qw(maybe_plan);
+use Text::ParseWords qw(shellwords);
my @script = qw(script sqlt-diff-old);
my @create1 = qw(data sqlite create.sql);
}
ok(-e $sqlt_diff, 'Found sqlt-diff script');
-my @cmd = ($^X, $sqlt_diff, "$create1=SQLite", "$create2=SQLite");
-my $out = `@cmd`;
+my $out = _run_cmd ($sqlt_diff, "$create1=SQLite", "$create2=SQLite");
like($out, qr/-- Target database SQLite is untested/, "Detected 'untested' comment");
like($out, qr/ALTER TABLE person CHANGE iq/, "Detected altered 'iq' field");
like($out, qr/ALTER TABLE person ADD is_rock_star/,
"Detected missing rock star field");
-@cmd = ($^X, $sqlt_diff, "$create1=SQLite", "$create1=SQLite");
-$out = `@cmd`;
+$out = _run_cmd ($sqlt_diff, "$create1=SQLite", "$create1=SQLite");
like($out, qr/There were no differences/, "Properly detected no differences");
: catfile($Bin, "t", @mysql_create2);
# Test for differences
-@cmd = ($^X, $sqlt_diff, "$mysql_create1=MySQL", "$mysql_create2=MySQL");
-$out = `@cmd`;
+$out = _run_cmd ($sqlt_diff, "$mysql_create1=MySQL", "$mysql_create2=MySQL");
unlike($out, qr/-- Target database MySQL is untested/, "Did not detect 'untested' comment");
like($out, qr/ALTER TABLE person CHANGE person_id/, "Detected altered 'person_id' field");
unlike($out, qr/ALTER TABLE employee ADD PRIMARY KEY/, "Primary key looks different when it shouldn't");
# Test for sameness
-@cmd = ($^X, $sqlt_diff, "$mysql_create1=MySQL", "$mysql_create1=MySQL");
-$out = `@cmd`;
+$out = _run_cmd ($sqlt_diff, "$mysql_create1=MySQL", "$mysql_create1=MySQL");
like($out, qr/There were no differences/, "Properly detected no differences");
? catfile($Bin, @oracle_create2)
: catfile($Bin, "t", @oracle_create2);
-@cmd = ($^X, $sqlt_diff, "$oracle_create1=Oracle", "$oracle_create2=Oracle");
-$out = `@cmd`;
+$out = _run_cmd ($sqlt_diff, "$oracle_create1=Oracle", "$oracle_create2=Oracle");
unlike($out, qr/-- Target database Oracle is untested/, "Did not detect 'untested' comment");
like($out, qr/ALTER TABLE TABLE1 DROP FOREIGN KEY/,
"Detected drop foreign key");
like($out, qr/ALTER TABLE TABLE1 ADD CONSTRAINT/,
"Detected add constraint");
+
+sub _run_cmd {
+ my $out;
+ my $pid = open3( undef, $out, undef, $^X, shellwords($ENV{HARNESS_PERL_SWITCHES}||''), @_ );
+ my $res = do { local $/; <$out> };
+ waitpid($pid, 0);
+ $res;
+}