Mercurial > hg > nginx-tests
changeset 392:c28ecaef065f
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.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 18 Apr 2014 18:36:26 +0400 |
parents | 915ef26ac6eb |
children | 3c9aeeb09ac8 |
files | access.t debug_connection.t fastcgi_buffering.t gunzip_memcached.t gunzip_static.t http_disable_symlinks.t http_resolver_aaaa.t lib/Test/Nginx.pm proxy_cache_lock.t proxy_cache_revalidate.t proxy_cookie.t xslt_params.t |
diffstat | 12 files changed, 26 insertions(+), 88 deletions(-) [+] |
line wrap: on
line diff
--- a/access.t Tue Apr 15 22:04:08 2014 +0400 +++ b/access.t Fri Apr 18 18:36:26 2014 +0400 @@ -82,14 +82,7 @@ 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); ###############################################################################
--- a/debug_connection.t Tue Apr 15 22:04:08 2014 +0400 +++ b/debug_connection.t Fri Apr 18 18:36:26 2014 +0400 @@ -54,14 +54,7 @@ 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); ###############################################################################
--- a/fastcgi_buffering.t Tue Apr 15 22:04:08 2014 +0400 +++ b/fastcgi_buffering.t Fri Apr 18 18:36:26 2014 +0400 @@ -62,16 +62,9 @@ '<!--#include virtual="/include$request_uri" set="x" -->' . 'set: <!--#echo var="x" -->'); -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'); ###############################################################################
--- a/gunzip_memcached.t Tue Apr 15 22:04:08 2014 +0400 +++ b/gunzip_memcached.t Fri Apr 18 18:36:26 2014 +0400 @@ -71,14 +71,7 @@ $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";
--- a/gunzip_static.t Tue Apr 15 22:04:08 2014 +0400 +++ b/gunzip_static.t Fri Apr 18 18:36:26 2014 +0400 @@ -74,14 +74,7 @@ $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); ###############################################################################
--- a/http_disable_symlinks.t Tue Apr 15 22:04:08 2014 +0400 +++ b/http_disable_symlinks.t Fri Apr 18 18:36:26 2014 +0400 @@ -154,13 +154,6 @@ 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 @@ 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");
--- a/http_resolver_aaaa.t Tue Apr 15 22:04:08 2014 +0400 +++ b/http_resolver_aaaa.t Fri Apr 18 18:36:26 2014 +0400 @@ -68,12 +68,7 @@ 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 @@ $t->waitforfile($t->testdir . '/8081'); $t->waitforfile($t->testdir . '/8082'); -$t->plan(72); - ############################################################################### my (@n, $response);
--- a/lib/Test/Nginx.pm Tue Apr 15 22:04:08 2014 +0400 +++ b/lib/Test/Nginx.pm Fri Apr 18 18:36:26 2014 +0400 @@ -172,6 +172,19 @@ 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) = @_;
--- a/proxy_cache_lock.t Tue Apr 15 22:04:08 2014 +0400 +++ b/proxy_cache_lock.t Fri Apr 18 18:36:26 2014 +0400 @@ -70,14 +70,8 @@ $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'); ###############################################################################
--- a/proxy_cache_revalidate.t Tue Apr 15 22:04:08 2014 +0400 +++ b/proxy_cache_revalidate.t Fri Apr 18 18:36:26 2014 +0400 @@ -67,13 +67,7 @@ $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); ###############################################################################
--- a/proxy_cookie.t Tue Apr 15 22:04:08 2014 +0400 +++ b/proxy_cookie.t Fri Apr 18 18:36:26 2014 +0400 @@ -73,14 +73,7 @@ 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); ###############################################################################
--- a/xslt_params.t Tue Apr 15 22:04:08 2014 +0400 +++ b/xslt_params.t Fri Apr 18 18:36:26 2014 +0400 @@ -86,14 +86,7 @@ $t->write_file('x2', '<root>data</root>'); $t->write_file('x3', '<root>data</root>'); -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); ###############################################################################