This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch jline3
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/jline3 by this push:
     new 7b66f75150 fix show and alias tests
7b66f75150 is described below

commit 7b66f751506b26c400f94240add688e6b467f3b8
Author: Paul King <pa...@asert.com.au>
AuthorDate: Mon Jun 30 20:55:53 2025 +1000

    fix show and alias tests
---
 .../groovysh/commands/AliasCommandTest.groovy      | 18 +++---
 .../groovysh/commands/ConsoleTestSupport.groovy    | 72 ++++++++++++++++++++++
 .../groovysh/commands/ShowCommandTest.groovy       | 11 +++-
 3 files changed, 91 insertions(+), 10 deletions(-)

diff --git 
a/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/AliasCommandTest.groovy
 
b/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/AliasCommandTest.groovy
index fcff8d78ea..4d38f57f3e 100644
--- 
a/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/AliasCommandTest.groovy
+++ 
b/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/AliasCommandTest.groovy
@@ -17,14 +17,18 @@
  *  under the License.
  */
 package org.apache.groovy.groovysh.commands
-
 /**
- * Tests for the {@link AliasCommand} class.
+ * Tests for the {@code /alias} command.
  */
-class AliasCommandTest extends CommandTestSupport {
-    void testAlias() {
-        shell.execute(AliasCommand.COMMAND_NAME)
-        shell.execute(AliasCommand.COMMAND_NAME + ' foo bar')
-        shell.execute(AliasCommand.COMMAND_NAME + ' history foo') // cannot 
rebind
+class AliasCommandTest extends ConsoleTestSupport {
+
+    void testAliasAndUnalias() {
+        assert !console.hasAlias('foo')
+        console.invoke(session, '/alias', 'foo', '/history')
+        assert console.hasAlias('foo')
+        assert console.getAlias('foo') == '/history'
+
+        console.invoke(session, '/unalias', 'foo')
+        assert !console.hasAlias('foo')
     }
 }
diff --git 
a/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/ConsoleTestSupport.groovy
 
b/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/ConsoleTestSupport.groovy
new file mode 100644
index 0000000000..27d4e5f01c
--- /dev/null
+++ 
b/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/ConsoleTestSupport.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 org.apache.groovy.groovysh.commands
+
+import groovy.test.GroovyTestCase
+import org.apache.groovy.groovysh.Main2
+import org.apache.groovy.groovysh.jline.GroovyConsoleEngine
+import org.apache.groovy.groovysh.jline.GroovyEngine
+import org.jline.builtins.ClasspathResourceUtil
+import org.jline.builtins.ConfigurationPath
+import org.jline.console.CommandInput
+import org.jline.console.CommandRegistry
+import org.jline.console.ConsoleEngine
+import org.jline.console.Printer
+import org.jline.reader.LineReaderBuilder
+import org.jline.reader.impl.DefaultParser
+
+import java.nio.file.Path
+
+/**
+ * Support for testing {@link ConsoleEngine} instances.
+ */
+abstract class ConsoleTestSupport extends GroovyTestCase {
+    protected GroovyEngine scriptEngine = new GroovyEngine()
+    private URL rootURL = Main2.getResource('/nanorc')
+    private Path root = ClasspathResourceUtil.getResourcePath(rootURL)
+    private Path temp = File.createTempDir().toPath()
+    private ConfigurationPath configPath = new ConfigurationPath(root, temp)
+    protected List<String> output = []
+    protected Printer printer = new DummyPrinter(output)
+    protected ConsoleEngine console = new GroovyConsoleEngine(scriptEngine, 
printer, null, configPath)
+    protected CommandRegistry.CommandSession session = new 
CommandRegistry.CommandSession()
+
+    @Override
+    void setUp() {
+        super.setUp()
+        console.lineReader = LineReaderBuilder.builder().parser(new 
DefaultParser()).build()
+    }
+
+    static class DummyPrinter implements Printer {
+        DummyPrinter(List<String> output) {
+            this.output = output
+        }
+        private List<String> output
+
+        @Override
+        void println(Map<String, Object> options, Object object) {
+            output << object.toString()
+        }
+
+        @Override
+        boolean refresh() {
+            false
+        }
+    }
+}
diff --git 
a/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/ShowCommandTest.groovy
 
b/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/ShowCommandTest.groovy
index 4cc3a19602..0256730c70 100644
--- 
a/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/ShowCommandTest.groovy
+++ 
b/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/ShowCommandTest.groovy
@@ -19,10 +19,15 @@
 package org.apache.groovy.groovysh.commands
 
 /**
- * Tests for the {@link ShowCommand} class.
+ * Tests for the /show command.
  */
-class ShowCommandTest extends CommandTestSupport {
+class ShowCommandTest extends ConsoleTestSupport {
     void testShow() {
-        shell.execute(ShowCommand.COMMAND_NAME + ' nocommandhere')
+        assert !console.hasVariable('foo')
+        console.execute('dummyName', "foo = 'bar'")
+        assert console.hasVariable('foo')
+        assert console.getVariable('foo') == 'bar'
+        console.invoke(session, '/show')
+        assert output.any{it == '[foo:bar]' }
     }
 }

Reply via email to