This is an automated email from the ASF dual-hosted git repository.
paulk-asert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 0c9ed73e7a minor refactor: improve test robustness for groovysh on CI
(cont'd)
0c9ed73e7a is described below
commit 0c9ed73e7aef70fc1d5570e1d115bb5c1d28d34b
Author: Paul King <[email protected]>
AuthorDate: Mon May 25 13:36:27 2026 +1000
minor refactor: improve test robustness for groovysh on CI (cont'd)
---
.../groovysh/commands/HelpCommandTest.groovy | 32 -----------
.../commands/HelpCompactCommandTest.groovy | 64 ++++++++++++++++++++++
.../groovysh/commands/SystemTestSupport.groovy | 55 ++++++++++++++-----
3 files changed, 104 insertions(+), 47 deletions(-)
diff --git
a/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/HelpCommandTest.groovy
b/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/HelpCommandTest.groovy
index 1b2d5ed0df..12ec379986 100644
---
a/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/HelpCommandTest.groovy
+++
b/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/HelpCommandTest.groovy
@@ -44,36 +44,4 @@ class HelpCommandTest extends SystemTestSupport {
assert out.contains('show')
assert out.contains('exit')
}
-
- /**
- * TEMP DIAGNOSTIC — investigating the JDK-specific flake on
helpListsKnownCommands.
- * <p>
- * Peeks at {@code SystemRegistryImpl.exception} after running {@code
/help}.
- * JLine's {@code helpTopic} silently stores any per-command exception
there via
- * {@code catch (Exception e) { exception = e; }}. If iteration aborts
mid-list
- * (one of the registered commands' {@code commandInfo}/description
throws),
- * we'd see the exception here.
- * <p>
- * Expected outcomes:
- * <ul>
- * <li>{@code exception == null} → iteration ran to completion; the
truncation
- * seen in the flake is pump-drain / native-terminal-binding
timing.</li>
- * <li>{@code exception != null} → iteration aborted; the stack trace
points
- * at the offending command.</li>
- * </ul>
- * Remove this test once the flake is understood.
- */
- @Test
- void diagSilentExceptionAfterHelp() {
- system.execute('/help')
- def field =
org.jline.console.impl.SystemRegistryImpl.class.getDeclaredField('exception')
- field.setAccessible(true)
- Exception ex = (Exception) field.get(system)
- if (ex) {
- ex.printStackTrace()
- throw new AssertionError(
- "SystemRegistryImpl.exception is non-null after /help:
${ex.class.name}: ${ex.message}",
- ex)
- }
- }
}
diff --git
a/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/HelpCompactCommandTest.groovy
b/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/HelpCompactCommandTest.groovy
new file mode 100644
index 0000000000..25d47e52d2
--- /dev/null
+++
b/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/HelpCompactCommandTest.groovy
@@ -0,0 +1,64 @@
+/*
+ * 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 org.apache.groovy.groovysh.commands
+
+import org.junit.jupiter.api.Test
+
+/**
+ * Companion to {@link HelpCommandTest} that exercises JLine's other
+ * {@code /help} rendering path — the {@code printCommands} compact
+ * multi-column listing.
+ * <p>
+ * {@code SystemRegistryImpl.helpTopic} chooses between two formats:
+ * <ul>
+ * <li>{@code withInfo == true} ({@code commands.size() <
terminal.getHeight()})
+ * → {@code printCommandInfo} per command — name + description, one
+ * line each. This is what {@link HelpCommandTest} covers.</li>
+ * <li>{@code withInfo == false} → {@code printCommands} — a compact
+ * grid of command names, no descriptions. This class covers it.</li>
+ * </ul>
+ * Both paths are reachable in production: the verbose format fires for
+ * tall terminals or short command lists; the compact format fires when the
+ * terminal is short enough that the verbose listing wouldn't fit on screen.
+ * Two tests give both paths coverage.
+ */
+class HelpCompactCommandTest extends SystemTestSupport {
+
+ /**
+ * Force the compact format by reporting a terminal height below the
+ * registered command count. The test setup has roughly 20-25 commands
+ * across the {@code console} and {@code groovy} registries plus system
+ * locals; 10 is safely under any plausible total.
+ */
+ @Override protected int terminalHeight() { 10 }
+
+ @Test
+ void helpInCompactFormatListsKnownCommands() {
+ system.execute('/help')
+ def out = terminalOutput()
+ assert !out.empty
+ // Command names appear regardless of format — compact lays them out
+ // in a grid rather than per line, but the substrings still match.
+ // Asserting on names only keeps the test robust across JLine
+ // cosmetic changes to the grid layout.
+ assert out.contains('help')
+ assert out.contains('show')
+ assert out.contains('exit')
+ }
+}
diff --git
a/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/SystemTestSupport.groovy
b/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/SystemTestSupport.groovy
index bee5fa903b..4b59df92b1 100644
---
a/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/SystemTestSupport.groovy
+++
b/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/SystemTestSupport.groovy
@@ -21,7 +21,7 @@ package org.apache.groovy.groovysh.commands
import org.apache.groovy.groovysh.jline.GroovySystemRegistry
import org.jline.terminal.Size
import org.jline.terminal.Terminal
-import org.jline.terminal.TerminalBuilder
+import org.jline.terminal.impl.DumbTerminal
import org.jline.terminal.impl.SixelGraphics
import org.jline.terminal.impl.TerminalGraphics
import org.jline.terminal.impl.TerminalGraphicsManager
@@ -91,26 +91,51 @@ abstract class SystemTestSupport extends ConsoleTestSupport
{
SixelGraphics.setSixelSupportOverride(null)
}
+ /**
+ * Terminal width reported to JLine. Override in a subclass to vary the
+ * per-line padding that {@code printCommandInfo} applies via
+ * {@code setLength(terminal().getWidth())}, or to keep the help renderer
+ * out of its {@code width == 0} truncation path. Default 80 — any
+ * non-zero value avoids the {@code setLength(0)} empty-line bug; the
+ * smaller value keeps total bytes per {@code /help} modest, which
+ * shrinks the pump-drain race window on graphics-capable host PTYs.
+ */
+ protected int terminalWidth() { 80 }
+
+ /**
+ * Terminal height reported to JLine. Override in a subclass to flip
+ * {@code helpTopic}'s {@code withInfo = commands.size() < getHeight()}
+ * switch (verbose info-per-line vs compact multi-column). Default 40 —
+ * comfortably above the test setup's registered command count, so the
+ * verbose format triggers consistently. Drop below the command count to
+ * force the compact format (see {@code HelpCompactCommandTest}).
+ */
+ protected int terminalHeight() { 40 }
+
@BeforeEach
@Override
void setUp() {
super.setUp()
Supplier workDir = { configPath.getUserConfig('.') }
terminalBytes = new ByteArrayOutputStream()
- // type('dumb') is the canonical dumb terminal selector — dumb(true)
is silently
- // ignored when custom streams are set, which would otherwise leave us
with a
- // PosixPtyTerminal typed xterm-256color and an active
grapheme-cluster probe
- // writing capability-probe escapes to terminalBytes.
graphemeCluster(false) is
- // belt-and-braces, and an explicit Size avoids the 0x0 path in
JLine's help
- // renderer which truncates via setLength(width).
- terminal = TerminalBuilder.builder()
- .type('dumb')
- .graphemeCluster(false)
- .size(new Size(120, 200))
- .streams(new ByteArrayInputStream(new byte[0]), terminalBytes)
- .encoding(StandardCharsets.UTF_8)
- .name('groovysh-test')
- .build()
+ // Instantiate DumbTerminal directly rather than going through
TerminalBuilder.
+ // TerminalBuilder's type('dumb') hint is advisory: when JLine's native
+ // bindings (jline-terminal-jni on JDK 17/18, jline-terminal-ffm on
JDK 22+)
+ // can attach to the inherited TTY, the builder may still create a
+ // PosixPtyTerminal — even with explicit streams — and route writes
through
+ // an asynchronous output-pump thread. That pump's drain timing races
with
+ // terminalOutput() on certain CI runners (consistently reproduces on
+ // Linux + JDK 17/18) and produces mid-line-truncated captures.
DumbTerminal
+ // is final, has no native code, no pump, and writes synchronously
straight
+ // through PrintWriter → ByteArrayOutputStream — eliminating the race.
+ // An explicit Size avoids JLine's 0x0 path which truncates via
setLength(0).
+ terminal = new DumbTerminal(
+ 'groovysh-test',
+ 'dumb',
+ new ByteArrayInputStream(new byte[0]),
+ terminalBytes,
+ StandardCharsets.UTF_8)
+ terminal.setSize(new Size(terminalWidth(), terminalHeight()))
system = new GroovySystemRegistry(reader.parser, terminal, workDir,
configPath).tap {
setCommandRegistries(console, groovy)
// Match production wiring: SystemRegistryImpl's built-in commands