diff js_internal_redirect.t @ 1811:520fb74cce4c

Tests: improved njs version check to account multi digit versions.
author Dmitry Volyntsev <xeioex@nginx.com>
date Fri, 02 Dec 2022 17:46:22 -0800
parents 3580ad4b575f
children
line wrap: on
line diff
--- a/js_internal_redirect.t
+++ b/js_internal_redirect.t
@@ -100,8 +100,7 @@ like(http_get('/test?a=A'), qr/redirectA
 like(http_get('/test?dest=named'), qr/named/s, 'redirect to named location');
 
 TODO: {
-local $TODO = 'not yet'
-	unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.7.4';
+local $TODO = 'not yet' unless has_version('0.7.4');
 
 like(http_get('/test?unsafe=1'), qr/500 Internal Server/s,
 	'unsafe redirect');
@@ -110,3 +109,22 @@ like(http_get('/test?quoted=1'), qr/200 
 }
 
 ###############################################################################
+
+sub has_version {
+	my $need = shift;
+
+	http_get('/njs') =~ /^([.0-9]+)$/m;
+
+	my @v = split(/\./, $1);
+	my ($n, $v);
+
+	for $n (split(/\./, $need)) {
+		$v = shift @v || 0;
+		return 0 if $n > $v;
+		return 1 if $v > $n;
+	}
+
+	return 1;
+}
+
+###############################################################################