You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2021/08/12 20:26:18 UTC

[groovy] 01/01: GROOVY-10199: ASTTest: evaluate with compliation unit's transform loader

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

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

commit 8bf5bc70258f8af8277af9ea59d788d76e103437
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Thu Aug 12 15:25:51 2021 -0500

    GROOVY-10199: ASTTest: evaluate with compliation unit's transform loader
---
 .../groovy/transform/ASTTestTransformation.groovy  |  3 +-
 src/test/groovy/bugs/Groovy10199.groovy            | 38 ++++++++++++++++++++++
 2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/src/main/groovy/org/codehaus/groovy/transform/ASTTestTransformation.groovy b/src/main/groovy/org/codehaus/groovy/transform/ASTTestTransformation.groovy
index a8d3ba0..456f3bb 100644
--- a/src/main/groovy/org/codehaus/groovy/transform/ASTTestTransformation.groovy
+++ b/src/main/groovy/org/codehaus/groovy/transform/ASTTestTransformation.groovy
@@ -135,7 +135,8 @@ class ASTTestTransformation implements ASTTransformation, CompilationUnitAware {
 
             def config = new CompilerConfiguration()
             config.addCompilationCustomizers(customizer)
-            new GroovyShell(binding, config).evaluate(testSource)
+            def loader = compilationUnit.transformLoader
+            new GroovyShell(loader, binding, config).evaluate(testSource)
         }
     }
 
diff --git a/src/test/groovy/bugs/Groovy10199.groovy b/src/test/groovy/bugs/Groovy10199.groovy
new file mode 100644
index 0000000..6d70d60
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy10199.groovy
@@ -0,0 +1,38 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package groovy.bugs
+
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.assertScript
+
+final class Groovy10199 {
+    @Test
+    void testTransformClasspath() {
+        def shell = new GroovyShell()
+        shell.classLoader.addClasspath('gradle/wrapper/gradle-wrapper.jar')
+
+        assertScript shell, '''
+            @groovy.transform.ASTTest(value={
+                org.gradle.wrapper.WrapperConfiguration // Cannot get property 'gradle' on null object
+            })
+            def var = null
+        '''
+    }
+}