Tests: reworked try_run() to redirect stderr.
Previously, if TEST_NGINX_VERBOSE was set, the code tried to use compiled-in
error log. While this works in typical development cases when --error-log-path
is relative to prefix, it is unlikely to work correctly if --error-log-path
is absolute.
The recently introduced '-e' command line option might be used to fix this.
On the other hand, a more compatible solution would be to redirect stderr
to a file instead.
diff --git a/lib/Test/Nginx.pm b/lib/Test/Nginx.pm
index 5ebfa2a..fa3d102 100644
--- a/lib/Test/Nginx.pm
+++ b/lib/Test/Nginx.pm
@@ -291,19 +291,24 @@
my ($self, $message) = @_;
eval {
- open OLDERR, ">&", \*STDERR; close STDERR;
+ open OLDERR, ">&", \*STDERR;
+ open NEWERR, ">", $self->{_testdir} . '/stderr'
+ or die "Can't open stderr: $!";
+ close STDERR;
+ open STDERR, ">&", \*NEWERR;
+ close NEWERR;
+
$self->run();
+
+ close STDERR;
open STDERR, ">&", \*OLDERR;
};
return $self unless $@;
if ($ENV{TEST_NGINX_VERBOSE}) {
- my $path = $self->{_configure_args} =~ m!--error-log-path=(\S+)!
- ? $1 : 'logs/error.log';
- $path = "$self->{_testdir}/$path" if index($path, '/');
-
- open F, '<', $path or die "Can't open $path: $!";
+ open F, '<', $self->{_testdir} . '/stderr'
+ or die "Can't open stderr: $!";
log_core($_) while (<F>);
close F;
}