# HG changeset patch # User Maxim Dounin # Date 1397831786 -14400 # Node ID c28ecaef065f2e54d929d3d75df042c00ffe07a8 # Parent 915ef26ac6ebdc642ddc1bbaf1658241a66fb473 Tests: try_run() introduced. This method replaces multiple ad-hoc solutions to grecefully skip tests if nginx startup fails, e.g., due to no support for a particular directive. diff --git a/access.t b/access.t --- a/access.t +++ b/access.t @@ -82,14 +82,7 @@ http { EOF -eval { - open OLDERR, ">&", \*STDERR; close STDERR; - $t->run(); - open STDERR, ">&", \*OLDERR; -}; -plan(skip_all => 'no inet6 and/or unix support') if $@; - -$t->plan(12); +$t->try_run('no inet6 and/or unix support')->plan(12); ############################################################################### diff --git a/debug_connection.t b/debug_connection.t --- a/debug_connection.t +++ b/debug_connection.t @@ -54,14 +54,7 @@ http { EOF -eval { - open OLDERR, ">&", \*STDERR; close STDERR; - $t->run(); - open STDERR, ">&", \*OLDERR; -}; -plan(skip_all => 'no inet6 support') if $@; - -$t->plan(5); +$t->try_run('no inet6 support')->plan(5); ############################################################################### diff --git a/fastcgi_buffering.t b/fastcgi_buffering.t --- a/fastcgi_buffering.t +++ b/fastcgi_buffering.t @@ -62,16 +62,9 @@ EOF '' . 'set: '); -eval { - open OLDERR, ">&", \*STDERR; close STDERR; - $t->run(); - open STDERR, ">&", \*OLDERR; -}; -plan(skip_all => 'no fastcgi_buffering') if $@; +$t->try_run('no fastcgi_buffering')->plan(2); -$t->run_daemon(\&fastcgi_daemon); - -$t->plan(2)->waitforsocket('127.0.0.1:8081'); +$t->run_daemon(\&fastcgi_daemon)->waitforsocket('127.0.0.1:8081'); ############################################################################### diff --git a/gunzip_memcached.t b/gunzip_memcached.t --- a/gunzip_memcached.t +++ b/gunzip_memcached.t @@ -71,14 +71,7 @@ if ($memhelp =~ /-U/) { $t->run_daemon('memcached', '-l', '127.0.0.1', '-p', '8081', @memopts); -eval { - open OLDERR, ">&", \*STDERR; close STDERR; - $t->run(); - open STDERR, ">&", \*OLDERR; -}; -plan(skip_all => 'no memcached_gzip_flag') if $@; - -$t->plan(2); +$t->try_run('no memcached_gzip_flag')->plan(2); $t->waitforsocket('127.0.0.1:8081') or die "Can't start memcached"; diff --git a/gunzip_static.t b/gunzip_static.t --- a/gunzip_static.t +++ b/gunzip_static.t @@ -74,14 +74,7 @@ IO::Compress::Gzip::gzip(\$in => \$out); $t->write_file('t2.gz', $out . $out); $t->write_file('t3', 'not compressed'); -eval { - open OLDERR, ">&", \*STDERR; close STDERR; - $t->run(); - open STDERR, ">&", \*OLDERR; -}; -plan(skip_all => 'no gzip_static always') if $@; - -$t->plan(12); +$t->try_run('no gzip_static always')->plan(12); ############################################################################### diff --git a/http_disable_symlinks.t b/http_disable_symlinks.t --- a/http_disable_symlinks.t +++ b/http_disable_symlinks.t @@ -154,13 +154,6 @@ http { EOF -eval { - open OLDERR, ">&", \*STDERR; close STDERR; - $t->run(); - open STDERR, ">&", \*OLDERR; -}; -plan(skip_all => 'no disable_symlinks') if $@; - my $uid = getuid(); my ($extfile) = grep { -f "$_" && $uid != (stat($_))[4] } ('/etc/resolv.conf', '/etc/protocols', '/etc/host.conf'); @@ -168,9 +161,9 @@ my ($extfile) = grep { -f "$_" && $uid ! plan(skip_all => 'no external file found') if !defined $extfile; -my $d = $t->testdir(); +$t->try_run('no disable_symlinks')->plan(28); -$t->plan(28); +my $d = $t->testdir(); mkdir("$d/on"); mkdir("$d/not_owner"); diff --git a/http_resolver_aaaa.t b/http_resolver_aaaa.t --- a/http_resolver_aaaa.t +++ b/http_resolver_aaaa.t @@ -68,12 +68,7 @@ http { EOF -eval { - open OLDERR, ">&", \*STDERR; close STDERR; - $t->run(); - open STDERR, ">&", \*OLDERR; -}; -plan(skip_all => 'no inet6 support') if $@; +$t->try_run('no inet6 support')->plan(72); $t->run_daemon(\&dns_daemon, 8081, $t); $t->run_daemon(\&dns_daemon, 8082, $t); @@ -81,8 +76,6 @@ plan(skip_all => 'no inet6 support') if $t->waitforfile($t->testdir . '/8081'); $t->waitforfile($t->testdir . '/8082'); -$t->plan(72); - ############################################################################### my (@n, $response); diff --git a/lib/Test/Nginx.pm b/lib/Test/Nginx.pm --- a/lib/Test/Nginx.pm +++ b/lib/Test/Nginx.pm @@ -172,6 +172,19 @@ sub has_daemon($) { return $self; } +sub try_run($$) { + my ($self, $message) = @_; + + eval { + open OLDERR, ">&", \*STDERR; close STDERR; + $self->run(); + open STDERR, ">&", \*OLDERR; + }; + + Test::More::plan(skip_all => $message) if $@; + return $self; +} + sub plan($) { my ($self, $plan) = @_; diff --git a/proxy_cache_lock.t b/proxy_cache_lock.t --- a/proxy_cache_lock.t +++ b/proxy_cache_lock.t @@ -70,14 +70,8 @@ EOF $t->run_daemon(\&http_fake_daemon); -eval { - open OLDERR, ">&", \*STDERR; close STDERR; - $t->run(); - open STDERR, ">&", \*OLDERR; -}; -plan(skip_all => 'no proxy_cache_lock') if $@; +$t->try_run('no proxy_cache_lock')->plan(19); -$t->plan(19); $t->waitforsocket('127.0.0.1:8081'); ############################################################################### diff --git a/proxy_cache_revalidate.t b/proxy_cache_revalidate.t --- a/proxy_cache_revalidate.t +++ b/proxy_cache_revalidate.t @@ -67,13 +67,7 @@ EOF $t->write_file('t', 'SEE-THIS'); $t->write_file('t2', 'SEE-THIS'); -eval { - open OLDERR, ">&", \*STDERR; close STDERR; - $t->run(); - open STDERR, ">&", \*OLDERR; -}; -plan(skip_all => 'no proxy_cache_revalidate') if $@; -$t->plan(9); +$t->try_run('no proxy_cache_revalidate')->plan(9); ############################################################################### diff --git a/proxy_cookie.t b/proxy_cookie.t --- a/proxy_cookie.t +++ b/proxy_cookie.t @@ -73,14 +73,7 @@ http { EOF -eval { - open OLDERR, ">&", \*STDERR; close STDERR; - $t->run(); - open STDERR, ">&", \*OLDERR; -}; -plan(skip_all => 'no proxy_cookie') if $@; - -$t->plan(8); +$t->try_run('no proxy_cookie')->plan(8); ############################################################################### diff --git a/xslt_params.t b/xslt_params.t --- a/xslt_params.t +++ b/xslt_params.t @@ -86,14 +86,7 @@ EOF $t->write_file('x2', 'data'); $t->write_file('x3', 'data'); -eval { - open OLDERR, ">&", \*STDERR; close STDERR; - $t->run(); - open STDERR, ">&", \*OLDERR; -}; - -plan(skip_all => 'no xslt_param') if $@; -$t->plan(3); +$t->try_run('no xslt_param')->plan(3); ###############################################################################