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 2025/05/07 14:21:09 UTC
(groovy) branch GROOVY-7439 created (now 2852afe9ba)
This is an automated email from the ASF dual-hosted git repository.
emilles pushed a change to branch GROOVY-7439
in repository https://gitbox.apache.org/repos/asf/groovy.git
at 2852afe9ba GROOVY-7439: add test case
This branch includes the following new commits:
new 2852afe9ba GROOVY-7439: add test case
The 1 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.
(groovy) 01/01: GROOVY-7439: 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-7439
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 2852afe9ba4b7c6e95bdc87b2f7e1a9d3d01eef5
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Wed May 7 09:20:45 2025 -0500
GROOVY-7439: add test case
---
.../groovy/groovy/util/logging/Slf4jTest.groovy | 45 ++++++++++++++++++----
.../traitx/TraitASTTransformationTest.groovy | 28 ++++++--------
2 files changed, 48 insertions(+), 25 deletions(-)
diff --git a/src/test/groovy/groovy/util/logging/Slf4jTest.groovy b/src/test/groovy/groovy/util/logging/Slf4jTest.groovy
index 880463c12e..5f7bcba37d 100644
--- a/src/test/groovy/groovy/util/logging/Slf4jTest.groovy
+++ b/src/test/groovy/groovy/util/logging/Slf4jTest.groovy
@@ -24,9 +24,12 @@ import ch.qos.logback.classic.LoggerContext
import ch.qos.logback.classic.spi.LoggingEvent
import ch.qos.logback.core.OutputStreamAppender
import ch.qos.logback.core.layout.EchoLayout
-import org.junit.After
-import org.junit.Before
-import org.junit.Test
+import groovy.test.NotYetImplemented
+import org.junit.jupiter.api.AfterEach
+import org.junit.jupiter.api.BeforeEach
+import org.junit.jupiter.api.Test
+import org.junit.jupiter.params.ParameterizedTest
+import org.junit.jupiter.params.provider.ValueSource
import org.slf4j.LoggerFactory
import java.lang.reflect.Modifier
@@ -60,7 +63,7 @@ final class Slf4jTest {
private LogbackInterceptingAppender appender
private Logger logger
- @Before
+ @BeforeEach
void setUp() {
appender = new LogbackInterceptingAppender()
appender.outputStream = new ByteArrayOutputStream()
@@ -74,7 +77,7 @@ final class Slf4jTest {
logger.level = Level.ALL
}
- @After
+ @AfterEach
void tearDown() {
logger.detachAppender(appender)
}
@@ -293,7 +296,8 @@ final class Slf4jTest {
assert events[ind].message == 'trace called'
}
- @Test // GROOVY-6373
+ // GROOVY-6373
+ @Test
void testLogWithInnerClasses() {
Class clazz = new GroovyClassLoader().parseClass('''
@groovy.util.logging.Slf4j('logger')
@@ -323,7 +327,8 @@ final class Slf4jTest {
assert events[ind].message == 'inner called'
}
- @Test // GROOVY-6834
+ // GROOVY-6834
+ @Test
void testLogTransformInteractionWithAnonInnerClass() {
assertScript '''
@groovy.util.logging.Slf4j
@@ -344,7 +349,8 @@ final class Slf4jTest {
'''
}
- @Test // GROOVY-6873
+ // GROOVY-6873
+ @Test
void testLogTransformInteractionWithAnonInnerClass2() {
Class clazz = new GroovyClassLoader().parseClass('''
@groovy.util.logging.Slf4j
@@ -367,6 +373,29 @@ final class Slf4jTest {
''')
}
+ // GROOVY-7439
+ @NotYetImplemented
+ @ParameterizedTest
+ @ValueSource(strings=[
+ 'log', // Cannot find matching method Object#debug(String)
+ '((org.slf4j.Logger) log)' // No such property: log for class: C
+ ])
+ void testLogTrait(String log) {
+ assertScript """
+ @groovy.transform.CompileStatic
+ @groovy.util.logging.Slf4j
+ trait T {
+ void test() {
+ ${log}.debug('trace')
+ }
+ }
+ class C implements T {
+ }
+
+ new C().test()
+ """
+ }
+
@Test
void testLogGuard() {
Class clazz = new GroovyClassLoader().parseClass('''
diff --git a/src/test/groovy/org/codehaus/groovy/transform/traitx/TraitASTTransformationTest.groovy b/src/test/groovy/org/codehaus/groovy/transform/traitx/TraitASTTransformationTest.groovy
index 3b70b0bcdc..97d53e52f9 100644
--- a/src/test/groovy/org/codehaus/groovy/transform/traitx/TraitASTTransformationTest.groovy
+++ b/src/test/groovy/org/codehaus/groovy/transform/traitx/TraitASTTransformationTest.groovy
@@ -2509,21 +2509,17 @@ final class TraitASTTransformationTest {
@Test
void testUseStaticFieldInTraitBody() {
assertScript shell, '''
- import java.util.logging.Logger
-
trait Loggable {
-
- static def LOGGER = Logger.getLogger(this.class.name)
-
+ private static LOGGER = java.util.logging.Logger.getLogger(this.class.name)
void info(String msg) {
LOGGER.info(msg)
}
}
+ class C implements Loggable {
+ }
- class Test implements Loggable {}
-
- def t = new Test()
- t.info('foo')
+ def pogo = new C()
+ pogo.info('foo')
'''
}
@@ -2531,21 +2527,19 @@ final class TraitASTTransformationTest {
void testUpdateStaticFieldInTraitBody() {
assertScript shell, '''
trait Loggable {
-
static int CALLS = 0
-
int call() {
CALLS += 1
CALLS
}
}
+ class C implements Loggable {
+ }
- class Test implements Loggable {}
-
- def t = new Test()
- assert t.call() == 1
- assert t.call() == 2
- assert Test.CALLS == 2
+ def pogo = new C()
+ assert pogo.call() == 1
+ assert pogo.call() == 2
+ assert pogo.CALLS == 2
'''
}