comparison lib/Test/Nginx.pm @ 27:fb94a224fef2

Tests: add has() functions for feature testing. Currently it just skips all tests if feature not found in nginx -V output.
author Maxim Dounin <mdounin@mdounin.ru>
date Fri, 10 Oct 2008 20:09:14 +0400
parents 89b00444c168
children 8f1519472ece
comparison
equal deleted inserted replaced
26:0880e0fafde4 27:fb94a224fef2
16 ############################################################################### 16 ###############################################################################
17 17
18 use File::Temp qw/ tempdir /; 18 use File::Temp qw/ tempdir /;
19 use IO::Socket; 19 use IO::Socket;
20 use Socket qw/ CRLF /; 20 use Socket qw/ CRLF /;
21 use Test::More qw//;
21 22
22 ############################################################################### 23 ###############################################################################
24
25 our $NGINX = '../nginx/objs/nginx';
23 26
24 sub new { 27 sub new {
25 my $self = {}; 28 my $self = {};
26 bless $self; 29 bless $self;
27 30
38 sub DESTROY { 41 sub DESTROY {
39 my ($self) = @_; 42 my ($self) = @_;
40 $self->stop(); 43 $self->stop();
41 } 44 }
42 45
46 sub has {
47 my ($self, $feature, %options) = @_;
48 Test::More::plan(skip_all => "$feature not compiled in")
49 unless `$NGINX -V 2>&1` =~ $feature;
50 Test::More::plan($options{plan}) if defined $options{plan};
51 }
52
43 sub run { 53 sub run {
44 my ($self, $conf) = @_; 54 my ($self, $conf) = @_;
45 55
46 my $testdir = $self->{_testdir}; 56 my $testdir = $self->{_testdir};
47 57
52 62
53 my $pid = fork(); 63 my $pid = fork();
54 die "Unable to fork(): $!\n" unless defined $pid; 64 die "Unable to fork(): $!\n" unless defined $pid;
55 65
56 if ($pid == 0) { 66 if ($pid == 0) {
57 exec('../nginx/objs/nginx', '-c', "$testdir/nginx.conf", '-g', 67 exec($NGINX, '-c', "$testdir/nginx.conf", '-g',
58 "pid $testdir/nginx.pid; " 68 "pid $testdir/nginx.pid; "
59 . "error_log $testdir/error.log debug;") 69 . "error_log $testdir/error.log debug;")
60 or die "Unable to exec(): $!\n"; 70 or die "Unable to exec(): $!\n";
61 } 71 }
62 72