This is an automated email from the ASF dual-hosted git repository.
jamesfredley pushed a commit to branch feat/8.0.x-legacy-command-compat
in repository https://gitbox.apache.org/repos/asf/grails-core.git
The following commit(s) were added to
refs/heads/feat/8.0.x-legacy-command-compat by this push:
new bdb98a6636 test: capture StackTrace filterer emissions via LogCapture
bdb98a6636 is described below
commit bdb98a663601037ca7fb70a818f3dd29726e1c26
Author: t <t@t>
AuthorDate: Wed Jul 29 16:30:17 2026 -0400
test: capture StackTrace filterer emissions via LogCapture
System.err redirection no longer observes DefaultStackTraceFilterer
STACK_LOG output under the SLF4J/Logback test classpath, which left
baos empty and failed the default-on positive-control specs in CI.
Align GrailsUtilStackFiltererSpec and GrailsBootstrapRegistryInitializerSpec
with StackTraceFiltererSpec by asserting against the StackTrace logger
through the shared LogCapture fixture.
Assisted-by: Sisyphus:xai/grok-4.5
---
.../grails/util/GrailsUtilStackFiltererSpec.groovy | 23 +++++++++-------------
.../GrailsBootstrapRegistryInitializerSpec.groovy | 19 +++++++-----------
2 files changed, 16 insertions(+), 26 deletions(-)
diff --git
a/grails-core/src/test/groovy/grails/util/GrailsUtilStackFiltererSpec.groovy
b/grails-core/src/test/groovy/grails/util/GrailsUtilStackFiltererSpec.groovy
index 1b99ab7b6a..c0c419bcd3 100644
--- a/grails-core/src/test/groovy/grails/util/GrailsUtilStackFiltererSpec.groovy
+++ b/grails-core/src/test/groovy/grails/util/GrailsUtilStackFiltererSpec.groovy
@@ -18,6 +18,7 @@
*/
package grails.util
+import org.apache.grails.core.testing.support.LogCapture
import org.grails.exceptions.reporting.DefaultStackTraceFilterer
import org.grails.exceptions.reporting.StackTraceFilterer
import spock.lang.Specification
@@ -104,10 +105,8 @@ class GrailsUtilStackFiltererSpec extends Specification {
}
def 'installed DefaultStackTraceFilterer honours
logFullStackTraceOnFilter=false'() {
- given: 'captured System.err'
- def originalErr = System.err
- def baos = new ByteArrayOutputStream()
- System.setErr(new PrintStream(baos, true))
+ given: 'a configured log appender to capture the StackTrace log entry'
+ def logCapture = new LogCapture('StackTrace')
and: 'a filterer with the side-effect emission disabled'
def quietFilterer = new DefaultStackTraceFilterer()
@@ -118,18 +117,15 @@ class GrailsUtilStackFiltererSpec extends Specification {
GrailsUtil.deepSanitize(exceptionWithApplicationFrame())
then: "no 'Full Stack Trace:' entry is emitted"
- System.err.flush()
- !baos.toString().contains(StackTraceFilterer.FULL_STACK_TRACE_MESSAGE)
+ logCapture.events.count {
it.formattedMessage.contains(StackTraceFilterer.FULL_STACK_TRACE_MESSAGE) } == 0
cleanup:
- System.setErr(originalErr)
+ logCapture.close()
}
def 'installed DefaultStackTraceFilterer emits Full Stack Trace by
default'() {
- given: 'captured System.err'
- def originalErr = System.err
- def baos = new ByteArrayOutputStream()
- System.setErr(new PrintStream(baos, true))
+ given: 'a configured log appender to capture the StackTrace log entry'
+ def logCapture = new LogCapture('StackTrace')
and: 'a filterer with the default (enabled) side-effect emission'
def loudFilterer = new DefaultStackTraceFilterer()
@@ -139,11 +135,10 @@ class GrailsUtilStackFiltererSpec extends Specification {
GrailsUtil.deepSanitize(exceptionWithApplicationFrame())
then: "a 'Full Stack Trace:' entry is emitted -- the positive control
proving the negative case above is meaningful"
- System.err.flush()
- baos.toString().contains(StackTraceFilterer.FULL_STACK_TRACE_MESSAGE)
+ logCapture.events.any {
it.formattedMessage.contains(StackTraceFilterer.FULL_STACK_TRACE_MESSAGE) }
cleanup:
- System.setErr(originalErr)
+ logCapture.close()
}
private static RuntimeException exceptionWithApplicationFrame() {
diff --git
a/grails-core/src/test/groovy/org/apache/grails/core/GrailsBootstrapRegistryInitializerSpec.groovy
b/grails-core/src/test/groovy/org/apache/grails/core/GrailsBootstrapRegistryInitializerSpec.groovy
index 6197711401..6fe1db680c 100644
---
a/grails-core/src/test/groovy/org/apache/grails/core/GrailsBootstrapRegistryInitializerSpec.groovy
+++
b/grails-core/src/test/groovy/org/apache/grails/core/GrailsBootstrapRegistryInitializerSpec.groovy
@@ -20,6 +20,7 @@ package org.apache.grails.core
import grails.config.Settings
import grails.util.GrailsUtil
+import org.apache.grails.core.testing.support.LogCapture
import org.grails.core.cfg.GroovyConfigPropertySourceLoader
import org.grails.exceptions.reporting.DefaultStackTraceFilterer
import org.grails.exceptions.reporting.StackTraceFilterer
@@ -225,39 +226,33 @@ class GrailsBootstrapRegistryInitializerSpec extends
Specification {
def context = contextWithProperties([
(Settings.SETTING_LOG_FULL_STACKTRACE_ON_FILTER): 'false'
])
- def originalErr = System.err
- def baos = new ByteArrayOutputStream()
- System.setErr(new PrintStream(baos, true))
+ def logCapture = new LogCapture('StackTrace')
when:
closeBootstrapContext(context)
GrailsUtil.deepSanitize(exceptionWithApplicationFrame())
then: "no 'Full Stack Trace:' entry is emitted"
- System.err.flush()
- !baos.toString().contains(StackTraceFilterer.FULL_STACK_TRACE_MESSAGE)
+ logCapture.events.count {
it.formattedMessage.contains(StackTraceFilterer.FULL_STACK_TRACE_MESSAGE) } == 0
cleanup:
- System.setErr(originalErr)
+ logCapture.close()
}
def 'defaults logFullStackTraceOnFilter to true on the promoted
DefaultStackTraceFilterer'() {
given:
def context = contextWithProperties([:])
- def originalErr = System.err
- def baos = new ByteArrayOutputStream()
- System.setErr(new PrintStream(baos, true))
+ def logCapture = new LogCapture('StackTrace')
when:
closeBootstrapContext(context)
GrailsUtil.deepSanitize(exceptionWithApplicationFrame())
then: 'the positive control proving the negative case above is
meaningful'
- System.err.flush()
- baos.toString().contains(StackTraceFilterer.FULL_STACK_TRACE_MESSAGE)
+ logCapture.events.any {
it.formattedMessage.contains(StackTraceFilterer.FULL_STACK_TRACE_MESSAGE) }
cleanup:
- System.setErr(originalErr)
+ logCapture.close()
}
private static StackTraceFilterer
promotedFilterer(GenericApplicationContext context) {