# HG changeset patch # User Sergey Kandaurov # Date 1432735115 -10800 # Node ID 355f2d5ff60ff5747fcb2514554f6e8c4ad7ec79 # Parent 0b059d5e68879d07020f4d1cdb7a259325525b7a 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. diff --git a/lib/Test/Nginx.pm b/lib/Test/Nginx.pm --- 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; } diff --git a/proxy_if.t b/proxy_if.t --- 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%%