Skip to content

Commit 3cbd88c

Browse files
committed
minor refactor: improve test robustness for groovysh on CI
1 parent fe8a7df commit 3cbd88c

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/SystemTestSupport.groovy

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.apache.groovy.groovysh.commands
2020

2121
import org.apache.groovy.groovysh.jline.GroovySystemRegistry
22+
import org.jline.terminal.Size
2223
import org.jline.terminal.Terminal
2324
import org.jline.terminal.TerminalBuilder
2425
import org.junit.jupiter.api.AfterEach
@@ -47,9 +48,8 @@ import java.util.function.Supplier
4748
* {@code [k:v]}.
4849
* <li>{@link #terminalOutput()} — for JLine builtins that write directly
4950
* through {@code terminal.writer()} (e.g. {@code /help}). Returns the
50-
* raw bytes decoded as UTF-8; the dumb terminal also emits a couple of
51-
* capability-probe escapes at startup, so prefer substring matches over
52-
* full-string compares.
51+
* raw bytes decoded as UTF-8; prefer substring matches over full-string
52+
* compares to stay robust across JLine cosmetic changes.
5353
* </ul>
5454
*
5555
* See {@code subprojects/groovy-groovysh/AGENTS.md} for the platform-fragility
@@ -67,8 +67,16 @@ abstract class SystemTestSupport extends ConsoleTestSupport {
6767
super.setUp()
6868
Supplier workDir = { configPath.getUserConfig('.') }
6969
terminalBytes = new ByteArrayOutputStream()
70+
// type('dumb') is the canonical dumb terminal selector — dumb(true) is silently
71+
// ignored when custom streams are set, which would otherwise leave us with a
72+
// PosixPtyTerminal typed xterm-256color and an active grapheme-cluster probe
73+
// writing capability-probe escapes to terminalBytes. graphemeCluster(false) is
74+
// belt-and-braces, and an explicit Size avoids the 0x0 path in JLine's help
75+
// renderer which truncates via setLength(width).
7076
terminal = TerminalBuilder.builder()
71-
.dumb(true)
77+
.type('dumb')
78+
.graphemeCluster(false)
79+
.size(new Size(80, 24))
7280
.streams(new ByteArrayInputStream(new byte[0]), terminalBytes)
7381
.encoding(StandardCharsets.UTF_8)
7482
.name('groovysh-test')

0 commit comments

Comments
 (0)