[PATCH] Tests: perl tests with scalar changed after $r->print()

Maxim Dounin mdounin at mdounin.ru
Wed Aug 5 21:31:52 UTC 2026


# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1785923744 -10800
#      Wed Aug 05 12:55:44 2026 +0300
# Node ID 0fb277edb976c00c91500e32d321077d9cf2be7e
# Parent  a9bdee1c091f077bd4b220bc07cf1e4b5b87180a
Tests: perl tests with scalar changed after $r->print().

diff --git a/perl_refcount.t b/perl_refcount.t
--- a/perl_refcount.t
+++ b/perl_refcount.t
@@ -22,7 +22,7 @@ use Test::Nginx;
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-my $t = Test::Nginx->new()->has(qw/http perl/)->plan(6)
+my $t = Test::Nginx->new()->has(qw/http perl/)->plan(8)
 	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
@@ -106,6 +106,34 @@ http {
                 return OK;
             }';
         }
+
+        location /print_changed {
+            perl 'sub {
+                my $r = shift;
+                $r->send_http_header;
+                my $foo = "it";
+                $foo .= " works";
+                $r->print($foo);
+                $foo = " changed";
+                $r->print($foo);
+                return OK;
+            }';
+        }
+
+        location /print_readonly_changed {
+            perl 'sub {
+                my $r = shift;
+                $r->send_http_header;
+                my $foo = "it";
+                $foo .= " works";
+                Internals::SvREADONLY($foo, 1);
+                $r->print($foo);
+                Internals::SvREADONLY($foo, 0);
+                $foo = " changed";
+                $r->print($foo);
+                return OK;
+            }';
+        }
     }
 }
 
@@ -162,4 +190,14 @@ like(http_get('/bless'), qr/500 Internal
 
 }
 
+TODO: {
+local $TODO = 'not yet' unless $t->has_version('1.31.4');
+
+like(http_get('/print_changed'), qr/works changed/,
+	'perl print scalar changed');
+like(http_get('/print_readonly_changed'), qr/works changed/,
+	'perl print scalar readonly changed');
+
+}
+
 ###############################################################################



More information about the nginx-devel mailing list