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 2022/03/13 18:53:35 UTC

[groovy] branch GROOVY_4_0_X updated (6d1902d -> f964cd2)

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

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


    from 6d1902d  GROOVY-10482: handle target type witness for parameterized static method
     new 4c260f5  GROOVY-10499: LUB of type args `Type` and `? extends Type` yields `Type`
     new ed3c755  convert to JUnit 4
     new f964cd2  GROOVY-9472: add test case

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../transform/stc/StaticTypeCheckingSupport.java   |   7 +-
 .../groovy/transform/stc/GenericsSTCTest.groovy    |  22 ++
 .../groovy/transform/AutoCloneTransformTest.groovy |  80 ++--
 .../groovy/transform/AutoFinalTransformTest.groovy |  20 +-
 .../transform/AutoImplementTransformTest.groovy    |  83 ++--
 .../transform/BaseScriptTransformTest.groovy       | 144 +++----
 .../groovy/transform/BuilderTransformTest.groovy   | 430 +++++++++++----------
 7 files changed, 417 insertions(+), 369 deletions(-)

[groovy] 02/03: convert to JUnit 4

Posted by em...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit ed3c7552eda7d2fbbd520a5768fa63a579edfa15
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sun Mar 13 12:56:58 2022 -0500

    convert to JUnit 4
---
 .../groovy/transform/AutoCloneTransformTest.groovy |  80 +++--
 .../groovy/transform/AutoFinalTransformTest.groovy |  20 +-
 .../transform/AutoImplementTransformTest.groovy    |  83 ++---
 .../transform/BaseScriptTransformTest.groovy       | 144 ++++----
 .../groovy/transform/BuilderTransformTest.groovy   | 388 ++++++++++-----------
 5 files changed, 348 insertions(+), 367 deletions(-)

diff --git a/src/test/org/codehaus/groovy/transform/AutoCloneTransformTest.groovy b/src/test/org/codehaus/groovy/transform/AutoCloneTransformTest.groovy
index aa284f8..c0d2674 100644
--- a/src/test/org/codehaus/groovy/transform/AutoCloneTransformTest.groovy
+++ b/src/test/org/codehaus/groovy/transform/AutoCloneTransformTest.groovy
@@ -18,51 +18,57 @@
  */
 package org.codehaus.groovy.transform
 
-import groovy.test.GroovyShellTestCase
+import org.codehaus.groovy.control.CompilerConfiguration
+import org.codehaus.groovy.control.customizers.ImportCustomizer
+import org.junit.Test
 
-class AutoCloneTransformTest extends GroovyShellTestCase {
+import static groovy.test.GroovyAssert.assertScript
+import static groovy.test.GroovyAssert.shouldFail
 
-    void testOk() {
-        assertScript """
-                import groovy.transform.AutoClone
-
-                @AutoClone
-                class Person {
-                    String first, last
-                    List favItems
-                    Date since
-                }
+/**
+ * Tests for the {@code @AutoClone} AST transform.
+ */
+final class AutoCloneTransformTest {
 
-                def p = new Person(first:'John', last:'Smith', favItems:['ipod', 'shiraz'], since:new Date())
-                def p2 = p.clone()
+    private final GroovyShell shell = new GroovyShell(new CompilerConfiguration().
+        addCompilationCustomizers(new ImportCustomizer().tap { addImports('groovy.transform.AutoClone') })
+    )
 
-                assert p instanceof Cloneable
-                assert p.favItems instanceof Cloneable
-                assert p.since instanceof Cloneable
-                assert !(p.first instanceof Cloneable)
+    @Test
+    void testBasics() {
+        assertScript shell, '''
+            @AutoClone
+            class Person {
+                String first, last
+                List favItems
+                Date since
+            }
 
-                assert !p.is(p2)
-                assert !p.favItems.is(p2.favItems)
-                assert !p.since.is(p2.since)
-                assert p.first.is(p2.first)
-            """
-    }
+            def p = new Person(first:'John', last:'Smith', favItems:['ipod','shiraz'], since:new Date())
 
-    void testExcludesWithInvalidPropertyNameResultsInError() {
-        def message = shouldFail {
-            evaluate """
-                    import groovy.transform.AutoClone
+            assert p instanceof Cloneable
+            assert p.favItems instanceof Cloneable
+            assert p.since instanceof Cloneable
+            assert p.first !instanceof Cloneable
 
-                    @AutoClone(excludes='sirName')
-                    class Person {
-                        String firstName
-                        String surName
-                    }
+            def p2 = p.clone()
 
-                    new Person(firstName: "John", surName: "Doe").clone()
-                """
-        }
-        assert message.contains("Error during @AutoClone processing: 'excludes' property 'sirName' does not exist.")
+            assert !p.is(p2)
+            assert !p.favItems.is(p2.favItems)
+            assert !p.since.is(p2.since)
+            assert  p.first.is(p2.first)
+        '''
     }
 
+    @Test
+    void testExcludesWithInvalidPropertyNameResultsInError() {
+        def err = shouldFail shell, '''
+            @AutoClone(excludes='sirName')
+            class Person {
+                String firstName
+                String surName
+            }
+        '''
+        assert err =~ /Error during @AutoClone processing: 'excludes' property 'sirName' does not exist./
+    }
 }
diff --git a/src/test/org/codehaus/groovy/transform/AutoFinalTransformTest.groovy b/src/test/org/codehaus/groovy/transform/AutoFinalTransformTest.groovy
index 55c64ab..6698618 100644
--- a/src/test/org/codehaus/groovy/transform/AutoFinalTransformTest.groovy
+++ b/src/test/org/codehaus/groovy/transform/AutoFinalTransformTest.groovy
@@ -18,17 +18,25 @@
  */
 package org.codehaus.groovy.transform
 
-import gls.CompilableTestSupport
+import org.codehaus.groovy.control.CompilerConfiguration
+import org.codehaus.groovy.control.customizers.ImportCustomizer
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.assertScript
 
 /**
  * Tests for the {@code @AutoFinal} AST transform.
  */
-class AutoFinalTransformTest extends CompilableTestSupport {
+final class AutoFinalTransformTest {
+
+    private final GroovyShell shell = new GroovyShell(new CompilerConfiguration().
+        addCompilationCustomizers(new ImportCustomizer().tap { addImports('groovy.transform.AutoFinal', 'groovy.transform.ASTTest') })
+    )
 
+    @Test
     void testAutoFinalOnClass() {
         // use ASTTest here since final modifier isn't put into bytecode so not available via reflection
-        assertScript '''
-            import groovy.transform.*
+        assertScript shell, '''
             import static java.lang.reflect.Modifier.isFinal
 
             @ASTTest(phase=SEMANTIC_ANALYSIS, value={
@@ -60,10 +68,10 @@ class AutoFinalTransformTest extends CompilableTestSupport {
         '''
     }
 
+    @Test
     void testAutoFinalOnClassButDisabledOnMethod() {
         // use ASTTest here since final modifier isn't put into bytecode so not available via reflection
-        assertScript '''
-            import groovy.transform.*
+        assertScript shell, '''
             import static java.lang.reflect.Modifier.isFinal
 
             @ASTTest(phase=SEMANTIC_ANALYSIS, value={
diff --git a/src/test/org/codehaus/groovy/transform/AutoImplementTransformTest.groovy b/src/test/org/codehaus/groovy/transform/AutoImplementTransformTest.groovy
index 05b108f..8de4040 100644
--- a/src/test/org/codehaus/groovy/transform/AutoImplementTransformTest.groovy
+++ b/src/test/org/codehaus/groovy/transform/AutoImplementTransformTest.groovy
@@ -18,6 +18,8 @@
  */
 package org.codehaus.groovy.transform
 
+import org.codehaus.groovy.control.CompilerConfiguration
+import org.codehaus.groovy.control.customizers.ImportCustomizer
 import org.junit.Test
 
 import static groovy.test.GroovyAssert.assertScript
@@ -25,11 +27,13 @@ import static groovy.test.GroovyAssert.shouldFail
 
 final class AutoImplementTransformTest {
 
+    private final GroovyShell shell = new GroovyShell(new CompilerConfiguration().
+        addCompilationCustomizers(new ImportCustomizer().tap { addImports('groovy.transform.AutoImplement') })
+    )
+
     @Test
     void testException() {
-        shouldFail UnsupportedOperationException, '''
-            import groovy.transform.*
-
+        shouldFail shell, UnsupportedOperationException, '''
             @AutoImplement(exception=UnsupportedOperationException)
             class Foo implements Iterator<String> { }
 
@@ -39,9 +43,7 @@ final class AutoImplementTransformTest {
 
     @Test
     void testExceptionWithMessage() {
-        def err = shouldFail UnsupportedOperationException, '''
-            import groovy.transform.*
-
+        def err = shouldFail shell, UnsupportedOperationException, '''
             @AutoImplement(exception=UnsupportedOperationException, message='Not supported by Foo')
             class Foo implements Iterator<String> { }
 
@@ -52,9 +54,7 @@ final class AutoImplementTransformTest {
 
     @Test
     void testClosureBody() {
-        shouldFail IllegalStateException, '''
-            import groovy.transform.*
-
+        shouldFail shell, IllegalStateException, '''
             @AutoImplement(code={ throw new IllegalStateException() })
             class Foo implements Iterator<String> { }
 
@@ -64,12 +64,12 @@ final class AutoImplementTransformTest {
 
     @Test
     void testInheritedMethodNotOverwritten() {
-        assertScript '''
+        assertScript shell, '''
             class WithNext {
                 String next() { 'foo' }
             }
 
-            @groovy.transform.AutoImplement
+            @AutoImplement
             class Foo extends WithNext implements Iterator<String> { }
 
             assert new Foo().next() == 'foo'
@@ -78,8 +78,8 @@ final class AutoImplementTransformTest {
 
     @Test
     void testExistingMethodNotOverwritten() {
-        assertScript '''
-            @groovy.transform.AutoImplement
+        assertScript shell, '''
+            @AutoImplement
             class Foo implements Iterator<String> {
                 String next() { 'foo' }
             }
@@ -90,12 +90,12 @@ final class AutoImplementTransformTest {
 
     @Test // GROOVY-9816
     void testPropertyMethodsNotOverwritten() {
-        assertScript '''
+        assertScript shell, '''
             interface Bar {
                 def getBaz(); void setBaz(baz)
             }
 
-            @groovy.transform.AutoImplement
+            @AutoImplement
             class Foo implements Bar {
                 def baz
             }
@@ -104,12 +104,12 @@ final class AutoImplementTransformTest {
             assert foo.baz == 123
         '''
 
-        assertScript '''
+        assertScript shell, '''
             interface Bar {
                 def getBaz(); void setBaz(baz)
             }
 
-            @groovy.transform.AutoImplement
+            @AutoImplement
             class Foo implements Bar {
                 final baz = 123
             }
@@ -119,12 +119,12 @@ final class AutoImplementTransformTest {
             assert foo.baz == 123
         '''
 
-        assertScript '''
+        assertScript shell, '''
             interface Bar {
                 boolean getBaz(); boolean isBaz()
             }
 
-            @groovy.transform.AutoImplement
+            @AutoImplement
             class Foo implements Bar {
                 boolean baz
             }
@@ -135,12 +135,12 @@ final class AutoImplementTransformTest {
             assert foo.baz
         '''
 
-        assertScript '''
+        assertScript shell, '''
             interface Bar {
                 boolean getBaz(); boolean isBaz()
             }
 
-            @groovy.transform.AutoImplement
+            @AutoImplement
             class Foo implements Bar {
                 boolean baz
                 boolean getBaz() { baz }
@@ -152,12 +152,12 @@ final class AutoImplementTransformTest {
             assert foo.baz
         '''
 
-        assertScript '''
+        assertScript shell, '''
             interface Bar {
                 boolean getBaz(); boolean isBaz()
             }
 
-            @groovy.transform.AutoImplement
+            @AutoImplement
             class Foo implements Bar {
                 boolean baz
                 boolean isBaz() { baz }
@@ -172,12 +172,12 @@ final class AutoImplementTransformTest {
 
     @Test
     void testVoidReturnType() {
-        assertScript '''
+        assertScript shell, '''
             interface Bar {
                 void baz()
             }
 
-            @groovy.transform.AutoImplement
+            @AutoImplement
             class Foo implements Bar { }
 
             new Foo().baz() // no value to assert
@@ -186,7 +186,7 @@ final class AutoImplementTransformTest {
 
     @Test
     void testGenericReturnTypes() {
-        assertScript '''
+        assertScript shell, '''
             interface HasXs<T> {
                 T[] x()
             }
@@ -197,7 +197,7 @@ final class AutoImplementTransformTest {
 
             interface MyIt<T> extends Iterator<T> { }
 
-            @groovy.transform.AutoImplement
+            @AutoImplement
             class Foo extends HasXsY<Integer> implements MyIt<String> { }
 
             def publicMethods = Foo.methods.findAll{ it.modifiers == 1 }.collect{ "$it.returnType.simpleName $it.name" }*.toString()
@@ -207,8 +207,8 @@ final class AutoImplementTransformTest {
 
     @Test // GROOVY-8270
     void testGenericParameterTypes() {
-        assertScript '''
-            @groovy.transform.AutoImplement
+        assertScript shell, '''
+            @AutoImplement
             class Foo implements Comparator<String> { }
             // Can't have an abstract method in a non-abstract class. The class 'Foo' must be declared
             // abstract or the method 'int compare(java.lang.Object, java.lang.Object)' must be implemented.
@@ -219,9 +219,7 @@ final class AutoImplementTransformTest {
 
     @Test // GROOVY-10472
     void testCovariantReturnTypes() {
-        assertScript '''
-            import groovy.transform.AutoImplement
-
+        assertScript shell, '''
             interface Super { List findAll() }
             interface Sub extends Super { Iterable findAll() }
 
@@ -230,9 +228,8 @@ final class AutoImplementTransformTest {
 
             assert !(new ThisClassFails().findAll())
         '''
-        assertScript '''
-            import groovy.transform.AutoImplement
 
+        assertScript shell, '''
             interface Super { ArrayList findAll() }
             interface Sub extends Super { Iterable findAll() }
 
@@ -241,9 +238,8 @@ final class AutoImplementTransformTest {
 
             assert !(new ThisClassFails().findAll())
         '''
-        assertScript '''
-            import groovy.transform.AutoImplement
 
+        assertScript shell, '''
             interface Super { Iterable findAll() }
             interface Sub extends Super { List findAll() }
 
@@ -252,9 +248,8 @@ final class AutoImplementTransformTest {
 
             assert !(new ThisClassFails().findAll())
         '''
-        assertScript '''
-            import groovy.transform.AutoImplement
 
+        assertScript shell, '''
             interface Super { Iterable findAll() }
             interface Sub extends Super { ArrayList findAll() }
 
@@ -263,9 +258,8 @@ final class AutoImplementTransformTest {
 
             assert !(new ThisClassFails().findAll())
         '''
-        assertScript '''
-            import groovy.transform.AutoImplement
 
+        assertScript shell, '''
             interface Super { AbstractList findAll() }
             interface Sub extends Super { List findAll() }
 
@@ -274,9 +268,8 @@ final class AutoImplementTransformTest {
 
             assert !(new ThisClassFails().findAll())
         '''
-        assertScript '''
-            import groovy.transform.AutoImplement
 
+        assertScript shell, '''
             interface Super { List findAll() }
             interface Sub extends Super { AbstractList findAll() }
 
@@ -285,9 +278,8 @@ final class AutoImplementTransformTest {
 
             assert !(new ThisClassFails().findAll())
         '''
-        assertScript '''
-            import groovy.transform.AutoImplement
 
+        assertScript shell, '''
             interface Super { AbstractList findAll() }
             interface Sub extends Super { ArrayList findAll() }
 
@@ -296,9 +288,8 @@ final class AutoImplementTransformTest {
 
             assert !(new ThisClassFails().findAll())
         '''
-        assertScript '''
-            import groovy.transform.AutoImplement
 
+        assertScript shell, '''
             interface Super { ArrayList findAll() }
             interface Sub extends Super { AbstractList findAll() }
 
diff --git a/src/test/org/codehaus/groovy/transform/BaseScriptTransformTest.groovy b/src/test/org/codehaus/groovy/transform/BaseScriptTransformTest.groovy
index cb38850..8db162d 100644
--- a/src/test/org/codehaus/groovy/transform/BaseScriptTransformTest.groovy
+++ b/src/test/org/codehaus/groovy/transform/BaseScriptTransformTest.groovy
@@ -18,86 +18,105 @@
  */
 package org.codehaus.groovy.transform
 
-import org.codehaus.groovy.control.CompilerConfiguration;
+import org.codehaus.groovy.control.CompilerConfiguration
+import org.codehaus.groovy.control.customizers.ImportCustomizer
+import org.junit.Test
 
-final class BaseScriptTransformTest extends gls.CompilableTestSupport {
+import static groovy.test.GroovyAssert.assertScript
+import static groovy.test.GroovyAssert.shouldFail
 
+/**
+ * Tests for the {@code @BaseScript} AST transform.
+ */
+final class BaseScriptTransformTest {
+
+    private final GroovyShell shell = new GroovyShell(new CompilerConfiguration().
+        addCompilationCustomizers(new ImportCustomizer().tap { addImports('groovy.transform.BaseScript') })
+    )
+
+    @Test
     void testInheritsFromCustomScript() {
-        assertScript '''
+        assertScript shell, '''
             abstract class Custom extends Script {
             }
 
-            @groovy.transform.BaseScript Custom self
+            @BaseScript Custom self
 
             assert this.class.superclass == Custom
         '''
     }
 
+    @Test
     void testBaseScriptMustExtendsScript() {
-        shouldNotCompile '''
+        shouldFail shell, '''
             abstract class Custom {
             }
 
-            @groovy.transform.BaseScript Custom self
+            @BaseScript Custom self
         '''
     }
 
+    @Test
     void testThisObjectIsAssignedToBaseScriptVariable() {
-        assertScript '''
+        assertScript shell, '''
             abstract class Custom extends Script {
             }
 
-            @groovy.transform.BaseScript Custom self
+            @BaseScript Custom self
 
             assert this == self
         '''
     }
 
+    @Test
     void testNotAllowedForClassFields() {
-        shouldNotCompile '''
+        shouldFail shell, '''
             abstract class Custom extends Script {
             }
 
             class Inner {
-                @groovy.transform.BaseScript Custom nope
+                @BaseScript Custom nope
             }
         '''
     }
 
+    @Test
     void testNotAllowedForScriptInnerClassFields() {
-        shouldNotCompile '''
+        shouldFail shell, '''
             abstract class Custom extends Script {
             }
 
             class Inner {
-                @groovy.transform.BaseScript Custom nope
+                @BaseScript Custom nope
             }
 
             println Inner.class.name
         '''
     }
 
+    @Test
     void testNotAllowedInClassMethods() {
-        shouldNotCompile '''
+        shouldFail shell, '''
             abstract class Custom extends Script {
             }
 
             class Inner {
                 void test() {
-                    @groovy.transform.BaseScript Custom nope
+                    @BaseScript Custom nope
                 }
             }
         '''
     }
 
+    @Test
     void testNotAllowedInScriptInnerClassMethods() {
-        shouldNotCompile '''
+        shouldFail shell, '''
             abstract class Custom extends Script {
             }
 
             class Inner {
                 void test() {
-                    @groovy.transform.BaseScript Custom nope
+                    @BaseScript Custom nope
                 }
             }
 
@@ -107,29 +126,23 @@ final class BaseScriptTransformTest extends gls.CompilableTestSupport {
 
     abstract class MyCustomScript extends Script {}
 
+    @Test
     void testBaseScriptFromCompiler() {
-        CompilerConfiguration config = new CompilerConfiguration()
-        config.scriptBaseClass = MyCustomScript.name
-        GroovyShell shell = new GroovyShell(config)
-
-        shell.evaluate('''
+        shell.config.scriptBaseClass = MyCustomScript.name
+        shell.evaluate '''
             abstract class Custom extends Script {
                 int meaningOfLife = 42
             }
 
-            @groovy.transform.BaseScript Custom self
+            @BaseScript Custom self
 
             assert meaningOfLife == 42
-        ''')
+        '''
     }
 
-    // GROOVY-6585
+    @Test // GROOVY-6585
     void testBaseScriptAbstractMethod() {
-        CompilerConfiguration config = new CompilerConfiguration()
-        config.scriptBaseClass = MyCustomScript.name
-        GroovyShell shell = new GroovyShell(config)
-
-        def answer = shell.evaluate('''
+        def answer = shell.evaluate '''
             abstract class Custom extends Script {
                 private int _meaningOfLife = 0
                 int getMeaningOfLife() { _meaningOfLife }
@@ -148,23 +161,23 @@ final class BaseScriptTransformTest extends gls.CompilableTestSupport {
                 }
             }
 
-            @groovy.transform.BaseScript Custom self
+            @BaseScript Custom self
 
             meaningOfLife |= 32
             assert meaningOfLife == 34
-        ''')
-
+        '''
         assert answer == 42
     }
 
+    @Test
     void testBaseScriptImplementsRunMethod() {
-        def result = new GroovyShell().evaluate('''
+        def result = shell.evaluate '''
             class Custom extends Script {
                 boolean iBeenRun
                 def run() { iBeenRun = true }
             }
 
-            @groovy.transform.BaseScript Custom self
+            @BaseScript Custom self
 
             assert !iBeenRun
 
@@ -173,26 +186,27 @@ final class BaseScriptTransformTest extends gls.CompilableTestSupport {
             assert iBeenRun
 
             iBeenRun
-        ''')
-
+        '''
         assert result
     }
 
+    @Test
     void testBaseScriptCanImplementRunMethodWithArgs() {
-        assertScript '''
+        assertScript shell, '''
             abstract class Custom extends Script {
                 def run() { run(null) }
                 abstract run(Object x)
             }
 
-            @groovy.transform.BaseScript Custom self
+            @BaseScript Custom self
 
             println "hello world"
         '''
     }
 
+    @Test
     void testScriptCanOverrideRun() {
-        assertScript '''
+        assertScript shell, '''
             abstract class Custom extends Script {
                 def depth = 3
                 def run() { myRun() }
@@ -206,14 +220,15 @@ final class BaseScriptTransformTest extends gls.CompilableTestSupport {
                 }
             }
 
-            @groovy.transform.BaseScript Custom self
+            @BaseScript Custom self
 
             println "hello world"
         '''
     }
 
+    @Test
     void testScriptCanOverrideRunButNotIfFinal() {
-        shouldNotCompile '''
+        shouldFail shell, '''
             abstract class Custom extends Script {
                 def depth = 3
                 final def run() { myRun() }
@@ -227,14 +242,15 @@ final class BaseScriptTransformTest extends gls.CompilableTestSupport {
                 }
             }
 
-            @groovy.transform.BaseScript Custom self
+            @BaseScript Custom self
 
             println "hello world"
         '''
     }
 
+    @Test
     void testBaseScriptOnImport() {
-        def result = new GroovyShell().evaluate('''
+        assertScript '''
             @BaseScript(Custom)
             import groovy.transform.BaseScript
 
@@ -248,14 +264,10 @@ final class BaseScriptTransformTest extends gls.CompilableTestSupport {
             super.run()
 
             assert iBeenRun
-
-            iBeenRun
-        ''')
-
-        assert result
+        '''
     }
 
-    // GROOVY-6706
+    @Test // GROOVY-6706
     void testBaseScriptOnImport2() {
         assertScript '''
             @BaseScript(Custom)
@@ -264,7 +276,7 @@ final class BaseScriptTransformTest extends gls.CompilableTestSupport {
             assert did_before
             assert !did_after
 
-            42
+            return 42
 
             abstract class Custom extends Script {
                 boolean did_before = false
@@ -285,13 +297,12 @@ final class BaseScriptTransformTest extends gls.CompilableTestSupport {
         '''
     }
 
+    @Test
     void testBaseScriptOnPackage() {
-        def result = new GroovyShell().evaluate('''
+        assertScript shell, '''
             @BaseScript(Custom)
             package foo
 
-            import groovy.transform.BaseScript
-
             class Custom extends Script {
                 boolean iBeenRun
                 def run() { iBeenRun = true }
@@ -302,23 +313,19 @@ final class BaseScriptTransformTest extends gls.CompilableTestSupport {
             super.run()
 
             assert iBeenRun
-
-            iBeenRun
-        ''')
-
-        assert result
+        '''
     }
 
-    // GROOVY-6586
+    @Test // GROOVY-6586
     void testBaseScriptVsBinding() {
-        assertScript '''
+        assertScript shell, '''
             abstract class Custom extends Script {
                 private int _something = 1
                 int getSomething() { _something }
                 void setSomething(int i) { _something = i }
             }
 
-            @groovy.transform.BaseScript Custom self
+            @BaseScript Custom self
 
             assert binding.variables.size() == 0
             assert something == 1
@@ -329,33 +336,34 @@ final class BaseScriptTransformTest extends gls.CompilableTestSupport {
         '''
     }
 
+    @Test
     void testShouldNotAllowClassMemberIfUsedOnADeclaration() {
-        shouldNotCompile '''import groovy.transform.BaseScript
-
+        shouldFail shell, '''
             @BaseScript(Script) Script foo
             println 'ok'
         '''
     }
 
+    @Test
     void testShouldNotAllowClassMemberIsNotClassLiteral() {
-        shouldNotCompile '''
+        shouldFail '''
             @BaseScript('Script')
             import groovy.transform.BaseScript
             println 'ok'
         '''
     }
 
+    @Test
     void testShouldNotAllowBaseScriptOnMultipleAssignment() {
-        shouldNotCompile '''import groovy.transform.BaseScript
-
+        shouldFail shell, '''
             @BaseScript def (Script a, Script b) = [null,null]
             println 'ok'
         '''
     }
 
+    @Test
     void testShouldNotAllowBaseScriptOnVariableAssignment() {
-        shouldNotCompile '''import groovy.transform.BaseScript
-
+        shouldFail shell, '''
             @BaseScript a = null
             println 'ok'
         '''
diff --git a/src/test/org/codehaus/groovy/transform/BuilderTransformTest.groovy b/src/test/org/codehaus/groovy/transform/BuilderTransformTest.groovy
index 461fd45..6193741 100644
--- a/src/test/org/codehaus/groovy/transform/BuilderTransformTest.groovy
+++ b/src/test/org/codehaus/groovy/transform/BuilderTransformTest.groovy
@@ -18,23 +18,32 @@
  */
 package org.codehaus.groovy.transform
 
-import gls.CompilableTestSupport
+import org.codehaus.groovy.control.CompilerConfiguration
+import org.codehaus.groovy.control.customizers.ImportCustomizer
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.assertScript
+import static groovy.test.GroovyAssert.shouldFail
 
 /**
- * Tests for {@code @Builder} transform.
+ * Tests for the {@code @Builder} transform.
  */
-class BuilderTransformTest extends CompilableTestSupport {
+final class BuilderTransformTest {
 
-    void testSimpleBuilder() {
-        assertScript """
-            import groovy.transform.builder.*
+    private final GroovyShell shell = new GroovyShell(new CompilerConfiguration().
+        addCompilationCustomizers(new ImportCustomizer().tap { addStarImports('groovy.transform', 'groovy.transform.builder') })
+    )
 
+    @Test
+    void testSimpleBuilder() {
+        assertScript shell, '''
             @Builder(builderStrategy=SimpleStrategy)
             class Person {
                 String firstName
                 String lastName
                 int age
             }
+
             def person = new Person().setFirstName("Robert").setLastName("Lewandowski").setAge(21)
             assert person.firstName == "Robert"
             assert person.lastName == "Lewandowski"
@@ -42,79 +51,82 @@ class BuilderTransformTest extends CompilableTestSupport {
 
             def methods = Person.methods.findAll{ it.name.startsWith('set') && it.name.endsWith('e') }
             assert methods*.name.toSet() == ['setLastName', 'setAge', 'setFirstName'] as Set
-            assert methods.every{ it.getAnnotation(groovy.transform.Generated) }
-         """
+            assert methods.every{ it.getAnnotation(Generated) }
+        '''
     }
 
+    @Test
     void testSimpleBuilderInvalidUseOfForClass() {
-        def message = shouldNotCompile """
-            import groovy.transform.builder.*
+        def err = shouldFail shell, '''
             @Builder(builderStrategy=SimpleStrategy, forClass=String)
-            class Person { }
-        """
-        assert message.contains("Annotation attribute 'forClass' not supported")
+            class Person {
+            }
+        '''
+        assert err.message.contains("Annotation attribute 'forClass' not supported")
     }
 
+    @Test
     void testSimpleBuilderInvalidUseOfBuilderClassName() {
-        def message = shouldNotCompile """
-            import groovy.transform.builder.*
+        def err = shouldFail shell, '''
             @Builder(builderStrategy=SimpleStrategy, builderClassName='Creator')
-            class Person { }
-        """
-        assert message.contains("Annotation attribute 'builderClassName' not supported")
+            class Person {
+            }
+        '''
+        assert err.message.contains("Annotation attribute 'builderClassName' not supported")
     }
 
+    @Test
     void testSimpleBuilderInvalidUseOfBuilderMethodName() {
-        def message = shouldNotCompile """
-            import groovy.transform.builder.*
+        def err = shouldFail shell, '''
             @Builder(builderStrategy=SimpleStrategy, builderMethodName='creator')
-            class Person { }
-        """
-        assert message.contains("Annotation attribute 'builderMethodName' not supported")
+            class Person {
+            }
+        '''
+        assert err.message.contains("Annotation attribute 'builderMethodName' not supported")
     }
 
+    @Test
     void testSimpleBuilderInvalidUseOfBuildMethodName() {
-        def message = shouldNotCompile """
-            import groovy.transform.builder.*
+        def err = shouldFail shell, '''
             @Builder(builderStrategy=SimpleStrategy, buildMethodName='create')
-            class Person { }
-        """
-        assert message.contains("Annotation attribute 'buildMethodName' not supported")
+            class Person {
+            }
+        '''
+        assert err.message.contains("Annotation attribute 'buildMethodName' not supported")
     }
 
+    @Test
     void testSimpleBuilderInvalidUseOfIncludeSuperProperties() {
-        def message = shouldNotCompile """
-            import groovy.transform.builder.*
+        def err = shouldFail shell, '''
             @Builder(builderStrategy=SimpleStrategy, includeSuperProperties=true)
-            class Person { }
-        """
-        assert message.contains("Annotation attribute 'includeSuperProperties' not supported")
+            class Person {
+            }
+        '''
+        assert err.message.contains("Annotation attribute 'includeSuperProperties' not supported")
     }
 
+    @Test
     void testSimpleBuilderCustomPrefix() {
-        assertScript """
-            import groovy.transform.builder.*
-
+        assertScript shell, '''
             @Builder(builderStrategy=SimpleStrategy, prefix="")
             class Person {
                 String firstName
                 String lastName
                 int age
             }
+
             def person = new Person()
             person.firstName("Robert").lastName("Lewandowski")
             person.setAge(21) // normal setters remain but can't be chained
             assert person.firstName == "Robert"
             assert person.lastName == "Lewandowski"
             assert person.age == 21
-        """
+        '''
     }
 
+    @Test
     void testSimpleBuilderSetters() {
-        assertScript """
-            import groovy.transform.builder.*
-            import groovy.transform.*
-
+        assertScript shell, '''
             @TupleConstructor(useSetters=true)
             @Builder(builderStrategy=SimpleStrategy, prefix="", useSetters=true)
             class Person {
@@ -137,14 +149,12 @@ class BuilderTransformTest extends CompilableTestSupport {
             p3.age = 15
             assert p3.name == "tom"
             assert p3.age == 30
-        """
+        '''
     }
 
+    @Test
     void testSimpleBuilderWithCanonicalAndExcludes() {
-        assertScript '''
-            import groovy.transform.builder.*
-            import groovy.transform.Canonical
-
+        assertScript shell, '''
             @Canonical(excludes='age')
             @Builder(builderStrategy=SimpleStrategy)
             class Person {
@@ -152,6 +162,7 @@ class BuilderTransformTest extends CompilableTestSupport {
                 String lastName
                 int age
             }
+
             def p = new Person().setFirstName("Robert").setLastName("Lewandowski")
             p.age = 21 // non-chained version should still be there
             assert "$p.firstName $p.lastName $p.age" == 'Robert Lewandowski 21'
@@ -162,31 +173,28 @@ class BuilderTransformTest extends CompilableTestSupport {
         '''
     }
 
+    @Test
     void testDefaultBuilder() {
-        def shell = new GroovyShell()
-        shell.parse """
-            import groovy.transform.builder.Builder
-
+        shell.parse '''
             @Builder
             class Person {
                 String firstName
                 String lastName
                 int age
             }
-        """
-        shell.evaluate """
+        '''
+        assertScript shell, '''
             def builder = new Person.PersonBuilder()
             def person = builder.firstName("Robert").lastName("Lewandowski").age(21).build()
             assert person.firstName == "Robert"
             assert person.lastName == "Lewandowski"
             assert person.age == 21
-        """
+        '''
     }
 
+    @Test
     void testDefaultBuilderUsingBuilderMethod() {
-        assertScript """
-            import groovy.transform.builder.Builder
-
+        assertScript shell, '''
             @Builder
             class Person {
                 String firstName
@@ -201,14 +209,13 @@ class BuilderTransformTest extends CompilableTestSupport {
             assert person.age == 21
 
             def methods = Person.builder().getClass().methods.findAll{ it.name in ['firstName', 'lastName', 'age'] }
-            assert methods.every{ it.getAnnotation(groovy.transform.Generated) }
-        """
+            assert methods.every{ it.getAnnotation(Generated) }
+        '''
     }
 
+    @Test
     void testDefaultBuilderGenerics() {
-        assertScript """
-            import groovy.transform.builder.Builder
-
+        assertScript shell, '''
             @Builder
             class CookBook {
                 List<String> recipes
@@ -216,29 +223,25 @@ class BuilderTransformTest extends CompilableTestSupport {
 
             def c = CookBook.builder().recipes(['Eggs Benedict', 'Poached Salmon']).build()
             assert c.recipes == ['Eggs Benedict', 'Poached Salmon']
-        """
-        def message = shouldNotCompile '''
-            import groovy.transform.builder.Builder
-            import groovy.transform.CompileStatic
+        '''
 
+        def err = shouldFail shell, '''
             @Builder
             class CookBook {
                 List<String> recipes
             }
 
-
             @CompileStatic
             def methodBadParams() {
                 CookBook.builder().recipes([35, 42]).build()
             }
         '''
-        assert message =~ /.*Cannot call.*recipes.*java.util.List\s?<java.lang.String>.*with arguments.*java.util.(Array)?List\s?<java.lang.Integer>.*/
+        assert err =~ /.*Cannot call.*recipes.*java.util.List\s?<java.lang.String>.*with arguments.*java.util.(Array)?List\s?<java.lang.Integer>.*/
     }
 
+    @Test
     void testInitializerGenerics() {
-        assertScript """
-            import groovy.transform.builder.*
-
+        assertScript shell, '''
             @Builder(builderStrategy=InitializerStrategy)
             class CookBook {
                 List<String> recipes
@@ -246,50 +249,44 @@ class BuilderTransformTest extends CompilableTestSupport {
 
             def c = new CookBook(CookBook.createInitializer().recipes(['Eggs Benedict', 'Poached Salmon']))
             assert c.recipes == ['Eggs Benedict', 'Poached Salmon']
-        """
-        def message = shouldNotCompile '''
-            import groovy.transform.builder.*
+        '''
 
+        def err = shouldFail shell, '''
             @Builder(builderStrategy=InitializerStrategy)
             class CookBook {
                 List<String> recipes
             }
 
-
-            @groovy.transform.CompileStatic
+            @CompileStatic
             def methodBadParams() {
                 new CookBook(CookBook.createInitializer().recipes([35, 42]))
             }
         '''
-        assert message =~ /.*Cannot call.*recipes.*java.util.List\s?<java.lang.String>.*with arguments.*java.util.(Array)?List\s?<java.lang.Integer>.*/
+        assert err =~ /.*Cannot call.*recipes.*java.util.List\s?<java.lang.String>.*with arguments.*java.util.(Array)?List\s?<java.lang.Integer>.*/
     }
 
+    @Test
     void testDefaultBuilderCustomNames() {
-        def shell = new GroovyShell()
-        shell.parse """
-            import groovy.transform.builder.Builder
-
+        shell.parse '''
             @Builder(builderClassName="Foo", buildMethodName="create")
             class Person {
                 String firstName
                 String lastName
                 int age
             }
-        """
-        shell.evaluate """
+        '''
+        assertScript shell, '''
             def builder = new Person.Foo()
             def person = builder.firstName("Robert").lastName("Lewandowski").age(21).create()
             assert person.firstName == "Robert"
             assert person.lastName == "Lewandowski"
             assert person.age == 21
-        """
+        '''
     }
 
+    @Test
     void testDefaultBuilderUsingCanonical() {
-        assertScript '''
-            import groovy.transform.builder.Builder
-            import groovy.transform.Canonical
-
+        assertScript shell, '''
             // explicit excludes overrides excludes from @Canonical
             @Builder(buildMethodName='make', builderMethodName='maker', prefix='with', excludes='age')
             @Canonical(includes='firstName,age')
@@ -304,26 +301,22 @@ class BuilderTransformTest extends CompilableTestSupport {
         '''
     }
 
+    @Test
     void testDefaultBuilderInvalidIncludeWithMethodAnnotation() {
-        def message = shouldNotCompile """
-            import groovy.transform.builder.*
-
+        def err = shouldFail shell, '''
             class NameUtil {
                 @Builder(includes='first')
                 static String join(String first, String last) {
                     first + ' ' + last
                 }
             }
-        """
-
-        assert message.contains("includes/excludes only allowed on classes")
+        '''
+        assert err.message.contains("includes/excludes only allowed on classes")
     }
 
+    @Test
     void testDefaultBuilderIncludeSuperProperties() {
-        assertScript """
-            import groovy.transform.builder.*
-            import groovy.transform.*
-
+        assertScript shell, '''
             @Builder
             class Mamal {
                 int age
@@ -343,13 +336,12 @@ class BuilderTransformTest extends CompilableTestSupport {
                 assert person.age == 21
             }
             parentBuilder()
-         """
+         '''
     }
 
+    @Test
     void testExternalBuilder() {
-        assertScript """
-            import groovy.transform.builder.*
-
+        assertScript shell, '''
             class Person {
                 String firstName
                 String lastName
@@ -363,32 +355,33 @@ class BuilderTransformTest extends CompilableTestSupport {
             assert person.lastName == "Lewandowski"
 
             def methods = PersonBuilder.methods.findAll{ it.name in ['firstName', 'lastName', 'age'] }
-            assert methods.every{ it.getAnnotation(groovy.transform.Generated) }
-        """
+            assert methods.every{ it.getAnnotation(Generated) }
+        '''
     }
 
+    @Test
     void testExternalBuilderInvalidUseOfBuilderClassName() {
-        def message = shouldNotCompile """
-            import groovy.transform.builder.*
+        def err = shouldFail shell, '''
             @Builder(builderStrategy=ExternalStrategy, forClass=String, builderClassName='Creator')
-            class DummyStringBuilder { }
-        """
-        assert message.contains("Annotation attribute 'builderClassName' not supported")
+            class DummyStringBuilder {
+            }
+        '''
+        assert err.message.contains("Annotation attribute 'builderClassName' not supported")
     }
 
+    @Test
     void testExternalBuilderInvalidUseOfBuilderMethodName() {
-        def message = shouldNotCompile """
-            import groovy.transform.builder.*
+        def err = shouldFail shell, '''
             @Builder(builderStrategy=ExternalStrategy, forClass=String, builderMethodName='creator')
-            class DummyStringBuilder { }
-        """
-        assert message.contains("Annotation attribute 'builderMethodName' not supported")
+            class DummyStringBuilder {
+            }
+        '''
+        assert err.message.contains("Annotation attribute 'builderMethodName' not supported")
     }
 
+    @Test
     void testExternalBuilderCustomPrefix() {
-        assertScript """
-            import groovy.transform.builder.*
-
+        assertScript shell, '''
             class Person {
                 String firstName
                 String lastName
@@ -403,14 +396,12 @@ class BuilderTransformTest extends CompilableTestSupport {
             p1.with { assert firstName == "Robert" && lastName == "Lewandowski" }
             def p2 = new PersonBuilder2().withFirstName("Robert").withLastName("Lewandowski").build()
             p2.with { assert firstName == "Robert" && lastName == "Lewandowski" }
-        """
+        '''
     }
 
+    @Test
     void testExternalBuilderWithIncludeAndCustomMethodName() {
-        assertScript """
-            import groovy.transform.builder.*
-            import groovy.transform.Canonical
-
+        assertScript shell, '''
             @Canonical
             class Person {
                 String firstName
@@ -425,13 +416,12 @@ class BuilderTransformTest extends CompilableTestSupport {
             assert person.firstName == "Robert"
             assert personBuilder.metaClass.methods.find { it.name == "lastName" } == null
             assert personBuilder.metaClass.methods.find { it.name == "firstName" } != null
-        """
+        '''
     }
 
+    @Test
     void testExternalBuilderWithExclude() {
-        assertScript """
-            import groovy.transform.builder.*
-
+        assertScript shell, '''
             class Person {
                 String firstName
                 String lastName
@@ -445,13 +435,12 @@ class BuilderTransformTest extends CompilableTestSupport {
             assert person.firstName == "Robert"
             assert personBuilder.metaClass.methods.find { it.name == "lastName" } == null
             assert personBuilder.metaClass.methods.find { it.name == "firstName" } != null
-        """
+        '''
     }
 
+    @Test
     void testExternalBuilderWithCanonicalAndExcludes() {
-        assertScript '''
-            import groovy.transform.builder.*
-            import groovy.transform.Canonical
+        assertScript shell, '''
             import static groovy.test.GroovyAssert.shouldFail
 
             @Canonical(excludes='born')
@@ -473,11 +462,9 @@ class BuilderTransformTest extends CompilableTestSupport {
         '''
     }
 
+    @Test
     void testExternalBuilderIncludeSuperProperties() {
-        assertScript """
-            import groovy.transform.builder.*
-            import groovy.transform.*
-
+        assertScript shell, '''
             class Mamal {
                 int age
             }
@@ -497,14 +484,12 @@ class BuilderTransformTest extends CompilableTestSupport {
                 assert person.age == 21
             }
             parentBuilder()
-        """
+        '''
     }
 
+    @Test
     void testInitializerStrategy() {
-        assertScript '''
-            import groovy.transform.builder.*
-            import groovy.transform.*
-
+        assertScript shell, '''
             @ToString
             @Builder(builderStrategy=InitializerStrategy)
             class Person {
@@ -523,12 +508,10 @@ class BuilderTransformTest extends CompilableTestSupport {
             assert new Person(Person.createInitializer().firstName("John").lastName("Smith").age(21)).toString() == 'Person(John, Smith, 21)'
 
             def methods = Person.createInitializer().getClass().methods.findAll{ it.name in ['firstName', 'lastName', 'age'] }
-            assert methods.every{ it.getAnnotation(groovy.transform.Generated) }
+            assert methods.every{ it.getAnnotation(Generated) }
         '''
-        def message = shouldNotCompile '''
-            import groovy.transform.builder.*
-            import groovy.transform.CompileStatic
 
+        def err = shouldFail shell, '''
             @Builder(builderStrategy=InitializerStrategy)
             class Person {
                 String firstName
@@ -541,15 +524,13 @@ class BuilderTransformTest extends CompilableTestSupport {
                 new Person(Person.createInitializer().firstName("John").lastName("Smith"))
             }
         '''
-        assert message.contains('[Static type checking] - Cannot call Person#<init>')
-        assert message =~ /.*SET.*SET.*UNSET.*/
+        assert err.message.contains('[Static type checking] - Cannot call Person#<init>')
+        assert err =~ /.*SET.*SET.*UNSET.*/
     }
 
+    @Test
     void testInitializerStrategyCanonical() {
-        assertScript '''
-            import groovy.transform.builder.*
-            import groovy.transform.*
-
+        assertScript shell, '''
             @Canonical
             @Builder(builderStrategy=InitializerStrategy)
             class Person {
@@ -566,11 +547,9 @@ class BuilderTransformTest extends CompilableTestSupport {
         '''
     }
 
+    @Test
     void testInitializerStrategyOnConstructorAndMethods() {
-        assertScript '''
-            import groovy.transform.builder.*
-            import groovy.transform.*
-
+        assertScript shell, '''
             @ToString
             @Builder(builderStrategy=InitializerStrategy)
             class Person {
@@ -611,11 +590,9 @@ class BuilderTransformTest extends CompilableTestSupport {
         '''
     }
 
+    @Test
     void testInitializerStrategySetters() {
-        assertScript '''
-            import groovy.transform.builder.*
-            import groovy.transform.*
-
+        assertScript shell, '''
             @Canonical(useSetters=true)
             @Builder(builderStrategy=InitializerStrategy)
             class Person {
@@ -629,10 +606,8 @@ class BuilderTransformTest extends CompilableTestSupport {
             }
             make()
         '''
-        assertScript '''
-            import groovy.transform.builder.*
-            import groovy.transform.*
 
+        assertScript shell, '''
             @Canonical
             @TupleConstructor(includes='')
             @Builder(builderStrategy=InitializerStrategy, useSetters=true, force=true)
@@ -649,11 +624,9 @@ class BuilderTransformTest extends CompilableTestSupport {
         '''
     }
 
+    @Test
     void testInitializerStrategyIncludeSuperProperties() {
-        assertScript '''
-            import groovy.transform.builder.*
-            import groovy.transform.*
-
+        assertScript shell, '''
             class Mamal {
                 int age
             }
@@ -674,10 +647,8 @@ class BuilderTransformTest extends CompilableTestSupport {
             // dynamic case
             assert new Person(Person.createInitializer().firstName("John").lastName("Smith").age(21)).toString() == 'Person(John, Smith, 21)'
         '''
-        def message = shouldNotCompile '''
-            import groovy.transform.builder.*
-            import groovy.transform.*
 
+        def err = shouldFail shell, '''
             class Mamal {
                 int age
             }
@@ -694,16 +665,15 @@ class BuilderTransformTest extends CompilableTestSupport {
                 new Person(Person.createInitializer().firstName("John").lastName("Smith"))
             }
         '''
-        assert message.contains('[Static type checking] - Cannot call Person#<init>')
-        assert message =~ /.*SET.*SET.*UNSET.*/
+        assert err.message.contains('[Static type checking] - Cannot call Person#<init>')
+        assert err =~ /.*SET.*SET.*UNSET.*/
     }
 
-    void testBuilderWithPackageName_GROOVY7501() {
-        assertScript '''
+    @Test // GROOVY-7501
+    void testBuilderWithPackageName() {
+        assertScript shell, '''
             package alfa.beta
 
-            import groovy.transform.builder.*
-
             @Builder class PersonDef { }
             assert PersonDef.builder().class.name == 'alfa.beta.PersonDef$PersonDefBuilder'
 
@@ -712,44 +682,45 @@ class BuilderTransformTest extends CompilableTestSupport {
         '''
     }
 
-    void testInitializerStrategyEmptyCases_GROOVY7503() {
-        def message = shouldNotCompile '''
-            import groovy.transform.builder.*
-            @Builder(builderStrategy=InitializerStrategy) class Foo { }
+    @Test // GROOVY-7503
+    void testInitializerStrategyEmptyCases() {
+        def err = shouldFail shell, '''
+            @Builder(builderStrategy=InitializerStrategy) class Foo {
+            }
         '''
-        assert message.contains('at least one property is required for this strategy')
-        message = shouldNotCompile '''
-            import groovy.transform.builder.*
-            @Builder(builderStrategy=InitializerStrategy, excludes='bar') class Foo { String bar }
+        assert err.message.contains('at least one property is required for this strategy')
+
+        err = shouldFail shell, '''
+            @Builder(builderStrategy=InitializerStrategy, excludes='bar') class Foo {
+                String bar
+            }
         '''
-        assert message.contains('at least one property is required for this strategy')
-        message = shouldNotCompile '''
-            import groovy.transform.builder.*
+        assert err.message.contains('at least one property is required for this strategy')
+
+        err = shouldFail shell, '''
             class Foo {
               @Builder(builderStrategy=InitializerStrategy)
               Foo() {
               }
             }
         '''
-        assert message.contains('at least one parameter is required for this strategy')
+        assert err.message.contains('at least one parameter is required for this strategy')
     }
 
-    void testInternalFieldsAreIncludedIfRequestedForSimpleStrategy_GROOVY6454() {
-        assertScript '''
-            import groovy.transform.builder.*
-
+    @Test // GROOVY-6454
+    void testInternalFieldsAreIncludedIfRequestedForSimpleStrategy() {
+        assertScript shell, '''
             @Builder(builderStrategy = SimpleStrategy, allNames = true)
             class HasInternalPropertyWithSimpleStrategy {
                 String $internal
             }
             assert new HasInternalPropertyWithSimpleStrategy().set$internal("foo").$internal == "foo"
-         '''
+        '''
     }
 
-    void testInternalFieldsAreIncludedIfRequestedForExternalStrategy_GROOVY6454() {
-        assertScript '''
-            import groovy.transform.builder.*
-
+    @Test // GROOVY-6454
+    void testInternalFieldsAreIncludedIfRequestedForExternalStrategy() {
+        assertScript shell, '''
             class HasInternalProperty {
                 String $internal
             }
@@ -758,26 +729,24 @@ class BuilderTransformTest extends CompilableTestSupport {
             class HasInternalPropertyBuilder { }
 
             assert new HasInternalPropertyBuilder().$internal("foo").build().$internal == "foo"
-         '''
+        '''
     }
 
-    void testInternalFieldsAreIncludedIfRequestedForDefaultStrategy_GROOVY6454() {
-        assertScript '''
-            import groovy.transform.builder.*
-
+    @Test // GROOVY-6454
+    void testInternalFieldsAreIncludedIfRequestedForDefaultStrategy() {
+        assertScript shell, '''
             @Builder(allNames = true)
             class HasInternalProperty {
                 String $internal
             }
 
             assert HasInternalProperty.builder().$internal("foo").$internal == "foo"
-         '''
+        '''
     }
 
-    void testInternalFieldsAreIncludedIfRequestedForInitializerStrategy_GROOVY6454() {
-        assertScript '''
-            import groovy.transform.builder.*
-
+    @Test // GROOVY-6454
+    void testInternalFieldsAreIncludedIfRequestedForInitializerStrategy() {
+        assertScript shell, '''
             @Builder(builderStrategy = InitializerStrategy, allNames = true)
             class HasInternalProperty {
                 String $internal
@@ -785,14 +754,12 @@ class BuilderTransformTest extends CompilableTestSupport {
 
             def initializer = HasInternalProperty.createInitializer()
             assert new HasInternalProperty(initializer.$internal("foo")).$internal == "foo"
-         '''
+        '''
     }
 
-    // GROOVY-8186
+    @Test // GROOVY-8186
     void testJavaBeanPropertiesAreProperlyProcessed() {
-        assertScript '''
-            import groovy.transform.builder.*
-
+        assertScript shell, '''
             class Foo {
               String getName() {
                 'John'
@@ -801,9 +768,10 @@ class BuilderTransformTest extends CompilableTestSupport {
             }
 
             @Builder(builderStrategy=ExternalStrategy, forClass=Foo)
-            class FooBuilder { }
+            class FooBuilder {
+            }
 
             assert new FooBuilder().name('Mary').build().name == 'John'
-         '''
+        '''
     }
 }

[groovy] 01/03: GROOVY-10499: LUB of type args `Type` and `? extends Type` yields `Type`

Posted by em...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 4c260f56beab0c9451cef4adf02c0635b101c9ea
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sun Mar 13 11:35:43 2022 -0500

    GROOVY-10499: LUB of type args `Type` and `? extends Type` yields `Type`
---
 .../transform/stc/StaticTypeCheckingSupport.java   |  7 +++++--
 .../groovy/transform/stc/GenericsSTCTest.groovy    | 22 ++++++++++++++++++++++
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
index ce00d87..cf3e035 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -1920,10 +1920,13 @@ public abstract class StaticTypeCheckingSupport {
         return genericsType.getType();
     }
 
-    static GenericsType getCombinedGenericsType(final GenericsType gt1, final GenericsType gt2) {
+    static GenericsType getCombinedGenericsType(GenericsType gt1, GenericsType gt2) {
+        // GROOVY-9998, GROOVY-10499: unpack "?" that is from "? extends T"
+        if (isUnboundedWildcard(gt1)) gt1 = gt1.getType().asGenericsType();
+        if (isUnboundedWildcard(gt2)) gt2 = gt2.getType().asGenericsType();
         ClassNode cn1 = GenericsUtils.makeClassSafe0(CLASS_Type, gt1);
         ClassNode cn2 = GenericsUtils.makeClassSafe0(CLASS_Type, gt2);
-        ClassNode lub = lowestUpperBound(cn1,cn2);
+        ClassNode lub = lowestUpperBound(cn1, cn2);
         return lub.getGenericsTypes()[0];
     }
 
diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
index 2e91b70..5a88260 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -2559,6 +2559,28 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
         }
     }
 
+    // GROOVY-10499
+    void testCompatibleArgumentsForPlaceholders7() {
+        ['?', 'Y', '? extends Y'].each {
+            assertScript """
+                class Foo<X> {
+                    Foo(X x) {
+                    }
+                }
+                class Bar<Y> {
+                    Bar(Foo<${it}> foo, Y y) {
+                    }
+                    Y baz(Y y) {
+                    }
+                }
+                def <Z> void test(Z z = null) {
+                    new Bar<>(new Foo<Z>(z), z).baz(z) // Cannot find matching method Bar#baz(Z)
+                }
+                test()
+            """
+        }
+    }
+
     void testIncompatibleArgumentsForPlaceholders1() {
         shouldFailWithMessages '''
             def <T extends Number> T test(T one, T two) { }

[groovy] 03/03: GROOVY-9472: add test case

Posted by em...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit f964cd2aeaa96545db8ff171b2098f1c5ff23667
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sun Mar 13 13:10:25 2022 -0500

    GROOVY-9472: add test case
---
 .../groovy/transform/BuilderTransformTest.groovy   | 42 ++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/src/test/org/codehaus/groovy/transform/BuilderTransformTest.groovy b/src/test/org/codehaus/groovy/transform/BuilderTransformTest.groovy
index 6193741..d0b5415 100644
--- a/src/test/org/codehaus/groovy/transform/BuilderTransformTest.groovy
+++ b/src/test/org/codehaus/groovy/transform/BuilderTransformTest.groovy
@@ -20,6 +20,7 @@ package org.codehaus.groovy.transform
 
 import org.codehaus.groovy.control.CompilerConfiguration
 import org.codehaus.groovy.control.customizers.ImportCustomizer
+import org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit
 import org.junit.Test
 
 import static groovy.test.GroovyAssert.assertScript
@@ -774,4 +775,45 @@ final class BuilderTransformTest {
             assert new FooBuilder().name('Mary').build().name == 'John'
         '''
     }
+
+    @Test // GROOVY-9472
+    void testInnerClassReference() {
+        def sourceDir = File.createTempDir()
+        def config = new CompilerConfiguration(
+            targetDirectory: File.createTempDir(),
+            jointCompilationOptions: [memStub: true]
+        )
+        try {
+            new File(sourceDir, 'p').mkdir()
+
+            def a = new File(sourceDir, 'Main.groovy')
+            a.write '''
+                import p.Pogo
+
+                /*Pogo.PogoBuilder*/ pb = Pogo.builder()
+                Pogo p = pb.name('Frank Grimes').build()
+
+                assert p.name == 'Frank Grimes'
+            '''
+            def b = new File(sourceDir, 'p/Pogo.groovy')
+            b.write '''
+                package p
+
+                @groovy.transform.builder.Builder
+                class Pogo {
+                    String name
+                }
+            '''
+
+            def loader = new GroovyClassLoader(this.class.classLoader)
+            def cu = new JavaAwareCompilationUnit(config, loader)
+            cu.addSources(a, b)
+            cu.compile()
+
+            loader.loadClass('Main').main()
+        } finally {
+            sourceDir.deleteDir()
+            config.targetDirectory.deleteDir()
+        }
+    }
 }