comparison lib/Test/Nginx.pm @ 1629:a1874249496d

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.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 30 Nov 2020 20:53:11 +0300
parents d7ec131d305a
children 6f573329e862
comparison
equal deleted inserted replaced
1628:54f867e69cb5 1629:a1874249496d
289 289
290 sub try_run($$) { 290 sub try_run($$) {
291 my ($self, $message) = @_; 291 my ($self, $message) = @_;
292 292
293 eval { 293 eval {
294 open OLDERR, ">&", \*STDERR; close STDERR; 294 open OLDERR, ">&", \*STDERR;
295 open NEWERR, ">", $self->{_testdir} . '/stderr'
296 or die "Can't open stderr: $!";
297 close STDERR;
298 open STDERR, ">&", \*NEWERR;
299 close NEWERR;
300
295 $self->run(); 301 $self->run();
302
303 close STDERR;
296 open STDERR, ">&", \*OLDERR; 304 open STDERR, ">&", \*OLDERR;
297 }; 305 };
298 306
299 return $self unless $@; 307 return $self unless $@;
300 308
301 if ($ENV{TEST_NGINX_VERBOSE}) { 309 if ($ENV{TEST_NGINX_VERBOSE}) {
302 my $path = $self->{_configure_args} =~ m!--error-log-path=(\S+)! 310 open F, '<', $self->{_testdir} . '/stderr'
303 ? $1 : 'logs/error.log'; 311 or die "Can't open stderr: $!";
304 $path = "$self->{_testdir}/$path" if index($path, '/');
305
306 open F, '<', $path or die "Can't open $path: $!";
307 log_core($_) while (<F>); 312 log_core($_) while (<F>);
308 close F; 313 close F;
309 } 314 }
310 315
311 Test::More::plan(skip_all => $message); 316 Test::More::plan(skip_all => $message);