ok(check_mode_recursive("$tempdir/data", 0750, 0640));
}
-command_ok([ 'pg_ctl', 'restart', '--pgdata' => "$tempdir/data" ],
+command_ok([ 'pg_ctl', 'restart', '--pgdata' => "$tempdir/data", '--log' => $logFileName ],
'pg_ctl restart with server running');
system_or_bail 'pg_ctl', 'stop', '--pgdata' => "$tempdir/data";
die "No $newname" unless -e $newname;
}
+# Log command output. Truncates to first/last 30 lines if over 60 lines.
+sub _diag_command_output
+{
+ my ($cmd, $stdout, $stderr) = @_;
+
+ diag(join(" ", @$cmd));
+
+ for my $channel (['stdout', $stdout], ['stderr', $stderr])
+ {
+ my ($name, $output) = @$channel;
+ next unless $output;
+
+ diag("-------------- $name --------------");
+ my @lines = split /\n/, $output;
+ if (@lines > 60)
+ {
+ diag(join("\n", @lines[0 .. 29]));
+ diag("... " . (@lines - 60) . " lines omitted ...");
+ diag(join("\n", @lines[-30 .. -1]));
+ }
+ else
+ {
+ diag($output);
+ }
+ }
+
+ diag("------------------------------------");
+}
+
=pod
=back
=item command_ok(cmd, test_name)
-Check that the command runs (via C<run_log>) successfully.
+Check that the command runs successfully.
=cut
{
local $Test::Builder::Level = $Test::Builder::Level + 1;
my ($cmd, $test_name) = @_;
- my $result = run_log($cmd);
- ok($result, $test_name);
+ my ($stdout, $stderr);
+ print("# Running: " . join(" ", @{$cmd}) . "\n");
+ my $result = IPC::Run::run $cmd, '>' => \$stdout, '2>' => \$stderr;
+ ok($result, $test_name) or do
+ {
+ diag("---------- command failed ----------");
+ _diag_command_output($cmd, $stdout, $stderr);
+ };
return;
}
=item command_fails(cmd, test_name)
-Check that the command fails (when run via C<run_log>).
+Check that the command fails.
=cut
{
local $Test::Builder::Level = $Test::Builder::Level + 1;
my ($cmd, $test_name) = @_;
- my $result = run_log($cmd);
- ok(!$result, $test_name);
+ my ($stdout, $stderr);
+ print("# Running: " . join(" ", @{$cmd}) . "\n");
+ my $result = IPC::Run::run $cmd, '>' => \$stdout, '2>' => \$stderr;
+ ok(!$result, $test_name) or do
+ {
+ diag("-- command succeeded unexpectedly --");
+ _diag_command_output($cmd, $stdout, $stderr);
+ };
return;
}