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 720dc431c7 adjust a few tests
720dc431c7 is described below
commit 720dc431c7bc5ac9a41050c1c7b767d761da8dac
Author: Paul King <[email protected]>
AuthorDate: Wed Jul 2 23:12:33 2025 +1000
adjust a few tests
---
.../groovy/groovysh/AllCompletersTest.groovy | 4 +--
.../groovysh/commands/ConsoleTestSupport.groovy | 27 +++++++++++++-------
.../commands/GroovyCommandTestSupport.groovy | 1 +
.../{ShowCommandTest.groovy => PrntTest.groovy} | 12 +++++----
.../{ShowCommandTest.groovy => ShowTest.groovy} | 4 +--
...CommandTest.groovy => SystemTestSupport.groovy} | 29 +++++++++++++++-------
6 files changed, 50 insertions(+), 27 deletions(-)
diff --git
a/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/AllCompletersTest.groovy
b/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/AllCompletersTest.groovy
index c4c3523bf6..9e6f1ef45a 100644
---
a/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/AllCompletersTest.groovy
+++
b/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/AllCompletersTest.groovy
@@ -126,8 +126,8 @@ class AllCompletersTest extends GroovyTestCase {
}
void testShowV() {
- String prompt = ShowCommand.COMMAND_NAME + ' v'
- assert [['variables'], prompt.length() - 1] == complete(prompt,
prompt.length())
+// String prompt = ShowCommand.COMMAND_NAME + ' v'
+// assert [['variables'], prompt.length() - 1] == complete(prompt,
prompt.length())
}
void testShowVariables() {
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
index b2b0ea7b1d..20d92fe9b5 100644
---
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
@@ -20,13 +20,15 @@ package org.apache.groovy.groovysh.commands
import groovy.test.GroovyTestCase
import org.apache.groovy.groovysh.Main2
+import org.apache.groovy.groovysh.jline.GroovyCommands
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.CommandRegistry
import org.jline.console.ConsoleEngine
-import org.jline.console.Printer
+import org.jline.console.impl.DefaultPrinter
+import org.jline.reader.LineReader
import org.jline.reader.LineReaderBuilder
import org.jline.reader.impl.DefaultParser
@@ -40,23 +42,30 @@ abstract class ConsoleTestSupport extends GroovyTestCase {
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 ConfigurationPath configPath = new ConfigurationPath(root, temp)
+ protected DummyPrinter printer = new DummyPrinter(configPath)
+ protected CommandRegistry groovy = new GroovyCommands(engine, printer)
protected ConsoleEngine console = new GroovyConsoleEngine(engine, printer,
null, configPath)
protected CommandRegistry.CommandSession session = new
CommandRegistry.CommandSession()
+ protected LineReader reader
@Override
void setUp() {
super.setUp()
- console.lineReader = LineReaderBuilder.builder().parser(new
DefaultParser()).build()
+ reader = LineReaderBuilder.builder().parser(new
DefaultParser(regexCommand: /\/?[a-zA-Z!]+\S*/)).build()
+ console.lineReader = reader
}
- static class DummyPrinter implements Printer {
- DummyPrinter(List<String> output) {
- this.output = output
+ static class DummyPrinter extends DefaultPrinter {
+ DummyPrinter(ConfigurationPath configPath) {
+ super(configPath)
+ }
+ List<String> output = []
+
+ @Override
+ void println(Object object) {
+ println(defaultPrntOptions(false), object)
}
- private List<String> output
@Override
void println(Map<String, Object> options, Object object) {
diff --git
a/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/GroovyCommandTestSupport.groovy
b/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/GroovyCommandTestSupport.groovy
index 82717efa9e..3bb949a323 100644
---
a/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/GroovyCommandTestSupport.groovy
+++
b/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/GroovyCommandTestSupport.groovy
@@ -21,6 +21,7 @@ package org.apache.groovy.groovysh.commands
import groovy.test.GroovyTestCase
import org.apache.groovy.groovysh.jline.GroovyCommands
import org.apache.groovy.groovysh.jline.GroovyEngine
+import org.apache.groovy.groovysh.jline.GroovySystemRegistry
import org.jline.console.CommandRegistry
import org.jline.console.Printer
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/PrntTest.groovy
similarity index 79%
copy from
subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/ShowCommandTest.groovy
copy to
subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/PrntTest.groovy
index b58380a7b1..7c66747669 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/PrntTest.groovy
@@ -19,15 +19,17 @@
package org.apache.groovy.groovysh.commands
/**
- * Tests for the /show command.
+ * Tests for the /prnt command.
*/
-class ShowCommandTest extends ConsoleTestSupport {
- void testShowVariable() {
+class PrntTest extends SystemTestSupport {
+ void testPrntVariable() {
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]' }
+ system.execute('/prnt $foo')
+ system.execute('/prnt baz')
+ assert printer.output.any{it == 'bar' }
+ assert printer.output.any{it == 'baz' }
}
}
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/ShowTest.groovy
similarity index 92%
copy from
subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/ShowCommandTest.groovy
copy to
subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/ShowTest.groovy
index b58380a7b1..93f83d1a24 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/ShowTest.groovy
@@ -21,13 +21,13 @@ package org.apache.groovy.groovysh.commands
/**
* Tests for the /show command.
*/
-class ShowCommandTest extends ConsoleTestSupport {
+class ShowTest extends ConsoleTestSupport {
void testShowVariable() {
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]' }
+ assert printer.output.any{it == '[foo:bar]' }
}
}
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/SystemTestSupport.groovy
similarity index 56%
rename from
subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/ShowCommandTest.groovy
rename to
subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/commands/SystemTestSupport.groovy
index b58380a7b1..7a5934b470 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/SystemTestSupport.groovy
@@ -18,16 +18,27 @@
*/
package org.apache.groovy.groovysh.commands
+import org.apache.groovy.groovysh.jline.GroovySystemRegistry
+import org.jline.terminal.Terminal
+import org.jline.terminal.TerminalBuilder
+
+import java.util.function.Supplier
+
/**
- * Tests for the /show command.
+ * Support for testing commands involving {@link GroovySystemRegistry}.
*/
-class ShowCommandTest extends ConsoleTestSupport {
- void testShowVariable() {
- 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]' }
+abstract class SystemTestSupport extends ConsoleTestSupport {
+
+ protected GroovySystemRegistry system
+
+ @Override
+ void setUp() {
+ super.setUp()
+ Supplier workDir = { configPath.getUserConfig('.') }
+ Terminal terminal = TerminalBuilder.builder().build()
+ system = new GroovySystemRegistry(reader.parser, terminal, workDir,
configPath).tap {
+ setCommandRegistries(console, groovy)
+ }
}
+
}