groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From emil...@apache.org
Subject [groovy] 02/03: GROOVY-9195: add test cases
Date Sun, 27 Oct 2019 15:43:51 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit ba0aa61150f14c049eab5ef24350a2b5d83d1887
Author: Eric Milles <eric.milles@thomsonreuters.com>
AuthorDate: Sun Oct 27 10:39:52 2019 -0500

    GROOVY-9195: add test cases
---
 src/test/groovy/bugs/Groovy9136.groovy             | 59 +++++++++++++++++++---
 .../packageScope/DifferentPackageTest.groovy       |  5 +-
 2 files changed, 53 insertions(+), 11 deletions(-)

diff --git a/src/test/groovy/bugs/Groovy9136.groovy b/src/test/groovy/bugs/Groovy9136.groovy
index 668af63..ea31af5 100644
--- a/src/test/groovy/bugs/Groovy9136.groovy
+++ b/src/test/groovy/bugs/Groovy9136.groovy
@@ -18,33 +18,76 @@
  */
 package groovy.bugs
 
-import groovy.transform.CompileStatic
+import groovy.test.NotYetImplemented
 import org.junit.Test
 
 import static groovy.test.GroovyAssert.assertScript
+import static groovy.test.GroovyAssert.shouldFail
 
-@CompileStatic
 final class Groovy9136 {
 
     @Test
-    void testMethodParameterAccessFromClosure() {
+    void testMethodParameterFieldAccessFromClosure1() {
         assertScript '''
-            @groovy.transform.CompileStatic
             class Foo {
                 public String field = 'foo'
             }
-            @groovy.transform.CompileStatic
             class Bar {
-                def doIt(Foo foo) {
+                @groovy.transform.CompileStatic
+                def test(Foo foo) {
                     'baz'.with {
-                        foo.field // GROOVY-9136: Access to Foo#foo is forbidden at line:
-1, column: -1
+                        foo.field // Access to Foo#foo is forbidden at line: -1, column:
-1
                     }
                 }
             }
 
             def bar = new Bar()
-            def out = bar.doIt(new Foo())
+            def out = bar.test(new Foo())
             assert out == 'foo'
         '''
     }
+
+    @Test @NotYetImplemented // GROOVY-9195
+    void testMethodParameterFieldAccessFromClosure2() {
+        def err = shouldFail '''
+            class Foo {
+                private String field = 'foo'
+            }
+            class Bar {
+                @groovy.transform.CompileStatic
+                def test(Foo foo) {
+                    'baz'.with {
+                        foo.field
+                    }
+                }
+            }
+
+            def bar = new Bar()
+            def out = bar.test(new Foo())
+        '''
+
+        assert err =~ /Access to Foo#field is forbidden/
+    }
+
+    @Test
+    void testMethodParameterFieldAccessFromClosure3() {
+        def err = shouldFail '''
+            class Foo {
+                private String field = 'foo'
+            }
+            @groovy.transform.CompileStatic
+            class Bar {
+                def test(Foo foo) {
+                    foo.with {
+                        field
+                    }
+                }
+            }
+
+            def bar = new Bar()
+            def out = bar.test(new Foo())
+        '''
+
+        assert err =~ /Access to Foo#field is forbidden/
+    }
 }
diff --git a/src/test/org/codehaus/groovy/transform/packageScope/DifferentPackageTest.groovy
b/src/test/org/codehaus/groovy/transform/packageScope/DifferentPackageTest.groovy
index a9204f8..42888eb 100644
--- a/src/test/org/codehaus/groovy/transform/packageScope/DifferentPackageTest.groovy
+++ b/src/test/org/codehaus/groovy/transform/packageScope/DifferentPackageTest.groovy
@@ -224,11 +224,10 @@ final class DifferentPackageTest {
                         }
                     }
                 ''')
-            // TODO: Don't need this once compiler errors
-            assert loader.loadClass('q.Two').half() == 21
+            loader.loadClass('q.Two').half()
         }
 
-        assert err =~ / Access to p.One#CONST is forbidden /
+        assert err =~ / MissingPropertyException: No such property: CONST for class: q.Two
/
     }
 
     @Test


Mime
View raw message