# HG changeset patch # User Maxim Dounin # Date 1223654954 -14400 # Node ID fb94a224fef255eac6369ef47fa9b71d6782c751 # Parent 0880e0fafde4b5db8a38a2872a9917d5b746e76c Tests: add has() functions for feature testing. Currently it just skips all tests if feature not found in nginx -V output. diff --git a/lib/Test/Nginx.pm b/lib/Test/Nginx.pm --- a/lib/Test/Nginx.pm +++ b/lib/Test/Nginx.pm @@ -18,9 +18,12 @@ our @EXPORT = qw/ log_in log_out http /; use File::Temp qw/ tempdir /; use IO::Socket; use Socket qw/ CRLF /; +use Test::More qw//; ############################################################################### +our $NGINX = '../nginx/objs/nginx'; + sub new { my $self = {}; bless $self; @@ -40,6 +43,13 @@ sub DESTROY { $self->stop(); } +sub has { + my ($self, $feature, %options) = @_; + Test::More::plan(skip_all => "$feature not compiled in") + unless `$NGINX -V 2>&1` =~ $feature; + Test::More::plan($options{plan}) if defined $options{plan}; +} + sub run { my ($self, $conf) = @_; @@ -54,7 +64,7 @@ sub run { die "Unable to fork(): $!\n" unless defined $pid; if ($pid == 0) { - exec('../nginx/objs/nginx', '-c', "$testdir/nginx.conf", '-g', + exec($NGINX, '-c', "$testdir/nginx.conf", '-g', "pid $testdir/nginx.pid; " . "error_log $testdir/error.log debug;") or die "Unable to exec(): $!\n"; diff --git a/smtp-greeting-delay.t b/smtp-greeting-delay.t --- a/smtp-greeting-delay.t +++ b/smtp-greeting-delay.t @@ -7,7 +7,7 @@ use warnings; use strict; -use Test::More tests => 2; +use Test::More; use MIME::Base64; use Socket qw/ CRLF /; @@ -23,7 +23,8 @@ use Test::Nginx::SMTP; select STDERR; $| = 1; select STDOUT; $| = 1; -my $t = Test::Nginx->new()->write_file_expand('nginx.conf', <<'EOF')->run(); +my $t = Test::Nginx->new()->has('mail', plan => 2) + ->write_file_expand('nginx.conf', <<'EOF')->run(); master_process off; daemon off; diff --git a/smtp.t b/smtp.t --- a/smtp.t +++ b/smtp.t @@ -9,7 +9,7 @@ use warnings; use strict; -use Test::More tests => 26; +use Test::More; use MIME::Base64; use Socket qw/ CRLF /; @@ -26,6 +26,7 @@ select STDERR; $| = 1; select STDOUT; $| = 1; my $t = Test::Nginx->new() + ->has('mail', plan => 26) ->run_daemon(\&Test::Nginx::SMTP::smtp_test_daemon) ->write_file_expand('nginx.conf', <<'EOF')->run();