changeset 574:2cd00179f4b2

Tests: has_feature() introduced in Test::Nginx. It is used to check in a platform-aware way for a non-standard capability. Use it for shared memory ('shmem') and symlink. Notably, this enables corresponding tests on win32 where/when appropriate.
author Sergey Kandaurov <pluknet@nginx.com>
date Thu, 14 May 2015 14:46:13 +0300
parents 517cde5075d8
children eea2b0158b51
files autoindex.t autoindex_format.t http_disable_symlinks.t image_filter_finalize.t lib/Test/Nginx.pm limit_conn.t limit_conn_complex.t limit_req.t not_modified_proxy.t proxy_cache.t proxy_cache_chunked.t proxy_cache_lock.t proxy_cache_lock_age.t proxy_cache_lock_ssi.t proxy_cache_path.t proxy_cache_range.t proxy_cache_revalidate.t proxy_cache_variables.t proxy_cache_vary.t proxy_force_ranges.t proxy_merge_headers.t proxy_unfinished.t random_index.t range_charset.t scgi_merge_params.t spdy.t ssi.t
diffstat 27 files changed, 55 insertions(+), 79 deletions(-) [+]
line wrap: on
line diff
--- a/autoindex.t
+++ b/autoindex.t
@@ -21,9 +21,7 @@ use Test::Nginx;
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-plan(skip_all => 'no symlinks on win32') if $^O eq 'MSWin32';
-
-my $t = Test::Nginx->new()->has(qw/http autoindex charset/)->plan(16)
+my $t = Test::Nginx->new()->has(qw/http autoindex charset symlink/)->plan(16)
 	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
--- a/autoindex_format.t
+++ b/autoindex_format.t
@@ -23,9 +23,7 @@ use Test::Nginx;
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-plan(skip_all => 'no symlinks on win32') if $^O eq 'MSWin32';
-
-my $t = Test::Nginx->new()->has(qw/http autoindex/)->plan(37)
+my $t = Test::Nginx->new()->has(qw/http autoindex symlink/)->plan(37)
 	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
--- a/http_disable_symlinks.t
+++ b/http_disable_symlinks.t
@@ -23,7 +23,7 @@ use Test::Nginx;
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-my $t = Test::Nginx->new()->has(qw/http rewrite/)
+my $t = Test::Nginx->new()->has(qw/http rewrite symlink/)
 	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
--- a/image_filter_finalize.t
+++ b/image_filter_finalize.t
@@ -21,10 +21,8 @@ use Test::Nginx;
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-plan(skip_all => 'win32') if $^O eq 'MSWin32';
-
-my $t = Test::Nginx->new()
-	->has(qw/http proxy cache image_filter limit_req rewrite/)->plan(4)
+my $t = Test::Nginx->new()->has(qw/http proxy cache image_filter limit_req/)
+	->has(qw/rewrite shmem/)->plan(4)
 	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
--- a/lib/Test/Nginx.pm
+++ b/lib/Test/Nginx.pm
@@ -73,8 +73,9 @@ sub has($;) {
 	my ($self, @features) = @_;
 
 	foreach my $feature (@features) {
-		Test::More::plan(skip_all => "$feature not compiled in")
-			unless $self->has_module($feature);
+		Test::More::plan(skip_all => "no $feature available")
+			unless $self->has_module($feature)
+			or $self->has_feature($feature);
 	}
 
 	return $self;
@@ -152,6 +153,20 @@ sub has_module($) {
 	return ($self->{_configure_args} =~ $re) ? 1 : 0;
 }
 
+sub has_feature($) {
+	my ($self, $feature) = @_;
+
+	if ($feature eq 'symlink') {
+		return $^O ne 'MSWin32';
+	}
+
+	if ($feature eq 'shmem') {
+		return $^O ne 'MSWin32' || $self->has_version('1.9.0');
+	}
+
+	return 0;
+}
+
 sub has_version($) {
 	my ($self, $need) = @_;
 
--- a/limit_conn.t
+++ b/limit_conn.t
@@ -21,9 +21,8 @@ use Test::Nginx;
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-plan(skip_all => 'win32') if $^O eq 'MSWin32';
-
-my $t = Test::Nginx->new()->has(qw/http proxy limit_conn limit_req/)->plan(8);
+my $t = Test::Nginx->new()->has(qw/http proxy limit_conn limit_req shmem/)
+	->plan(8);
 
 $t->write_file_expand('nginx.conf', <<'EOF');
 
--- a/limit_conn_complex.t
+++ b/limit_conn_complex.t
@@ -24,9 +24,8 @@ use Test::Nginx;
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-plan(skip_all => 'win32') if $^O eq 'MSWin32';
-
-my $t = Test::Nginx->new()->has(qw/http proxy limit_conn limit_req/)->plan(4);
+my $t = Test::Nginx->new()->has(qw/http proxy limit_conn limit_req shmem/)
+	->plan(4);
 
 $t->write_file_expand('nginx.conf', <<'EOF');
 
--- a/limit_req.t
+++ b/limit_req.t
@@ -21,9 +21,7 @@ use Test::Nginx;
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-plan(skip_all => 'win32') if $^O eq 'MSWin32';
-
-my $t = Test::Nginx->new()->has(qw/http limit_req/)->plan(5);
+my $t = Test::Nginx->new()->has(qw/http limit_req shmem/)->plan(5);
 
 $t->write_file_expand('nginx.conf', <<'EOF');
 
--- a/not_modified_proxy.t
+++ b/not_modified_proxy.t
@@ -26,9 +26,7 @@ use Test::Nginx;
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-plan(skip_all => 'win32') if $^O eq 'MSWin32';
-
-my $t = Test::Nginx->new()->has(qw/http proxy cache/)->plan(9)
+my $t = Test::Nginx->new()->has(qw/http proxy cache shmem/)->plan(9)
 	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
--- a/proxy_cache.t
+++ b/proxy_cache.t
@@ -21,9 +21,7 @@ use Test::Nginx qw/ :DEFAULT :gzip /;
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-plan(skip_all => 'win32') if $^O eq 'MSWin32';
-
-my $t = Test::Nginx->new()->has(qw/http proxy cache gzip/)->plan(14)
+my $t = Test::Nginx->new()->has(qw/http proxy cache gzip shmem/)->plan(14)
 	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
--- a/proxy_cache_chunked.t
+++ b/proxy_cache_chunked.t
@@ -24,9 +24,7 @@ use Test::Nginx;
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-plan(skip_all => 'win32') if $^O eq 'MSWin32';
-
-my $t = Test::Nginx->new()->has(qw/http proxy cache/)->plan(2);
+my $t = Test::Nginx->new()->has(qw/http proxy cache shmem/)->plan(2);
 
 $t->write_file_expand('nginx.conf', <<'EOF');
 
--- a/proxy_cache_lock.t
+++ b/proxy_cache_lock.t
@@ -21,9 +21,7 @@ use Test::Nginx qw/ :DEFAULT http_end /;
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-plan(skip_all => 'win32') if $^O eq 'MSWin32';
-
-my $t = Test::Nginx->new()->has(qw/http proxy cache/)->plan(18)
+my $t = Test::Nginx->new()->has(qw/http proxy cache shmem/)->plan(18)
 	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
--- a/proxy_cache_lock_age.t
+++ b/proxy_cache_lock_age.t
@@ -24,9 +24,7 @@ use Test::Nginx;
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-plan(skip_all => 'win32') if $^O eq 'MSWin32';
-
-my $t = Test::Nginx->new()->has(qw/http proxy cache/)->plan(2)
+my $t = Test::Nginx->new()->has(qw/http proxy cache shmem/)->plan(2)
 	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
--- a/proxy_cache_lock_ssi.t
+++ b/proxy_cache_lock_ssi.t
@@ -21,9 +21,7 @@ use Test::Nginx qw/ :DEFAULT http_end /;
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-plan(skip_all => 'win32') if $^O eq 'MSWin32';
-
-my $t = Test::Nginx->new()->has(qw/http proxy cache ssi/)
+my $t = Test::Nginx->new()->has(qw/http proxy cache ssi shmem/)
 	->write_file_expand('nginx.conf', <<'EOF')->plan(2);
 
 %%TEST_GLOBALS%%
--- a/proxy_cache_path.t
+++ b/proxy_cache_path.t
@@ -22,9 +22,7 @@ use Test::Nginx;
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-plan(skip_all => 'win32') if $^O eq 'MSWin32';
-
-my $t = Test::Nginx->new()->has(qw/http proxy cache/)->plan(7)
+my $t = Test::Nginx->new()->has(qw/http proxy cache shmem/)->plan(7)
 	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
--- a/proxy_cache_range.t
+++ b/proxy_cache_range.t
@@ -21,9 +21,7 @@ use Test::Nginx;
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-plan(skip_all => 'win32') if $^O eq 'MSWin32';
-
-my $t = Test::Nginx->new()->has(qw/http proxy cache/)->plan(7)
+my $t = Test::Nginx->new()->has(qw/http proxy cache shmem/)->plan(7)
 	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
--- a/proxy_cache_revalidate.t
+++ b/proxy_cache_revalidate.t
@@ -21,9 +21,7 @@ use Test::Nginx qw/ :DEFAULT :gzip /;
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-plan(skip_all => 'win32') if $^O eq 'MSWin32';
-
-my $t = Test::Nginx->new()->has(qw/http proxy cache rewrite/)->plan(23)
+my $t = Test::Nginx->new()->has(qw/http proxy cache rewrite shmem/)->plan(23)
 	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
--- a/proxy_cache_variables.t
+++ b/proxy_cache_variables.t
@@ -22,9 +22,7 @@ use Test::Nginx;
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-plan(skip_all => 'win32') if $^O eq 'MSWin32';
-
-my $t = Test::Nginx->new()->has(qw/http proxy cache/)->plan(9)
+my $t = Test::Nginx->new()->has(qw/http proxy cache shmem/)->plan(9)
 	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
--- a/proxy_cache_vary.t
+++ b/proxy_cache_vary.t
@@ -21,10 +21,8 @@ use Test::Nginx;
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-plan(skip_all => 'win32') if $^O eq 'MSWin32';
-
-my $t = Test::Nginx->new()->has(qw/http proxy cache gzip rewrite/)->plan(42)
-	->write_file_expand('nginx.conf', <<'EOF');
+my $t = Test::Nginx->new()->has(qw/http proxy cache gzip rewrite shmem/)
+	->plan(42)->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
 
--- a/proxy_force_ranges.t
+++ b/proxy_force_ranges.t
@@ -23,9 +23,7 @@ use Test::Nginx;
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-plan(skip_all => 'win32') if $^O eq 'MSWin32';
-
-my $t = Test::Nginx->new()->has(qw/http proxy cache/)->plan(5)
+my $t = Test::Nginx->new()->has(qw/http proxy cache shmem/)->plan(5)
 	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
--- a/proxy_merge_headers.t
+++ b/proxy_merge_headers.t
@@ -21,9 +21,7 @@ use Test::Nginx;
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-plan(skip_all => 'win32') if $^O eq 'MSWin32';
-
-my $t = Test::Nginx->new()->has(qw/http proxy cache rewrite/)->plan(7)
+my $t = Test::Nginx->new()->has(qw/http proxy cache rewrite shmem/)->plan(7)
 	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
--- a/proxy_unfinished.t
+++ b/proxy_unfinished.t
@@ -31,9 +31,7 @@ use Test::Nginx;
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-plan(skip_all => 'win32') if $^O eq 'MSWin32';
-
-my $t = Test::Nginx->new()->has(qw/http proxy cache sub/)->plan(15)
+my $t = Test::Nginx->new()->has(qw/http proxy cache sub shmem/)->plan(15)
 	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
--- a/random_index.t
+++ b/random_index.t
@@ -21,9 +21,7 @@ use Test::Nginx;
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-plan(skip_all => 'no symlinks on win32') if $^O eq 'MSWin32';
-
-my $t = Test::Nginx->new()->has(qw/http random_index/)->plan(1)
+my $t = Test::Nginx->new()->has(qw/http random_index symlink/)->plan(1)
 	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
--- a/range_charset.t
+++ b/range_charset.t
@@ -22,9 +22,7 @@ use Test::Nginx;
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-plan(skip_all => 'win32') if $^O eq 'MSWin32';
-
-my $t = Test::Nginx->new()->has(qw/http proxy cache charset/)->plan(10)
+my $t = Test::Nginx->new()->has(qw/http proxy cache charset shmem/)->plan(10)
 	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
--- a/scgi_merge_params.t
+++ b/scgi_merge_params.t
@@ -23,9 +23,8 @@ select STDOUT; $| = 1;
 
 eval { require SCGI; };
 plan(skip_all => 'SCGI not installed') if $@;
-plan(skip_all => 'win32') if $^O eq 'MSWin32';
 
-my $t = Test::Nginx->new()->has(qw/http scgi cache/)->plan(9)
+my $t = Test::Nginx->new()->has(qw/http scgi cache shmem/)->plan(9)
 	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
--- a/spdy.t
+++ b/spdy.t
@@ -33,10 +33,9 @@ eval {
 	Compress::Raw::Zlib->WANT_GZIP_OR_ZLIB;
 };
 plan(skip_all => 'Compress::Raw::Zlib not installed') if $@;
-plan(skip_all => 'win32') if $^O eq 'MSWin32';
 
 my $t = Test::Nginx->new()
-	->has(qw/http proxy cache limit_conn rewrite spdy realip/);
+	->has(qw/http proxy cache limit_conn rewrite spdy realip shmem/);
 
 $t->plan(82)->write_file_expand('nginx.conf', <<'EOF');
 
--- a/ssi.t
+++ b/ssi.t
@@ -21,9 +21,8 @@ use Test::Nginx;
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-plan(skip_all => 'win32') if $^O eq 'MSWin32';
-
-my $t = Test::Nginx->new()->has(qw/http ssi cache proxy rewrite/)->plan(28);
+my $t = Test::Nginx->new()->has(qw/http ssi cache proxy rewrite shmem/)
+	->plan(28);
 
 $t->write_file_expand('nginx.conf', <<'EOF');
 
@@ -102,7 +101,7 @@ EOF
 	'X<!--#include virtual="/proxy/empty.html" -->X');
 $t->write_file('empty.html', '');
 
-$t->write_file('unescape.html?', 'SEE-THIS');
+$t->write_file('unescape.html?', 'SEE-THIS') unless $^O eq 'MSWin32';
 $t->write_file('unescape1.html',
 	'X<!--#include virtual="/tes%741.html?test=test" -->X');
 $t->write_file('unescape2.html',
@@ -165,11 +164,17 @@ like(http_get('/test-empty-postpone.html
 # handling of escaped URIs
 
 like(http_get('/unescape1.html'), qr/^XXtestXX$/m, 'escaped in path');
+
+SKIP: {
+skip 'incorrect filename on win32', 2 if $^O eq 'MSWin32';
+
 like(http_get('/unescape2.html'), qr/^XSEE-THISX$/m,
 	'escaped question in path');
 like(http_get('/unescape3.html'), qr/404 Not Found/,
 	'escaped query separator');
 
+}
+
 # handling of embedded date variables
 
 my $re_date_gmt = qr/X-Var: x\w+, \d\d-\w{3}-\d{4} \d\d:\d\d:\d\d [\w ]+x/;