You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2024/01/20 09:06:44 UTC

(groovy) branch master updated: GROOVY-11272: Add a test case for captured variable

This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new e2fc02e1af GROOVY-11272: Add a test case for captured variable
e2fc02e1af is described below

commit e2fc02e1afa73be4c21e85e563b968d508210501
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Jan 20 17:06:26 2024 +0800

    GROOVY-11272: Add a test case for captured variable
---
 src/test/groovy/bugs/Groovy11272.groovy | 45 +++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/src/test/groovy/bugs/Groovy11272.groovy b/src/test/groovy/bugs/Groovy11272.groovy
index 9753241a7e..237359d66c 100644
--- a/src/test/groovy/bugs/Groovy11272.groovy
+++ b/src/test/groovy/bugs/Groovy11272.groovy
@@ -53,6 +53,28 @@ final class Groovy11272 {
         '''
     }
 
+    @Test
+    void testSerialVersionUID_3() {
+        assertScript '''
+            class C {
+                static test() {
+                    def out = new ByteArrayOutputStream()
+                    out.withObjectOutputStream {
+                        def greeting = "Hello"
+                        def c = {p -> "$greeting, $p"}
+                        it.writeObject(c)
+                    }
+                    out.toByteArray()
+                }
+            }
+            def serializedClosureBytes = C.test()
+            new ByteArrayInputStream(serializedClosureBytes).withObjectInputStream(this.class.classLoader) {
+                def c = it.readObject()
+                assert c.call('Daniel') == 'Hello, Daniel'
+            }
+        '''
+    }
+
     @Test
     void testSerialVersionUID_1_CS() {
         assertScript '''
@@ -87,4 +109,27 @@ final class Groovy11272 {
             }
         '''
     }
+
+    @Test
+    void testSerialVersionUID_3_CS() {
+        assertScript '''
+            @groovy.transform.CompileStatic
+            class C {
+                static test() {
+                    def out = new ByteArrayOutputStream()
+                    out.withObjectOutputStream {
+                        def greeting = "Hello"
+                        def c = {p -> "$greeting, $p"}
+                        it.writeObject(c)
+                    }
+                    out.toByteArray()
+                }
+            }
+            def serializedClosureBytes = C.test()
+            new ByteArrayInputStream(serializedClosureBytes).withObjectInputStream(this.class.classLoader) {
+                def c = it.readObject()
+                assert c.call('Daniel') == 'Hello, Daniel'
+            }
+        '''
+    }
 }