You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2019/08/12 01:46:22 UTC
[groovy] 01/02: Convert some recent tests to JUnit 4
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit cf6888cbcd7df169246a59818134f805a6957866
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Thu Jul 18 11:15:14 2019 -0500
Convert some recent tests to JUnit 4
---
src/test/groovy/bugs/Groovy8962.groovy | 311 +++++++++++----------
.../bugs/{Groovy9063.groovy => Groovy8964.groovy} | 37 +--
src/test/groovy/bugs/Groovy8964Bug.groovy | 43 ---
.../{Groovy9007Bug.groovy => Groovy9007.groovy} | 39 +--
.../bugs/{Groovy9153.groovy => Groovy9010.groovy} | 18 +-
src/test/groovy/bugs/Groovy9010Bug.groovy | 30 --
src/test/groovy/bugs/Groovy9063.groovy | 6 +-
src/test/groovy/bugs/Groovy9103.groovy | 72 +++++
src/test/groovy/bugs/Groovy9103Bug.groovy | 62 ----
src/test/groovy/bugs/Groovy9115.groovy | 66 +++++
src/test/groovy/bugs/Groovy9115Bug.groovy | 59 ----
src/test/groovy/bugs/Groovy9127.groovy | 11 +-
src/test/groovy/bugs/Groovy9136.groovy | 34 ++-
src/test/groovy/bugs/Groovy9141.groovy | 8 +-
src/test/groovy/bugs/Groovy9153.groovy | 6 +-
src/test/groovy/bugs/Groovy9170.groovy | 6 +-
src/test/groovy/bugs/Groovy9176.groovy | 6 +-
src/test/groovy/bugs/Groovy9184.groovy | 3 -
18 files changed, 404 insertions(+), 413 deletions(-)
diff --git a/src/test/groovy/bugs/Groovy8962.groovy b/src/test/groovy/bugs/Groovy8962.groovy
index 1756dfa..6a8b657 100644
--- a/src/test/groovy/bugs/Groovy8962.groovy
+++ b/src/test/groovy/bugs/Groovy8962.groovy
@@ -1,162 +1,165 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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 junit.framework.TestCase
import org.codehaus.groovy.control.CompilerConfiguration
import org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit
+import org.junit.Test
-class Groovy8962 extends GroovyTestCase {
+final class Groovy8962 {
+
+ @Test
void testShouldCompileProperly_memStub() {
- def config = new CompilerConfiguration()
- config.with {
- targetDirectory = createTempDir()
- jointCompilationOptions = [memStub: true]
- }
+ def config = new CompilerConfiguration(
+ targetDirectory: File.createTempDir(),
+ jointCompilationOptions: [memStub: true]
+ )
- File parentDir = createTempDir()
+ def parentDir = File.createTempDir()
try {
def a = new File(parentDir, 'A.groovy')
a.write '''
- class A {
- Map<String, Map<String, Integer[]>> columnsMap = [:]
- }
+ class A {
+ Map<String, Map<String, Integer[]>> columnsMap = [:]
+ }
'''
def b = new File(parentDir, 'B.java')
b.write '''
- public class B {
- public void f(A a) {
- System.out.println(a.getColumnsMap());
+ public class B {
+ public void f(A a) {
+ System.out.println(a.getColumnsMap());
+ }
}
- }
- '''
+ '''
+
def loader = new GroovyClassLoader(this.class.classLoader)
def cu = new JavaAwareCompilationUnit(config, loader)
- cu.addSources([a, b] as File[])
+ cu.addSources(a, b)
cu.compile()
} finally {
parentDir.deleteDir()
- config.targetDirectory?.deleteDir()
+ config.targetDirectory.deleteDir()
}
-
}
+ @Test
void testShouldCompileProperly2_memStub() {
- def config = new CompilerConfiguration()
- config.with {
- targetDirectory = createTempDir()
- jointCompilationOptions = [memStub: true]
- }
+ def config = new CompilerConfiguration(
+ targetDirectory: File.createTempDir(),
+ jointCompilationOptions: [memStub: true]
+ )
- File parentDir = createTempDir()
+ def parentDir = File.createTempDir()
try {
def a = new File(parentDir, 'A.groovy')
a.write '''
- class A {
- Map<String, Map<String, List<Integer[]>[]>> columnsMap = [:]
- }
+ class A {
+ Map<String, Map<String, List<Integer[]>[]>> columnsMap = [:]
+ }
'''
def b = new File(parentDir, 'B.java')
b.write '''
- public class B {
- public void f(A a) {
- System.out.println(a.getColumnsMap());
+ public class B {
+ public void f(A a) {
+ System.out.println(a.getColumnsMap());
+ }
}
- }
- '''
+ '''
+
def loader = new GroovyClassLoader(this.class.classLoader)
def cu = new JavaAwareCompilationUnit(config, loader)
- cu.addSources([a, b] as File[])
+ cu.addSources(a, b)
cu.compile()
} finally {
parentDir.deleteDir()
- config.targetDirectory?.deleteDir()
+ config.targetDirectory.deleteDir()
}
-
}
+ @Test
void testShouldCompileProperly3_memStub() {
- def config = new CompilerConfiguration()
- config.with {
- targetDirectory = createTempDir()
- jointCompilationOptions = [memStub: true]
- }
+ def config = new CompilerConfiguration(
+ targetDirectory: File.createTempDir(),
+ jointCompilationOptions: [memStub: true]
+ )
- File parentDir = createTempDir()
+ def parentDir = File.createTempDir()
try {
def a = new File(parentDir, 'A.groovy')
a.write '''
- package x
- import y.B
- class A {
- Map<String, Map<String, List<Integer[]>[]>> columnsMap = [:]
- B b = null
- }
+ package x
+ import y.B
+ class A {
+ Map<String, Map<String, List<Integer[]>[]>> columnsMap = [:]
+ B b = null
+ }
'''
def b = new File(parentDir, 'B.java')
b.write '''
- package y;
- import x.A;
- public class B {
- public void f(A a) {
- System.out.println(a.getColumnsMap());
+ package y;
+ import x.A;
+ public class B {
+ public void f(A a) {
+ System.out.println(a.getColumnsMap());
+ }
}
- }
- '''
+ '''
+
def loader = new GroovyClassLoader(this.class.classLoader)
def cu = new JavaAwareCompilationUnit(config, loader)
- cu.addSources([a, b] as File[])
+ cu.addSources(a, b)
cu.compile()
} finally {
parentDir.deleteDir()
- config.targetDirectory?.deleteDir()
+ config.targetDirectory.deleteDir()
}
-
}
+ @Test
void testShouldAllowConstantInSwitch_memStub() {
- def config = new CompilerConfiguration()
- config.with {
- targetDirectory = createTempDir()
- jointCompilationOptions = [memStub: true]
- }
+ def config = new CompilerConfiguration(
+ targetDirectory: File.createTempDir(),
+ jointCompilationOptions: [memStub: true]
+ )
- File parentDir = createTempDir()
+ def parentDir = File.createTempDir()
try {
def b = new File(parentDir, 'B.java')
b.write '''
- public class B {
- public static void main(String...args) {
- int x = 4;
- switch (x) {
- case groovy.bugs.Groovy8962.Constants.constant: x=1;
+ public class B {
+ public static void main(String...args) {
+ int x = 4;
+ switch (x) {
+ case groovy.bugs.Groovy8962.Constants.constant: x=1;
+ }
}
}
- }
- '''
+ '''
+
def loader = new GroovyClassLoader(this.class.classLoader)
addToClassPath(loader)
def cu = new JavaAwareCompilationUnit(config, loader)
- cu.addSources([b] as File[])
+ cu.addSources(b)
cu.compile()
} finally {
parentDir.deleteDir()
@@ -164,14 +167,14 @@ class Groovy8962 extends GroovyTestCase {
}
}
+ @Test
void testShouldAllowConstantInSwitchWithStubs_memStub() {
- def config = new CompilerConfiguration()
- config.with {
- targetDirectory = createTempDir()
- jointCompilationOptions = [memStub: true]
- }
+ def config = new CompilerConfiguration(
+ targetDirectory: File.createTempDir(),
+ jointCompilationOptions: [memStub: true]
+ )
- File parentDir = createTempDir()
+ def parentDir = File.createTempDir()
try {
def a = new File(parentDir, 'A.groovy')
a.write '''
@@ -181,19 +184,20 @@ class Groovy8962 extends GroovyTestCase {
'''
def b = new File(parentDir, 'B.java')
b.write '''
- public class B {
- public static void main(String...args) {
- int x = 4;
- switch (x) {
- case A.constant: x=1;
+ public class B {
+ public static void main(String...args) {
+ int x = 4;
+ switch (x) {
+ case A.constant: x=1;
+ }
}
}
- }
- '''
+ '''
+
def loader = new GroovyClassLoader(this.class.classLoader)
addToClassPath(loader)
def cu = new JavaAwareCompilationUnit(config, loader)
- cu.addSources([a, b] as File[])
+ cu.addSources(a, b)
cu.compile()
} finally {
parentDir.deleteDir()
@@ -201,36 +205,31 @@ class Groovy8962 extends GroovyTestCase {
}
}
- static addToClassPath(GroovyClassLoader loader) {
- loader.addURL(this.getProtectionDomain().getCodeSource().getLocation())
- loader.addURL(GroovyTestCase.class.getProtectionDomain().getCodeSource().getLocation())
- loader.addURL(TestCase.class.getProtectionDomain().getCodeSource().getLocation())
- }
-
+ @Test
void testShouldAllowCharConstantInSwitchWithoutStubs_memStub() {
- def config = new CompilerConfiguration()
- config.with {
- targetDirectory = createTempDir()
- jointCompilationOptions = [memStub: true]
- }
+ def config = new CompilerConfiguration(
+ targetDirectory: File.createTempDir(),
+ jointCompilationOptions: [memStub: true]
+ )
- File parentDir = createTempDir()
+ def parentDir = File.createTempDir()
try {
def b = new File(parentDir, 'B.java')
b.write '''
- public class B {
- public static void main(String...args) {
- char x = 'z';
- switch (x) {
- case groovy.bugs.Groovy8962.Constants.FOOCHAR: x='y';
+ public class B {
+ public static void main(String...args) {
+ char x = 'z';
+ switch (x) {
+ case groovy.bugs.Groovy8962.Constants.FOOCHAR: x='y';
+ }
}
}
- }
- '''
+ '''
+
def loader = new GroovyClassLoader(this.class.classLoader)
config.setClasspathList([getClasspathElement(this.class), getClasspathElement(GroovyTestCase), getClasspathElement(TestCase)])
def cu = new JavaAwareCompilationUnit(config, loader)
- cu.addSources([b] as File[])
+ cu.addSources(b)
cu.compile()
} finally {
parentDir.deleteDir()
@@ -238,20 +237,14 @@ class Groovy8962 extends GroovyTestCase {
}
}
- private static getClasspathElement(Class c) {
- def codeSource = c.protectionDomain.codeSource
- def file = new File(codeSource.getLocation().toURI()).getPath()
- return file.toString()
- }
-
+ @Test
void testShouldAllowCharConstantInSwitchWithStubs_memStub() {
- def config = new CompilerConfiguration()
- config.with {
- targetDirectory = createTempDir()
- jointCompilationOptions = [memStub: true]
- }
+ def config = new CompilerConfiguration(
+ targetDirectory: File.createTempDir(),
+ jointCompilationOptions: [memStub: true]
+ )
- File parentDir = createTempDir()
+ def parentDir = File.createTempDir()
try {
def a = new File(parentDir, 'A.groovy')
a.write '''
@@ -261,18 +254,19 @@ class Groovy8962 extends GroovyTestCase {
'''
def b = new File(parentDir, 'B.java')
b.write '''
- public class B {
- public static void main(String...args) {
- char x = 'z';
- switch (x) {
- case A.constant: x='y';
+ public class B {
+ public static void main(String...args) {
+ char x = 'z';
+ switch (x) {
+ case A.constant: x='y';
+ }
}
}
- }
- '''
+ '''
+
def loader = new GroovyClassLoader(this.class.classLoader)
def cu = new JavaAwareCompilationUnit(config, loader)
- cu.addSources([a, b] as File[])
+ cu.addSources(a, b)
cu.compile()
} finally {
parentDir.deleteDir()
@@ -280,14 +274,14 @@ class Groovy8962 extends GroovyTestCase {
}
}
+ @Test
void testAccessConstantStringFromJavaClass_memStub() {
- def config = new CompilerConfiguration()
- config.with {
- targetDirectory = createTempDir()
- jointCompilationOptions = [memStub: true]
- }
+ def config = new CompilerConfiguration(
+ targetDirectory: File.createTempDir(),
+ jointCompilationOptions: [memStub: true]
+ )
- File parentDir = createTempDir()
+ def parentDir = File.createTempDir()
try {
def a = new File(parentDir, 'A.groovy')
a.write '''
@@ -297,16 +291,18 @@ class Groovy8962 extends GroovyTestCase {
'''
def b = new File(parentDir, 'B.java')
b.write '''
- public class B {
- public static void main(String...args) {
- if (!"hello, world!".equals(A.CONSTANT)) throw new RuntimeException("Constant should not be: ["+A.CONSTANT+"]");
+ public class B {
+ public static void main(String...args) {
+ if (!"hello, world!".equals(A.CONSTANT)) throw new RuntimeException("Constant should not be: ["+A.CONSTANT+"]");
+ }
}
- }
- '''
+ '''
+
def loader = new GroovyClassLoader(this.class.classLoader)
def cu = new JavaAwareCompilationUnit(config, loader)
- cu.addSources([a, b] as File[])
+ cu.addSources(a, b)
cu.compile()
+
Class clazz = loader.loadClass("B")
clazz.newInstance().main()
} finally {
@@ -315,8 +311,17 @@ class Groovy8962 extends GroovyTestCase {
}
}
- private static File createTempDir() {
- File.createTempDir("groovyTest${System.currentTimeMillis()}", "")
+ //--------------------------------------------------------------------------
+
+ private static void addToClassPath(GroovyClassLoader loader) {
+ loader.addURL(this.protectionDomain.codeSource.location)
+ loader.addURL(GroovyTestCase.protectionDomain.codeSource.location)
+ loader.addURL(TestCase.protectionDomain.codeSource.location)
+ }
+
+ private static String getClasspathElement(Class c) {
+ def codeSource = c.protectionDomain.codeSource
+ new File(codeSource.location.toURI()).path.toString()
}
static class Constants {
diff --git a/src/test/groovy/bugs/Groovy9063.groovy b/src/test/groovy/bugs/Groovy8964.groovy
similarity index 56%
copy from src/test/groovy/bugs/Groovy9063.groovy
copy to src/test/groovy/bugs/Groovy8964.groovy
index 488e870..ec287e8 100644
--- a/src/test/groovy/bugs/Groovy9063.groovy
+++ b/src/test/groovy/bugs/Groovy8964.groovy
@@ -7,7 +7,7 @@
* "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
+ * 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
@@ -18,27 +18,32 @@
*/
package groovy.bugs
-import groovy.transform.CompileStatic
+import org.junit.Test
-@CompileStatic
-final class Groovy9063 extends GroovyTestCase {
+import static groovy.test.GroovyAssert.assertScript
- void testProtectedFieldAccessFromNestedClosure() {
+final class Groovy8964 {
+
+ @Test
+ void testInstanceVarargMethodNotMaskedByStaticMethodWithSameNumberOfArgs() {
assertScript '''
- @groovy.transform.CompileStatic
- class Groovy9063 {
- protected String message = 'hello'
-
- int nestedClosures() {
- { ->
- { ->
- message.length()
- }.call()
- }.call()
+ class Example {
+
+ def method(String... args) {
+ 'vararg'
+ }
+
+ static method(List<String> args, File workDirectory, Appendable out, Appendable err) {
+ 'multi'
+ }
+
+ def execute() {
+ method("a", "b", "c", "d")
}
}
- assert new Groovy9063().nestedClosures() == 5
+ Example ex = new Example()
+ assert ex.execute() == 'vararg'
'''
}
}
diff --git a/src/test/groovy/bugs/Groovy8964Bug.groovy b/src/test/groovy/bugs/Groovy8964Bug.groovy
deleted file mode 100644
index 47b5109..0000000
--- a/src/test/groovy/bugs/Groovy8964Bug.groovy
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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
-
-class Groovy8964Bug extends GroovyTestCase {
- void testInstanceVarargMethodNotMaskedByStaticMethodWithSameNumberOfArgs() {
- assertScript '''
- class Example {
-
- def method(String... args) {
- 'vararg'
- }
-
- static method(List<String> args, File workDirectory, Appendable out, Appendable err) {
- 'multi'
- }
-
- def execute() {
- method("a", "b", "c", "d")
- }
- }
-
- Example ex = new Example()
- assert ex.execute() == 'vararg'
- '''
- }
-}
diff --git a/src/test/groovy/bugs/Groovy9007Bug.groovy b/src/test/groovy/bugs/Groovy9007.groovy
similarity index 65%
rename from src/test/groovy/bugs/Groovy9007Bug.groovy
rename to src/test/groovy/bugs/Groovy9007.groovy
index a75e452..307b2b3 100644
--- a/src/test/groovy/bugs/Groovy9007Bug.groovy
+++ b/src/test/groovy/bugs/Groovy9007.groovy
@@ -1,24 +1,30 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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
-class Groovy9007Bug extends GroovyTestCase {
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.assertScript
+
+final class Groovy9007 {
+
+ @Test
void testProtectedFieldInClosureInEnum() {
assertScript '''
@groovy.transform.CompileStatic
@@ -35,6 +41,7 @@ class Groovy9007Bug extends GroovyTestCase {
'''
}
+ @Test
void testPrivateFieldInClosureInEnum() {
assertScript '''
@groovy.transform.CompileStatic
@@ -51,7 +58,7 @@ class Groovy9007Bug extends GroovyTestCase {
'''
}
- // GROOVY-8978
+ @Test // GROOVY-8978
void testProtectedFieldInChildWithExplicitThis() {
assertScript '''
import groovy.transform.CompileStatic
diff --git a/src/test/groovy/bugs/Groovy9153.groovy b/src/test/groovy/bugs/Groovy9010.groovy
similarity index 69%
copy from src/test/groovy/bugs/Groovy9153.groovy
copy to src/test/groovy/bugs/Groovy9010.groovy
index e28b629..f7ca70a 100644
--- a/src/test/groovy/bugs/Groovy9153.groovy
+++ b/src/test/groovy/bugs/Groovy9010.groovy
@@ -7,7 +7,7 @@
* "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
+ * 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
@@ -19,18 +19,18 @@
package groovy.bugs
import groovy.transform.CompileStatic
-import org.codehaus.groovy.ast.expr.ConstantExpression
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.assertScript
@CompileStatic
-final class Groovy9153 extends GroovyTestCase {
+final class Groovy9010 {
- void testConstantExpressionNULL() {
+ @Test
+ void testASTTestWithNoSpacesInClosure() {
assertScript '''
- @groovy.transform.CompileStatic
- File tempDir() {
- return File.createTempDir()
- }
+ @groovy.transform.ASTTest({assert 1==1})
+ def x
'''
- assert ConstantExpression.NULL.getNodeMetaData().isEmpty()
}
}
diff --git a/src/test/groovy/bugs/Groovy9010Bug.groovy b/src/test/groovy/bugs/Groovy9010Bug.groovy
deleted file mode 100644
index d8b7045..0000000
--- a/src/test/groovy/bugs/Groovy9010Bug.groovy
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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 gls.CompilableTestSupport
-
-class Groovy9010Bug extends CompilableTestSupport {
- void testASTTestWithNoSpacesInClosure() {
- shouldCompile '''
- @groovy.transform.ASTTest({assert 1==1})
- def x
- '''
- }
-}
diff --git a/src/test/groovy/bugs/Groovy9063.groovy b/src/test/groovy/bugs/Groovy9063.groovy
index 488e870..9bd5172 100644
--- a/src/test/groovy/bugs/Groovy9063.groovy
+++ b/src/test/groovy/bugs/Groovy9063.groovy
@@ -19,10 +19,14 @@
package groovy.bugs
import groovy.transform.CompileStatic
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.assertScript
@CompileStatic
-final class Groovy9063 extends GroovyTestCase {
+final class Groovy9063 {
+ @Test
void testProtectedFieldAccessFromNestedClosure() {
assertScript '''
@groovy.transform.CompileStatic
diff --git a/src/test/groovy/bugs/Groovy9103.groovy b/src/test/groovy/bugs/Groovy9103.groovy
new file mode 100644
index 0000000..28d6fcd
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy9103.groovy
@@ -0,0 +1,72 @@
+/*
+ * 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
+
+// TODO: add JVM option `--illegal-access=deny` when all warnings fixed
+final class Groovy9103 {
+
+ @Test
+ void testProperties() {
+ String str = ''
+ assert str.properties
+ }
+
+ @Test
+ void testBigIntegerMultiply() {
+ assert 2G * 1
+ }
+
+ @Test
+ void testClone() {
+ assertScript '''
+ def broadcastSeq(Object value) {
+ value.clone()
+ }
+
+ assert broadcastSeq(new Tuple1('abc'))
+ '''
+ }
+
+ @Test
+ void testClone2() {
+ assertScript '''
+ class Value {
+ @Override
+ public Value clone() {
+ return new Value()
+ }
+ }
+ def broadcastSeq(Object value) {
+ value.clone()
+ }
+
+ assert broadcastSeq(new Value())
+ '''
+ }
+
+ @Test
+ void testClone3() {
+ Object obj = new Tuple1('abc')
+ assert obj.clone()
+ }
+}
diff --git a/src/test/groovy/bugs/Groovy9103Bug.groovy b/src/test/groovy/bugs/Groovy9103Bug.groovy
deleted file mode 100644
index 322bd36..0000000
--- a/src/test/groovy/bugs/Groovy9103Bug.groovy
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * 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
-
-// TODO add JVM option `--illegal-access=deny` when all warnings fixed
-class Groovy9103Bug extends GroovyTestCase {
- void testProperties() {
- String str = ''
- assert str.properties
- }
-
- void testBigIntegerMultiply() {
- assert 2G * 1
- }
-
- void testClone() {
- assertScript '''
- def broadcastSeq(Object value) {
- value.clone()
- }
-
- assert broadcastSeq(new Tuple1('abc'))
- '''
- }
-
- void testClone2() {
- assertScript '''
- class Value {
- @Override
- public Value clone() {
- return new Value()
- }
- }
- def broadcastSeq(Object value) {
- value.clone()
- }
-
- assert broadcastSeq(new Value())
- '''
- }
-
- void testClone3() {
- Object obj = new Tuple1('abc')
- assert obj.clone()
- }
-}
diff --git a/src/test/groovy/bugs/Groovy9115.groovy b/src/test/groovy/bugs/Groovy9115.groovy
new file mode 100644
index 0000000..5393713
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy9115.groovy
@@ -0,0 +1,66 @@
+/*
+ * 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 groovy.transform.CompileStatic
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.assertScript
+
+@CompileStatic
+final class Groovy9115 {
+
+ @Test
+ void testSetPropertyInIfStmt() {
+ assertScript '''
+ @groovy.transform.CompileStatic
+ class Derived {
+ def m() {
+ if (true) {
+ File file = File.createTempFile("hello${System.nanoTime()}", ".tmp")
+ file.text = 'Groovy9115Bug'
+ assert 'Groovy9115Bug' == file.text
+ }
+
+ return null
+ }
+ }
+
+ new Derived().m()
+ '''
+ }
+
+ @Test
+ void testSetProperty() {
+ assertScript '''
+ @groovy.transform.CompileStatic
+ class Derived {
+ def m() {
+ File file = File.createTempFile("hello${System.nanoTime()}", ".tmp")
+ file.text = 'Groovy9115Bug'
+ assert 'Groovy9115Bug' == file.text
+
+ return null
+ }
+ }
+
+ new Derived().m()
+ '''
+ }
+}
diff --git a/src/test/groovy/bugs/Groovy9115Bug.groovy b/src/test/groovy/bugs/Groovy9115Bug.groovy
deleted file mode 100644
index 0c7026c..0000000
--- a/src/test/groovy/bugs/Groovy9115Bug.groovy
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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 gls.CompilableTestSupport
-
-class Groovy9115Bug extends CompilableTestSupport {
- void testSetPropertyInIfStmt() {
- assertScript '''
- @groovy.transform.CompileStatic
- class Derived {
- def m() {
- if (true) {
- File file = File.createTempFile("hello${System.nanoTime()}", ".tmp")
- file.text = 'Groovy9115Bug'
- assert 'Groovy9115Bug' == file.text
- }
-
- return null
- }
- }
-
- new Derived().m()
- '''
- }
-
- void testSetProperty() {
- assertScript '''
- @groovy.transform.CompileStatic
- class Derived {
- def m() {
- File file = File.createTempFile("hello${System.nanoTime()}", ".tmp")
- file.text = 'Groovy9115Bug'
- assert 'Groovy9115Bug' == file.text
-
- return null
- }
- }
-
- new Derived().m()
- '''
- }
-}
diff --git a/src/test/groovy/bugs/Groovy9127.groovy b/src/test/groovy/bugs/Groovy9127.groovy
index 96a5efd..9f22acf 100644
--- a/src/test/groovy/bugs/Groovy9127.groovy
+++ b/src/test/groovy/bugs/Groovy9127.groovy
@@ -21,12 +21,16 @@ package groovy.bugs
import groovy.transform.CompileStatic
import org.codehaus.groovy.control.CompilationFailedException
import org.codehaus.groovy.control.CompilationUnit
+import org.junit.Test
+import static groovy.test.GroovyAssert.assertScript
+import static groovy.test.GroovyAssert.shouldFail
import static org.codehaus.groovy.control.Phases.CLASS_GENERATION
@CompileStatic
-final class Groovy9127 extends GroovyTestCase {
+final class Groovy9127 {
+ @Test
void testReadOnlyPropertyAssignment1() {
assertScript '''
@groovy.transform.CompileStatic
@@ -48,6 +52,7 @@ final class Groovy9127 extends GroovyTestCase {
'''
}
+ @Test
void testReadOnlyPropertyAssignment2() {
assertScript '''
@groovy.transform.CompileStatic
@@ -69,6 +74,7 @@ final class Groovy9127 extends GroovyTestCase {
'''
}
+ @Test
void testReadOnlyPropertyAssignment3() {
assertScript '''
@groovy.transform.CompileStatic
@@ -90,6 +96,7 @@ final class Groovy9127 extends GroovyTestCase {
'''
}
+ @Test
void testReadOnlyPropertyAssignment4() {
new CompilationUnit().with {
addSource 'Foo.groovy', '''
@@ -122,6 +129,7 @@ final class Groovy9127 extends GroovyTestCase {
}
}
+ @Test
void testReadOnlyPropertyAssignment5() {
def err = shouldFail CompilationFailedException, '''
@groovy.transform.CompileStatic
@@ -141,6 +149,7 @@ final class Groovy9127 extends GroovyTestCase {
assert err =~ /\[Static type checking\] - Cannot set read-only property: field/
}
+ @Test
void testAttributeAssignmentVariation() {
assertScript '''
@groovy.transform.CompileStatic
diff --git a/src/test/groovy/bugs/Groovy9136.groovy b/src/test/groovy/bugs/Groovy9136.groovy
index f85aff2..b7da0b9 100644
--- a/src/test/groovy/bugs/Groovy9136.groovy
+++ b/src/test/groovy/bugs/Groovy9136.groovy
@@ -1,28 +1,32 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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 groovy.transform.CompileStatic
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.assertScript
@CompileStatic
-final class Groovy9136 extends GroovyTestCase {
+final class Groovy9136 {
+ @Test
void testMethodParameterAccessFromClosure() {
assertScript '''
@groovy.transform.CompileStatic
diff --git a/src/test/groovy/bugs/Groovy9141.groovy b/src/test/groovy/bugs/Groovy9141.groovy
index b3b6389..f836226 100644
--- a/src/test/groovy/bugs/Groovy9141.groovy
+++ b/src/test/groovy/bugs/Groovy9141.groovy
@@ -21,12 +21,15 @@ package groovy.bugs
import groovy.transform.CompileStatic
import org.codehaus.groovy.control.CompilationFailedException
import org.codehaus.groovy.control.CompilerConfiguration
+import org.junit.Test
+import static groovy.test.GroovyAssert.shouldFail
import static org.codehaus.groovy.control.ParserPluginFactory.antlr2
@CompileStatic
-final class Groovy9141 extends GroovyTestCase {
+final class Groovy9141 {
+ @Test
void testAbstractMethodWithBodyInClass() {
def err = shouldFail CompilationFailedException, '''
abstract class Main {
@@ -36,7 +39,7 @@ final class Groovy9141 extends GroovyTestCase {
assert err =~ / You defined an abstract method\[meth\] with a body. Try removing the method body @ line /
}
- // not a language requirement but script-level check takes precedence in current implementation
+ @Test // not a language requirement but script-level check takes precedence in current implementation
void testAbstractMethodWithBodyInScript() {
def err = shouldFail CompilationFailedException, '''
abstract void meth() {}
@@ -44,6 +47,7 @@ final class Groovy9141 extends GroovyTestCase {
assert err =~ / You cannot define an abstract method\[meth\] in the script. Try removing the 'abstract' /
}
+ @Test
void testAbstractMethodWithBodyInScript_oldParser() {
def shell = new GroovyShell(new CompilerConfiguration(pluginFactory: antlr2()))
diff --git a/src/test/groovy/bugs/Groovy9153.groovy b/src/test/groovy/bugs/Groovy9153.groovy
index e28b629..6d6ae91 100644
--- a/src/test/groovy/bugs/Groovy9153.groovy
+++ b/src/test/groovy/bugs/Groovy9153.groovy
@@ -20,10 +20,14 @@ package groovy.bugs
import groovy.transform.CompileStatic
import org.codehaus.groovy.ast.expr.ConstantExpression
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.assertScript
@CompileStatic
-final class Groovy9153 extends GroovyTestCase {
+final class Groovy9153 {
+ @Test
void testConstantExpressionNULL() {
assertScript '''
@groovy.transform.CompileStatic
diff --git a/src/test/groovy/bugs/Groovy9170.groovy b/src/test/groovy/bugs/Groovy9170.groovy
index 6ee0368..8d8ed19 100644
--- a/src/test/groovy/bugs/Groovy9170.groovy
+++ b/src/test/groovy/bugs/Groovy9170.groovy
@@ -19,10 +19,14 @@
package groovy.bugs
import groovy.transform.CompileStatic
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.shouldFail
@CompileStatic
-final class Groovy9170 extends GroovyTestCase {
+final class Groovy9170 {
+ @Test
void testOverrideJavaLangObjectClone() {
shouldFail CloneNotSupportedException, '''
class C implements Cloneable, Serializable {
diff --git a/src/test/groovy/bugs/Groovy9176.groovy b/src/test/groovy/bugs/Groovy9176.groovy
index 7d0a562..c2aad6b 100644
--- a/src/test/groovy/bugs/Groovy9176.groovy
+++ b/src/test/groovy/bugs/Groovy9176.groovy
@@ -20,10 +20,14 @@ package groovy.bugs
import groovy.transform.CompileStatic
import org.codehaus.groovy.control.CompilationFailedException
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.shouldFail
@CompileStatic
-final class Groovy9176 extends GroovyTestCase {
+final class Groovy9176 {
+ @Test
void testGroovyPropertyCovariantMethodCheck() {
def err = shouldFail CompilationFailedException, '''
class Pojo {
diff --git a/src/test/groovy/bugs/Groovy9184.groovy b/src/test/groovy/bugs/Groovy9184.groovy
index 28c763d..6d4d34c 100644
--- a/src/test/groovy/bugs/Groovy9184.groovy
+++ b/src/test/groovy/bugs/Groovy9184.groovy
@@ -21,13 +21,10 @@ package groovy.bugs
import groovy.transform.CompileStatic
import org.codehaus.groovy.control.CompilerConfiguration
import org.junit.Test
-import org.junit.runner.RunWith
-import org.junit.runners.JUnit4
import static org.codehaus.groovy.control.ParserPluginFactory.antlr2
@CompileStatic
-@RunWith(JUnit4)
final class Groovy9184 {
@Test(timeout=1500L)