Mercurial > hg > nginx-tests
changeset 592:355f2d5ff60f
Tests: catch nginx alerts on exit.
The new todo_alerts() function is used to mark such a test as TODO.
Notably, proxy_if.t is currently expected to produce alerts.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 27 May 2015 16:58:35 +0300 |
parents | 0b059d5e6887 |
children | 6c0a5903d0ae |
files | lib/Test/Nginx.pm proxy_if.t |
diffstat | 2 files changed, 19 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/Test/Nginx.pm +++ b/lib/Test/Nginx.pm @@ -36,6 +36,7 @@ sub new { bless $self; $self->{_pid} = $$; + $self->{_alerts} = 1; $self->{_testdir} = tempdir( 'nginx-test-XXXXXXXXXX', @@ -61,6 +62,14 @@ sub DESTROY { $self->stop(); $self->stop_daemons(); + if (Test::More->builder->expected_tests) { + local $Test::Nginx::TODO = 'alerts' unless $self->{_alerts}; + + my $alerts = $self->read_file('error.log'); + $alerts = join "\n", $alerts =~ /.+\[alert\].+/gm; + Test::More::is($alerts, '', 'no alerts'); + } + if ($ENV{TEST_NGINX_CATLOG}) { system("cat $self->{_testdir}/error.log"); } @@ -223,7 +232,15 @@ sub try_run($$) { sub plan($) { my ($self, $plan) = @_; - Test::More::plan(tests => $plan); + Test::More::plan(tests => $plan + 1); + + return $self; +} + +sub todo_alerts() { + my ($self) = @_; + + $self->{_alerts} = 0; return $self; }
--- a/proxy_if.t +++ b/proxy_if.t @@ -25,7 +25,7 @@ select STDOUT; $| = 1; my $t = Test::Nginx->new()->has(qw/http proxy rewrite http_ssl/) ->has_daemon('openssl')->plan(15); -$t->write_file_expand('nginx.conf', <<'EOF'); +$t->write_file_expand('nginx.conf', <<'EOF')->todo_alerts(); %%TEST_GLOBALS%%